Nutrient React Native SDK 4 migration guide
Backward compatibility: This version adds support for React Native’s new architecture, but backward compatibility is maintained for projects still using the old architecture.
This guide covers migrating to Nutrient React Native SDK 4. The steps below only apply to projects where the new architecture is enabled. If you’re still using the old architecture, no changes are required.
Moved APIs in the new architecture
disableAutomaticSavingis now a property of thePDFConfigurationclass:
<NutrientView disableAutomaticSaving={true}/><NutrientView configuration={{ disableAutomaticSaving: true, }}/>toolbarTitleis now a property of thePDFConfigurationclass:
<NutrientView toolbarTitle={"My Title"}/><NutrientView configuration={{ toolbarTitle: "My Title", }}/>In the new architecture, the following deprecated APIs have been removed from the root of the NutrientView component and are now only available on the PDFDocument class.
getAnnotations: Usethis.pdfRef.current?.getDocument().getAnnotations()orgetAnnotationsForPage()instead.addAnnotation: Usethis.pdfRef.current?.getDocument().addAnnotations()orapplyInstantJSON()instead.addAnnotations: Usethis.pdfRef.current?.getDocument().addAnnotations()orapplyInstantJSON()instead.removeAnnotation: Usethis.pdfRef.current?.getDocument().removeAnnotations()instead.removeAnnotations: Usethis.pdfRef.current?.getDocument().removeAnnotations()instead.getAllUnsavedAnnotations: Usethis.pdfRef.current?.getDocument().getAllUnsavedAnnotations()instead.getAllAnnotations: Usethis.pdfRef.current?.getDocument().getAnnotations()instead.getAnnotations: Usethis.pdfRef.current?.getDocument().getAnnotations()orgetAnnotationsForPage()instead.setAnnotationFlags: Usethis.pdfRef.current?.getDocument().setAnnotationFlags()instead.getAnnotationFlags: Usethis.pdfRef.current?.getDocument().getAnnotationFlags()instead.saveCurrentDocument: Usethis.pdfRef.current?.getDocument().save()instead.importXFDF: Usethis.pdfRef.current?.getDocument().importXFDF()instead.exportXFDF: Usethis.pdfRef.current?.getDocument().exportXFDF()instead.setFormFieldValue: Use one of theupdateAPIs on thePDFDocument.formsobject instead.getFormFieldValue: Use thegetFormElementsAPI on thePDFDocument.formsobject instead, and filter byfullyQualifiedFieldName.
The following APIs or properties have been consolidated into one.
setLeftBarButtonItems: UseleftBarButtonItemsinthis.pdfRef.current?.setToolbar()instead.setRightBarButtonItems: UserightBarButtonItemsthis.pdfRef.current?.setToolbar()instead.setToolbarMenuItems: UsetoolbarMenuItemsinthis.pdfRef.current?.setToolbar()instead.leftBarButtonItems,rightBarButtonItemsandtoolbarMenuItemsnow fall under thetoolbarprop inNutrientView:
<NutrientView leftBarButtonItems={{}} rightBarButtonItems={{}} toolbarMenuItems={{}}/><NutrientView toolbar={{ leftBarButtonItems: {}, rightBarButtonItems: {}, toolbarMenuItems: {} }}/>API signature changes
- All
NotificationCentercallback events are now typed — for example:
this.pdfRef.current?.getNotificationCenter().subscribe(NotificationCenter.DocumentEvent.LOADED, (event: any) => { console.log(event);});this.pdfRef.current?.getNotificationCenter().subscribe(NotificationCenter.DocumentEvent.LOADED, (payload: NotificationCenter.DocumentLoadedPayload) => { console.log(payload.documentID); });- The
onDocumentLoadFailedandNotificationCenter.DocumentEvent.LOAD_FAILEDcallbacks now contain an object with acodeandmessagefield to indicate the error reason. - In the new architecture,
Nutrient.versionStringis no longer a property; it’s now a method that returns the version string:
const version = Nutrient.versionString;const version = Nutrient.versionString();For more information, refer to the Nutrient React Native SDK 4 changelog.