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

Should NavigationActions.back have an action option? #938

Closed
vlexaargas opened this issue Apr 6, 2017 · 2 comments
Closed

Should NavigationActions.back have an action option? #938

vlexaargas opened this issue Apr 6, 2017 · 2 comments

Comments

@vlexaargas
Copy link

I have the following Navigator setup (simplified):

const SimpleStack = StackNavigator({
    Screen1: { screen: Screen1 },
    Screen2: { screen: Screen2 },
    Screen3: { screen: Screen3 }
});

const Drawer = DrawerNavigator({
    Drawer1: { screen: Drawer1 },
    Drawer2: { screen: Drawer2 },
    Drawer3: { screen: Drawer3 }
});

const Modal = const SimpleStack = StackNavigator({
    SimpleStack: { screen: SimpleStack },
    Drawer: { screen: Drawer}
}, {
    mode: Platform.OS === 'ios' ? 'modal' : 'card'
});

Here is what I am trying to accomplish:

Initially, I am in the SimpleStack in Screen1. I navigate to Screen2, then Screen 3, then over to Drawer/Drawer1 which is displayed modally. When I dispatch the NavigationActions.back() action, the modal view is popped and I land back on SimpleStack/Screen3. The problem here is I'd really like to be able to land back on SimpleStack/Screen2.

To tackle this problem, I think it would be nice to mirror the navigate API and be able to something like this, in my case, from Drawer/Drawer1:

import { NavigationActions } from 'react-navigation'

const backAction = NavigationActions.back({

  params: {},

  action: NavigationActions.navigate({ routeName: 'Screen2'})

})

this.props.navigation.dispatch(navigateAction)

Does this line of thinking make sense? Is there an alternative here that I am missing?

@rxb
Copy link

rxb commented Aug 8, 2017

Did you ever find a solution to this? I'm trying to do the same thing, I think.

@brentvatne brentvatne changed the title NavigationActions.back with action option? Should NavigationActions.back have an action option? Jan 23, 2018
@ericvicenti
Copy link
Contributor

In this case, I think you can dispatch several actions at once, and the correct thing will happen. Or, after we merge #3393, you can go back by providing a key on the navigate action, which allows you to navigate back to the specified screen.

Feel free to open a new issue if that doesn't work.

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

No branches or pull requests

7 participants