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

Missing tabbar shadow on Android

Open jwhscholten opened this issue 9 years ago • 27 comments

Current Behavior

I'm not seeing an elevation shadow under my tabbar on Android. I've tried using elevation as style property.

        tabBarOptions: {
            activeTintColor: AppStyles.color.secondary,
            inactiveTintColor: Platform.OS === 'ios' ? '#BBBBBB' : '#000000',
            upperCaseLabel: false,
            showIcon: true,
            indicatorStyle: { opacity: 0 },
            labelStyle: {
                fontFamily: AppStyles.fontFamily.medium,
                fontSize: AppStyles.fontSize.small,
                marginBottom: 8
            },
            style: {
                paddingTop: 4,
                backgroundColor: '#fff',
                height: 57,

                ...Platform.select({
                    android: {
                     elevation: 3
                    }
                })
            }
        }, 

Expected Behavior

I'd expect to see a drop shadow behind my tabbar based on elevation value.

Your Environment

software version
react-navigation 1.0.0-beta.11
react-native 0.43.2
node
npm or yarn

jwhscholten avatar Jul 19 '17 09:07 jwhscholten

Can you sent us a screenshot?

Do you use a StackNavigator into a TabNavigator ?

jonathanroze avatar Jul 19 '17 12:07 jonathanroze

Current rendering on Android: tabbar_noshadow

Desired effect: tabbar

The TabNavigator is inside a StackNavigator.

jwhscholten avatar Jul 19 '17 12:07 jwhscholten

Hi, i have the same issue. Any ideas to fix this? My TabNavigator is the Root navigator.

programmende avatar Jul 19 '17 21:07 programmende

I have another problem, on iOS I am trying to remove this top shadow and I cannot do that, anyone managed to do this ?

azghibarta avatar Jul 20 '17 13:07 azghibarta

+1 having the same issue for "normal" tab screens aswell as tab screens which are themselves StackNavigators

phillipwinder avatar Jul 20 '17 23:07 phillipwinder

Vou ficar esperando uma resposta também, no meu caso o TabBar é Top (padrão android), mas isso é o de menos.

ghost avatar Aug 03 '17 22:08 ghost

try:

tabBarOptions: {
	style: {				
		elevation: 4,
		marginBottom: 5
	}
}

ryam4u avatar Aug 08 '17 04:08 ryam4u

None is working for me. I tried elevation in both style and tabStyle. None was helpful.

megamind2301 avatar Aug 11 '17 12:08 megamind2301

Hi! In an effort to get the hundreds of issues on this repo under control I'm closing issues tagged as questions. Please don't take this personally - it's simply something we need to do to get the issues to a manageable point. If you still have a question I encourage you to re-read the docs, ask on StackOverflow, or ask on the #react-navigation Reactiflux channel. Thank you!

spencercarli avatar Aug 28 '17 02:08 spencercarli

This is what worked for me.

tabBarOptions: {
    style: {				
        paddingBottom: 2,
    }
}

I know the look isn't the same as a shadow, but for me this worked better.

rootedsoftware avatar Aug 31 '17 18:08 rootedsoftware

Any update regarding this, I am using 0.48 and elevation is not working?

YasirSherzad avatar Oct 15 '17 11:10 YasirSherzad

Elevation is mostly a bottom-shadow. Try this tabBarOptions: { style: { borderTopWidth: 0, elevation: 8 } }

vbhv19 avatar Dec 04 '17 17:12 vbhv19

Hi, nothing here worked for me so I created a component to simulated a shadow with react-native-linear-gradient and I putted it in top of the tabBar component (I created a custom tab bar)

Here is the code for the shadow component, it's pretty easy:

import { StyleSheet } from 'react-native';
import LinearGradient from 'react-native-linear-gradient';

import { colors } from '../../config/colors';


const ShadowTabBar = () => (
  <LinearGradient
    start={{ x: 1, y: 0 }} // for a vertical gradient
    end={{ x: 1, y: 1 }} // for a vertical gradient
    locations={[0, 0.3, 1]} // 3 "steps" of color
    colors={['#ededed', '#e2e2e2', '#c6c6c6']} // top color, middle color, bottom color
    style={styles.gradient}
  />
);

const styles = StyleSheet.create({
  gradient: {
    height: 3
  }
});

export default ShadowTabBar;

And here is the code for the custom tab bar:

import React, { Component } from 'react';
import { View, StyleSheet, TouchableWithoutFeedback } from 'react-native';

import PartyNowGradient from '../components/common/PartyNowGradient';
import ShadowTabBar from '../components/tab_bar/ShadowTabBar';
import { colors } from '../config/colors';


class CustomTabBar extends Component {

  render() {

    const {
      navigation,
      renderIcon,
      activeTintColor,
      inactiveTintColor,
      jumpToIndex
    } = this.props;

    const {
      routes
    } = navigation.state;

    return (
      <View>
        <ShadowTabBar />
        <View style={styles.tabBar}>
          {routes && routes.map((route, index) => {
            const focused = index === navigation.state.index;
            const tintColor = focused ? activeTintColor : inactiveTintColor;
            return (
              <TouchableWithoutFeedback
                key={route.key}
                style={styles.tab}
                onPress={() => jumpToIndex(index)}
              >
                <View style={styles.tab}>
                  {renderIcon({
                    route,
                    index,
                    focused,
                    tintColor
                  })}
                </View>
              </TouchableWithoutFeedback>
            );
          })}
        </View>
      </View>
    );
  }

}

const styles = StyleSheet.create({
  tabBar: {
    height: 45,
    flexDirection: 'row',
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: "white",
    borderRadius: 3
  },
  tab: {
    alignSelf: 'stretch',
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  }
});

export default CustomTabBar;

zygama avatar May 23 '18 23:05 zygama

@zygama Can i see your preview UI with that code?

sooxt98 avatar Jun 08 '18 09:06 sooxt98

tabBarOptions: { style: { elevation: 0 } } worked for me

Zvukamar avatar Oct 23 '18 16:10 Zvukamar

If it is still relevant for you:

    tabBarOptions: {
      showLabel: false,
      style: {
        backgroundColor: colors.light[3],
        elevation: 5,
        borderTopWidth: 2,
        top: 1, // This is the important part.. without it there will be no shadow effect on the top edge of the tab bar.
      },
    },

omerman avatar Mar 16 '19 10:03 omerman

I had the same issue and turns out that it is because of style prop of screens of tabs. I had used backgroundColor in my components, so they covered the shadow of the tab bar. I removed backgroundColor and shadow appeared.

diyorbek avatar Apr 22 '19 10:04 diyorbek

Is it possible to add offset for shadow on android?

kesha-antonov avatar Jun 06 '19 11:06 kesha-antonov

@omerman do you have a working example? top: 1 does not have any effect for me, I just get a shadow at the bottom of the tabbar, which is obviously not visible for a bottom tab bar

leabaertschi avatar Jun 19 '19 07:06 leabaertschi

top: 10 will move your tab buttons down and you will see the shadow over some other ui component beneath which actually hides it when top is 0.

ChiragMDave avatar Aug 04 '20 07:08 ChiragMDave