Skip to content

Instantly share code, notes, and snippets.

@rotemmiz
Last active October 3, 2016 22:49
Show Gist options
  • Save rotemmiz/199d9a597b1f2ffbf8429ea9206648b3 to your computer and use it in GitHub Desktop.
Save rotemmiz/199d9a597b1f2ffbf8429ea9206648b3 to your computer and use it in GitHub Desktop.
Killing a webview bridge component
class MyBridgedComponent extends Component {
constructor(props) {
super(props);
this.state = {
isLoaded: false
};
}
onBridgeMessage(message) {
message = JSON.parse(message);
this.setState({
isLoaded: true
});
}
render() {
if (this.state.isLoaded) {
return false;
}
const injectScript = `
if (window.WebViewBridge) {
var message = {
data: "myData"
}
webViewBridge.send(JSON.stringify(message));
}`
return (
<View style={{width:0, height:0}}>
<WebViewBridge
ref="webviewbridge"
onBridgeMessage={this.onBridgeMessage.bind(this)}
injectedJavaScript={injectScript}
javaScriptEnabled={true}
source={{uri: "example.com"}}/>
</View>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment