I'm trying to use the onMessage listener. The website is executing a postMessage (window.postMessage("Post message from web");
) but react native's webview onMessage listener is not doing anything! I don't know what I'm doing wrong.
Here is the HTML
<script type="text/javascript">
window.postMessage("Post message from web");
</script>
And here is the react-native code:
<WebView
ref={( webView ) => this.webView = webView}
onMessage={this.onMessage}
source={{uri: 'https://app.sodge.co/login/response.html'}}
/>
onMessage react native function:
onMessage( event ) {
Alert.alert(
'On Message',
event.nativeEvent.data,
[
{text: 'OK'},
],
{ cancelable: true }
)
}
Here is an expo snack too... I don't know that I'm doing wrong (: ...
https://snack.expo.io/S17AQqWbf
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…