Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show keyboard programmatically using React native

How do I show Keyboard for TextInput programmatically using react native? Using a ScrollView, tapping between TextInput causes the keyboard to be dismissed. I want to show the Keyboard again using onFocus method of TextInput. Anyway to accomplish this?

like image 295
vijayst Avatar asked Aug 17 '16 09:08

vijayst


2 Answers

Your ScrollView needs to include the keyboardShouldPersistTaps prop:

<ScrollView keyboardShouldPersistTaps></ScrollView>
like image 130
Shawn Avatar answered Sep 23 '22 08:09

Shawn


consider have a reference of your textInput :

<TextInput ref={(ref)=>{this.myTextInput = ref}} />

And when you have to focus it again use : this.myTextInput.focus()

edit React16

For react16 use React.createRef to create a reference.

like image 43
LHIOUI Avatar answered Sep 22 '22 08:09

LHIOUI