Closed qiaolin-pan closed 5 years ago
+1
+1,Is there a solution?
YellowBox.js:67 Sending RNDownloaderProgress
with no listeners registered.
Sending DoneButtonEvent
with no listeners registered.
I have these two warnings
The package documentation should be updated regarding the best practices to handle these events. I added these lines to my component (along with relevant imports) to satisfy this warning:
private eventEmitter: EventEmitter = new NativeEventEmitter(NativeModules.RNReactNativeDocViewer);
componentDidMount = () => {
// Prevent warnings by listening to the DoneButtonEvent that is emitted when closing the iOS QuickLook preview
this.eventEmitter.addListener('DoneButtonEvent', this.doneEvent);
};
componentWillUnmount = () => {
this.eventEmitter.removeListener('DoneButtonEvent', this.doneEvent);
};
doneEvent = () => {
console.log('Closing QuickLook viewer');
};
Edit: expanded to include named function and properly remove listeners.
how to use this eventemitter in hooks component?
For Functional components use this:
// Function to handle the DoneButtonEvent
const doneEvent = () => {
console.log('Closing QuickLook viewer');
};
useEffect(() => {
// Create an instance of the NativeEventEmitter and associate it with the RNReactNativeDocViewer native module
const eventEmitter = new NativeEventEmitter(NativeModules.RNReactNativeDocViewer);
// Add the event listener for the DoneButtonEvent when the component mounts
const doneButtonListener = eventEmitter.addListener('DoneButtonEvent', doneEvent);
// Clean up: Remove the event listener when the component unmounts
return () => {
doneButtonListener.remove();
};
}, []);
When I click the
Done
button, I get the following error:Sending 'DoneButtonEvent' with no listeners registered.