我有一个 ScrollView 到 TextInput 控件。
<ScrollView contentContainerStyle={styles.container}>
<TextInput style={styles.input}/>
<TextInput style={styles.input}/>
</ScrollView>
单击 TextInput 时,键盘会按预期出现。如果我在 View 区域中的 TextInput 外部单击,键盘应该会消失,就像现在发生的那样。此外,我单击另一个 TextInput,键盘应保留在屏幕上。在屏幕上从一个 TextInput 移动到另一个时,需要单击或点击两次。
这类似于另一个StackOverflow question .当我实现问题中的答案时,点击 ScrollView 时键盘不会消失。
可以找到 RNPlay here .
最佳答案
在 ScrollView
上使用 keyboardShouldPersistTaps
应该移除点击其他 TextInput
时的关闭行为
<ScrollView contentContainerStyle={styles.container}
keyboardShouldPersistTaps ={true}>
<TextInput style={styles.input}/>
<TextInput style={styles.input}/>
</ScrollView>
但在 TextInput
考虑在 ScrollView
上添加点击监听器,当检测到点击时使用 react-native-dismiss-keyboard 隐藏键盘模块
关于ios - 在 ScrollView 中从一个 TextInput 轻敲到另一个 TextInput 不应关闭键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38990484/