I'm following the guide here to create a Turbo Module in React Native. https://reactnative.dev/docs/next/the-new-architecture/pillars-turbomodules
How do you emit events on iOS? The documentation only shows how to call a native function from React, but not how to emit an event from the Turbo Module.
For Android, you get a ReactApplicationContext
object, which lets you create an emitter like this using the context object.
private val emitter = context.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
emitter.emit(eventName, eventArray)
How do you do the same thing on iOS?
To emit events to RN from iOS you should make your own emitter class that is inherited from
RCTEventEmitter
and then init it on JS side withNativeEventEmitter
and add listeners for needed events withaddListener
:EventEmitter.h
EventEmitter.m
How to call:
RN/JS