Utilize the JavaScript VM running inside an iOS UIWebView to exploit libraries targeting the DOM (e.g. Google Charts).
npm install react-native-webview-js-contextInteractive JavaScript between a UIWebView and React Native.
Example: Google Charts used to render a chart (base64 encoded image) in a component

``javascript
const GC_HTML =
;const CHART_JS =
var options = { enableInteractivity: false,
legend: {position: 'none'},
lineWidth: 3, width:750, height:420,
pointShape: 'circle', pointSize: 8,
chartArea: { left: 30, width: 690 }, areaOpacity: 0.07,
colors: ['#e14c4d'], backgroundColor: { 'fill': '#34343f' },
annotations: {
textStyle: { fontSize: 26, bold: true, color: '#bbbbbd', auroColor: '#3f3f3f' },
},
hAxis: {
format: 'MMM d',
textStyle: {color: '#bbbbbd', fontSize: 16,}, gridlines: { color: 'transparent' },
},
vAxis: { gridlines: { count: 3, color: '#3f414f' } },
};
var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
chart.draw(data, options);
resolve(chart.getImageURI()); / <--- resolve() is called by RNWebViewJSContext /;
import WebViewJSContext from 'react-native-webview-js-context';
class RNCharts {
state: { imageUri: null };
componentWillMount() {
WebViewJSContext.createWithHTML(GC_HTML)
.then(context => {
this.ctx = context;
this.loadChart();
});
}
componentWillUnmount() {
this.ctx && this.ctx.destroy();
},
render() {
return this.state.imageUri ?
:
}
async loadChart() {
var imageUri = await this.ctx.evaluateScript(CHART_JS);
this.setState({ imageUri });
}
}
`
First you need to install react-native-webview-js-context:
`javascript`
npm install react-native-webview-js-context --save
1. In XCode, in the project navigator, right click Libraries ➜ Add Files to [your project's name]node_modules
2. Go to ➜ react-native-webview-js-context ➜ ios and add RNWebViewJSContext.xcodeprojlibRNWebViewJSContext.a
3. In XCode, in the project navigator, select your project. Add to your project's Build Phases ➜ Link Binary With LibrariesCmd+R
4. Run your project ()
* android/settings.gradle
`gradle`
...
include ':react-native-webview-js-context'
project(':react-native-webview-js-context').projectDir = new File(settingsDir, '../node_modules/react-native-webview-js-context/android')android/app/build.gradle
*
`gradle`
dependencies {
...
compile project(':react-native-webview-js-context')
}
* register module (in MainActivity.java)
`java
...
import com.shaynesweeney.react_native_webview_js_context.RNWebViewJSContextPackage; // <--- IMPORT
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mReactRootView = new ReactRootView(this);
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModuleName("index.android")
.addPackage(new MainReactPackage())
.addPackage(new RNWebViewJSContextPackage()) // <- ADD HERE
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
mReactRootView.startReactApplication(mReactInstanceManager, "YourProject", null);
setContentView(mReactRootView);
}
}
``