Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Navigation Bottom TabBar Icon Spacing

I am using React Navigation with React Native. This is on Android.

  1. 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.

  2. I am trying to change the bottom border color ie Yellow line.

  3. 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
      }
    }
  }

BottomTabBar

like image 862
Kelvin Avatar asked Jul 10 '17 10:07

Kelvin


People also ask

How do tabs work in react navigation?

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.

How to use tabbaricon in Bottom TaB navigator?

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.

Should I use React or standalone components for back button navigation?

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.

How to add a navigation prop for a Tabbar?

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.


3 Answers

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 ;)

like image 96
Hristo Eftimov Avatar answered Sep 24 '22 15:09

Hristo Eftimov


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,
    }
}
like image 34
Dr. Younes Henni Avatar answered Sep 21 '22 15:09

Dr. Younes Henni


Try the indicatorStyle config option:

tabBarOptions: {

    indicatorStyle: {
      backgroundColor: 'transparent'
    }
}
like image 35
Francesco Avatar answered Sep 23 '22 15:09

Francesco