On react-navigation
's DrawerNavigator
, is there a way to change the text color and background color for the item?
By default, the color scheme looks like the following:
Which is initialized by the following:
export const Drawer = DrawerNavigator({
dOne: {
screen: Screen1,
},
dTwo: {
screen: Screen2,
}
}
);
Setting the color
property within the screen's contentOptions
's style
does not appear to have an effect.
Should I extend new components for each row (labeled "Primary", "Secondary", etc. right now)? or is there an easier way to stylize the existing implementation of the rows?
You can render your custom label
:
import { DrawerItem } from '@react-navigation/drawer';
// ...
<DrawerItem label={() => <Text style={{ color: '#fff' }}>White text</Text>} />;
https://reactnavigation.org/docs/drawer-navigator/#providing-a-custom-drawercontent
A google search landed me here but the answer could not resolve my issue: I wanted to change the text color but have it switch between different colors depending on whether active and or inactive. Chnangin the colorin labelstyle effectively ensured the labels are the same color irrespective of the state. So I used the tint colors in content options of the drawer.
export const DrawerStack = DrawerNavigator(
{... /drawer items}
,
{
contentOptions: {
activeTintColor: colors.primary,
activeBackgroundColor: 'transparent',
inactiveTintColor: 'black',
inactiveBackgroundColor: 'transparent',
labelStyle: {
fontSize: 15,
marginLeft: 10,
},
},
drawerWidth: SCREEN_WIDTH * 0.7,
drawerOpenRoute: 'DrawerOpen',
drawerCloseRoute: 'DrawerClose',
drawerToggleRoute: 'DrawerToggle',
}
);
This way I can alternate colors depending on whether a drawer item is active or not using the activeTintColor and inactiveTintColor
options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With