Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native TextInput: no newline with hardware keyboard Enter key

We have a React Native TextInput component in our app. Using the virtual keyboard, pressing enter creates a new line. If we use a hardware keyboard (attached to an Android 6 tablet using an USB OTG adapter), the Enter key (the large one in the middle of the keyboard) doesn't change the text, the TextInput only loses the focus. The Return key (the smaller one on the right side of common keyboards) creates a new line.

The TextInput is setup very basic:

<TextInput multiline={true} />

I tried different values for the returnKeyType attribute, but none of them created a new line. Am I missing something?

like image 698
cweilguny Avatar asked Aug 23 '17 09:08

cweilguny


People also ask

How do you prevent new line when Enter is pressed in React Native?

You can setup your TextInput with multiline and blurOnSubmit to false. This will keep the keyboard and allow multiline in the input. And use the onKeyPress props only for sending a message. This should work in both Android and iOS.

How do I disable the keyboard in React Native TextInput?

The easiest solution is to use the onFocus prop on TextInput. Then pass Keyboard. dismiss() to TextInput onFocus prop, to stop the keyboard from popping up when focused.


1 Answers

You're welcome: blurOnSubmit={true}

like image 175
arled Avatar answered Sep 20 '22 14:09

arled