Reputation: 93
I really tried to make a connection between my react native component and my webview but it doesn't work . Have you any solution ? Here is my code :
let Script = `
document.getElementById("input").addEventListener("focus", function(data)
{alert(data.data)})
`;
render(){
return(
<View>
<WebView
style={{ flex: 1 }}
source={{
html:
'</br></br></br></br><form > <input id="input" class="input"
type="text"
placeholder="Product barcode "/></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 => {
alert("HI")
}}
onLoad={() => {}}
/>
<Button
onPress={ this.refs.WEBVIEW_REF.postMessage("Hello from RN");}
title="Scan Barcode"
color="#6495ED"
/>
</View> })
I want just to dispatch the alert after clicking on the button so when i focus the input of the WebView .
Upvotes: 0
Views: 1261
Reputation: 1336
you can try wrap webview into TouchableWithoutFeedback
Upvotes: 1