Reputation: 163
I have created a custom drawer navigator using react navigation version: 5.X, But the current active tab is not getting highlighted in custom drawer menu.
Please find the below code images. And let me know in case I have made any mistake.
Navigator Code :
Custom Drawer Component :
Current Active Tab : Home
Upvotes: 7
Views: 10248
Reputation: 248
I used the custom focus i.e const focused = props.state.index; and used the map and style prop accordingly as activeTintColor,focused prop of that element was only working with the DrawerItemList only.
Upvotes: 0
Reputation: 136
You can use DrawerItemList to display the Drawer.Screen defined in Drawer.Navigator, as below:-
1) Define your Drawer Navigator:-
<Drawer.Navigator drawerContentOptions={{ activeBackgroundColor: '#5cbbff', activeTintColor: '#ffffff' }} drawerContent={props => <CustomDrawerContent {...props} />}>
<Drawer.Screen name="Home" component={HomeScreen} options={{
drawerIcon: config => <Icon
size={23}
name={Platform.OS === 'android' ? 'md-list' : 'ios-list'}></Icon>
}} />
/>
2) In CustomDrawerContent function:-
<DrawerContentScrollView {...props} >
----- your custom header ----
<DrawerItemList {...props} />
----- add other custom components, if any ----
</DrawerContentScrollView>
That solves the issue for me.
Upvotes: 11
Reputation: 573
@Vishal Tank add your styling in js file where your class function is define like that
class Home extends Component
{
....
static navigationOptions =
{
labelStyle: {
fontFamily: 'SomeFont',
color: 'white',
fontSize:24,
paddingLeft:8
},
drawerLabel: 'Home',
drawerIcon: ({tintColor}) =>
(
<Icon name="home" paddingLeft={8} color={tintColor} width={30} size={24} style={{color:tintColor}}/>
)
};
........
render()
{
return(
...........
);
};
};
here is the link, example give on it https://reactnavigation.org/docs/drawer-based-navigation/
Upvotes: 0