简体   繁体   中英

Native Modules Bridges React Native

I have an issue when i try to bridge an Native Modules.

I have a function in Java , the function will calculate the progress when i write a byte , i have a while loop at there. The problem is whenever i return the value inside of loop , the loop is gonna be broke, but if i put the return value outside of the while loop its gonna return the value only the calculation done which is in this case (only once). I want return an increment value from the while or for loop process. when i log the index its shown correctly . Honestly i have no knowledge about Java

 public void sendData(String message,Promise promise) {

    if(message.length() < 1) {
      return;
    }

    byte[] data = new byte[message.length() / 2];
    for (int i = 0; i < data.length; i++) {
      int index = i * 2;

      String hex = message.substring(index, index + 2);
promise.resolve(index)

      int v = Integer.parseInt(hex, 16);
      data[i] = (byte) v;
    }
    serialPort.write(data);
  }

You should handle this sending events from Java and listen for them in JS. You can use DeviceEventManagerModule.RCTDeviceEventEmitter for this purpose.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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