I’m trying to adjust space between icon and text in drawer screen.
Here’s an image to explain better.
Here’s my code
<Drawer.Navigator screenOptions={(navigation) => ({
drawerItemStyle: {
borderRadius: 0,
width: '100%',
marginLeft: 0
}
})}>
<Drawer.Screen
name="HomeScreen"
component={HomeScreen}
options={{
headerShown: true,
headerTransparent: true,
headerTitle: "",
title: 'Start Delivery',
drawerIcon: (({focused}) => <Icon name="car" size={25} color={focused ? "#288df9" : "#777"} style={{padding:0, margin:0}} />)
}}
/>
</Drawer.Navigator>
Thanks
2
Answers
The default
Drawer
uses aDrawerItemList
which is a list of DrawerItems. Looking at the source code, the view that wraps the label implements amarginLeft
of32
. This is hardcoded and cannot be changed without using dirty tricks.Let us test this using the following example.
The above uses a
View
as a dummy image with a red background. Here is the result.Adding a
marginRight
of-32
to our icon removes the "gap" completely.Here is the result.
This is not ideal since we have to do this for each icon, thus we could create a custom component and reuse it.
Then, use it for each screen.
There is a second way. We could create a custom drawer. This would allow us to not use the
DrawerItem
component but a custom component with custom stylings.Another option that solves that problem as well is to use negative
marginLeft
directly in the Text rendered inside every list Item. You can reach this solution usingdrawerLabelStyle
property inside option prop as is showed below: