如果键盘与 Android 上的 TextInput 重叠,TextInput 将失去焦点
我在屏幕上有一个非常简单的 TextInput
组件和一个 onEndEditing
方法,如下所示:
<TextInput
style={Styles.input}
placeholder='testing placeholder'
placeholderTextColor={Colors.gray}
onEndEditing={this.onEndEditing}
selectionColor={Colors.darkCursor}>
</TextInput>
onEndEditing = async (event): Promise<void> => {
console.log('in update');
};
它位于 FlatList
内部,该 FlatList
包装在KeyboardAvoidingView
。
在 Android 上,当点击 TextInput
并获得焦点时,如果屏幕键盘弹出并与输入重叠,则输入将失去焦点,必须再次点击。但是,如果键盘不与输入重叠,则输入将保持其原始焦点。 iOS 上不会发生这种情况。
我注意到,当输入因键盘重叠而失去焦点时,会调用 onEndEditing
方法。
更新:将 FlatList
包装在 ScrollView
中可以修复它,无论出于何种原因,但显然这不是一个好的解决方案。
I have a very simple TextInput
component on a screen like and an onEndEditing
method like so:
<TextInput
style={Styles.input}
placeholder='testing placeholder'
placeholderTextColor={Colors.gray}
onEndEditing={this.onEndEditing}
selectionColor={Colors.darkCursor}>
</TextInput>
onEndEditing = async (event): Promise<void> => {
console.log('in update');
};
It is inside of a FlatList
which is wrapped in a KeyboardAvoidingView
.
On Android, when the TextInput
is tapped on and focused, if the onscreen keyboard pops up and overlaps the input, the input will lose focus and must be tapped on again. However, if the keyboard DOES NOT overlap the input, the input will keep its original focus. This does not happen on iOS.
I'm noticing that the onEndEditing
method is called when the input loses focus from the keyboard overlap.
Update: Wrapping the FlatList
in a ScrollView
fixes it for whatever reason, but obviously that is not a good solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论