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.

Bottom Navigation active background visible for multiple screens.

See original GitHub issue

Current behaviour

When I click on a different screen I get Navigated to that page and it’s background becomes highlighted, however, the background of the previous tab is still highlighted.

Expected behaviour

The background of non active tabs should not be highlighted.

Code sample

import React from 'react';
import {createMaterialBottomTabNavigator} from '@react-navigation/material-bottom-tabs';
import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
import {Dashboard} from '../pages/Dashboard';
import {Statistics} from '../pages/Statistics';
import {Settings} from '../pages/Settings';

const Tab = createMaterialBottomTabNavigator();

export const NavigationBar = () => {
  return (
    <Tab.Navigator initialRouteName="Home">
      <Tab.Screen
        name="Home"
        component={Dashboard}
        options={{
          tabBarLabel: 'Home',
          tabBarIcon: ({color}) => (
            <MaterialIcons name="home" color={color} size={26} />
          ),
        }}
      />
      <Tab.Screen
        name="Statistics"
        component={Statistics}
        options={{
          tabBarLabel: 'Statistics',
          tabBarIcon: ({color}) => (
            <MaterialIcons name="bar-chart" color={color} size={26} />
          ),
        }}
      />
      <Tab.Screen
        name="Settings"
        component={Settings}
        options={{
          tabBarLabel: 'Settings',
          tabBarIcon: ({color}) => (
            <MaterialIcons name="settings" color={color} size={26} />
          ),
        }}
      />
    </Tab.Navigator>
  );
};

Screenshots (if applicable)

What have you tried

I have tried testing the code given in snack, but it didn’t worked

Your Environment

software version
ios or android ios 16.0
react-native v0.70.0
react-native-paper v5.0.0-rc.5
node v16.17.0
npm or yarn v1.22.19
expo sdk Using native cli

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rakshit087commented, Sep 18, 2022

Okay, I will create one.

0reactions
abdullahkhan70commented, Sep 22, 2022

I hope it will fix your problem.

import React from 'react';
import {createMaterialBottomTabNavigator} from '@react-navigation/material-bottom-tabs';
import {NavigationContainer} from '@react-navigation/native';
import MaterialIcons from 'react-native-vector-icons/MaterialIcons';

const Tab = createMaterialBottomTabNavigator();

 <NavigationContainer independent={true}>
      <Tab.Navigator
        initialRouteName={screen.HOME}
        activeColor={colors.offWhite}
        inactiveColor={colors.primaryDarkColor}
        barStyle={{backgroundColor: '#694fad', }}
        backBehavior={'history'}>
        <Tab.Screen
          name={screen.HOME}
          component={Home}
          options={({navigation}) => ({
            tabBarColor: colors.homeScreenColor,
            tabBarLabel: tabNames.homeTabName,
            tabBarIcon: ({color, focused}) => (
        <MaterialIcons name="bar-chart" color={color} size={26} />
            ),
          })}
        />
</Tab.Navigator>
</NavigationContainer>

You just need to add a “tabBarColor” props in the “Tab.Screen” component. This will dynamically, change the background color of the selected Bottom Tab item.

By the way, which “@react-navigation/material-bottom-tabs” version are you using in your application?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Keep the bottom navigation bar in every screens flutter
Create a stateful widget to hold the list of all possible views, current index of the view to be displayed and the bottom...
Read more >
Bottom Tabs Navigator | React Navigation
A simple tab bar on the bottom of the screen that lets you switch between different routes. Routes are lazily initialized -- their...
Read more >
BottomNavigationBar class - material library - Dart API
A material widget that's displayed at the bottom of an app for selecting among a small number of views, typically between three and...
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 >
Bottom Tab Navigator - Thunkable Docs
Active Tint Color. Select a text color for the tab currently in use. Color. Active Background Color ; Navigation Button Name. Text that...
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