首页 > 解决方案 > react-native-navigation 侧边菜单

问题描述

我正在尝试使用库 react-native-navigation v2,我需要一些帮助我被侧边菜单卡住了,我无法让它工作......

我像这样初始化我的布局:

Navigation.events().registerAppLaunchedListener(() => {
Navigation.setRoot({
    root: {
        sideMenu: {
            id: "sideMenu",
            left: {
                component: {
                    id: "Drawer",
                    name: "navigation.Drawer"
                }
            },
            center: {
                stack: {
                    id: "AppRoot",
                    children: [
                        {
                            component: {
                                id: "App",
                                name: "navigation.AppScreen"
                            }
                        }
                    ]
                }
            }
        }
    }
});

});

使用之前注册的组件,并且在 Drawer 组件中,我希望当用户单击该项目时,它将触发 goToScreen2(),

我试过了 : Navigation.setStackRoot(this.props.componentId, {...} Navigation.mergeOptions(this.props.componentId, {...} Navigation.push(this.props.componentId, {...}

但是,没有一个工作......有人可以解释我怎样才能让它工作?

谢谢。

标签: react-nativereact-native-navigationdrawerside-menu

解决方案


您应该添加要从根堆栈中心的侧面菜单导航到的所有组件,如下所示:

center: {
   stack: {
    id: "AppRoot",
    children: [{
        component: {
        id: "anyID",
        name: "Screen2"
        }
    }]
  }
}

推荐阅读