Viewer events
Nutrient React Native SDK provides a NotificationCenter
class, which can be used to subscribe to viewer events. This includes events specifically related to a document.
Registering for viewer events in the notification center
The example below shows how to register for an event listener to be notified when a document has loaded:
override componentDidMount() { this.pdfRef.current?.getNotificationCenter().subscribe(NotificationCenter.DocumentEvent.LOADED, (event: any) => { Alert.alert('Nutrient', JSON.stringify(event)); }); }
Unregistering from viewer events in the notification center
The example below shows how to unregister from document-loaded listener events:
override componentWillUnmount () {
this.pdfRef.current?.getNotificationCenter().unsubscribe(NotificationCenter.DocumentEvent.LOADED);
}
If you registered for multiple events and want to unregister from all of them, use the following API:
override componentWillUnmount () {
this.pdfRef.current?.getNotificationCenter().unsubscribeAllEvents();
}
For a list of all the viewer-related events you can register for, see DocumentEvent
and TextEvent
. For more details and sample code, see the EventListeners.tsx
example from the Catalog example project.