I am using React Navigation with React Native. This is on Android.
I am trying to add some spacing between the icon and the top of the tab bar and reduce the spacing between icon and the label.
I am trying to change the bottom border color ie Yellow line.
I am trying to reduce the spacing, padding left and right inside each cell.
Any idea how I can achieve this?
{
tabBarPosition: 'bottom',
animationEnabled: true,
swipeEnabled: true,
tabBarOptions: {
showIcon: true,
labelStyle: {
fontSize: 8
},
style: {
backgroundColor: 'grey',
},
tabStyle: {
height: 49
},
iconStyle: {
flexGrow: 0,
marginTop: 1.5
}
}
}
Usually tabs don't just display one screen — for example, on your Twitter feed, you can tap on a tweet and it brings you to a new screen within that tab with all of the replies. You can think of this as there being separate navigation stacks within each tab, and that's exactly how we will model it in React Navigation.
tabBarIcon is a supported option in bottom tab navigator. So we know we can use it on our screen components in the options prop, but in this case chose to put it in the screenOptions prop of Tab.Navigator in order to centralize the icon configuration for convenience. tabBarIcon is a function that is given the focused state, color, and size params.
You should be warned, however, that you may run into some frustrating unanticipated issues when doing this. For example, React Navigation's tab navigator takes care of handling the Android back button for you, while standalone components typically do not.
You get a navigation prop for your tabBar which you can use instead: The following options can be used to configure the screens in the navigator. These can be specified under screenOptions prop of Tab.navigator or options prop of Tab.Screen. Generic title that can be used as a fallback for headerTitle and tabBarLabel.
Regarding the first problem about the spacing between the icon and the top of the tab bar you can add padding to the tabStyle
property in tabBarOptions
:
tabBarOptions: {
tabStyle: {
paddingVertical: 5
}
}
For reducing the space between the icon and the label, you can add some padding or margin to your Icon
object:
tabBarIcon: ({ tintColor }) => {
return <Icon containerStyle={{ marginTop: 6 }} name="map" size={25} color={tintColor} />;
},
About the problem with the active Yellow line on Android, you can change the background color property to be transparent
or set 0
for height:
tabBarOptions: {
indicatorStyle: {
height: 0
}
}
And for the last problem about the problem about the space between the cells, I don't think that there is a solution for now.
You can try to make the navigation smaller ( for example: width: '80%'
)... this will set the cells closer to each other... but I have never tried that and I am not sure is it a good solution ;)
To change the distance between the icon and the top of the bar (Question 1 as of react-navigation 4.x), add padding to tabStyle inside tabBarOptions:
tabBarOptions: {
tabStyle: {
paddingBottom: 8,
paddingTop: 8,
}
}
Try the indicatorStyle config option:
tabBarOptions: {
indicatorStyle: {
backgroundColor: 'transparent'
}
}
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