I have js code with a next emitter:
DeviceEventEmitter.addListener('keyboardWillShow1', function(e: Event) {
console.log(e);
});
How I can emit this event from Activity onPause
/onResume
?
You can send event from java using RCTDeviceEventEmitter.emit
method defined here: DeviceEventManagerModule.java#L27
To do it you first need to have reference to ReactApplicationContext
, then call:
reactAppContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("keyboardWillShow1", null);
Instead of "null" you can send arbitrary data that will then be attached to the event you receive on JS side.
See this DeviceEventManagerModule.java#L49 as an example - this is how back button events are being send to JS.
You can then use similar pattern to dispatch events from activity onPause
/onResume
assuming you have reference to ReactApplicationContext
Another way would be to create your custom module, which can register for receiving lifecycle events. See how it's done in "Timing" module:
onHostPause
and onHostResume
methods of that interface and use the snippet from the above to dispatch events from thereI believe now the react-native-activity-android module accomplishes this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With