react-native-eval
React has a good tutorial how to integrate React View to already existing application, but it doesn't provide a good way if you decided to migrate some of your business logic to JS first while maintaining the same UI.
Installation
npm init
. Initialize npmnpm install --save react-native-eval
. Install react-native-eavl
iOS
pod init
. Initialize CocoaPods.- Add following line to Podfile:
pod 'react-native-eval',:path => 'node_modules/react-native-eval/ios'
pod install
. Update the project.
Android
android/settings.gradle
...include ':react-native-eval'project(':react-native-eval').projectDir = new File(settingsDir, '../node_modules/react-native-eval/android')
android/app/build.gradle
dependencies { ... compile project(':react-native-eval')}
- register module (in MainActivity.java)
... // <--- import
Buckle up, Dorothy
iOS
- Get a reference to
RCTBridge
, by getting it fromRCTRootView.bridge
that you have created (if you have any React Native view) or by creatingRCTBridge
manually:
RCTBridge* bridge = ;RCTRootView* view = ; // Call sync function ; // You can call async function as well. It has to have callback as a last argument. // If callback would be called with Error object then it will be converted to // NSString and passed as a first argument of native callback. Otherwise callback // value would be passed as a second parameter
Javascript
- Call
require('react-native-eval')
, to ensure that the module is included.