You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native中BottomTabNavigator无法显示求助(React Navigation 5)

Hey there, let's dig into why your BottomTabNavigator isn't showing up in the DrawerHome screen as expected. The core issue here is how you've structured your navigation layers—right now, your TabComp is set up as a separate screen in your root StackNavigator, but you actually need to nest it inside the DrawerHome component instead. Let's fix this step by step:

Step 1: Clean up your root StackNavigator

First, remove the standalone Tab screen from your root Stack, since we don't need it as a top-level route anymore:

const Stack = createStackNavigator();
export default class App extends React.Component {
  render() {
    return (
      <NavigationContainer>
        <Stack.Navigator headerMode="none" initialRouteName="HomePage">
          <Stack.Screen name="Home" component={HomePage} />
          <Stack.Screen name="Login" component={LoginSignUp} />
          <Stack.Screen name="DrawerScreenss" component={DrawerScreens} />
          {/* Remove the Tab screen entry here */}
        </Stack.Navigator>
      </NavigationContainer>
    );
  }
}

Step 2: Nest the TabNavigator inside DrawerHome

Next, move your tab navigation logic directly into the DrawerHome component. This ensures the tab bar renders whenever DrawerHome is active. Note: I've renamed the original DrawerHome content to HomeContent to avoid circular references (since you previously tried to use DrawerHome as a tab screen):

// DrawerHome.js
import React, { Component } from "react";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import HomeContent from "./HomeContent"; // Replace with your original DrawerHome content
import Bookmarks from "./Bookmarks";

const Tab = createBottomTabNavigator();

export default class DrawerHome extends Component {
  render() {
    return (
      <Tab.Navigator 
        initialRouteName="Home" 
        tabBarOptions={{
          activeTintColor: "#e91e63",
          inactiveTintColor: "grey",
          style: { backgroundColor: "white", borderTopColor: "red" },
          labelStyle: { fontSize: 12, fontWeight: "normal" },
          indicatorStyle: { borderBottomColor: "red", borderBottomWidth: 4 }
        }} 
      >
        <Tab.Screen name="Home" component={HomeContent} />
        <Tab.Screen name="Bookmarks" component={Bookmarks} />
      </Tab.Navigator>
    );
  }
}

Why this works

Your navigation structure now follows the correct nested hierarchy:
Root Stack → Drawer Navigator → DrawerHome → Bottom Tab Navigator

When you navigate to the DrawerScreenss route and select DrawHome from the drawer, the DrawerHome component will render the tab navigator, making the bottom tab bar visible as expected.

内容的提问来源于stack exchange,提问作者Talha Nadeem

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 14:47:35