在react-native中按下回车时如何防止换行 [英] How to prevent new line when enter is pressed in react-native
问题描述
对于多行文本输入,当用户按下回车键时,我想实现目标:
for a multiline textinput, when user press enter key, I want to achieve the goals:
- 当用户按下回车键时保持文本输入焦点.
- 防止添加新行.
我没有看到任何道具可以做到这一点,有人有想法吗?
i have't see any props what can do it, anyone has ideas?
react-native 版本为 0.28+,需要支持 ios 和 android.
react-native version is 0.28+, need supports ios and android.
推荐答案
在 TextInput 中传递 props
In TextInput passing the props
blurOnSubmit = {true}
然后在 onBlur 道具中使用 ref 聚焦 textInput 字段,这两个将阻止输入新行并且焦点保留在文本输入字段上.如果只想防止用户输入换行符 blurOnSubmit = {true}
就足够了
blurOnSubmit = {true}
and then in onBlur props focus the textInput field using ref,these two will prevents from entering a new line and the focus is retained on the text input field. If you want only to prevent the user from entering a newline blurOnSubmit = {true}
is sufficient
这里的缺点是您可以看到键盘隐藏一会儿然后弹出.它有点像一个黑客.希望有人能想出另一个或即兴创作
The drawback here is you can see keyboard hides for a moment then pops up. Its bit like a hack. Hope someone can come up with another or improvise this
这篇关于在react-native中按下回车时如何防止换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!