思路:
1、用TouchableWithoutFeedback包裹Modal中的视图
2、transparent属性赋值为true
3、使用useState记录对话框开关状态
示例代码如下:
const [modalVisible, setModalVisible] = useState(false);
<Modal
animationType="fade"
transparent={true}
visible={modalVisible}
onRequestClose={() => {
setModalVisible(false);
}}>
<TouchableWithoutFeedback style={{ flex: 1 }} onPress={() => setModalVisible(false)}>
<View style={{ justifyContent: 'center', alignItems: 'center', flex: 1 }} >
<Text style={{backgroundColor:Colors.white}}>hello</Text>
</View>
</TouchableWithoutFeedback>
</Modal>