react-navigation icon indicating copy to clipboard operation
react-navigation copied to clipboard

Cannot set bottomTabNavigator background to transparent ( other hex values work ).

Open itsyogesh opened this issue 8 years ago • 5 comments

Current behaviour

Background color for react-navigation bottomTabNavigator doesn't change to transparent even with custom styles.

Expected behaviour

Background color should change to transparent for bottomTabNavigator

Code sample

Here is the code for the navigator

const MainTabNavigator = createBottomTabNavigator(
  {
    Dashboard: DashboardStackNavigator,
    Map: MapStackNavigator,
    Explore: ExploreStackNavigator
  },
  {
    style: { backgroundColor: 'rgba(0, 0, 0, 0)' },
    tabBarComponent: (props) => <BottomTabComponent {...props} />
  }
)

Here is the code for the custom TabComponent

class BottomTabComponent extends Component {

  render () {
    const { navigation, onTabPress } = this.props
    console.log(this.props)
    return (
      <Container style={styles.mainContainer}>
        <Image
          style={styles.blurShadow}
          source={BlurShadow}
          resizeMode='contain'
        />
        <Svg height='82' width='375'>
          <Path
            d='M0,33.5390625 C62.6402995,26.5130208 125.140299,23 187.5,23 C249.859701,23 312.359701,26.5130208 375,33.5390625 L375,82 L0,82 L0,33.5390625 Z'
            fill='#fff'
            stroke='none'
          />
        </Svg>
        <Container style={styles.tabContainer}>
          {
            navigation.state.routes.map((route, index) => {
              switch (route.routeName) {
              case 'Dashboard':
                return <DashboardTab key={route.routeName} route={route} onTabPress={onTabPress} isSelected={index === navigation.state.index} />

              case 'Map':
                return <MapTab key={route.routeName} route={route} onTabPress={onTabPress} isSelected={index === navigation.state.index} />

              case 'Explore':
                return <ExploreTab key={route.routeName} route={route} onTabPress={onTabPress} isSelected={index === navigation.state.index} />

              default:
                return null
              }
            })
          }

        </Container>
      </Container>
    )
  }
}

Screenshots (if applicable)

image

What have you tried

I have tried setting it to transparent in both the navigator and the customTabComponent, while it work with other colors, I am not able to set it to transparent.

Your Environment

software version
ios or android ios
react-native 0.55.4
react-navigation 2.9.3
node 10.6.0
yarn 1.9.2

itsyogesh avatar Aug 08 '18 00:08 itsyogesh

I was able to solve this by using absolute position for customTabComponent. For anyone looking into this, here is the style that I used:

{
    position: 'absolute',
    bottom: 0,
    left: 0
}

itsyogesh avatar Aug 09 '18 00:08 itsyogesh

Would you please tell me how you solved this problem?

ajangi avatar Jun 07 '19 15:06 ajangi

Would you please tell me how you solved this problem?

nguyenductoan1995 avatar Sep 03 '19 06:09 nguyenductoan1995

@nguyenductoan1995 I just set the properties in style prop

  position: 'absolute',
  bottom: 0,
  left: 0,
  width: '100%',
  height: 50,

this makes the parent (that have the white bg) lose its height and become 'transparent'

linconkusunoki avatar Sep 03 '19 13:09 linconkusunoki

@linconkusunoki But this will affect the bottom of other components. Eg If you have a scrollView then it will not consider the tab bar as bottom and will span to the screen end. See here: https://imgur.com/0zIzko0

mukeshsharma1201 avatar Sep 30 '19 10:09 mukeshsharma1201