I want to be able to hit the enter button on the keyboard, keep focus on the TextInput
, and keep the keyboard open. How can this be done?
The answers about ScrollView
implmentation refer to touching a button outside of the TextInput
as opposed to actually hitting the return key on the keyboard.
Use android:windowSoftInputMode="adjustResize". KeyboardAvoidingView and other keyboard-related components don't work quite well if you have "adjustPan" set for your android:windowSoftInputMode in AndroidManifest. xml . Instead, you should use "adjustResize" and have a wonderful life.
Method 2: Using ScrollView: We will make use of the ScrollView component along with the keyboardShouldPersistTaps='handled' attribute as the outermost view for our application. This will enable us to dismiss the keyboard whenever we tap on the screen apart from the buttons and text input regions.
You can dismiss the keyboard by using Keyboard. dismiss .
The way to do this on a TextInput
is to set blurOnSubmit={false}
and then use onSubmitEditing
as the submit handler instead of onEndEditing
.
onTextChange(input) {
this.setState({ value: input })
}
submitValue() {
// Do things with the value
...
// Then reset it so the TextInput can be reused
this.setState({ value: '' })
}
<TextInput
blurOnSubmit={false}
style={styles.inputBox}
onChangeText={input => this.onTextChange(input)}
onSubmitEditing={() => this.submitValue(this.state.value)}
value={this.state.value}
/>
On pressing of the return key this.setState({ value: '' })
to clear the text from the TextInput
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With