React Native如何防止键盘在文本提交时被解雇?

Phi*_*ews 4 javascript android ios react-native

我希望能够点击键盘上的输入按钮,保持对焦TextInput,并保持键盘打开.如何才能做到这一点?

关于ScrollView实施的答案是指触摸外部的按钮TextInput而不是实际敲击键盘上的返回键.

Phi*_*ews 9

在a上执行此操作的方法TextInput是设置blurOnSubmit={false}然后onSubmitEditing用作提交处理程序而不是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}
   />
Run Code Online (Sandbox Code Playgroud)

按下返回键this.setState({ value: '' })以清除文本TextInput.