Nutrient React Native SDK 4 migration guide
Backward compatibility — This version adds support for React Native’s new architecture(opens in a new tab), but the SDK maintains backward compatibility 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 you have enabled the new architecture. If you’re still using the old architecture, you don’t need to make any changes.
Enabling the new architecture
To use the new architecture with Nutrient React Native SDK 4, you need to enable it in your project.
iOS
Add the following at the beginning of your Podfile:
ENV['RCT_NEW_ARCH_ENABLED'] = '1'Then reinstall your pods:
cd iosrm -rf Pods Podfile.lockpod install --repo-updateAndroid
Add the following to your android/gradle.properties file:
newArchEnabled=trueThen clean and rebuild your project:
cd android./gradlew cleancd ..npx react-native run-androidLicense key and NativeModules.Nutrient API
The NativeModules.Nutrient API works the same way in both old and new architectures. The SDK uses TurboModules that export the same module name, so your existing code will continue to work:
import { NativeModules } from 'react-native';
const Nutrient = NativeModules.Nutrient;Nutrient.setLicenseKey('YOUR_LICENSE_KEY');You don’t need to change your license key setup when migrating to the new architecture.
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", }}/>The new architecture removes the following deprecated APIs from the root of the NutrientView component. Use the PDFDocument class instead.
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.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 thegetFormElements()API on thePDFDocument.formsobject instead, and filter byfullyQualifiedFieldName.
The new architecture consolidates the following APIs into one. Refer to the setToolbar() method in the NutrientView API reference for details.
setLeftBarButtonItems: UseleftBarButtonItemsinthis.pdfRef.current?.setToolbar()instead.setRightBarButtonItems: UserightBarButtonItemsinthis.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.