简体   繁体   English

在react-native中使用react-navigation时的空白视图

[英]Blank view when i use react-navigation in react-native

I have a problem, when i use TabNavigator on 'react-navigation'. 我在“反应导航”上使用TabNavigator时遇到问题。 The problem is my screen show the blank view. 问题是我的屏幕显示空白视图。

this is my code: 这是我的代码:

App.js App.js

      import React from 'react';
  import { StyleSheet, Text, View } from 'react-native';
  import { TabNavigator } from 'react-navigation';

  import AuthScreen from './screens/AuthScreen';
  import WelcomeScreen from './screens/WelcomeScreen';

  export default class App extends React.Component {
    render() {
      const MainNavigator = TabNavigator({
        welcome: { screen: WelcomeScreen },
        auth: { screen: AuthScreen }
      });

      return (
        <View style={styles.container}>
          <MainNavigator />
        </View>
      );
    }
  }

  const styles = StyleSheet.create({
    container: {
      flex: 1,
      backgroundColor: '#fff',
      alignItems: 'center',
      justifyContent: 'center',
    },
  });

WelcomeScreen.js WelcomeScreen.js

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

  class WelcomeScreen extends React.Component {
    render() {
      return (
        <View>
          <Text>WelcomeScreen</Text>
          <Text>WelcomeScreen</Text>
          <Text>WelcomeScreen</Text>
          <Text>WelcomeScreen</Text>
          <Text>WelcomeScreen</Text>
          <Text>WelcomeScreen</Text>
        </View>
      );
    }
  }

  export default WelcomeScreen;

AuthScreen.js Like WelcomeScreen.js 像WelcomeScreen.js一样的AuthScreen.js

I hope you can help me,thanks 我希望你能帮助我,谢谢

Because your styles on App.js. 因为您的样式在App.js上。 Remove alignItems: "center" 删除alignItems: "center"

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    justifyContent: 'center',
  },
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 react-native 和 react-navigation 上使用反应钩子 - How to use react hooks on react-native with react-navigation 嗨,我正在使用 react-native 和 react-navigation - hi i'm using react-native and react-navigation 如何在 react-navigation 中使用独立的 Header 和 react-native? - How do I use standalone Header in react-navigation with react-native? 使用react-navigation在React-Native中的DrawerNavigator中出现问题 - Problems in DrawerNavigator in React-Native with react-navigation 具有react-navigation的React-Native Handle推送通知 - React-Native Handle push notification with react-navigation 如何在 React-navigation/react-native 中隐藏后退按钮 - how to hide back button in React-navigation/react-native React-Native —如何使用react-navigation传递参数? - React-Native — How to pass parameters using react-navigation? 在反应本地/反应导航应用程序中存储全局状态? - Storing global state in react-native/react-navigation app? 反应本机启动屏幕和反应导航 - React-native splash screen and react-navigation React-Native:组件仅在使用react-native-navigation或react-navigation时在加载的最后一个选项卡上正常工作 - React-Native: components only working properly on the last tab loaded in when using react-native-navigation or react-navigation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM