我在 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/