【发布时间】:2020-08-05 18:07:17
【问题描述】:
我正在使用nested navigation。据我所知,根导航器是StackNavigator,子导航器是DrawerNavigator,无法通过DrawerNavigator 放置标题栏。
所以我通过StackNavigator 实现了它,但是当我浏览DrawerNavigator 中的屏幕时,我无法更新标题标题。如何更新 DrawerScreen 中的标题标题
根导航器:
<Stack.Navigator screenOptions={screenOptions} initialRouteName="Login">
<Stack.Screen name="Login" component={Login} />
// ...
<Stack.Screen // This is the screen that contains a child navigator
name="Main"
component={Main}
options={({navigation}) => ({
title: 'Main Page',
headerLeft: () => <MenuIcon stackNavigation={navigation} />,
})}
/>
</Stack.Navigator>
儿童导航器:
<Drawer.Navigator>
//...
<Drawer.Screen
name="Bids"
component={Bids}
options={{
title: text.bids, // This updates the title that in the drawer navigator menu not the header bar title.
headerTitle: () => <SearchBar />, //Also this doesn't work I can not update header bar specific to a DrawerComponent.
}}
/>
//...
</Drawer.Navigator>
我尝试将 Stack Screen 的导航属性传递给 Drawer Screens,但找不到任何方法。
<Drawer.Screen
component={<Bids stackNavigation={navigation} />} // This does not compile :(
//...
/>
我尝试使用 setOptions:
const Bids = ({navigation}) => {
navigation.setOptions({title: 'Bids'});
//...
};
但它再次更新抽屉菜单中的标题而不是标题栏标题。
如何从抽屉屏幕更新标题栏?
【问题讨论】:
-
你拿到了吗?
-
是的,但我是通过 redux 实现的,我认为这不是解决此类简单问题的好方法。但是,如果您希望我可以分享我的解决方案。但这不是最佳实践。
标签: react-native react-navigation react-navigation-stack react-navigation-drawer react-navigation-v5