首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >sideMenu不能在react-native-navigation版本2中工作吗?

sideMenu不能在react-native-navigation版本2中工作吗?
EN

Stack Overflow用户
提问于 2019-04-03 21:41:53
回答 1查看 497关注 0票数 0

我在react native的世界里是新手,我想在我的应用程序中从左侧显示侧边菜单,我正在使用react-native导航来实现这一点,但我面临着这个问题

首先,我像下面这样设置导航根:

代码语言:javascript
复制
Navigation.setRoot({
        root: {

            bottomTabs: {
                children: [
                    {
                        stack: {
                            children: [
                                {
                                    component: {
                                        name: "FindPlace",
                                        options: {
                                            bottomTab: {
                                                text: "find place",
                                                icon: response[0],
                                            },
                                            topBar: {
                                                title: {
                                                    text: "find place"
                                                },
                                                leftButtons: [
                                                    {
                                                        icon: response[2],
                                                        id: 'leftSideDrawer',
                                                    },
                                                ],
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    },

                ],
            },
            sideMenu: {
                left: {
                    component: {
                        name: 'SideDrawer',
                        id: 'leftSideDrawer'
                    }
                },

            },

        }
    })

其中我声明了bottomTabs和sideMenu,并添加了一个在findPlace组件上触发事件的按钮,其中我添加了一个Navigation.event() listner,用于切换左侧sideMenu的可见性,如下所示:

代码语言:javascript
复制
 constructor(props) {
    super(props);
    Navigation.events().bindComponent(this)
}

navigationButtonPressed({ buttonId }) {

    Navigation.mergeOptions('leftSideDrawer', {
        sideMenu: {
          left: {
            visible: true
          }
        }
  });


}

但是这根本不起作用,它只是显示一个空白屏幕,如果我从setRoot中删除sideMenu部分,它会显示bottomTabs,当我再次添加sideMenu时,它会显示一个空白屏幕。

在RNN版本2文档上没有重新调整这一点的例子我搜索了很多,我没有找到任何对我有帮助的东西,所以请让我知道我做错了什么,这样我就可以摆脱这些东西

提前感谢!!

EN

回答 1

Stack Overflow用户

发布于 2020-01-10 23:56:58

它的工作原理是将bottomTabs放在层次结构的根sideMenu中。sideMenu也有一个center字段,它是requireddocs说:

center所需的,包含主应用程序,要求有一个topBar,也就是stack

代码必须像下面这样实现:

代码语言:javascript
复制
Navigation.setRoot({
    root: {
        sideMenu: {
            left: {
                component: {
                    id: "leftSideDrawer",
                    name: "SideDrawer"
                }
            },
            center: {
                bottomTabs: {
                    children: [
                        {
                            component: {
                                name: "FindPlace",
                                options: {
                                    bottomTab: {
                                        text: "find place",
                                        icon: response[0]
                                    },
                                    topBar: {
                                            title: {
                                            text: "find place"
                                        },
                                        leftButtons: [
                                            {
                                                icon: response[2],
                                                id: "leftSideDrawer",
                                            },
                                        ],
                                    }
                                }

                            }
                        }

                    ],
                }
            }

        }
    }
});

使用此结构使其正常工作。请注意,如果您需要push其他屏幕,那么您需要使用stack

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55496655

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档