How do I hide the shadow under react-navigation headers?

邮差的信 提交于 2019-12-12 07:45:01

问题


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


回答1:


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.




回答2:


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,
    }
  }
});



回答3:


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
  },
},
})



回答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
        }
    }
);



回答5:


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




回答6:


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
  }
}



回答7:


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,
      },
    },
  },
);




回答8:


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
      }
    }
  }
});



回答9:


The shadow is achieved via elevation, use:

 headerStyle: {
     backgroundColor: 'white',
     shadowColor: 'transparent',
     elevation: 0,
 },


来源:https://stackoverflow.com/questions/42709730/how-do-i-hide-the-shadow-under-react-navigation-headers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!