3434import com .pspdfkit .annotations .Annotation ;
3535import com .pspdfkit .preferences .PSPDFKitPreferences ;
3636import com .pspdfkit .react .annotations .ReactAnnotationPresetConfiguration ;
37+ import com .pspdfkit .react .AnnotationConfigurationAdaptor ;
38+ import com .pspdfkit .react .ConfigurationAdapter ;
3739import com .pspdfkit .react .events .PdfViewDataReturnedEvent ;
3840import com .pspdfkit .react .menu .ReactGroupingRule ;
41+ import com .pspdfkit .react .ToolbarMenuItemsAdapter ;
3942import com .pspdfkit .views .PdfView ;
4043import com .pspdfkit .configuration .activity .PdfActivityConfiguration ;
4144import org .json .JSONObject ;
@@ -148,109 +151,30 @@ public Map<String, Integer> getCommandsMap() {
148151 return commandMap ;
149152 }
150153
151- @ ReactProp (name = "documentWithOrderedProps " )
152- public void setDocumentWithOrderedProps (PdfView view , @ Nullable ReadableMap orderedProps ) {
153- if (orderedProps == null ) return ;
154+ @ ReactProp (name = "documentAndConfiguration " )
155+ public void setDocumentAndConfiguration (PdfView view , @ Nullable ReadableMap documentAndConfiguration ) {
156+ if (documentAndConfiguration == null ) return ;
154157
155- // Process in exact order
156- if (orderedProps .hasKey ("configuration" ) && !orderedProps .isNull ("configuration" )) {
157- ReadableMap configuration = orderedProps .getMap ("configuration" );
158+ // Process configuration first
159+ if (documentAndConfiguration .hasKey ("configuration" ) && !documentAndConfiguration .isNull ("configuration" )) {
160+ ReadableMap configuration = documentAndConfiguration .getMap ("configuration" );
158161 setConfiguration (view , configuration );
159162 }
160163
161- if (orderedProps .hasKey ("annotationPresets" ) && !orderedProps .isNull ("annotationPresets" )) {
162- ReadableMap annotationPresets = orderedProps .getMap ("annotationPresets" );
163- List <ReactAnnotationPresetConfiguration > annotationsConfiguration = AnnotationConfigurationAdaptor .convertAnnotationConfigurations (
164- view .getContext (), annotationPresets
165- );
166- view .setAnnotationConfiguration (annotationsConfiguration );
167- }
168-
169- if (orderedProps .hasKey ("fragmentTag" ) && !orderedProps .isNull ("fragmentTag" )) {
170- String fragmentTag = orderedProps .getString ("fragmentTag" );
171- view .setFragmentTag (fragmentTag );
172- }
173-
174- if (orderedProps .hasKey ("menuItemGrouping" ) && !orderedProps .isNull ("menuItemGrouping" )) {
175- ReadableArray menuItemGrouping = orderedProps .getArray ("menuItemGrouping" );
176- ReactGroupingRule groupingRule = new ReactGroupingRule (view .getContext (), menuItemGrouping );
177- view .setMenuItemGroupingRule (groupingRule );
178- }
179-
180- // Load document
181- if (orderedProps .hasKey ("document" ) && !orderedProps .isNull ("document" )) {
182- String document = orderedProps .getString ("document" );
164+ // Then load document
165+ if (documentAndConfiguration .hasKey ("document" ) && !documentAndConfiguration .isNull ("document" )) {
166+ String document = documentAndConfiguration .getString ("document" );
183167 // Always set the document, even if it's the same path, to ensure it loads
184168 view .setDocument (document , this .reactApplicationContext );
185169 }
186-
187- // Process post-document props
188- if (orderedProps .hasKey ("pageIndex" ) && !orderedProps .isNull ("pageIndex" )) {
189- int pageIndex = orderedProps .getInt ("pageIndex" );
190- view .setPageIndex (pageIndex );
191- }
192-
193- if (orderedProps .hasKey ("toolbar" ) && !orderedProps .isNull ("toolbar" )) {
194- ReadableMap toolbar = orderedProps .getMap ("toolbar" );
195- setToolbar (view , toolbar );
196- }
197-
198- if (orderedProps .hasKey ("toolbarMenuItems" ) && !orderedProps .isNull ("toolbarMenuItems" )) {
199- ReadableArray toolbarMenuItems = orderedProps .getArray ("toolbarMenuItems" );
200- setToolbarMenuItems (view , toolbarMenuItems );
201- }
202-
203- if (orderedProps .hasKey ("annotationContextualMenu" ) && !orderedProps .isNull ("annotationContextualMenu" )) {
204- ReadableMap annotationContextualMenu = orderedProps .getMap ("annotationContextualMenu" );
205- setAnnotationContextualMenu (view , annotationContextualMenu );
206- }
207170 }
208171
209-
210-
211- @ ReactProp (name = "disableDefaultActionForTappedAnnotations" )
212- public void setDisableDefaultActionForTappedAnnotations (PdfView view , boolean disableDefaultActionForTappedAnnotations ) {
213- view .setDisableDefaultActionForTappedAnnotations (disableDefaultActionForTappedAnnotations );
214- }
215-
216- @ ReactProp (name = "disableAutomaticSaving" )
217- public void setDisableAutomaticSaving (PdfView view , boolean disableAutomaticSaving ) {
218- view .setDisableAutomaticSaving (disableAutomaticSaving );
219- }
220-
221- @ ReactProp (name = "annotationAuthorName" )
222- public void setAnnotationAuthorName (PdfView view , String annotationAuthorName ) {
223- PSPDFKitPreferences .get (view .getContext ()).setAnnotationCreator (annotationAuthorName );
224- }
225-
226- @ ReactProp (name = "imageSaveMode" )
227- public void setImageSaveMode (PdfView view , String imageSaveMode ) {
228- view .setImageSaveMode (imageSaveMode );
229- }
230-
231-
232-
233- @ ReactProp (name = "showNavigationButtonInToolbar" )
234- public void setShowNavigationButtonInToolbar (@ NonNull final PdfView view , final boolean showNavigationButtonInToolbar ) {
235- view .setShowNavigationButtonInToolbar (showNavigationButtonInToolbar );
236- }
237-
238- @ ReactProp (name = "hideDefaultToolbar" )
239- public void setHideDefaultToolbar (@ NonNull final PdfView view , final boolean hideDefaultToolbar ) {
240- view .setHideDefaultToolbar (hideDefaultToolbar );
241- }
242-
243- @ ReactProp (name = "availableFontNames" )
244- public void setAvailableFontNames (@ NonNull final PdfView view , @ Nullable final ReadableArray availableFontNames ) {
245- view .setAvailableFontNames (availableFontNames );
246- }
247-
248- @ ReactProp (name = "selectedFontName" )
249- public void setSelectedFontName (@ NonNull final PdfView view , @ Nullable final String selectedFontName ) {
250- view .setSelectedFontName (selectedFontName );
172+ @ ReactProp (name = "fragmentTag" )
173+ public void setFragmentTag (PdfView view , @ NonNull String fragmentTag ) {
174+ view .setFragmentTag (fragmentTag );
251175 }
252176
253- // Helper methods for setDocumentWithOrderedProps (not @ReactProp methods )
177+ // Helper method for setDocumentAndConfiguration (not @ReactProp method )
254178 private void setConfiguration (PdfView view , @ NonNull ReadableMap configuration ) {
255179 ConfigurationAdapter configurationAdapter = new ConfigurationAdapter (view .getContext (), configuration );
256180 PdfActivityConfiguration configurationBuild = configurationAdapter .build ();
@@ -276,7 +200,21 @@ private void setConfiguration(PdfView view, @NonNull ReadableMap configuration)
276200 }
277201 }
278202
279- private void setToolbar (@ NonNull final PdfView view , @ NonNull ReadableMap toolbar ) {
203+ @ ReactProp (name = "annotationPresets" )
204+ public void setAnnotationPresets (PdfView view , @ NonNull ReadableMap annotationPresets ) {
205+ List <ReactAnnotationPresetConfiguration > annotationsConfiguration = AnnotationConfigurationAdaptor .convertAnnotationConfigurations (
206+ view .getContext (), annotationPresets
207+ );
208+ view .setAnnotationConfiguration (annotationsConfiguration );
209+ }
210+
211+ @ ReactProp (name = "pageIndex" )
212+ public void setPageIndex (PdfView view , int pageIndex ) {
213+ view .setPageIndex (pageIndex );
214+ }
215+
216+ @ ReactProp (name = "toolbar" )
217+ public void setToolbar (@ NonNull final PdfView view , @ NonNull ReadableMap toolbar ) {
280218 if (toolbar .hasKey ("toolbarMenuItems" )) {
281219 ReadableMap toolbarMenuItems = toolbar .getMap ("toolbarMenuItems" );
282220 ArrayList buttons = toolbarMenuItems .getArray ("buttons" ).toArrayList ();
@@ -306,12 +244,14 @@ private void setToolbar(@NonNull final PdfView view, @NonNull ReadableMap toolba
306244 }
307245 }
308246
309- private void setMenuItemGrouping (PdfView view , @ NonNull ReadableArray menuItemGrouping ) {
247+ @ ReactProp (name = "menuItemGrouping" )
248+ public void setMenuItemGrouping (PdfView view , @ NonNull ReadableArray menuItemGrouping ) {
310249 ReactGroupingRule groupingRule = new ReactGroupingRule (view .getContext (), menuItemGrouping );
311250 view .setMenuItemGroupingRule (groupingRule );
312251 }
313252
314- private void setToolbarMenuItems (@ NonNull final PdfView view , @ Nullable final ReadableArray toolbarItems ) {
253+ @ ReactProp (name = "toolbarMenuItems" )
254+ public void setToolbarMenuItems (@ NonNull final PdfView view , @ Nullable final ReadableArray toolbarItems ) {
315255 if (toolbarItems != null ) {
316256 PdfActivityConfiguration currentConfiguration = view .getConfiguration ();
317257 ToolbarMenuItemsAdapter newConfigurations = new ToolbarMenuItemsAdapter (currentConfiguration , toolbarItems , view .getInitialConfiguration ());
@@ -324,12 +264,53 @@ private void setToolbarMenuItems(@NonNull final PdfView view, @Nullable final Re
324264 }
325265 }
326266
327- private void setAnnotationContextualMenu (@ NonNull final PdfView view , @ NonNull ReadableMap annotationContextualMenuItems ) {
267+ @ ReactProp (name = "annotationContextualMenu" )
268+ public void setAnnotationContextualMenu (@ NonNull final PdfView view , @ NonNull ReadableMap annotationContextualMenuItems ) {
328269 if (annotationContextualMenuItems != null ) {
329270 view .setAnnotationToolbarMenuButtonItems (annotationContextualMenuItems );
330271 }
331272 }
332273
274+ @ ReactProp (name = "disableDefaultActionForTappedAnnotations" )
275+ public void setDisableDefaultActionForTappedAnnotations (PdfView view , boolean disableDefaultActionForTappedAnnotations ) {
276+ view .setDisableDefaultActionForTappedAnnotations (disableDefaultActionForTappedAnnotations );
277+ }
278+
279+ @ ReactProp (name = "disableAutomaticSaving" )
280+ public void setDisableAutomaticSaving (PdfView view , boolean disableAutomaticSaving ) {
281+ view .setDisableAutomaticSaving (disableAutomaticSaving );
282+ }
283+
284+ @ ReactProp (name = "annotationAuthorName" )
285+ public void setAnnotationAuthorName (PdfView view , String annotationAuthorName ) {
286+ PSPDFKitPreferences .get (view .getContext ()).setAnnotationCreator (annotationAuthorName );
287+ }
288+
289+ @ ReactProp (name = "imageSaveMode" )
290+ public void setImageSaveMode (PdfView view , String imageSaveMode ) {
291+ view .setImageSaveMode (imageSaveMode );
292+ }
293+
294+ @ ReactProp (name = "showNavigationButtonInToolbar" )
295+ public void setShowNavigationButtonInToolbar (@ NonNull final PdfView view , final boolean showNavigationButtonInToolbar ) {
296+ view .setShowNavigationButtonInToolbar (showNavigationButtonInToolbar );
297+ }
298+
299+ @ ReactProp (name = "hideDefaultToolbar" )
300+ public void setHideDefaultToolbar (@ NonNull final PdfView view , final boolean hideDefaultToolbar ) {
301+ view .setHideDefaultToolbar (hideDefaultToolbar );
302+ }
303+
304+ @ ReactProp (name = "availableFontNames" )
305+ public void setAvailableFontNames (@ NonNull final PdfView view , @ Nullable final ReadableArray availableFontNames ) {
306+ view .setAvailableFontNames (availableFontNames );
307+ }
308+
309+ @ ReactProp (name = "selectedFontName" )
310+ public void setSelectedFontName (@ NonNull final PdfView view , @ Nullable final String selectedFontName ) {
311+ view .setSelectedFontName (selectedFontName );
312+ }
313+
333314 @ ReactProp (name = "measurementValueConfigurations" )
334315 public void setMeasurementValueConfigurations (@ NonNull final PdfView view , @ Nullable final ReadableArray measurementValueConfigs ) {
335316 if (measurementValueConfigs != null ) {
0 commit comments