繁体   English   中英

React Native - 桥接 Android Native 到 React Native 性能变慢

[英]React Native - Bridge Android Native to React Native get Slow Performance

我是将 Native (Android) 桥接到 React Native 的新手。

我想从 Android Native 向 React Native 发送大量数据,但遇到性能问题(慢)。

这是我的示例代码:

Android 原生(使用回调):

for(int i = 0 ; i < 10000000000000 ; i++){    
this.dispatchEvent("MyEvent","hello this is my message");
}

反应本机:

var myFunction = (tags) => {
            console.log("Message :"+tags);
}

RNTry.on("MyEvent", myFunction);

我得到什么结果:

  1. 来自 Android Native 的消息发送到 React Native 并显示成功结果
  2. React Native UI 冻结,当我触摸按钮时没有响应

我的问题 :

如何在不让 React Native UI 冻结/滞后的情况下从 Android Native 向 React Native 发送大量数据(实时)?

尝试从 android 发送事件以做出反应

private void sendEvent(ReactContext reactContext,
                      String eventName,
                      @Nullable WritableMap params) {
 reactContext
     .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
     .emit(eventName, params);
}

阅读它https://reactnative.dev/docs/native-modules-android

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM