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

Nested Navigators in Redux #16

Closed
dmhood opened this issue Jan 27, 2017 · 2 comments
Closed

Nested Navigators in Redux #16

dmhood opened this issue Jan 27, 2017 · 2 comments

Comments

@dmhood
Copy link

dmhood commented Jan 27, 2017

Hello,

I'm trying to set up a TabNavigator inside a StackedNavigator, sort of like this:

TabsNavigator = TabNavigator({
            HomeScreen: {
                screen: HomeScreen,
                navigationOptions: {
                    tabBar: () => ({
                        label: 'Home'
                    })
                }
            },
            MyAction: {
                screen: Settings,
                navigationOptions: {
                    tabBar: () => ({
                        label: 'Settings'
                    })
                }
            },
        }, {
            tabBarPosition: 'bottom',
            animationEnabled: true,
            swipeEnabled: true
        });
        ModalNavigator = StackNavigator({
            Home: {
                screen: TabsNavigator
            }
        });

My issue is, since I'm using Redux, I can pass the outer StackedNavigator the nav state easily enough:

import { ModalNavigator } from '../scenes';
const AppNavigatorWithRedux = connect()(ModalNavigator);
<AppNavigatorWithRedux
         navigation={navigation}
/>

But I don't know how to pass the TabNavigator's state down to it. I'm assuming right now I'm going to have to wrap it in another component and get my other navigation state, but is there another/simpler way?

My reducer is:

import { ModalNavigator, TabsNavigator } from '../scenes';
const navReducer = (state, action) => {
    return {
        ModalNavigator: ModalNavigator.router.getStateForAction(action, state),
        TabNavigator: TabNavigator.router.getStateForAction(action, state)
    };
};

const appReducer = combineReducers({
    navReducer,
    mainReducer
});
@ericvicenti
Copy link
Contributor

So this should actually just work out of the box, and here's why:

Because TabsNavigator is set up as a screen on ModalNavigator, it will automatically nest routers. This means that the output of ModalRouter.getStateForAction actually contains the state from the tabs router.

ModalRouter is your app's main router, so it is the only reducer you need. You don't need to attach TabNavigator to redux manually.

Closing for now but please re-open if you run into issues with this approach

@dmhood
Copy link
Author

dmhood commented Jan 27, 2017

Looks like its working, thanks!

grabbou pushed a commit that referenced this issue Feb 9, 2017
* Add clarification for Redux <-> Nested Navigators

See also #16

* Update per comments

* Update per comments in PR #26
ManuelKu1223 pushed a commit to ManuelKu1223/react-navigation that referenced this issue Jun 5, 2019
* Add clarification for Redux <-> Nested Navigators

See also react-navigation/react-navigation#16

* Update per comments

* Update per comments in PR #26
satya164 added a commit that referenced this issue Feb 7, 2020
Closes #16

When the statusbar is not translucent, the view resizes when the keyboard is shown on Android. The tab bar stays above the keyboard. This PR makes the tab bar hide automatically when the keyboard is shown.

The behaviour is enabled by default and can be disabled with `keyboardHidesTabBar: false` in `tabBarOptions`
sourcecode911 pushed a commit to sourcecode911/react-navigation that referenced this issue Mar 9, 2020
* Add clarification for Redux <-> Nested Navigators

See also react-navigation#16

* Update per comments

* Update per comments in PR react-navigation#26
ShyJuno pushed a commit to ShyJuno/custom-react-navigation that referenced this issue Apr 18, 2024
* Add clarification for Redux <-> Nested Navigators

See also react-navigation/react-navigation#16

* Update per comments

* Update per comments in PR #26
ShyJuno pushed a commit to ShyJuno/react-navigation that referenced this issue Apr 19, 2024
ShyJuno pushed a commit to ShyJuno/react-navigation that referenced this issue Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants