Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set transparent BG of Tab Navigator Screen #8076

Closed
chasepoirier opened this issue Apr 20, 2020 · 17 comments
Closed

Unable to set transparent BG of Tab Navigator Screen #8076

chasepoirier opened this issue Apr 20, 2020 · 17 comments

Comments

@chasepoirier
Copy link

Current Behavior
I'm not able to set the background color of the Tab Navigator screen to transparent, it instead shows the default gray background. I can set the tabbar component to transparent as seen in the screenshot (the color behind the tab navigator is black), but the screen does not do the same.

Screen Shot 2020-04-19 at 7 48 23 PM

  • current code
import React from "react";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import { View, Text } from "react-native";
import { NavigationContainer } from "@react-navigation/native";

const Tab = createBottomTabNavigator();

const Component = () => {
  return (
    <View
      style={{
        flex: 1,
        backgroundColor: "transparent",
        justifyContent: "center",
        alignItems: "center"
      }}>
      <Text>Component</Text>
    </View>
  );
};

export default function MockTabStack() {
  return (
    <NavigationContainer>
      <Tab.Navigator
        tabBarOptions={{
          style: {
            backgroundColor: "transparent"
          }
        }}>
        <Tab.Screen component={Component} name="Initial" />
      </Tab.Navigator>
    </NavigationContainer>
  );
}

Expected Behavior

When setting the background to transparent for the tab navigator screen, it should show the color below the navigator (black in this case).

How to reproduce

  • Set the background style to "transparent" for the screen

Your Environment

software version
@react-navigation/native 5.1.6
@react-navigation/bottom-tabs 5.2.7
react-native-screens 2.5.0
react-native 0.61.2
node 10.16.3
@ozerty
Copy link

ozerty commented May 8, 2020

Hi, any news about this one ?

Thanks

@ShivamJoker
Copy link

I am screwed too
image
Can someone please help ?

@bartekkaminski
Copy link

bartekkaminski commented Jun 7, 2020

@ShivamJoker

Add elevation: 0

The code below will make a transparent Bottom Bar

<NavigationContainer>
  <Tab.Navigator tabBarOptions={{
    style: {
      backgroundColor: 'transparent',
      position: 'absolute',
      borderTopWidth: 0,
      elevation: 0,
    }
  }}>
    <Tab.Screen name="Home" component={Home} />
    <Tab.Screen name="Second" component={Second} />
  </Tab.Navigator>
</NavigationContainer>

@ShivamJoker
Copy link

@ShivamJoker

Add elevation: 0

The code below will make a transparent Bottom Bar

<NavigationContainer>
  <Tab.Navigator tabBarOptions={{
    style: {
      backgroundColor: 'transparent',
      position: 'absolute',
      borderTopWidth: 0,
      elevation: 0,
    }
  }}>
    <Tab.Screen name="Home" component={Home} />
    <Tab.Screen name="Second" component={Second} />
  </Tab.Navigator>
</NavigationContainer>

Thanks this works we should close the issue now :)

@steventeague
Copy link

Hi,

This issue remains, as the OP stated the BG colour can't not be set on the screen ( not the bar ) it is always the default grey. Having a requirement to make the background transparent to overlay over native screens means this is broken.

@crrobinson14
Copy link

Not sure if this is the same issue holding this ticket open, but I was able to address this with sceneContainerStyle={{backgroundColor: 'transparent'}} in my <Tab.Navigator element.

@piesrtasty
Copy link

piesrtasty commented Sep 29, 2020

@chasepoirier @crrobinson14 This took me hours to figure out. I had to go into the actual package to see how the styles were being applied.

This is for react-navigation Version 5.x. I can't speak for previous versions.

But the only way to change the background color of the actual tab views that are for each scene in the bottom tab navigator is to pass a theme into the top level NavigationContainer component where you specify transparent for colors.background

import { NavigationContainer } from "@react-navigation/native";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";

const Tab = createBottomTabNavigator();

const theme = {
    colors: {
      background: "transparent",
    },
  };

<NavigationContainer theme={theme}>
     <Tab.Navigator>
          <Tab.Screen component={ComponentA} name="A" />
          <Tab.Screen component={ComponentB} name="B" />
     </Tab.Navigator>
</NavigationContainer>

In the above example ComponentA and ComponentB the screens for each of the tabs will have transparent backgrounds.

Hope this helps! 😄

@mvrdrew
Copy link

mvrdrew commented Oct 9, 2020

@LukeHamilton Thanks for that suggestion, I've tried out it and it works but it breaks other components in the hierarchy so it's still not a 100% solution.

@crrobinson14 I've had a look for that setting, but it doesn't exist in bottom-tabs, only on drawerNavigator and materialTopTabNavigator.

It seems like that's the ideal prop for this situation though, has it been left off bottom-tabs for a reason or has it just been overlooked in the v5 rewrite? It does seem very odd that there's no way to change the background colour of tab screens like you can in other navigators.

@mvrdrew
Copy link

mvrdrew commented Oct 9, 2020

I thought I'd have a go at implementing sceneContainerStyle into the bottom-tabs navigator. It's partially based on the drawer implementation, so you can still use a theme but also override using this prop's styles.

Before I submit a PR, I thought I'd put it up here first to see if there's any glaring errors I've made.

(see PR below - have submitted it under my personal account)

If any maintainers see this, I'd be really keen to hear their feedback and if it's worth continuing with.

satya164 added a commit that referenced this issue Oct 23, 2020
This feature adds the sceneContainerStyle prop to the bottom-tabs navigator, to allow setting styles on the container's view. It's already implemented in the material-top-tabs and drawer navigators, I've simply ported it into the bottom-tabs navigator.

It also fixes this issue:

#8076

Co-authored-by: Satyajit Sahoo <satyajit.happy@gmail.com>
@mvrdrew
Copy link

mvrdrew commented Oct 25, 2020

This ticket can be closed now this PR has been merged.

@bondansebastian
Copy link

@ShivamJoker

Add elevation: 0

The code below will make a transparent Bottom Bar

<NavigationContainer>
  <Tab.Navigator tabBarOptions={{
    style: {
      backgroundColor: 'transparent',
      position: 'absolute',
      borderTopWidth: 0,
      elevation: 0,
    }
  }}>
    <Tab.Screen name="Home" component={Home} />
    <Tab.Screen name="Second" component={Second} />
  </Tab.Navigator>
</NavigationContainer>

You saved my life buddy.

YAfullStack pushed a commit to YAfullStack/React-navigation that referenced this issue Dec 4, 2021
This feature adds the sceneContainerStyle prop to the bottom-tabs navigator, to allow setting styles on the container's view. It's already implemented in the material-top-tabs and drawer navigators, I've simply ported it into the bottom-tabs navigator.

It also fixes this issue:

react-navigation/react-navigation#8076

Co-authored-by: Satyajit Sahoo <satyajit.happy@gmail.com>
redhawkIT pushed a commit to redhawkIT/react-navigation that referenced this issue Dec 23, 2021
This feature adds the sceneContainerStyle prop to the bottom-tabs navigator, to allow setting styles on the container's view. It's already implemented in the material-top-tabs and drawer navigators, I've simply ported it into the bottom-tabs navigator.

It also fixes this issue:

react-navigation/react-navigation#8076

Co-authored-by: Satyajit Sahoo <satyajit.happy@gmail.com>
darkhorse-coder pushed a commit to darkhorse-coder/react-navigation that referenced this issue Apr 7, 2022
This feature adds the sceneContainerStyle prop to the bottom-tabs navigator, to allow setting styles on the container's view. It's already implemented in the material-top-tabs and drawer navigators, I've simply ported it into the bottom-tabs navigator.

It also fixes this issue:

react-navigation/react-navigation#8076

Co-authored-by: Satyajit Sahoo <satyajit.happy@gmail.com>
nenad0212 pushed a commit to nenad0212/temp1 that referenced this issue Sep 6, 2022
This feature adds the sceneContainerStyle prop to the bottom-tabs navigator, to allow setting styles on the container's view. It's already implemented in the material-top-tabs and drawer navigators, I've simply ported it into the bottom-tabs navigator.

It also fixes this issue:

react-navigation/react-navigation#8076

Co-authored-by: Satyajit Sahoo <satyajit.happy@gmail.com>
@predbjorn
Copy link

predbjorn commented May 29, 2023

@ShivamJoker
Add elevation: 0
The code below will make a transparent Bottom Bar

<NavigationContainer>
  <Tab.Navigator tabBarOptions={{
    style: {
      backgroundColor: 'transparent',
      position: 'absolute',
      borderTopWidth: 0,
      elevation: 0,
    }
  }}>
    <Tab.Screen name="Home" component={Home} />
    <Tab.Screen name="Second" component={Second} />
  </Tab.Navigator>
</NavigationContainer>

Thanks this works we should close the issue now :)

Works on v6.x too:

       tabBarStyle: {
            backgroundColor: 'transparent',
            position: 'absolute',
            borderTopWidth: 0,
            elevation: 0,
        },
    }}      

@github-actions
Copy link

Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro.

@Lakshya-Katarmal
Copy link

@ShivamJoker

Add elevation: 0

The code below will make a transparent Bottom Bar

<NavigationContainer>
  <Tab.Navigator tabBarOptions={{
    style: {
      backgroundColor: 'transparent',
      position: 'absolute',
      borderTopWidth: 0,
      elevation: 0,
    }
  }}>
    <Tab.Screen name="Home" component={Home} />
    <Tab.Screen name="Second" component={Second} />
  </Tab.Navigator>
</NavigationContainer>

this worked for me.
Thanks @ShivamJoker

@aliciabarczak
Copy link

For anyone who is struggling and none of the above worked, this is what worked for me:

<Tab.Navigator
  screenOptions={({ route }) => ({
    ...
    tabBarStyle: [{
      backgroundColor: 'transparent',
      position: 'absolute',
      borderTopWidth: 0,
      elevation: 0,
    }],
  })}>

@ToxicoFR
Copy link

For anyone who is struggling and none of the above worked, this is what worked for me:

<Tab.Navigator
  screenOptions={({ route }) => ({
    ...
    tabBarStyle: [{
      backgroundColor: 'transparent',
      position: 'absolute',
      borderTopWidth: 0,
      elevation: 0,
    }],
  })}>

Thanks!!

@abuayaan-01
Copy link

Not sure if this is the same issue holding this ticket open, but I was able to address this with sceneContainerStyle={{backgroundColor: 'transparent'}} in my <Tab.Navigator element.

Thanks a lot I have been putting this inside ScreenOptions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests