在 React Native 中按下 Enter 键时如何禁用在多行 TextInput 中插入新行

use*_*568 5 textinput react-native

我想构建一个多行 TextInput 聊天应用程序,用户可以在按下 Enter 时发送消息。然而,似乎当用户按下 Enter 时,无论如何都会插入新行,这给用户带来了不好的体验。

我已经尝试过如何在react-native中按下回车键时防止换行,但在用户按键盘中的Enter键后,新行仍然存在。我还尝试在触发时修剪文本onChangeText,但似乎新行仍然插入。我知道它在 时有效blurOnSubmit=true,但我想在用户按 Enter 时保持键盘打开。

小智 7

只需将其添加到 TextInput ->blurOnSubmit={true}

例如:

<TextInput multiline={true} numberOfLines={1} blurOnSubmit={true} />
Run Code Online (Sandbox Code Playgroud)