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);
}
CodePudding user response:
You should handle this sending events from Java and listen for them in JS.
You can use DeviceEventManagerModule.RCTDeviceEventEmitter
for this purpose.