iosreact-nativereact-native-iosnative-module

Call JavaScript function from native code


I have a react-native app and want to integrate it with native SDK. At some point I need to call js function which will return me data, and this call I should make from native side. Here is the flow:

  1. some iOS handler require more info
  2. native layer calls js code
  3. js code calculate/fetch required data
  4. js code return data back to native code
  5. native code receive data and continue working

Is it possible? There is a lib react-native-eval but may be there is more elegant way to do this?


Solution

  • There is currently no clean way of doing this. My suggestion would be to use either a Callback or an Event from native to JS to notify that there is some information needed and to then invoke a function from JS to the native code that gives the required data to the native layer.