我有两个堆栈导航器,第二个堆栈嵌套在第二个堆栈中:
export default createStackNavigator( //Settings navigator
{
HomeSettings: SettingsScreen
},
{
headerLayoutPreset: "center",
headerMode: "none"
}
);
export default createStackNavigator( //Main navigator
{
HomeProfile: ProfileScreen,
Prescriptions: PrescriptionsScreen,
PrescriptionDetails: PrescriptionDetailsScreen,
Settings: SettingsNavigator
},
{
initialRouteName: "HomeProfile",
headerLayoutPreset: "center",
headerMode: "screen"
})
在我的孩子导航器的屏幕上,我无法使用设置标题:
SettingsScreen.navigationOptions = {
headerTitle: "My custom header"
}
(不附加任何内容)
执行此操作的最佳模式是什么?请注意,我想保留标题后退按钮以从“设置”导航器返回到主导航器。
答案 0 :(得分:0)
在navigationOptions
上添加SettingsScreen
仅会影响其所在的导航器的选项,即SettingsNavigator
。但是,您想在父导航器(MainNavigator
)中更改标题。您需要这样做:
SettingsNavigator,navigationOptions = {
// ...
}
https://reactnavigation.org/docs/en/navigation-options-resolution.html