Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TabNavigator extra padding

How to style the TabNavigator Tab's height and padding? Im doing the following:

import Icon from "react-native-vector-icons/MaterialIcons";
const tabNav = TabNavigator({
  TabItem1: {
      screen: MainScreen,
      navigationOptions: {
          tabBarLabel:"Home",
          tabBarIcon: ({ tintColor }) => <Icon name={"home"} size={20} color={tintColor} />
      }
    },
    TabItem2: {
      screen: MainScreen,
      navigationOptions: {
        tabBarLabel:"Home",
        tabBarIcon: ({ tintColor }) => <Icon name={"home"} size={30} color={tintColor}  />
      }
    },
    TabItem3: {
      screen: MainScreen,
      navigationOptions: {
        tabBarLabel:"Browse",
        tabBarIcon: ({ tintColor }) => <Icon name={"home"} color={tintColor} />
      }
    }
}, {
    tabBarPosition: 'bottom',
    tabBarOptions: {
        activeTintColor: '#222',
        activeBackgroundColor :'yellow',  //Doesn't work
        showIcon: true,
        tabStyle: {
            padding: 0, margin:0,   //Padding 0 here
        },
    iconStyle: {
        width: 30,
        height: 30,
        padding:0       //Padding 0 here
    },
    }
});

enter image description here

How do I get rid of the padding between the icon and the label? I did padding:0 in iconStyle and also in tabStyle but no luck. I want no padding below the label too. How do I do that? Thanks.

Found the extra padding is caused by View: enter image description here

How do i get rid of that?

like image 434
Somename Avatar asked Oct 18 '17 16:10

Somename


People also ask

How do you use useBottomTabBarHeight?

Android (correct height) useBottomTabBarHeight to return the correct height so I can use it as the bottom margin of my container view. Just create an empty react native app with a bottom tab navigator and try to use the useBottomTabBarHeight to set the bottom margin of the container view.

How do you style the tab bar in react native?

Add icons to the tab bar To add icons to each tab, first import the Icon component from react-native-vector-icons library inside the navigation/TabNavigator/index. js file. For this example, let's use AntDesign based icons. // after other import statements import Icon from 'react-native-vector-icons/AntDesign';

How do I increase the bottom tab height in react native?

With react navigation 6 you can just use: tabBarStyle : { height: 150, ... }


3 Answers

Solved by setting:

tabBarOptions: {
  labelStyle: {
    margin: 0
  },
}
like image 136
Denis Avatar answered Nov 19 '22 09:11

Denis


Try just style under tabBarOptions

  tabBarOptions: {
    style: {
      height: 45
    }
  }
like image 37
Rami Enbashi Avatar answered Nov 19 '22 10:11

Rami Enbashi


Unfortunately plenty of layout settings are hardcoded in this lib (like padding: 12 for tab which comes by default from elsewhere).

The only option is to look in node_modules\react-navigation\lib\views\TabView\ files and adjust as needed to your requirements.

Right now I'm hacking those sourses to find a quick-n-dirty way to allow rectangular (x>y), not only square (x=y, as defaulted) tab icons.

Other option is to create your custom tabBar component as maintainers suggest

like image 29
Alex Green Avatar answered Nov 19 '22 08:11

Alex Green