【问题标题】:Screen is not showing up while using nested navigators使用嵌套导航器时屏幕未显示
【发布时间】:2020-08-29 06:42:13
【问题描述】:

我想要标签导航器内的 4 个屏幕,并且只有堆栈导航器内的登录和注册屏幕以及我的主标签,因此我正在尝试使用嵌套导航器,我在堆栈导航器内有嵌套标签导航器,但是当我运行时软件,白屏如下:

我写的具体代码如下:

import React from 'react';
import 'react-native-gesture-handler';
import {StatusBar} from 'react-native';
import {NavigationContainer, DarkTheme} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';
import {createMaterialBottomTabNavigator} from '@react-navigation/material-bottom-tabs';
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialIcons';

import Home from '../screens/Home';
import Search from '../screens/Search';
import Library from '../screens/Library';
import ProfileAuthor from '../screens/ProffileAuthor';
import Shoot from '../screens/Shoot';
import LoginScreen from '../screens/LoginScreen';
import SignUp from '../screens/SignUp';

const Stack = createStackNavigator();
const Tab = createMaterialBottomTabNavigator();

function myTabs() {
  return (
    <Tab.Navigator
      initialRouteName="Home"
      activeColor="#000"
      inactiveColor="#000"
      barStyle={{
        backgroundColor: '#FFF',
      }}>
      <Tab.Screen
        name="Home"
        component={Home}
        options={{
          title: 'Home',
          tabBarLabel: 'Home',
          tabBarIcon: ({color}) => (
            <MaterialCommunityIcons color={color} name="home" size={26} />
          ),
        }}
      />
      <Tab.Screen
        name="Search"
        component={Search}
        options={{
          title: 'Search',
          tabBarLabel: 'Search',
          tabBarIcon: ({color}) => (
            <MaterialCommunityIcons color={color} name="search" size={26} />
          ),
        }}
      />
      <Tab.Screen
        name="Upload"
        component={Shoot}
        options={{
          title: 'Upload',
          tabBarLabel: 'Upload',
          tabBarIcon: ({color}) => (
            <MaterialCommunityIcons color={color} name="add-box" size={26} />
          ),
        }}
      />
      <Tab.Screen
        name="Library"
        component={Library}
        options={{
          title: 'Library',
          tabBarLabel: 'Library',
          tabBarIcon: ({color}) => (
            <MaterialCommunityIcons
              color={color}
              name="person-outline"
              size={26}
            />
          ),
        }}
      />
    </Tab.Navigator>
  );
}

const Routes = () => {
  return (
  
      <NavigationContainer theme={DarkTheme}>
        <Stack.Screen
          name="login"
          component={LoginScreen}
          options={{
            header: () => null,
          }}
        />
        <Stack.Screen
          name="signup"
          component={SignUp}
          options={{
            header: () => null,
          }}
        />
        <Stack.Screen
          name="Home"
          component={myTabs}
          options={{
            header: () => null,
          }}
        />
        <Stack.Screen
          name="Video"
          component={ProfileAuthor}
          options={{
            header: () => null,
          }}
        />
      </NavigationContainer>
   
  );
};


export default Routes;

谁能告诉我哪里出错了?任何帮助都会很棒,谢谢。

【问题讨论】:

    标签: reactjs react-native react-navigation react-navigation-v5 react-navigation-bottom-tab


    【解决方案1】:

    我错过了添加 一个非常愚蠢的错误,但解决了。

    所以在 Routes 内部的代码应该是

    const Routes = () => {
      return (
        <NavigationContainer theme={DarkTheme}>
          <Stack.Navigator>
            <Stack.Screen
              name="login"
              component={LoginScreen}
              options={{
                header: () => null,
              }}
            />
            <Stack.Screen
              name="signup"
              component={SignUp}
              options={{
                header: () => null,
              }}
            />
            <Stack.Screen
              name="Home"
              component={myTabs}
              options={{
                header: () => null,
              }}
            />
            <Stack.Screen
              name="Video"
              component={ProfileAuthor}
              options={{
                header: () => null,
              }}
            />
          </Stack.Navigator>
        </NavigationContainer>
      );
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-26
      • 2022-01-22
      • 2023-04-02
      • 1970-01-01
      • 2021-08-29
      • 1970-01-01
      相关资源
      最近更新 更多