我有下一个发射器JS代码:阵营原生的Android +活动的onPause /的onResume
DeviceEventEmitter.addListener('keyboardWillShow1', function(e: Event) {
console.log(e);
});
我怎么能发出从活动/onResume
这个活动?
我有下一个发射器JS代码:阵营原生的Android +活动的onPause /的onResume
DeviceEventEmitter.addListener('keyboardWillShow1', function(e: Event) {
console.log(e);
});
我怎么能发出从活动/onResume
这个活动?
您可以从Java中使用定义在这里RCTDeviceEventEmitter.emit
方法来发送事件:DeviceEventManagerModule.java#L27
要做到这一点,你首先需要有参考ReactApplicationContext
,然后调用:
reactAppContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("keyboardWillShow1", null);
而不是“空”,您可发送随机数据,然后将其附加到您在JS端收到的事件。
查看这个DeviceEventManagerModule.java#L49作为一个例子 - 这是如何返回按钮事件发送到JS。
然后,您可以使用类似的方式分派从活动/onResume
事件,假设你有参考ReactApplicationContext
另一种方法是创建自定义模块,可用于接收生命周期事件注册。看看它是如何在“定时”模块进行:
onHostPause
和onHostResume
方法的接口,并使用上面的代码片段从那里派遣事件我相信现在react-native-activity-android模块完成了秒。
谢谢!我一直在寻找如何实现onPause和onResume! –