react-native - 我在 React-navigation V6 中自定义标题时遇到问题
问题描述
我正在尝试在 React Navigation v6 中自定义标头,问题是我有两个标头,即默认标头和自定义标头,如下所示:
这是我的堆栈导航代码:
export const HomeNavigation = () => {
const HomeStack = createNativeStackNavigator<RootStackHomeParamList>();
return (
<HomeStack.Navigator headerMode="none" screenOptions={{headerMode :"none"}}>
<HomeStack.Screen
options={{
headerTitle: 'Home',
headerStyle: styles.header,
headerTitleStyle: styles.headerTitle,
}}
name="HomeScreen"
component={HomeScreen}
/>
<HomeStack.Screen
options={{
headerTitle: 'Play',
headerStyle: styles.header,
headerTitleStyle: styles.headerTitle,
}}
name="PlayScreen"
component={PlayScreen}
/>
</HomeStack.Navigator>
);
};
风格 :
const styles = StyleSheet.create({
headerTitle: {
fontWeight: '600',
color: colors.white,
fontSize: 16,
},
header: {
backgroundColor: colors.secondary,
},
tabBarIcon: {
marginBottom: -3,
},
});
我发现在旧版本中使用headerMode : "none"
将解决这个问题,所以我尝试在任何地方添加它,但它并没有解决它,任何线索是什么问题或解决方案?
解决方案
尝试这个
options={({ navigation }: any) => ({
headerTitle: "Page Title",
headerTitleStyle: { fontSize: 20 },
headerTitleAlign: "center",
headerLeft: () => (
<Component/>
),
headerRight: () => (
<Component/>
),
})}
推荐阅读
- php - 用 PHP 数据调用图表 JS(文件结构)
- react-redux - 用 dispatch 替换 return 会导致错误
- angular - 使用路由器插座时向 Angular 母版页注入组件
- php - WP - 根据帖子类别隐藏特定的 div
- xamarin - Xamarin 使用 CrossSimpleAudioPlayer 播放声音
- linux - FusionPBX安装502 Bad Gateway
- wordpress - 如何更改 woocommerce 描述标签名称
- blockchain - 如何使用 Waves IDE 为资产设置脚本?
- ios - 如何在使用 ESTabBarController 执行操作时推送控制器
- javascript - 如何使构造函数原型可枚举?