23

How to keep keyboard opened when i have TextInput and Touchable near input that sends message. So i want to send message without double tap on touchable. First to hide keyboard, second to send message. How to do that?

IC_
  • 1,624
  • 1
  • 23
  • 57
  • 1
    Possible duplicate of [React Native have to double click for onPress to work](https://stackoverflow.com/questions/42808294/react-native-have-to-double-click-for-onpress-to-work) – WayneC Aug 25 '17 at 14:51

4 Answers4

29

Use keyboardShouldPersistTaps to handle this.

Example:-

<ScrollView
        keyboardDismissMode="on-drag"
        keyboardShouldPersistTaps={'always'} >
</ScrollView>

Deprecated Properties:-

false, deprecated, use 'never' instead

true, deprecated, use 'always' instead

source

RajnishCoder
  • 3,455
  • 6
  • 20
  • 35
csath
  • 1,248
  • 11
  • 25
7

Check out keyboardShouldPersistTaps.

The following keeps the keyboard open when content is tapped but closes the keyboard when dragged.

<ScrollView keyboardShouldPersistTaps="always" keyboardDismissMode="on-drag">

  {/* Content containing interactive elements such as <Touchable /> */}

</ScrollView>

Note
Any parent ScrollViews/VirtualizedLists/Flatlists/SectionLists will also need to set keyboardShouldPersistTaps="always"

Here are some gory details if you're interested.

GollyJer
  • 23,857
  • 16
  • 106
  • 174
3

Have a look at the keyboardShouldPersistTaps property of ScrollView. Setting it to "handled" should do what you are looking for.

WayneC
  • 5,569
  • 2
  • 32
  • 43
0

just only wrap you submit button with scrollview and then make sure u need to add two props keyboardShouldPersistTaps="always" and keyboardDismissMode="on-drag" like this ...

<TextInput/> 
<ScrollView
            contentContainerStyle={{
              width: SIZES.width / 6,
              height: 60,
            }}
            keyboardShouldPersistTaps="always"
            keyboardDismissMode="on-drag">
<TouchableOpacity onPress={}>
</TouchableOpacity>
</ScrollView>
faery
  • 61
  • 2
  • 5