admin管理员组文章数量:1429190
This is the official react-native modal documentation and this is a live example for iOS and Android.
How can I add a clickable backdrop overlay which is over my view and under the modal?
This is the official react-native modal documentation and this is a live example for iOS and Android.
How can I add a clickable backdrop overlay which is over my view and under the modal?
Share Improve this question asked May 27, 2020 at 8:53 Dimitri KopriwaDimitri Kopriwa 14.5k33 gold badges117 silver badges232 bronze badges4 Answers
Reset to default 3You can wrap the Modal content in a Touchable Opacity and style it with a background. I edited the sample given in the documentation.
<Modal
animationType="slide"
transparent={true}
visible={modalVisible}
onRequestClose={() => {
Alert.alert('Modal has been closed.');
}}>
<TouchableOpacity
style={{ backgroundColor: 'black', flex: 1,justifyContent:'center' }}
onPress={() => setModalVisible(!modalVisible)}>
<View style={styles.modalView}>
<Text style={styles.modalText}>Hello World!</Text>
<TouchableHighlight
style={{ ...styles.openButton, backgroundColor: '#2196F3' }}
onPress={() => {
setModalVisible(!modalVisible);
}}>
<Text style={styles.textStyle}>Hide Modal</Text>
</TouchableHighlight>
</View>
</TouchableOpacity>
</Modal>
React Native Elements has a fantastic ponent called Overlay
that would solve your problem. It saved me earlier this week. The only issue is that it is part of a larger library.
https://react-native-elements.github.io/react-native-elements/docs/overlay.html
I think if the separation between the backdrop and your modal is not crucial to your project, you can handle it like this:
<Modal
animationType="slide"
transparent={true}
style={{ width: '100%', alignSelf: 'center', height: '100%', justifyContent: 'flex-start' }}
visible={this.state.modalVisible}
onRequestClose={() => {
// Do smth
}}>
<TouchableWithoutFeedback style={{ flex: 1 }} onPress={() => {
// Do the backdrop action
}}>
<View style={{ backgroundColor: '#fff', flex: 1, width: '80%', height: '50%' }} >
<Text> Your content </Text>
</View>
</TouchableWithoutFeedback>
</Modal>
<Modal
animationType="slide"
transparent={true}
visible={modalVisible}
onRequestClose={() => {
Alert.alert('Modal has been closed.');
}}>
// Touchable Opacity
<TouchableOpacity
style={{ position: 'absolute' , flex: 1 }}
onPress={() => setModalVisible(!modalVisible)} />
<View style={styles.modalView}>
// Other..
<View>
design
</View>
</Modal>
本文标签: javascriptHow to add a backdrop clickable overlay on official reactnative ModalStack Overflow
版权声明:本文标题:javascript - How to add a backdrop clickable overlay on official react-native Modal? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745473040a2659836.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论