React Native Modal Not Closing

React Native Modal Not Closing

本文关键字:Closing Not Modal Native React      更新时间:2023-09-26

我正在我的iOS应用程序中覆盖以下Modal组件,同时等待几个异步请求回来。

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

this.state。一旦所有请求都返回,Visible被设置为false。然而,大约有50%的时间,即使在请求返回之后,模态仍然无限期地留在屏幕上。我已经在我的渲染函数的顶部记录了this.state.visible,正如预期的那样,它是假的,但模态并没有消失。你知道为什么会这样吗?

也许这和我现在面临的问题是一样的。

当关闭一个模态并打开另一个模态时,我得到这个问题,有些人正在使用模态和警报…

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

目前,解决方案是在操作之前超时(600ms应该可以解决)。

现在有一个简单的解决方案,在再次显示对话框之前,首先,使用时间延迟使其不可见,然后再次显示对话框

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

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

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