我在react native的世界里是新手,我想在我的应用程序中从左侧显示侧边菜单,我正在使用react-native导航来实现这一点,但我面临着这个问题
首先,我像下面这样设置导航根:
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的可见性,如下所示:
constructor(props) {
super(props);
Navigation.events().bindComponent(this)
}
navigationButtonPressed({ buttonId }) {
Navigation.mergeOptions('leftSideDrawer', {
sideMenu: {
left: {
visible: true
}
}
});
}但是这根本不起作用,它只是显示一个空白屏幕,如果我从setRoot中删除sideMenu部分,它会显示bottomTabs,当我再次添加sideMenu时,它会显示一个空白屏幕。
在RNN版本2文档上没有重新调整这一点的例子我搜索了很多,我没有找到任何对我有帮助的东西,所以请让我知道我做错了什么,这样我就可以摆脱这些东西
提前感谢!!
发布于 2020-01-10 23:56:58
它的工作原理是将bottomTabs放在层次结构的根sideMenu中。sideMenu也有一个center字段,它是required。docs说:
center是所需的,包含主应用程序,要求有一个topBar,也就是stack。
代码必须像下面这样实现:
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",
},
],
}
}
}
}
],
}
}
}
}
});https://stackoverflow.com/questions/55496655
复制相似问题