[英]React Native prevent modal closing on overlay click
I have a Modal with a custom height which doesn't take up the entire screen.我有一个不占用整个屏幕的自定义高度的模态。 I would like to prevent the Modal from closing when the user clicks on the overlay or outside the Modal Container.
当用户单击覆盖层或模态容器外部时,我想防止模态关闭。 Below is a screen shot of how the modal displays
下面是模态显示方式的屏幕截图
I have wrapped the Modal Component around TouchableWithoutFeedback
and setting the Modal transparent to false
but it still closes when the user taps outside the Modal.我已经将模态组件包裹在
TouchableWithoutFeedback
周围,并将模态透明设置为false
,但是当用户在模态外部点击时它仍然会关闭。
Below is my current configurations of the Modal.以下是我当前的模态配置。
onShow = () => {
// performs slide in animation
this.animation();
};
return (
<Modal transparent visible={visible} onShow={this.onShow}>
<View
style={styles.flex}
onLayout={event => {
let {height: heightFull} = event.nativeEvent.layout;
this.setState({
height: getHeightView(heightFull, ratioHeight),
});
}}>
{* Modal Body * }
<Animated.View>
{* Some other content *}
</Animated.View>
{* End of Modal Body *}
</View>
</Modal>
)
I would use the react-native-modal package, with it's style set to margin: 0 and justifyContent: "flex-end".我会使用 react-native-modal package,它的样式设置为 margin: 0 和 justifyContent: "flex-end"。 Within this, I maintain a View with flex:1 and justifyContent: "flex-end".
在此,我使用 flex:1 和 justifyContent: "flex-end" 维护一个视图。 Then create the modal container (the white section) and wrap the children within TouchableWithoutFeedback inside this container.
然后创建模态容器(白色部分)并将子组件包裹在该容器内的 TouchableWithoutFeedback 中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.