react-navigation - createBottomTabNavigator不工作

问题描述 投票:1回答:3

您好我正在使用expo制作一个本机应用程序。以下是我的app.js文件:

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import {createBottomTabNavigator} from 'react-navigation';
import WelcomeScreen from "./screens/WelcomeScreen";
import AuthScreen from "./screens/AuthScreen";

export default class App extends React.Component {
  render() {
    const MainNavigator = createBottomTabNavigator({
       Welcome: WelcomeScreen,
       Auth: AuthScreen
    });

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

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

以下是我的package.json文件:

{
  "main": "node_modules/expo/AppEntry.js",
  "private": true,
  "dependencies": {
    "expo": "^28.0.0",
    "react": "16.3.1",
    "react-native": "https://github.com/expo/react-native/archive/sdk-28.0.0.tar.gz",
    "react-navigation": "^2.6.2"
  }
}

该应用程序正在运行,没有任何错误,但它不显示底部导航选项卡!我也检查了官方文档中的语法,我担心它可能是由于react-navigation的版本。任何帮助,将不胜感激。

以下是我的welcomescreen组件文件:

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

class WelcomeScreen extends Component{
    render(){
        return(
            <View>
                <Text>
                    Hello this is working!
                </Text>
            </View>
        );
    }
}

export default WelcomeScreen;

除名称更改外,auth组件也相同。

javascript reactjs react-native react-navigation expo
3个回答
1
投票

版本不是问题。问题在于自定义StyleSheet<View/>组件

你可以View the edited app here

万一你想尝试使用你的应用程序包.json是:

{
  "dependencies": {
    "@expo/vector-icons": "6.2.1",
    "react-native-elements": "0.18.5",
    "react-navigation": "^2.6.2"
  }
}

和App.js是:

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { createBottomTabNavigator } from 'react-navigation'; // Version can be specified in package.json

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

class WelcomeScreen extends React.Component{
    render(){
        return(
            <View>
                <Text>
                    Hello this is working!
                </Text>
            </View>
        );
    }
}

export default class App extends React.Component {
    render() {
        const MainNavigator = createBottomTabNavigator({
            Auth: { screen: AuthScreen },
            Welcome: { screen: WelcomeScreen },
        });

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

        return <MainNavigator/>
    }
}

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

0
投票

尝试将堆栈导航器作为第一个屏幕,然后尝试加载欢迎屏幕和其他屏幕作为底部选项卡导航器,我在我的许多应用程序中使用此结构尝试此https://github.com/davekedar/React-Navigation-V2-Authflow


0
投票

我通过升级来解决这个问题

"react-navigation": "^2.13.0"
© www.soinside.com 2019 - 2024. All rights reserved.