React Native:在 ScrollView 中更改焦点时键盘关闭 [英] React Native: Keyboard dismiss when changing focus in ScrollView

查看:60
本文介绍了React Native:在 ScrollView 中更改焦点时键盘关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 React Native 0.22 iOS 应用程序中,我有一个 ScrollView,其中包含多个 TextInput 元素.

In my React Native 0.22 iOS app, I have a ScrollView with multiple TextInput element in it.

我注意到当我通过点击下一个 TextInput 将焦点从一个 TextInput 更改为另一个时,键盘将关闭并且下一个 TextInput 不会立即获得焦点.它只会在我第二次点击它时才得到关注(然后键盘又回来了,真的很糟糕的体验).

I noticed that when I change focus from one TextInput to another by tapping on the next TextInput, the keyboard will dismiss and the next TextInput won't get focused immediately. It only get focus on the second time I tap on it (and then keyboard comes back again, really bad experience).

此行为仅发生在 ScrollView 中的 TextInput 上,而不发生在 View 上.我想知道是否有办法解决它?

This behavior only happen on TextInput in ScrollView, but not View. I am wondering if there's any way to work around it?

谢谢!

推荐答案

只需为您的滚动视图提供 keyboardShouldPersistTaps="always" 道具.

Just provide keyboardShouldPersistTaps="always" prop to your scrollview.

来自文档 -

  • 'never'(默认值),当键盘向上时,在焦点文本输入之外敲击会关闭键盘.发生这种情况时,儿童将不会收到水龙头.
  • 'always',键盘不会自动关闭,滚动视图不会捕捉点击,但滚动视图的孩子可以捕捉点击.
  • 'handled',当点击被孩子处理(或被祖先捕获)时,键盘不会自动关闭.错误,已弃用,使用从不"代替正确,已弃用,请改用始终"

文档:https://facebook.github.io/react-native/docs/scrollview#keyboardshouldpersisttaps

这篇关于React Native:在 ScrollView 中更改焦点时键盘关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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