Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 通过Android上React Native中的模块发出事件_React Native - Fatal编程技术网

React native 通过Android上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(){

在Swift中,React Native有一个事件发射器模式,其作用域为模块级,如下所示

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的类似方向发展?有一些承诺暗示他们想这样做,但没有任何结果。