You can send an event from java using the RCTDeviceEventEmitter.emit method defined here: DeviceEventManagerModule.java # L27
To do this, you first need to access the ReactApplicationContext , and then call:
reactAppContext .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit("keyboardWillShow1", null);
Instead of null, you can send arbitrary data, which will then be attached to the event that you receive on the JS side.
See this DeviceEventManagerModule.java # L49 for an example - this is how back button events are sent to JS.
Then you can use a similar template to send events from onPause / onResume , provided that you have a link to ReactApplicationContext
Another way is to create your own custom module that can register to receive life cycle events. See how this is done in the Timing module:
- The Timing module implements the LifecycleEventListener.java interface
- When a module is initialized, it registers to receive the life cycle through this interface Timing.java # L126
- You can implement the
onHostPause and onHostResume this interface and use the fragment from the above to send events from there
kzzzf source share