【发布时间】:2017-03-10 03:35:23
【问题描述】:
【问题讨论】:
标签: react-native react-navigation
【问题讨论】:
标签: react-native react-navigation
将以下内容添加到 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。
【讨论】:
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)
在 React Navigation V5 中,您可以这样做:
为所有屏幕执行此操作将screenOptions prop 应用于<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 选项隐藏标题阴影。而不是你可以使用布尔选项headerShadowVisible 并将其设置为false,如下例所示:
<Stack.Screen
name="Example"
component={ExampleComponent}
options={{headerShadowVisible: false}}
/>
【讨论】:
以下对我有用,因为原始样式表使用"borderBottomWidth" on iOS:
const navigator = StackNavigator(screens, {
navigationOptions: {
headerStyle: {
elevation: 0,
shadowOpacity: 0,
borderBottomWidth: 0,
}
}
});
【讨论】:
我不知道这个答案有多大价值,但分享我的代码让你知道这对我有用 react-navigation 版本:3.9.1
const AppNavigation = StackNavigator(
{
FirstScreen,
},
{
defaultNavigationOptions: {
headerStyle: {
elevation: 0, //for android
shadowOpacity: 0, //for ios
borderBottomWidth: 0, //for ios
},
},
})
【讨论】:
在 v5 中,您可以执行以下操作
<Stack.Navigator>
<Stack.Screen
name="Example"
component={ExampleComponent}
options={{
headerStyle: {
elevation: 0,
shadowOpacity: 0
},
}}
/>
</Stack.Navigator>
【讨论】:
这对我有用:
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
}
}
);
【讨论】:
Login.navigationOptions = { headerStyle: { elevation: 0, shadowOpacity: 0, } }
在 react-navigation 版本 5.x.x 中:
<Tab.Navigator
tabBarOptions={{
activeTintColor: colors.darkGray,
labelStyle: { fontSize: 12 },
style: { backgroundColor: colors.white, borderTopWidth: 0, elevation: 0, shadowOpacity: 0, },
}}
>
【讨论】:
尝试传递cardStyle: { shadowColor: 'transparent' }
export const AppNavigator = StackNavigator(
{
Login: { screen: LoginScreen },
Main: { screen: MainScreen },
Profile: { screen: ProfileScreen },
},
cardStyle: { shadowColor: 'transparent' }
根据这个问题React Navigation Stack Navigator default shadow styling
【讨论】:
过去几个小时我一直在尝试解决这个问题,终于找到了解决方案。 我的问题是标题与其他组件的 Z 位置不同。
尝试:
const styles = {
headerStyle: {
zIndex: 1
}
}
【讨论】:
截至 2019 年,此答案在版本 3 中不起作用。
新的做法是:
const AppNavigation = StackNavigator(
{
'The First Screen!': { screen: FirstScreen },
},
{
defaultNavigationOptions: {
headerStyle: {
elevation: 0,
shadowOpacity: 0,
},
},
},
);
【讨论】:
我正在使用反应导航 v5,我使用此代码:
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>
);
将shadowOpacity和elevation放在headerStyle中
【讨论】:
下午好,React Navigation 6:
<Stack.Navigator screenOptions={{headerShadowVisible:false}}>
【讨论】:
你可以试试这个,它对我有用!
export const SignedOut = StackNavigator({
SignIn: {
screen: SignInScreen,
navigationOptions: {
title: "SignIn",
headerStyle: {
shadowOpacity: 0, // This is for ios
elevation: 0 // This is for android
}
}
}
});
【讨论】:
阴影是通过高程实现的,使用:
headerStyle: {
backgroundColor: 'white',
shadowColor: 'transparent',
elevation: 0,
},
【讨论】:
对于 React Native Navigation 5
<Stack.Screen
name={"Profile"}
component={Profile}
options={{
headerTitle: "Profile",
headerHideShadow: true,
}}
/>
或者
<Stack.Navigator
screenOptions={{
headerHideShadow: true,
}}
>
【讨论】: