gpt4 book ai didi

javascript - 在框外单击时尝试关闭 react-native modal

转载 作者:行者123 更新时间:2023-11-30 07:52:24 25 4
gpt4 key购买 nike

所以我目前可以在框外单击时关闭模态,但问题是当我在框内单击时它仍然会关闭。我尝试添加 pointerEvents="none",但似乎不起作用。

这是我的代码:

<View>
<Modal
animationType="slide"
transparent={true}
style={{width: '100%', alignSelf: 'center', height: '100%', justifyContent: 'flex-start', backgroundColor:'green'}}
visible={this.state.modalVisible}
onRequestClose={() => {
alert('Modal has been closed.');
}}>
<TouchableWithoutFeedback onPress={() => {
this.setModalVisible(!this.state.modalVisible);
}}>
<View style={{ backgroundColor: 'red', flex: 1}} >

<View pointerEvents="none" style={{alignSelf: 'center', width: '80%', height: '50%', backgroundColor: 'purple', top: 100}}>
<Text pointerEvents="none" >Hello World!</Text>


</View>

</View>
</TouchableWithoutFeedback>
</Modal>
</View>

最佳答案

/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/

import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View,
TouchableOpacity,
Modal,
TouchableWithoutFeedback
} from 'react-native';

const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' +
'Cmd+D or shake for dev menu',
android: 'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});

type Props = {};
export default class App extends Component<Props> {
constructor(props) {
super(props)
this.state = { modalVisible: true }
}
setModalVisible(modalVisible) {
this.setState({ modalVisible })
}
render() {
return (
<View>
<Modal
animationType="slide"
transparent={true}
style={{ width: '100%', alignSelf: 'center', height: '100%', justifyContent: 'flex-start', backgroundColor: 'green' }}
visible={this.state.modalVisible}
onRequestClose={() => {
alert('Modal has been closed.');
}}>
<TouchableWithoutFeedback onPress={() => {
this.setModalVisible(!this.state.modalVisible);
}}>
<View style={{ backgroundColor: 'red', flex: 1 }} >
<TouchableWithoutFeedback onPress={() => { }}>
<View style={{ alignSelf: 'center', width: '80%', height: '50%', backgroundColor: 'purple', top: 100 }}>
<Text>Hello World!</Text>
</View>
</TouchableWithoutFeedback>
</View>
</TouchableWithoutFeedback>
</Modal>
</View>
);
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});a

关于javascript - 在框外单击时尝试关闭 react-native modal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49782698/

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