0

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 .

1 Answer 1

1

you can try wrap webview into TouchableWithoutFeedback

Sign up to request clarification or add additional context in comments.

2 Comments

thank you for your response but i don't think it will be a good solution because i am using a generated webview it's not simple like the example here . So i search a solution which can be suitable to all types of webview
Did you use it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.