I have created a webview in my react-native component then i wanted to use postMessage to send data and read it through OnMessage . I don't know actually if the problem was in my postMessage or in my onMessage option of the webView . Can you tell me where is the problem please ? Here is my app Component :
let Script1 = `
var data = {
message : "OnFocusEvent"
};
window.postMessage(JSON.stringify({data}),"*");
`;
export default class App extends Component {
constructor(props) {
super(props);}
render() {
return (
<View style={styles.container}>
<RNEnhanceWebview
ref={ref => (this.webView = ref)}
style={{ flex: 1 }}
source={{
html:
' </br></br></br></br><form> <input id="input" class="input"
type="text" placeholder="name"/></form>'
}}
keyboardDisplayRequiresUserAction={false} //ios
autoFocus={true} //android
injectedJavaScript={Script1}
automaticallyAdjustContentInsets={false}
allowFileAccessFromFileURLs={true}
scalesPageToFit={false}
mixedContentMode={"always"}
javaScriptEnabled={true}
javaScriptEnabledAndroid={true}
startInLoadingState={true}
onMessage={event => {
console.log(event.nativeEvent.data);
console.log(JSON.parse(event.nativeEvent.data));
}}
onLoad={() => {}}
/>
</View>
}
Do you have any suggestion to show my message data ?