Show keyboard programmatically using React native

前端 未结 3 634
甜味超标
甜味超标 2020-12-20 15:00

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 t

相关标签:
3条回答
  • 2020-12-20 15:52

    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.

    0 讨论(0)
  • 2020-12-20 15:54

    Your ScrollView needs to include the keyboardShouldPersistTaps prop:

    <ScrollView keyboardShouldPersistTaps></ScrollView>
    
    0 讨论(0)
  • 2020-12-20 16:01

    Without ScrollView works only on ios. Place this component around the code you need the keyboard to appear on:

    <ScrollView keyboardShouldPersistTaps='always'>
    </ScrollView>
    

    link: https://reactnative.dev/docs/scrollview#keyboardshouldpersisttaps

    0 讨论(0)
提交回复
热议问题