Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
React Native native module - trigger JS event from launched Activity?

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?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda