44

如何隐藏反应导航标题下的阴影?
他们看起来像这样。
在此处输入图像描述

4

15 回答 15

72

将以下内容添加到 navigationOptions 标题样式。

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

文档还不是很好,但你可以在React Navigation Docs中了解 navigationOptions 。

于 2017-03-10T03:35:23.093 回答
28

在 React Navigation V5 中,您可以这样做:为所有屏幕执行此操作,将screenOptionsprop 应用于<Stack.Navigator>

例如:

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

为特定屏幕执行此操作将options道具应用于<Stack.Screen>

例如:

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

更新 V6:

自发布 React Navigation V6 以来,您无法使用headerStyle选项隐藏标题阴影。而不是您可以使用 bolean 选项headerShadowVisible并将其设置为false如下示例:

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

于 2020-10-20T13:13:23.737 回答
26

以下对我有用,因为原始样式表在 iOS 上使用“borderBottomWidth”

const navigator = StackNavigator(screens, {
  navigationOptions: {
    headerStyle: {
      elevation: 0,
      shadowOpacity: 0,
      borderBottomWidth: 0,
    }
  }
});
于 2017-12-29T19:44:06.463 回答
20

我不知道这个答案会有多少价值,但分享我的代码让你知道这对我来说适用于react-navigation 版本:3.9.1

const AppNavigation = StackNavigator(
{
  FirstScreen,
},
{
 defaultNavigationOptions: {
  headerStyle: {
    elevation: 0, //for android
    shadowOpacity: 0, //for ios
    borderBottomWidth: 0, //for ios
  },
},
})
于 2019-05-10T20:37:57.410 回答
9

在 v5 中,您可以执行以下操作

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

于 2020-08-07T07:28:43.030 回答
4

这对我有用:

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

或者

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
        }
    }
);
于 2017-06-23T11:07:56.270 回答
3

在反应导航版本 5.xx 中:

      <Tab.Navigator
        tabBarOptions={{
          activeTintColor: colors.darkGray,
          labelStyle: { fontSize: 12 },
          style: { backgroundColor: colors.white, borderTopWidth: 0, elevation: 0, shadowOpacity: 0, },
        }}
      >
于 2020-05-02T10:58:00.540 回答
2

尝试通过cardStyle: { shadowColor: 'transparent' }

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

根据这个问题React Navigation Stack Navigator 默认阴影样式

于 2017-09-11T20:15:58.317 回答
1

下午好,React Navigation 6

<Stack.Navigator screenOptions={{headerShadowVisible:false}}>
于 2021-11-15T12:03:07.580 回答
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

于 2020-07-31T08:57:50.703 回答
1

截至 2019 年,此答案在版本 3 中不起作用。

新的做法是:


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

于 2019-05-05T08:06:24.753 回答
1

在过去的几个小时里,我一直在尝试解决这个问题,终于找到了解决方案。在我的情况下,问题是标题与其他组件的 Z 位置不同。

尝试:

const styles = {
  headerStyle: {
    zIndex: 1
  }
}
于 2018-03-30T19:35:15.237 回答
0

你可以试试这个,它对我有用!

export const SignedOut = StackNavigator({
  SignIn: {
    screen: SignInScreen,
    navigationOptions: {
      title: "SignIn",
      headerStyle: {
        shadowOpacity: 0, // This is for ios
        elevation: 0 // This is for android
      }
    }
  }
});
于 2018-03-03T17:37:17.963 回答
0

阴影是通过高程实现的,使用:

 headerStyle: {
     backgroundColor: 'white',
     shadowColor: 'transparent',
     elevation: 0,
 },
于 2019-02-05T13:01:28.883 回答
-2

For React Native Navigation 5

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

Or

<Stack.Navigator
    screenOptions={{
      headerHideShadow: true,
    }}
  >
于 2021-01-27T08:35:22.133 回答