Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to combine bottom tab navigator with drawer navigator

My tab below code is a bottom-tab navigator code and I want to display it on every screen by rendering it on app.js as I did for the drawer navigator (in simple words I want to call the bottom tab navigator on screen)

const Stack = createStackNavigator();
const Drawer = createDrawerNavigator();
let user1=""
let data=""
export function DrwaerNav(props) {


  
  if(props.route.params!=undefined){

    console.log('props arent undefined')


    
   
 user1=props.route.params.user.auth
 data=props.route.params.user.auth


  }


  return (

      <Drawer.Navigator initialRouteName="homeS"  drawerContent={(props) => <DrawerContent props={props} data={user1}/>}
      
      screenOptions={{
        headerStyle:{
          backgroundColor:'transparent',
          },
        headerTintColor:'black',
        headerTitleStyle:{
          fontWeight:'bold',
        }
      }}
      >
 
        <Drawer.Screen name="complaints" component={complaints} 
        options={{
          title:'Home',
          headerTitleAlign:'left',
          headerRight:()=>(
            <View style={{marginEnd:10,flexDirection:'row'}}> 
           <Text style={{paddingRight:15,paddingTop:13,fontWeight:"normal",}}>{user1.email}</Text>
            <Avatar.Image 
            source={{   uri:base64.decode(user1.avatar)}} 
            size={40}
            />
{/* <Text>Email:{user1.email}</Text> */}
            </View>
          ),
        }}/>

        <Drawer.Screen name="homeS" component={homeS} options={{
          title:'Home',
          headerTitleAlign:'left',
          headerRight:()=>(
            <View style={{marginEnd:10,flexDirection:'row'}}> 
           {/* <Text style={{paddingRight:15,paddingTop:13,fontWeight:"normal",fontSize:12,}}>{user1.email}</Text> */}
            <TouchableOpacity 
            onPress={()=>{
              props.navigation.navigate('Profile',data={data})
              }
            }>

            <Avatar.Image 
            source={{   uri:base64.decode(user1.avatar)}} 
            size={40}
            />
            </TouchableOpacity>
{/* <Text>Email:{user1.email}</Text> */}
            </View>
          ),
        }}/>
        <Drawer.Screen name="Updates" component={updates} 
        
        options={{
          title:'Home',
          headerTitleAlign:'left',
          headerRight:()=>(
            <View style={{marginEnd:10,flexDirection:'row'}}> 
           <Text style={{paddingRight:15,paddingTop:13,fontWeight:"normal",}}>{user1.email}</Text>
            <Avatar.Image 
            source={{   uri:base64.decode(user1.avatar)}} 
            size={40}
            />
{/* <Text>Email:{user1.email}</Text> */}
            </View>
          ),
        }}/>
        <Drawer.Screen name="userComplaints" component={userComplaints} 
        
        options={{
          title:'Home',
          headerTitleAlign:'left',
          headerRight:()=>(
            <View style={{marginEnd:10,flexDirection:'row'}}> 
           <Text style={{paddingRight:15,paddingTop:13,fontWeight:"normal",}}>{user1.email}</Text>
            <Avatar.Image 
            source={{   uri:base64.decode(user1.avatar)}} 
            size={40}
            />
{/* <Text>Email:{user1.email}</Text> */}
            </View>
          ),
        }}/>
        <Drawer.Screen name="GuestReg" component={Guest} 
       options={{
        title:'Home',
        headerTitleAlign:'left',
        headerRight:()=>(
          <View style={{marginEnd:10,flexDirection:'row'}}> 
         <Text style={{paddingRight:15,paddingTop:13,fontWeight:"normal",}}>{user1.email}</Text>
          <Avatar.Image 
          source={{   uri:base64.decode(user1.avatar)}} 
          size={40}
          />
{/* <Text>Email:{user1.email}</Text> */}
          </View>
        ),
      }}/>
        <Drawer.Screen name="myGuests" component={myGuest} 
        
        options={{
          title:'Home',
          headerTitleAlign:'left',
          headerRight:()=>(
            <View style={{marginEnd:10,flexDirection:'row'}}> 
           <Text style={{paddingRight:15,paddingTop:13,fontWeight:"normal",}}>{user1.email}</Text>
            <Avatar.Image 
            source={{   uri:base64.decode(user1.avatar)}} 
            size={40}
            />
{/* <Text>Email:{user1.email}</Text> */}
            </View>
          ),
        }}/>
        <Drawer.Screen name="Updateguest" component={Updateguest} 
        
        options={{
          title:'Home',
          headerTitleAlign:'left',
          headerRight:()=>(
            <View style={{marginEnd:10,flexDirection:'row'}}> 
           <Text style={{paddingRight:15,paddingTop:13,fontWeight:"normal",}}>{user1.email}</Text>
            <Avatar.Image 
            source={{   uri:base64.decode(user1.avatar)}} 
            size={40}
            />  
{/* <Text>Email:{user1.email}</Text> */}
            </View>
          ),
        }}/>



<Drawer.Screen name="updateprofile" component={updateprofile} 
        
        options={{
          title:'Update Profile',
          headerTitleAlign:'left',
          headerRight:()=>(
            <View style={{marginEnd:10,flexDirection:'row'}}> 
           <Text style={{paddingRight:15,paddingTop:13,fontWeight:"normal",}}>{user1.email}</Text>
            <Avatar.Image 
            source={{   uri:base64.decode(user1.avatar)}} 
            size={40}
            />  
{/* <Text>Email:{user1.email}</Text> */}
            </View>
          ),
        }}/>


        <Drawer.Screen name="Profile" component={Profile}  />
        
       
      </Drawer.Navigator>

      
  );
}

My drawer navigator is working fine I want to add a bottom tab navigator its code is below:

const Tab = createMaterialBottomTabNavigator();

function MyTabs() {
  return (
    <Tab.Navigator
     
      activeColor="#e91e63"
      barStyle={{ backgroundColor: 'tomato' }}
    >
      <Tab.Screen
        name="homes"
        component={DrwaerNav}
        options={{
          tabBarLabel: 'Home',
          tabBarIcon: ({ color }) => (
            <MaterialCommunityIcons name="home" color={color} size={26} />
          ),
        }}
      />
      <Tab.Screen
        name="Updates"
        component={updates}
        options={{
          tabBarLabel: 'Updates',
          tabBarIcon: ({ color }) => (
            <MaterialCommunityIcons name="bell" color={color} size={26} />
          ),
        }}
      />
      <Tab.Screen
        name="Profile"
        component={Profile}
        options={{
          tabBarLabel: 'Profile',
          tabBarIcon: ({ color }) => (
            <MaterialCommunityIcons name="account" color={color} size={26} />
          ),
        }}
      />
    </Tab.Navigator>
  );
}

export default function App() {
  return (
    <NavigationContainer>
      
    <Stack.Navigator initialRouteName="Login" screenOptions={{
        headerShown: false
      }}>
    {/* <Stack.Navigator initialRouteName="SignUp" headerShown="false"> */}
      <Stack.Screen name="Login" component={Login} />
      <Stack.Screen name="SignUp" component={SignUp} />
      <Stack.Screen name="dashboard" component={DrwaerNav} />  
    </Stack.Navigator>
    
    </NavigationContainer>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});
like image 985
Zeeshan Zamurd Attari Avatar asked Nov 15 '25 03:11

Zeeshan Zamurd Attari


1 Answers

Please try below code with basic setup

import React from 'react'
import {NavigationContainer} from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack'
import { createDrawerNavigator } from '@react-navigation/drawer'
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'
import { View, Text } from 'react-native'

const Stack = createStackNavigator()
const DrawerStack = createDrawerNavigator()
const BottomStack = createBottomTabNavigator()

// Drawer code
function AppDrawerStack() {
    return (
        <DrawerStack.Navigator drawerContent={props => <DrawerView {...props} />}>
            <DrawerStack.Screen name='AppBottomStack' component={AppBottomStack} />
        </DrawerStack.Navigator>
    )


}

function DrawerView() {
    return (
        <View>
            <Text>
                Drawer View
            </Text>
        </View>
    )
}

// Bottom Stack Part

function AppBottomStack() {
    return (
        <BottomStack.Navigator>
            <BottomStack.Screen
                name='BottomScreenOne'
                component={BottomScreenOne}

            />
            <BottomStack.Screen
                name='BottomScreenTwo'
                component={BottomScreenTwo}
            />
        </BottomStack.Navigator>
    )
}

function BottomScreenOne() {
    return (
        <View>
            <Text>
                BottomScreenOne
            </Text>
        </View>
    )
}

function BottomScreenTwo() {
    return (
        <View>
            <Text>
                BottomScreenTwo
            </Text>
        </View>
    )
}



export default function App() {
    return (
      <NavigationContainer>
        <Stack.Navigator>
            <Stack.Screen name="AppDrawerStack" component={AppDrawerStack} />
        </Stack.Navigator>
      </NavigationContainer>
    )
}

enter image description here

like image 70
Hardik Desai Avatar answered Nov 17 '25 19:11

Hardik Desai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!