React Native Modal 可见道具什么都不做
React Native Modal visible prop does nothing
你好,我正在尝试在我的 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>
);
}
}
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"
},
基本上模式总是显示,即使 visible 设置为 false。我在这里遗漏了什么吗?
我试了很多方法想找到问题所在。结果是:
它似乎无法在 "web site" 节目上正常工作,但在 ios 或 Android 模拟器上可以正常工作。
我试过你的代码在 Doc 上可以工作,但在沙箱(网站)上不行。
也许你可以改用其他模拟器或 Expo 除了 "web apps",比如 "expo ios" 或 "expo Android"?
你好,我正在尝试在我的 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>
);
}
}
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"
},
基本上模式总是显示,即使 visible 设置为 false。我在这里遗漏了什么吗?
我试了很多方法想找到问题所在。结果是:
它似乎无法在 "web site" 节目上正常工作,但在 ios 或 Android 模拟器上可以正常工作。
我试过你的代码在 Doc 上可以工作,但在沙箱(网站)上不行。
也许你可以改用其他模拟器或 Expo 除了 "web apps",比如 "expo ios" 或 "expo Android"?