首页 > 解决方案 > React Native Modal 可见 prop 什么都不做

问题描述

您好,我正在尝试在我的 react native 应用程序中放置一个简单的 react native 模态(在 expo 上运行它),但它始终可见。当我将 visible 道具设置为 false 时,它​​仍然显示。相关代码如下:

主要部件

import React, {Component} from 'react';
import {View, Text, Modal} from 'react-native';

class Home extends Component {
render() {
    return (
      <View>
        <Modal visible={false}>
          <Text>Test</Text>
        </Modal>
      </View>
    );
  }
}

包.json

"dependencies": {
    "expo": "~37.0.3",
    "react": "~16.9.0",
    "react-dom": "~16.9.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz",
    "react-native-web": "~0.11.7",
    "react-redux": "^7.2.0",
    "redux": "^4.0.5"
  },

基本上,模式总是显示,即使可见设置为 false。我在这里错过了什么吗?

标签: reactjsreact-nativereact-native-modal

解决方案


我尝试了很多方法想找到问题。结果是:

在“网站”节目上似乎无法正常工作,但在 ios 或 Android 模拟器上工作。

我在Doc上尝试您的代码可以工作,但在沙盒(网站)上却不能。

也许您可以更改以尝试除“expo ios”或“expo Android”之类的“网络应用程序”之外的其他模拟器或Expo?


推荐阅读