Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native - Select row on ListView when keyboard is open


I'm building a React Native app that has a view that contains TextInput and ListView.
The way it works is when the TextInput receives focus - the keyboard opens and the user can filter the data in the ListView.
The desired functionality is that in case the user taps/selects on of the rows in the list view the tap should be detected and a method called.

The issue:
When the keyboard is open, tapping the list view closes the keyboard and a second tap will be detected by the row (the tap event is not propagated to the ListView row).
Any idea how the first tap be detected by the onPress method?

Thanks in advance for the help.

like image 644
Code Monkey Avatar asked Feb 24 '16 13:02

Code Monkey


1 Answers

You need to add the property keyboardShouldPersistTaps={always} to your ScrollView.

Here is what the docs say :

keyboardShouldPersistTaps

Determines when the keyboard should stay visible after a tap.

'never' (the default), tapping outside of the focused text input when the keyboard is up dismisses the keyboard. When this happens, children won't receive the tap.

'always', the keyboard will not dismiss automatically, and the scroll view will > not catch taps, but children of the scroll view can catch taps.

'handled', the keyboard will not dismiss automatically when the tap was handled by a children, (or captured by an ancestor).

false, deprecated, use 'never' instead

true, deprecated, use 'always' instead

like image 112
G. Hamaide Avatar answered Nov 20 '22 06:11

G. Hamaide