gpt4 book ai didi

react-native - 如何通过在 React Native 中点击模态主体来隐藏模态

转载 作者:行者123 更新时间:2023-12-04 17:46:39 30 4
gpt4 key购买 nike

我已经编写了一个代码来在用户单击模态中的“隐藏我”文本时隐藏模态,但我也希望当我们在模态外单击时隐藏模态。我可以使用“TouchableWithoutFeedback”,但它对我不起作用。我如何为此使用“TouchableWithoutFeedback”或任何其他解决方案?

this.state = {
showPopupModal: false
}
hideModal(){
this.setState({showPopupModal: false});
}
showModal(){
this.setState({showPopupModal: true});
}

return(
<Conatiner>
<View>
<TouchableOpacity onPress={() => { showModal(); }}>
<Text> open modal <Text>
</TouchableOpacity>
</View>

<Modal visible={this.state.showPopupModal}>
<View>
<TouchableOpacity onPress={() => { hideModal(); }}>
<Text> hide me </Text>
</TouchableOpacity>
</View>
</Modal>
</Container>
);

最佳答案

您必须设置 Modal 的 isVisible 和 onBackdropPress 属性,例如:

  <Modal isVisible={this.state.showPopupModal} onBackdropPress={() => this.hideModal()} >
..
</Modal>

关于react-native - 如何通过在 React Native 中点击模态主体来隐藏模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48207237/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com