javascript - react 原生 : modal always visible

标签 javascript react-native react-native-modal

我知道有关于此主题的问题,但这并没有解决我的问题。我希望在按下“开始”按钮时呈现模式,但模式始终显示为这个红色框,而不是弹出我的显示器。有人可以帮我制作它,以便模态仅在按下“开始”时呈现,并且模态

enter image description here

我的模态在 signUpModal.js 中定义为:

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


const SignUpModal = (props) => (

    <Modal 
        isVisible={props.display}
        animationType={'slide'}
        onRequestClose={() => console.log('closed')}
    >
        <View style={{ flex: 1 }}>
        <Text>I am the modal content!</Text>
        <Button title="Hide modal" />
        </View>
    </Modal>
);
    
export default SignUpModal;

我的模态是从 HomePage.js 调用的。相关代码如下:

import React, {Component} from 'react';
import {StyleSheet, Text, View, Button, Image} from 'react-native';
import Swiper from 'react-native-swiper/src';
import { LinearGradient } from 'expo-linear-gradient';


import SignUpModal from '../modals/signUpModal';

export default class HomePage extends Component {
  
  constructor(props) {
    super(props);
    this.state = {
      isModalVisible: false
    };
  }

 
  toggleModal = () => {
    this.setState({isModalVisible: !this.state.isModalVisible});
  };

 render() {
   return (
    <Swiper
    loop={false}
    showsPagination={false}
    index={0}
    showsButtons = {true}
    >
     <View style={styles.container}>
      <LinearGradient colors={['rgba(14, 25, 39, 0.5)', 'rgba(11, 19, 27, 0.8)']} style={styles.container}>
       <Text style={styles.welcome}>Invest In Your Favorite Players</Text>
       <Text style={styles.instructions}>{subtitle}</Text>
       <Button title = "Get Started" onPress = {this.toggleModal} style={{width:150, height:50}}/>
       <SignUpModal
          display = {this.state.isModalVisible}
       />
       <Image
          style={{ width: 335, height: 356 }}
          source={require('../assets/images/PSHomePageMobile.png')}
        />
      </LinearGradient>
     </View>

最佳答案

这显然是在 web 上显示时 react-native-modal 的一个已知问题。相反,使用 modal-enhanced-react-native-web组件工作。

关于javascript - react 原生 : modal always visible,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62781010/

相关文章:

javascript - 如何使用 jQuery 在按钮单击时触发事件

javascript - 从功能上将整数分成 block

javascript - 为什么scope.$watch不起作用?

javascript - React native paper TextInput in Modal,输入一个字符后光标向后闪烁

javascript - 具有分页功能的 Dojo 增强型网格需要访问页面中的行数

firebase - Firestore 文档获取请求 promise 未解决。我该如何解决这个问题?

react-native - 在 react-navigation 中使用 react-redux connect 方法显示错误 "The component for route ' x' must be a React component

javascript - 无法使用 EventListener 对未安装的组件执行 React 状态更新

react-native - 如何在 native react 中打开半模态?

react-native - React Native 模态 : Transparent Background & Layout Problem