I try to load a HTML file depends on someother .js file.
So I write code like this, but got plain text in webview.
render = () => {
let source;
if (__DEV__) {
source = require('./vendor/Editor/index.html');
} else {
source =
Platform.OS === 'ios'
? require('./vendor/Editor/index.html')
: {uri: 'file:///android_asset/vendor/Editor/index.html'};
}
return (
<WebView
startInLoadingState
source={source}
onMessage={this.handleMessage}
automaticallyAdjustContentInsets={false}
style={[
AppStyles.container,
styles.container,
{height: this.state.visibleHeight},
]}
/>
);
};
And I simplify the code like this, but it doesn't work too.
render = () => {
setTimeout(() => {
this.webview.injectJavaScript(
'window.ReactNativeWebView.postMessage(document.body.innerHTML)',
);
}, 3000);
return (
<WebView
source={require('./vendor/GrEditor/index.html')}
onMessage={e => console.log('e: ', e)}
/>
);
};
Sorry for poor grammar.