最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - React Native How to prevent keyboard from dismissing on text submit? - Stack Overflow

programmeradmin4浏览0评论

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.

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.

Share Improve this question edited Dec 20, 2017 at 2:13 Max Phillips asked Dec 20, 2017 at 2:00 Max PhillipsMax Phillips 7,48911 gold badges48 silver badges72 bronze badges 1
  • Could you provide some code – Subramanya Chakravarthy Commented Dec 20, 2017 at 2:12
Add a comment  | 

1 Answer 1

Reset to default 24

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.

发布评论

评论列表(0)

  1. 暂无评论