React native 通过Android上React Native中的模块发出事件
在Swift中,React Native有一个事件发射器模式,其作用域为模块级,如下所示React native 通过Android上React Native中的模块发出事件,react-native,React Native,在Swift中,React Native有一个事件发射器模式,其作用域为模块级,如下所示 class MyModule : RCTEventEmitter { @objc func rnMethod(){ self.sendEvent(withName: "EventName" , body: "something") } } 有没有类似的安卓系统?到目前为止,我发现最好的是一个在iOS中被弃用的全局变量,如下所示: fun rnMethod(){
class MyModule : RCTEventEmitter {
@objc
func rnMethod(){
self.sendEvent(withName: "EventName" , body: "something")
}
}
有没有类似的安卓系统?到目前为止,我发现最好的是一个在iOS中被弃用的全局变量,如下所示:
fun rnMethod(){
val eventEmitter = reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) as DeviceEventManagerModule.RCTDeviceEventEmitter
eventEmitter.emit(event.eventName, context)
}
这就是我目前使用的,它为我做了工作。你现在使用的是正确的,而且不反对AndroidAny,暗示他们将来会朝着Android的类似方向发展?有一些承诺暗示他们想这样做,但没有任何结果。