Detecting if annotations have changed in React Native
Nutrient React Native SDK lets you detect when one or more annotations have changed via the AnnotationEvent
event listeners. Here’s how to register for the event listeners to be notified when one or more annotations have changed:
override componentDidMount() { this.pdfRef.current?.getNotificationCenter().subscribe(NotificationCenter.AnnotationsEvent.CHANGED, (event: any) => { Alert.alert('PSPDFKit', JSON.stringify(event)); }); this.pdfRef.current?.getNotificationCenter().subscribe(NotificationCenter.AnnotationsEvent.ADDED, (event: any) => { Alert.alert('PSPDFKit', JSON.stringify(event)); }); this.pdfRef.current?.getNotificationCenter().subscribe(NotificationCenter.AnnotationsEvent.REMOVED, (event: any) => { Alert.alert('PSPDFKit', JSON.stringify(event)); }); }
When done, remember to unregister from the event listeners:
override componentWillUnmount () { this.pdfRef.current?.getNotificationCenter().unsubscribe(NotificationCenter.AnnotationsEvent.CHANGED); this.pdfRef.current?.getNotificationCenter().unsubscribe(NotificationCenter.AnnotationsEvent.ADDED); this.pdfRef.current?.getNotificationCenter().unsubscribe(NotificationCenter.AnnotationsEvent.REMOVED); }