Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native How to prevent keyboard from dismissing on text submit?

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.

like image 216
Phil Andrews Avatar asked Dec 20 '17 02:12

Phil Andrews


People also ask

How do you control what keyboard pushes up react native?

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.

How do I hide the keyboard in react native?

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.

How do you close keyboard on button click in react native?

You can dismiss the keyboard by using Keyboard. dismiss .


1 Answers

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.

like image 108
Phil Andrews Avatar answered Sep 21 '22 12:09

Phil Andrews