react native TextInput 键盘弹起点击两次才能触发子组件解决方案

关于react native TextInput 键盘弹起点击两次才能触发子组件解决方案:

1. TextInput组件用ScrollView或FlatList组件包裹,给ScrollView或FlatList组件添加如下属性:

keyboardShouldPersistTaps="handled"
  • 'handled',当点击事件被子组件捕获时,键盘不会自动收起。这样切换TextInput时键盘可以保持状态。多数带有TextInput的情况下你应该选择此项。

2.  如果需要在触发子组件点击事件同时收起键盘,则可以在处理子组件点击事件的同时让键盘失焦:

  • 可以使用react native API “KeyBoard”
import {
    KeyBoard
} from 'react-native';

KeyBoard.dismiss()
  • 或者直接使用“ref”让TextInput键盘失焦
<TextInput
     ref={(ref) => { this.textInput = ref; }}
     ...
/> 

this.textInput.blur();
发布了36 篇原创文章 · 获赞 64 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/u010379595/article/details/84063237
今日推荐