【发布时间】:2019-08-05 17:48:27
【问题描述】:
我已经制作了聊天应用程序,每当我按下 textInput 右侧的发送按钮时,键盘就会关闭。我想在发送按钮(检查按钮)按下键盘。
这是代码示例,请检查。
class MessageForm extends React.Component {
constructor() {
super();
this.handleMessageChange = message => {
this.props.updateMessage(message);
};
this.handleButtonPress = () => {
this.props.sendMessage(this.props.message, this.props.receiver.uid);
};
}
componentDidUpdate(prevProps) {
if (!prevProps.sendingError && this.props.sendingError) {
Alert.alert('Error', this.props.sendingError);
}
}
render() {
const sending = this.props.sending;
const isButtonDisabled = sending || this.props.message.trim().length === 0;
return (
<View style={styles.container}>
<TextInput
style={styles.textInput}
placeholder={'Write something ...'}
placeholderTextColor={Colors.textColorLight}
returnKeyType="send"
onChangeText={this.handleMessageChange}
value={this.props.message}
underlineColorAndroid={'transparent'}
editable={!sending}
/>
<TouchableOpacity
style={styles.button}
onPress={this.handleButtonPress}
onBlur={() => this.input.focus()}
disabled={isButtonDisabled}>
<CustomIcon
vectorIcon
name="checkcircle"
type="antdesign"
size={40}
color={Colors.messageSendButtonColor}
/>
</TouchableOpacity>
</View>
);
}
}
【问题讨论】:
-
了解如何显示键盘,然后在发送后立即执行。
-
做到了,但它关闭然后打开键盘。显然不好看。
-
在这种情况下您需要共享代码。消息输入字段是否始终呈现?您如何处理发送按钮上的点击?等等。如果发送只是清除输入,我认为键盘不应该消失,所以它一定是你正在做的事情。
-
我不确定点击处理是否重要,我只是调用一个api将数据保存到服务器。
-
不提供代码是“关闭问题”的原因之一,所以现在我不确定我还能告诉你什么。即使点击处理无关紧要,您仍然遇到此问题但没有提供任何代码供我们查看。我们究竟应该如何提供帮助?随便猜?