I have created header component and i want to open drawer from there

Viewed 199

I have created header component and i want to open drawer from header component from icon click, currently swipe is opening drawer. please help if anyone know what is the issue

this is my app js code where i created drawer navigator

<NavigationContainer>
          <Drawers.Navigator drawerContent={props => <Drawer {...props} />} >
            <Drawers.Screen
                  name="Home"
                  component={Home}
                  initialParams={({navigation}) => {
                    return{
                      headerTitle:() => <HomeHeader navigation={navigation}/>,
                    }
                  }}
                  
              />
            <Drawers.Screen
                name="Orders"
                component={Orders}
                
                
            />
             <Drawers.Screen
                name="Account"
                component={Account}
            />
            
        </Drawers.Navigator>
    </NavigationContainer>
     

and this is my header component where i was trying to navigation.openDrawer

export default function HomeHeader({navigation}) {
    const openMenu = () => {
        navigation.openDrawer();
    }
    return (
        <View style={GlobalStyle.hheader} >
            <View style={GlobalStyle.mainMenu} >
                <Icon type="material" name="menu" size={26} color="black" onPress={openMenu} />
            </View>
            <View style={GlobalStyle.near} >
                <Text style={GlobalStyle.nTitle}>Your Location</Text>
                <Text style={GlobalStyle.nLocate}>Mehran Town <Icon   iconStyle={{ marginBottom:-1, }} name='chevron-down' size= {16}  type='font-awesome' color='#000' 
    /></Text>
            </View>
            
        </View>
    )
}

and finally draweritem code

<DrawerItem 
                        
                        label="Profile"
                        onPress={() => {props.navigation.navigate('Account')}}
                        labelStyle={{color: '#000', fontSize:15}}
                                                  
                        icon={() => (
                            <Icon 
                            name='account-circle'
                            type='material'
                            color='#4285F4'
                            size={18}
                            
                            />
                        )}
                    />
                <DrawerItem 
                        
                        label="Orders"
                        onPress={() => {props.navigation.navigate('Orders')}}
                        labelStyle={{color: '#000', fontSize:15}}
                        navigation={props.navigation}
                        icon={() => (
                            <Icon 
                            name='receipt'
                            type='material-icons'
                            color='#4285F4'
                            size={18}
                            
                            />
                        )}
                    />
         </View>
         
1 Answers

I don't think headerTitle is place for you return custom header menu.

My suggestion you can render customer header in each screen content and using navigation.openDrawer(); or try create wrapper view for Drawer and render header first. Or create BaseScreen with your custom header and inheritance for each your screen. But headerTitle I don't think it work.

Related