34
34
import com .pspdfkit .annotations .Annotation ;
35
35
import com .pspdfkit .preferences .PSPDFKitPreferences ;
36
36
import com .pspdfkit .react .annotations .ReactAnnotationPresetConfiguration ;
37
+ import com .pspdfkit .react .AnnotationConfigurationAdaptor ;
38
+ import com .pspdfkit .react .ConfigurationAdapter ;
37
39
import com .pspdfkit .react .events .PdfViewDataReturnedEvent ;
38
40
import com .pspdfkit .react .menu .ReactGroupingRule ;
41
+ import com .pspdfkit .react .ToolbarMenuItemsAdapter ;
39
42
import com .pspdfkit .views .PdfView ;
40
43
import com .pspdfkit .configuration .activity .PdfActivityConfiguration ;
41
44
import org .json .JSONObject ;
@@ -148,109 +151,30 @@ public Map<String, Integer> getCommandsMap() {
148
151
return commandMap ;
149
152
}
150
153
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 ;
154
157
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" );
158
161
setConfiguration (view , configuration );
159
162
}
160
163
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" );
183
167
// Always set the document, even if it's the same path, to ensure it loads
184
168
view .setDocument (document , this .reactApplicationContext );
185
169
}
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
- }
207
170
}
208
171
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 );
251
175
}
252
176
253
- // Helper methods for setDocumentWithOrderedProps (not @ReactProp methods )
177
+ // Helper method for setDocumentAndConfiguration (not @ReactProp method )
254
178
private void setConfiguration (PdfView view , @ NonNull ReadableMap configuration ) {
255
179
ConfigurationAdapter configurationAdapter = new ConfigurationAdapter (view .getContext (), configuration );
256
180
PdfActivityConfiguration configurationBuild = configurationAdapter .build ();
@@ -276,7 +200,21 @@ private void setConfiguration(PdfView view, @NonNull ReadableMap configuration)
276
200
}
277
201
}
278
202
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 ) {
280
218
if (toolbar .hasKey ("toolbarMenuItems" )) {
281
219
ReadableMap toolbarMenuItems = toolbar .getMap ("toolbarMenuItems" );
282
220
ArrayList buttons = toolbarMenuItems .getArray ("buttons" ).toArrayList ();
@@ -306,12 +244,14 @@ private void setToolbar(@NonNull final PdfView view, @NonNull ReadableMap toolba
306
244
}
307
245
}
308
246
309
- private void setMenuItemGrouping (PdfView view , @ NonNull ReadableArray menuItemGrouping ) {
247
+ @ ReactProp (name = "menuItemGrouping" )
248
+ public void setMenuItemGrouping (PdfView view , @ NonNull ReadableArray menuItemGrouping ) {
310
249
ReactGroupingRule groupingRule = new ReactGroupingRule (view .getContext (), menuItemGrouping );
311
250
view .setMenuItemGroupingRule (groupingRule );
312
251
}
313
252
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 ) {
315
255
if (toolbarItems != null ) {
316
256
PdfActivityConfiguration currentConfiguration = view .getConfiguration ();
317
257
ToolbarMenuItemsAdapter newConfigurations = new ToolbarMenuItemsAdapter (currentConfiguration , toolbarItems , view .getInitialConfiguration ());
@@ -324,12 +264,53 @@ private void setToolbarMenuItems(@NonNull final PdfView view, @Nullable final Re
324
264
}
325
265
}
326
266
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 ) {
328
269
if (annotationContextualMenuItems != null ) {
329
270
view .setAnnotationToolbarMenuButtonItems (annotationContextualMenuItems );
330
271
}
331
272
}
332
273
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
+
333
314
@ ReactProp (name = "measurementValueConfigurations" )
334
315
public void setMeasurementValueConfigurations (@ NonNull final PdfView view , @ Nullable final ReadableArray measurementValueConfigs ) {
335
316
if (measurementValueConfigs != null ) {
0 commit comments