javascript - react native : iOS dictation unable to clear text input

标签 javascript ios react-native

我在 React Native 应用程序中有一个非常基本的 TextInput + Button 组合,用于编写和发送消息,如下所示:

<TextInput
    type="text"
    ref={input => {
       this.inputRef = input;
    }}
    style={styles.userInput}
    name="userInput"
    autoCorrect={false}
    placeholder="Type something..."
    autoFocus={false}
    autoComplete="off"
    onChangeText={this.watchInput}
    returnKeyType="done"
/>

<Button
    disabled={!this.state.isValidInput}
    style={styles.sendButton}
    title="Send"
    textStyle={{fontSize: 12}}
    onPress={this.handleSubmit}
    accessibilityLabel="Press this button to send your message"
/>

当按下按钮时,我使用handleSubmit函数来处理输入字段的消息发送和重置,如下所示:

handleSubmit = async () => {
   const message = this.state.input; // get input from state

   Keyboard.dismiss() // hide keyboard
   this.inputRef.clear(); // clear TextInput
   this.setState({ input: '' }); // reset input state
   this.setState({ isValidInput: false }); // reset input state
   this.stretchInputField()
   var r = await this.props.myAwesomeSendMessageFunction() // send message
 }

当使用实际的按钮进行发送时,这工作得很好,但如果我在 iOS 键盘中使用听写,它会在我说完时发送消息,但输入字段不会被清除,所以我' m 在字段中留下与处理程序已发送的相同输入。

有什么想法为什么它会像听写一样工作以及如何让它在发送时清除输入字段吗?

React Native 版本 0.57.8

最佳答案

您是否在文本输入中绑定(bind)了您的值?

尝试在文本输入中绑定(bind)您的输入,例如 value ={this.state.input}

关于javascript - react native : iOS dictation unable to clear text input,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54927329/

相关文章:

iOS 12 无故终止后台应用

react-native - RabbitMQ React Native 发送示例

javascript - 整个 div 正在删除而不是图像

ios - CloudKit 查询出现奇怪错误

iphone - 如何在 MKMapView 上的用户当前位置添加 UIImageView

ios - 如何在我的设备上而不是在 iPhone 6 模拟器中运行我的 React Native 应用程序?

reactjs - 可以在没有连接的情况下调度操作吗?

javascript - 定义的静态方法未定义

javascript - D3 强制引导未捕获类型错误

javascript - 定期触发 React 效果