如果键盘与 Android 上的 TextInput 重叠,TextInput 将失去焦点

发布于 2025-01-16 18:57:32 字数 795 浏览 5 评论 0原文

我在屏幕上有一个非常简单的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文