简体   繁体   中英

React Native Modal visible prop does nothing

Hello I am trying to put a simple react native modal in my react native app (running it on expo) but it is always visible. When I set the visible prop to false, it still displays. The relevant code is below:

Main Component

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>
    );
  }
}

package.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"
  },

Basically the modal is always displaying, even though visible is set to false. Am I missing something here?

I try many ways want to found the problem. The result is:

It seems couldn't work correct on "web site" show, but work on ios or Android emulator.

I try your code on Doc could work, but on sandbox(web site) couldn't.

Maybe you could change to try on other emulator or Expo except "web apps" like "expo ios" or "expo Android"?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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