React Native Navigation v2 sideMenu无法导航到屏幕

问题描述 投票:6回答:3

我试图从sideMenu调用Navigate.push,但没有任何反应。

Navigation.setRoot({
    root: {
      sideMenu: {
        left: {
          component: {
            name: 'app.SideMenu',
          },
          children: [
           {
             stack: {
             children: [
                {
                  component: {
                    name: TERMS_SCREEN.id,
                  }
                },
             ]
           }
        }
      ]
        },
        center: {
          bottomTabs: {
            id: 'BottomTabsId',
            options: {
              topbar: {
                visible: true,
              }
            },
            children: [
              {
                stack: {
                  id: 'Tabs',
                  children: [
                    {

..而我正试图像这样在sideMenu中推出一个屏幕

console.log(this.props.componentId);
Navigation.push(this.props.componentId, {
  component: {
    name: 'app.Terms',
  }
})

我收到日志但没有任何反应。我很肯定我需要对我的布局做一些事情,但我没有在文档中看到示例或解释。

react-native react-native-navigation
3个回答
2
投票

如何在菜单中构建组件有问题。问题是你必须有一个堆栈才能推送其他屏幕,从它看起来 - 你的侧面菜单屏幕不是这种情况。

这就是你如何设置left sideMenu组件,这是一个stack;一旦你这样做,你将能够像使用Navigation.push(this.props.componentId...一样完全按下屏幕:

left: {
  stack: {
    children: [
      {
        component: {
          name: 'app.SideMenu',
        }
      }
    ]
  }
}

2
投票

我做错了其实是因为我传递sidemenu componentId实际上我需要传递当前选项卡的id。像这样的东西。

    Navigation.push(`Tab${this.props.activeTabIndex + 1}`,{
        component: {
            name: Screens.ACCOUNTS,
        }
      }
    )

侧面菜单布局就是这个

root: {
  sideMenu: {
    id: 'SideMenu',
    left: {
      component: {
        id: 'SideMenu.left',
        name: Screens.SIDEMENU,
      }
    },

0
投票

而在children对象中拥有stacksidemenu可能是一种解决方案。但你也可以这样做。考虑以下

Navigation.setRoot({
        root: {
            sideMenu: {
                left: {
                    id: "AppSideMenu",
                    component: {
                        id: "HomeScreenDrawer",
                        name: "YO.HomeScreen.Drawer",
                    },
                },
                center: {
                    stack: {
                        id: "AppHomeStack",
                        children: [
                            {
                                component: {
                                    id: "AppHomeScreen",
                                    name: "YO.HomeScreen",
                                    options: {
                                        topBar: {
                                            visible: false,
                                            drawBehind: true,
                                            height: 0,
                                        },
                                        statusBar: {
                                            style: "light",
                                        },
                                    },
                                },
                            },
                        ],
                    },
                },
            },
        },
    });

这样当你要推送时只需调用主堆栈的ID,该堆栈位于center{stack:{}}下,ID为AppHomeStack

现在在应用程序的任何地方,这将只是做的伎俩

Navigation.push("AppHomeStack", {
    component: {
    name: "YO.UserScreen",
    },
});
© www.soinside.com 2019 - 2024. All rights reserved.