简体   繁体   English

如何使用 React Navigation Drawer 切换屏幕

[英]How to switch screens using React Navigation Drawer

I have the following navigation structure:我有以下导航结构:

  • App Navigator (switch navigator) App Navigator(切换导航器)
    • Auth Screens (stack navigator)身份验证屏幕(堆栈导航器)
    • Home (tab navigator)主页(标签导航器)
      • Feed喂养
      • Others其他
      • Profile (contains drawer)型材(含抽屉)
    • Settings, Legal info etc.设置、法律信息等。

Example Drawer contents示例抽屉内容

  • Settings (navigates to screen out of tab navigator)设置(导航到选项卡导航器之外的屏幕)
  • Notifications & Sound通知和声音

How would I add the labels of and navigate to 'Settings, Legal info' through the drawer?我将如何通过抽屉添加标签并导航到“设置,法律信息”? Extra: 'Profile' label shouldn't show on the drawer.额外:“个人资料”标签不应显示在抽屉上。

A similar example is the Instagram drawer in the profile tab.一个类似的例子是个人资料选项卡中的 Instagram 抽屉。 When you chose an option it pushes a new screen.当您选择一个选项时,它会推送一个新屏幕。

Thanks in advance.提前致谢。

I've come up with clunky yet working solution.我想出了笨拙但有效的解决方案。

Drawer navigation routes抽屉导航路线

`...
// To hide a specific route (Profile)
HiddenLabel:{
    screen:ScreenA,
    navOptions:{
        drawerLabel:()=>null
    }
}
A:{
    screen:()=>null
    navOptions:{
        drawerLabel:'Settings'
    }
}
...`

Drawer navigation custom component抽屉导航自定义组件

`
...
contentComponent:(props)=>(
    // Should be wrapped in SafeAreaView
    <DrawerItems {...props} onItemPress={
        ({route})=>{
            // query and use props.navigation to navigate to route.routeName
        }
    }/>
)
...
`

And that's pretty much it.仅此而已。 If you have another solution please do post it.如果您有其他解决方案,请发布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM