简体   繁体   English

反应本机模式未关闭

[英]React Native Modal Not Closing

I'm overlaying the following Modal component in my iOS app while waiting for several async requests to come back.在等待几个异步请求返回时,我在我的 iOS 应用程序中覆盖了以下Modal组件。

<Modal transparent={true} visible={this.state.visible}>
    <View style={{flex: 1}}>
        <ActivityIndicator color="white" size="large"/>
    </View>
</Modal>

this.state.visible is set to false once all the requests have returned.一旦所有请求都返回,this.state.visible 设置为 false。 However, about 50% of the time the modal remains on the screen indefinitely, even after the requests have come back.然而,大约 50% 的时间模态会无限期地保留在屏幕上,即使在请求返回之后也是如此。 I've logged this.state.visible at the top of my render function and it is false as expected, yet the modal does not disappear.我已经在我的渲染函数顶部记录了 this.state.visible 并且它是错误的,但模态不会消失。 Any thoughts as to why this may be happening?关于为什么会发生这种情况的任何想法?

Perhaps it was the same problem I'm facing here.也许这与我在这里面临的问题相同。

I get this problem when closing one modal and opening another, some people are getting this with a modal and an alert...我在关闭一个模态并打开另一个时遇到这个问题,有些人通过模态和警报来解决这个问题......

https://github.com/facebook/react-native/issues/10471 https://github.com/facebook/react-native/issues/10471

For now, the solution is a timeout before the action (600ms should solve it).目前,解决方案是在操作之前超时(600 毫秒应该解决它)。

A simple solution for now, before showing the dialog again, first, make it invisible with time delay, then show the dialog again现在一个简单的解决方案,在再次显示对话框之前,首先将其延迟不可见,然后再次显示对话框

this.setState({
    showPopUp: false,
  }, () => {
    let timer = setTimeout(() => {
      this.setState({
        showPopUp: true,
      });
    }, 300);
  })

您可以使用 react-native-paper 模式。

import { Modal } from 'react-native-paper';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM