50

How do I hide the shadow under react-navigation headers?
They look like this.
enter image description here

GollyJer
  • 23,857
  • 16
  • 106
  • 174

17 Answers17

75

Add the following to the navigationOptions header style.

const AppNavigation = StackNavigator(
  {
    'The First Screen!': { screen: FirstScreen },
  },
  {
    navigationOptions: {
      header: {
        style: {
          elevation: 0, // remove shadow on Android
          shadowOpacity: 0, // remove shadow on iOS
        },
      },
    },
  },
);

The documentation isn't great yet, but you can learn about navigationOptions in the React Navigation Docs.

GollyJer
  • 23,857
  • 16
  • 106
  • 174
  • 1
    This gives me error: ```ExceptionsManager.js:63 Objects are not valid as a React child (found: object with keys {style}). If you meant to render a collection of children, use an array instead. in View (at CardStack.js:391)``` – zarcode Jun 22 '17 at 09:39
48

in react navigation V5 this how you can do it: to do it for all screens apply screenOptions prop to <Stack.Navigator>

in example:

      <Stack.Navigator
        screenOptions={{
          headerStyle: {
            elevation: 0,
            shadowOpacity: 0
          },
        }}
      />
      </Stack.Navigator>

to do it for a specific screen apply options prop to <Stack.Screen>

in example:

      <Stack.Screen
        name="Example"
        component={ExampleComponent}
        options={{
          headerStyle: {
            elevation: 0,
            shadowOpacity: 0
          },
        }}
      />

UPDATE V6:

since released React Navigation V6, you can't hide header shadow using headerStyle option. instead of that you can use bolean option headerShadowVisible and set it to be false like example bellow:

    <Stack.Screen
      name="Example"
      component={ExampleComponent}
      options={{headerShadowVisible: false}}
    />

Anas
  • 1,000
  • 11
  • 18
26

The following works for me as the original Stylesheet uses "borderBottomWidth" on iOS:

const navigator = StackNavigator(screens, {
  navigationOptions: {
    headerStyle: {
      elevation: 0,
      shadowOpacity: 0,
      borderBottomWidth: 0,
    }
  }
});
spaceemotion
  • 1,404
  • 4
  • 24
  • 32
20

I don't know how much this answer will value, but sharing my code to let you know that this worked for me for react-navigation version: 3.9.1

const AppNavigation = StackNavigator(
{
  FirstScreen,
},
{
 defaultNavigationOptions: {
  headerStyle: {
    elevation: 0, //for android
    shadowOpacity: 0, //for ios
    borderBottomWidth: 0, //for ios
  },
},
})
Neel Gala
  • 2,350
  • 1
  • 19
  • 20
9

In v5 you can do the following

<Stack.Navigator>
      <Stack.Screen
        name="Example"
        component={ExampleComponent}
        options={{
          headerStyle: {
            elevation: 0,
            shadowOpacity: 0
          },
        }}
      />
</Stack.Navigator>
Sjonchhe
  • 790
  • 8
  • 16
8

Good afternoon, React Navigation 6:

<Stack.Navigator screenOptions={{headerShadowVisible:false}}>
Alberto Perez
  • 2,561
  • 1
  • 14
  • 21
Ambesh Tiwari
  • 648
  • 7
  • 11
4

This works for me:

export const AppNavigator = StackNavigator(
    {
      Login: { screen: LoginScreen },
      Main: { screen: MainScreen },
      Profile: { screen: ProfileScreen },
    },
    navigationOptions: {
        headerStyle: {
            elevation: 0,
            shadowOpacity: 0,
        }
    }
);

or

export const AppNavigator = StackNavigator(
    {
      Login: { screen: LoginScreen },
      Main: { screen: MainScreen },
      Profile: { screen: ProfileScreen },
    },
    header: {
        style: {
            elevation: 0, //remove shadow on Android
            shadowOpacity: 0, //remove shadow on iOS
        }
    }
);
zarcode
  • 2,465
  • 17
  • 31
  • @GregBenner try adding code inside components, example `Login.navigationOptions = { headerStyle: { elevation: 0, shadowOpacity: 0, } }` – zarcode Sep 12 '17 at 11:12
  • const stackNavigatorLoggedInConfig = { cardStyle: { shadowColor: 'transparent' }, headerStyle: { height: 0, padding: '0', border: 'none' }, } – Greg Benner Oct 03 '17 at 20:30
3

in react-navigation version 5.x.x:

      <Tab.Navigator
        tabBarOptions={{
          activeTintColor: colors.darkGray,
          labelStyle: { fontSize: 12 },
          style: { backgroundColor: colors.white, borderTopWidth: 0, elevation: 0, shadowOpacity: 0, },
        }}
      >
Gray
  • 531
  • 1
  • 10
  • 28
3

it is:

options: {{
  headerShadowVisible: false,
}}

check the docs for more info:

https://reactnavigation.org/docs/native-stack-navigator/#headershadowvisible

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 13 '22 at 21:59
2

Try passing cardStyle: { shadowColor: 'transparent' }

export const AppNavigator = StackNavigator(
{
  Login: { screen: LoginScreen },
  Main: { screen: MainScreen },
  Profile: { screen: ProfileScreen },
},
cardStyle: { shadowColor: 'transparent' }

As per this question React Navigation Stack Navigator default shadow styling

Greg Benner
  • 668
  • 7
  • 15
1

I have been trying to solve this problem for the past couple of hours and have finally found the solution. The problem in my case was that the header was in a different Z position than the rest of the other components.

try:

const styles = {
  headerStyle: {
    zIndex: 1
  }
}
LarsTech
  • 80,625
  • 14
  • 153
  • 225
1

As of 2019 this answer doesn't work in version 3.

The new way of doing it is:


const AppNavigation = StackNavigator(
  {
    'The First Screen!': { screen: FirstScreen },
  },
  {
    defaultNavigationOptions: {
      headerStyle: {
        elevation: 0,
        shadowOpacity: 0,
      },
    },
  },
);

Harvey Kadyanji
  • 515
  • 6
  • 8
1

I'm using react navigation v5, i use this code :

 const HomeStackScreen = ({navigation}) => (
  <HomeStack.Navigator
    initialRouteName="Home"
    headerMode="screen"
    mode="modal"
    screenOptions={{
      headerStyle: {
        backgroundColor: COLORS.WHITE,
        elevation: 0, // remove shadow on Android
        shadowOpacity: 0, // remove shadow on iOS
        borderBottomWidth: 0,
      },
      headerTintColor: COLORS.GREY,
      headerTitleStyle: {
        fontFamily: 'Montserrat-SemiBold',
        fontWeight: '600',
        fontSize: 18,
      },
    }}>
    <HomeStack.Screen
      name="Home"
      component={Home}
      options={{
        title: 'Expanded',
        headerLeft: () => <RenderHeaderLeft />,
        headerRight: () => <RenderHeaderRight navigation={navigation} />,
        headerTitleAlign: 'left',
      }}
    />
    <HomeStack.Screen name="HomeDetails" component={HomeDetails} />
  </HomeStack.Navigator>
);

put shadowOpacity and elevation inside headerStyle

Khaled Boussoffara
  • 1,567
  • 2
  • 25
  • 53
1

As of 2023, what works for me is:

options={{
    headerShadowVisible: false,
}}
0

You can try this, and it worked for me !

export const SignedOut = StackNavigator({
  SignIn: {
    screen: SignInScreen,
    navigationOptions: {
      title: "SignIn",
      headerStyle: {
        shadowOpacity: 0, // This is for ios
        elevation: 0 // This is for android
      }
    }
  }
});
Iam ByeBlogs
  • 715
  • 1
  • 6
  • 15
0

The shadow is achieved via elevation, use:

 headerStyle: {
     backgroundColor: 'white',
     shadowColor: 'transparent',
     elevation: 0,
 },
Pingolin
  • 3,161
  • 6
  • 25
  • 40
Peter Mugendi
  • 565
  • 6
  • 15
-2

For React Native Navigation 5

<Stack.Screen
      name={"Profile"}
      component={Profile}
      options={{
        headerTitle: "Profile",
        headerHideShadow: true,
      }}
    />

Or

<Stack.Navigator
    screenOptions={{
      headerHideShadow: true,
    }}
  >