Sunday, May 6, 2018

How to focus a <WebView> in react native?

Leave a Comment

I'm looking for a way to auto focus an input / textarea field OR trigger a tap inside of a WebView component in React Native. The goal behind autofocus is to make sure the keyboard pops-up right away...

Does anyone have any ideas? Tips to open or close the keyboard are also useful...

I also filed an issue here: https://github.com/facebook/react-native/issues/18965

1 Answers

Answers 1

See https://facebook.github.io/react-native/docs/webview.html#injectedjavascript

You can execute any javascript on WebView page

let injectScript = `document.querySelector('#myInput').focus();`;  <WebView         injectedJavaScript={injectScript}         source={{uri:"XXX"}}         startInLoadingState       /> 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment