Last active
October 3, 2016 22:49
-
-
Save rotemmiz/199d9a597b1f2ffbf8429ea9206648b3 to your computer and use it in GitHub Desktop.
Killing a webview bridge component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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