我正在使用这个模块,问题是弹出的对话框元素(Modal)有两个TouchableOpacity按钮。在输入后,当键盘弹起时,单击“提交”TouchableOpacity将首先清除/隐藏键盘,只有第二次点击“提交”TouchableOpacity才会触发onPress事件。在这里,我该怎么办?我已经尝试将其从
react-native
和react-native-elements
更改为Button,但它的行为方式相同。
编辑:
组件:
return (
<Modal
animationType="fade"
transparent={true}
visible={this.props.isDialogVisible}
onRequestClose={() => {
this.props.closeDialog();
this.setState({ inputModal: "" });
}}
>
<View style={[styles.container, { ...modalStyleProps }]}>
<TouchableOpacity
style={styles.container}
activeOpacity={1}
onPress={() => {
this.props.closeDialog();
this.setState({ inputModal: "", openning: true });
}}
>
<View style={[styles.modal_container, { ...dialogStyleProps }]}>
<View style={styles.modal_body}>
<Text style={styles.title_modal}>{title}</Text>
<Text
style={[
this.props.message ? styles.message_modal : { height: 0 }
]}
>
{this.props.message}
</Text>
<TextInput
style={styles.input_container}
autoCorrect={
textProps && textProps.autoCorrect == false ? false : true
}
autoCapitalize={
textProps && textProps.autoCapitalize
? textProps.autoCapitalize
: "none"
}
clearButtonMode={
textProps && textProps.clearButtonMode
? textProps.clearButtonMode
: "never"
}
clearTextOnFocus={
textProps && textProps.clearTextOnFocus == true
? textProps.clearTextOnFocus
: false
}
keyboardType={
textProps && textProps.keyboardType
? textProps.keyboardType
: "default"
}
autoFocus={true}
onKeyPress={() => this.setState({ openning: false })}
underlineColorAndroid="transparent"
placeholder={hintInput}
onChangeText={inputModal => {
if (this.props.setBackupCommentText) {
this.props.setBackupCommentText(inputModal);
}
this.setState({ inputModal });
}}
value={value || this.props.backupCommentText}
multiline={true}
/>
</View>
<View style={styles.btn_container}>
<TouchableOpacity
style={styles.touch_modal}
onPress={() => {
this.props.closeDialog();
this.setState({ inputModal: "", openning: true });
}}
>
<Text style={styles.btn_modal_left}>{cancelText}</Text>
</TouchableOpacity>
<View style={styles.divider_btn}></View>
<TouchableOpacity
style={styles.touch_modal}
onPress={() => {
if (
this.props.initValueTextInput &&
this.props.initValueTextInput.trim().length === 0
) {
Toast.show("Comment cannot be empty");
} else {
this.props.submitInput(value);
this.setState({ inputModal: "", openning: true });
if (this.props.setBackupCommentText) {
this.props.setBackupCommentText("");
}
}
}}
>
<Text style={styles.btn_modal_right}>{submitText}</Text>
</TouchableOpacity>
</View>
</View>
</TouchableOpacity>
</View>
</Modal>
);