Amr*_*tha 17 react-native react-native-android
我有一个 textInput 和一个按钮。当 textInput 被聚焦时,键盘会出现,但如果你在键盘可见的情况下点击按钮,首先键盘消失,然后只有你可以点击按钮。为什么?我怎样才能让它工作,以便可以在键盘可见的情况下点击按钮?在 android studio(android native)中开发的应用程序可以获取键盘可见的点击监听器。但是在本机反应中,它不起作用。如果你点击按钮以外的任何地方,那么键盘应该消失,不是吗?但是如果你点击键盘可见的按钮,btn 应该接收监听器。我正在android设备上测试它。
PS你可以在这里试试:https : //snack.expo.io/@codebyte99/addcomponents
<TextInput
placeholder={'Type smth'}
style={[{ borderBottomColor: 'gray', borderBottomWidth: 1 }]}
/>
<TouchableOpacity onPress={() => { this._onPressOut(); }}>
<Text>click here</Text>
</TouchableOpacity>
Run Code Online (Sandbox Code Playgroud)
Tha*_*hik 43
滚动视图包含一个keyboardShouldPersistTaps处理滚动视图内键盘点击行为的道具。
对于您的情况,请将其作为 <ScrollView keyboardShouldPersistTaps='handled'>
仅供参考:如果您使用的是react-native-keyboard-aware-scroll-view,您需要这样做:
<KeyboardAwareScrollView keyboardShouldPersistTaps="always">
Run Code Online (Sandbox Code Playgroud)
作为@thakur-karthik 回答的补充:
需要注意的是,在 scrollview 场景中,当您在 react-native modal 中有一个 scrollview 时,会发生一些奇怪的事情。
只需添加keyboardShouldPersistTaps={'always'}上的模式滚动视图独自将无法正常工作。
如果您在任何祖先中有滚动视图,它们也必须keyboardShouldPersistTaps={'always'}在其组件上声明
| 归档时间: |
|
| 查看次数: |
7022 次 |
| 最近记录: |