Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TabNavigator's tabs are not displayed when nested in a DrawerNavigator #38

Closed
Colmea opened this issue Jan 27, 2017 · 12 comments
Closed
Labels

Comments

@Colmea
Copy link

Colmea commented Jan 27, 2017

Hi,

First, thank you for this module !

I have an issue when using a TabNavigator nested in a DrawerNavigator: tabs are not displayed.
This issue appears only when I go to the nested TabNavigator from the Drawer menu link and when using navigate('MyNestedTabStack') like in the get started guide.

Here is an example:

class HomeScreen extends React.Component {
    render() {
        return <Button
            onPress={() => this.props.navigation.navigate('Projects')}
            title="Go to Projects"
        />;
    }
}

class RecentProjectsScreen extends React.Component {
    render() {
        return <Text>List of recent projects</Text>
    }
}

class AllProjectsScreen extends React.Component {
    render() {
        return <Text>List of all projects</Text>
    }
}

const ProjectScreenNavigator = TabNavigator({
    Recent: { screen: RecentProjectsScreen },
    All: { screen: AllProjectsScreen },
});


const App = DrawerNavigator({
    Home: { screen: HomeScreen },
    Projects: { screen: ProjectScreenNavigator }
});

AppRegistry.registerComponent('App', () => App);
@hilkeheremans
Copy link

hilkeheremans commented Jan 27, 2017

I can confirm this issue, and it is also related to issue #31.

I have tracked down this issue to the way DrawerNavigator attempts to retrieve the components it renders. DrawerNavigator internally uses a TabRouter to find out what content it needs to render. However, whenever you nest a StackNavigator, or in this case a TabNavigator, this TabRouter will retrieve the deepest component in the navigation tree, bypassing all intermediary navigators from rendering.

The root cause of this seems to lie in TabRouter's getComponentForState function, which will automatically recurse through all child routers:

getComponentForState(state: NavigationState) {
  const routeName = order[state.index];
  invariant(
    routeName,
    `There is no route defined for index ${state.index}. Check that
    that you passed in a navigation state with a valid tab/screen index.`
  );
  const childRouter = tabRouters[routeName];
  if (childRouter) {
    return childRouter.getComponentForState(state.routes[state.index]);
  }
  return getScreenForRouteName(routeConfigs, routeName);
},

Bypassing/removing this recursion allows tabs and stacks inside drawers to function normally. However, I want to hold off on a PR as I assume this recursion is there for a reason, and I do not yet grok react-navigation sufficiently to fully understand the consequences.

I believe that, ideally, DrawerNavigation should get its own router to cleanly separate concerns with TabRouter.

@ericvicenti @skevy Any insight for us laypeople?

@frankrowe
Copy link

frankrowe commented Jan 27, 2017

Can confirm the same issue with embedding StackNavigators in a DrawerNavigator

@knowbody knowbody added the bug label Jan 27, 2017
@ericvicenti
Copy link
Contributor

Maybe the drawer navigator should use the router.getComponentForRouteName instead? If you can find a fix inside the drawer navigator without changing any routers, then the PR would be quickly accepted!

cc @satya164

@hilkeheremans
Copy link

hilkeheremans commented Jan 27, 2017 via email

@satya164
Copy link
Member

Fixed in #46

@hilkeheremans
Copy link

Thanks @satya164! FYI, I was doing the same fix at the same time. I have tested it in the following scenarios:

Tab in Drawer --> ok
Tab in Tab in Drawer --> ok
Stack in Tab in Drawer --> ok
Tab in Drawer in Tab --> ok
Tab in Drawer in Stack --> ok

... so we should be golden!

@satya164
Copy link
Member

Awesome!

@Colmea
Copy link
Author

Colmea commented Jan 27, 2017

Wow 4 hours after my issue, thank you ! Best.Customer.Service.Ever

@PManager1
Copy link

How can we handle the scenarios of Drawer inside the Tab , Can you please point me to some working code ?

@markusguenther
Copy link

That would be interesting. Or a way to have both - a TabNavigator and a DrawerNavigator.

I have a project where I should have 3 Tabs on all screens and a drawer with other NavigationItems.

@PManager1
Copy link

PManager1 commented Jul 14, 2017 via email

@markusguenther
Copy link

Which link should I share? It is more or less a question ... will try to join this with a stacknavigator or so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants