首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >react native:模式始终可见

react native:模式始终可见
EN

Stack Overflow用户
提问于 2020-07-08 01:42:51
回答 2查看 528关注 0票数 2

我知道有一个关于这个话题的问题,但是这并没有解决我的问题。我希望在按下“开始”按钮时呈现一个模式,但模式始终显示为这个红色框,而不是在我的显示器上弹出。有没有人可以帮我使模式只有在按下开始时才会呈现,这样模式

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

代码语言:javascript
运行
复制
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调用的。相关代码如下:

代码语言:javascript
运行
复制
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>
EN

回答 2

Stack Overflow用户

发布于 2020-07-10 10:25:04

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

票数 6
EN

Stack Overflow用户

发布于 2021-08-20 08:02:17

Modal现在已经在react-native-web中实现了,所以如果你遇到这个错误,你应该直接使用upgrade to > 0.14

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62781010

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档