I have a custom react-native module that has an SDK which launches an activity. I want to execute JS code while the SDK's activity is running via an "onFormSubmit" event/callback.
My native module has a service that the activity uses:
class MyService : SDKService() {
companion object {
private var instance: MyService? = null
fun getInstance() : MyService? {
return instance
}
}
// ...
override fun onSDKFormSubmitRequest(actionState: SDKActionState<*>, formJSON: JSONObject) {
val instance = MyModule.getInstance()
val event = RNUtils.jsonToWritableMap(formJSON)
if (event != null && instance != null) {
instance.onFormSubmit(event, this) // <-- the important part
}
}
// ...
}
In my native module:
// ...
@ReactMethod
fun onFormSubmit(event: WritableMap, service: MyService) {
this._service = service
this.reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent( // <-- the important part
this._view!!.id,
"onFormSubmit",
event
)
}
// ...
It seems the main activity (the android app) gets app state "background" when the native module opens the activity. I suspect that causes the main activity to be suspended because I get the following error when my JS event is supposed to run:
W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([3,"onFormSubmit",{"data":"***"}])
I want to be able to run the onFormSubmit while the SDK's activity is running and THEN close the SDK's activity. I want to be able to make network requests in the JS part with onFormSubmit so I can reuse my requests logic. Is there some way to do this?