React Native-打开键盘时在ListView上选择行 [英] React Native - Select row on ListView when keyboard is open

查看:86
本文介绍了React Native-打开键盘时在ListView上选择行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在构建一个具有本机视图的React Native应用程序,该视图包含TextInputListView.
它的工作方式是当TextInput获得焦点时-键盘将打开,用户可以在ListView中过滤数据.
期望的功能是,如果用户轻击/选择列表视图中的行,则应检测到轻击并调用方法.

问题:
打开键盘后,点击列表视图将关闭键盘,并且该行将检测到第二次点击(tap事件不会传播到ListView行).
知道怎么用onPress方法检测到第一次点击吗?


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?

预先感谢您的帮助.

推荐答案

您需要添加属性 keyboardShouldPersistTaps={always} 到您的ScrollView.

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

这是文档所说的:

键盘应保持提示

确定点击后键盘何时保持可见状态.

Determines when the keyboard should stay visible after a tap.

'never'(默认设置),当键盘向上弹起时,在突出显示的文字输入之外点击可关闭键盘.发生这种情况时,孩子们将不会收到水龙头.

'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',键盘不会自动关闭,并且滚动视图>不会捕获水龙头,但是滚动视图的子级可以捕获水龙头.

'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',当水龙头被儿童操纵(或被祖先捕捉)时,键盘不会自动关闭.

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

false,已弃用,请改用从不"

false, deprecated, use 'never' instead

true,已弃用,请改用始终"

true, deprecated, use 'always' instead

这篇关于React Native-打开键盘时在ListView上选择行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆