在 React Native 中关闭多行 TextInput 中的键盘 [英] Dismiss keyboard in multiline TextInput in React native

查看:30
本文介绍了在 React Native 中关闭多行 TextInput 中的键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户在多行 TextInput 中按下 Return 键时,将创建一个新行并且键盘继续可见.如何在 React Native 中为多行 TextInput 关闭键盘?

When the user presses the Return key in a multiline TextInput, a new line is created and the keyboard continues to be visible. How should the keyboard be dismissed for multiline TextInput in React native?

我做了一些研究.我发现单击 TextInput 外部的 View 不会模糊 TextInput,这会导致键盘保持可见.

I did some research. I found that clicking on the View outside the TextInput does not blur the TextInput, which is causing the keyboard to remain visible.

<View style={styles.container}>
  <TextInput
    placeholder="To"
    style={styles.input}
    value={this.state.to}
    onChangeText={(to) => this.setState({to})}
  />
  <TextInput
    placeholder="Text"
    style={styles.textarea}
    multiline={true}
    numberOfLines={4}
    value={this.state.text}
    onChangeText={(text) => this.setState({text})}
  />
</View>

对于 ScrollView,有一个道具 - keyboardShouldPersistTaps 会导致 TextInput 模糊.View 是否有任何等价物?我希望多行 TextInput 模糊,以便关闭键盘.

For ScrollView, there is a prop - keyboardShouldPersistTaps which causes the TextInput to blur. Is there any equivalent of that for View? I want the multiline TextInput to blur so that the keyboard gets dismissed.

推荐答案

TextInput 有一个 blurOnSubmit 道具;设置为 true 时,返回键会关闭键盘.

TextInput has a blurOnSubmit prop; when set to true, the return key dismisses the keyboard.

但是目前该道具在 Android 上不起作用.我已经发布了一个关于这个主题的问题:https://github.com/facebook/react-native/issues/8778

However currently the prop does not work on Android. I've posted an issue on the subject: https://github.com/facebook/react-native/issues/8778

这篇关于在 React Native 中关闭多行 TextInput 中的键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆