Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Navigation v2 sideMenu not able to navigate to screen

I'm trying to call Navigate.push from sideMenu but nothing happens.

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: [
                    {

..and I'm trying to push a screen in sideMenu like this

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

I am getting the log but nothing happens. I'm positive that I need to do something with my layout but I don't see an example or explanation in docs.

like image 964
Damathryx Avatar asked Aug 23 '18 08:08

Damathryx


2 Answers

There's something wrong with how you structure the components in the menu. The issue is that you must have a stack to be able to push other screens, and from what it looks - this is not the case for your side menu screen.

This is how you would set a left sideMenu component which is a stack; once you do that, you'll be able to push screens exactly as you did with Navigation.push(this.props.componentId...:

left: {
  stack: {
    children: [
      {
        component: {
          name: 'app.SideMenu',
        }
      }
    ]
  }
}
like image 194
Artal Avatar answered Sep 22 '22 15:09

Artal


What I was doing wrong is actually because I'm passing the sidemenu componentId when in fact I need to pass the id of the current tab. Something like this.

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

also sidemenu layout is this

root: {
  sideMenu: {
    id: 'SideMenu',
    left: {
      component: {
        id: 'SideMenu.left',
        name: Screens.SIDEMENU,
      }
    },
like image 26
Damathryx Avatar answered Sep 20 '22 15:09

Damathryx