question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add customizable icon size for BottomNavigation

See original GitHub issue

Current behaviour

Icons are fixed at size 24 in BottomNavigation.

Expected behaviour

Add a prop to support custom icon sizes.

Code sample

I’m using react-navigation-material-bottom-tabs which in turn uses this library. If I specify icon sizes greater than 24, the labels render in the center of the icon instead of below (see screenshot below).

let iconSize = sizes.h2;
let iconContainerStyle = [s.aic, {width: iconSize, height: iconSize}];

this.tabNav = createMaterialBottomTabNavigator(
  {
    Docs: { screen: Docs,
      navigationOptions: {
        tabBarLabel: 'Docs',
        tabBarIcon: ({ tintColor }) => (<View style={iconContainerStyle}><Icon style={[{color: tintColor}]} size={iconSize} name={'document'}/></View>),
        gesturesEnabled: false,
      }
    },
    Add: { screen: Add/>,
      navigationOptions: {
        tabBarLabel: 'Add',
        tabBarIcon: ({ tintColor }) => (<View style={iconContainerStyle}><Icon style={[{color: tintColor}]} size={iconSize} name={'add'}/></View>),
        gesturesEnabled: false,
      }
    },
    Search: { screen: Add/>,
      navigationOptions: {
        tabBarLabel: 'Search',
        tabBarIcon: ({ tintColor }) => (<View style={iconContainerStyle}><Icon style={[{color: tintColor}]} size={iconSize} name={'search'}/></View>),
        gesturesEnabled: false,
      }
    },
    Profile: { screen: Profile,
      navigationOptions: {
        tabBarLabel: 'Profile',
        tabBarIcon: ({ tintColor }) => (<View style={iconContainerStyle}><Icon style={[{color: tintColor}]} size={iconSize} name={'user'}/></View>),
        gesturesEnabled: false,
      }
    },
  },
  {
    initialRouteName: 'Manifest',
    stateName: props.name,
    activeTintColor: lightColors.primaryButtonFontColor,
    inactiveTintColor: lightColors.secondaryColor,
    barStyle: [navBackground, s.h4],
  }
);

Screenshots (if applicable)

What have you tried

Different icon sizes. Only renders properly if icon size is 24, the fixed size set in BottomNavigation.js. https://github.com/callstack/react-native-paper/blob/master/src/components/BottomNavigation.js#L895

Your Environment

software version
ios or android ios and android
react-native 0.55
react-native-paper 1.11.0
node 6
npm or yarn 4.5

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
peacechencommented, Aug 13, 2018

As explained in the OP, the icon size is fixed at 24: https://github.com/callstack/react-native-paper/blob/master/src/components/BottomNavigation.js#L895

The label and labelContainer styles use fixed sizes as well. Looks like the labelContainer size is too small and truncates letters that extend below the baseline.

The labelContainer should not have a fixed height. It will size automatically to the font size.

It would be great if the icon size and label font size were configurable via props.

3reactions
satya164commented, Aug 13, 2018

If you have a bigger icon and label size, everything should automatically adapt to that size. Shouldn’t be hard to implement.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to increase icon size in android bottom navigation layout?
The size of the icon is 24dp; It has 0dp padding. Note: you can use a custom icon if you wish to do...
Read more >
Bottom navigation - Material Design
Bottom navigation bars display three to five destinations at the bottom of a screen. Each destination is represented by an icon and an...
Read more >
Android BottomNavigationView: Change Icon Size
NOTE: Default icon size is 24dp . Edit res/values/dimens.xml to avoid icon overlap with text.
Read more >
Creating a Bottom Navigation Bar with Custom Icons in ...
In this video I'm going to show you how to create a bottom navigation with custom colours and icons. You can add whatever...
Read more >
Flutter - Custom Bottom Navigation Bar - GeeksforGeeks
Now add 4 buttons in the children list of the Row add all the required arguments. Some required arguments are Icon, onTap callback, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found