Skip to content

How to reset the navigation stack without animation? #1493

Closed
@diegorodriguesvieira

Description

@diegorodriguesvieira

How can I reset the navigation stack without this animation?

My code:

resetTabAction = NavigationActions.navigate({
  routeName: 'Dashboard',
  action: NavigationActions.reset({
    index: 0,
    actions: [NavigationActions.navigate({ routeName: 'DashboardInitial' })],
  }),
});
props.navigation.dispatch(resetTabAction);

Activity

changed the title [-]Hot to reset the navigation stack without animation?[/-] [+]How to reset the navigation stack without animation?[/+] on May 12, 2017
turnipdabeets

turnipdabeets commented on May 15, 2017

@turnipdabeets

I'm having the same problem with animations when I reset or navigate backwards more than 1 screen. Here's the StackOverflow question

davidysong

davidysong commented on May 17, 2017

@davidysong

I have the same issue also. I am wondering if using a custom Transitioner would allow resetting the stack without any animations: https://reactnavigation.org/docs/views/transitioner

aqnaruto

aqnaruto commented on May 17, 2017

@aqnaruto

@diegorodriguesvieira hey, you need not to jump to another page, just use header null , and setstate in one page render different component

LaurensLang

LaurensLang commented on May 17, 2017

@LaurensLang

@diegorodriguesvieira i don't understand?

diegorodriguesvieira

diegorodriguesvieira commented on May 17, 2017

@diegorodriguesvieira
Author

@aqnaruto but if I just navigate to a page without a header, I'll still have the navigation stack with the items because it has not been reset, can I have performance issues with that?

diegorodriguesvieira

diegorodriguesvieira commented on May 17, 2017

@diegorodriguesvieira
Author

@LaurensLang I need to reset to the first navigation page inside the tab, however without seeing the animations for each card in the stack

diegorodriguesvieira

diegorodriguesvieira commented on May 17, 2017

@diegorodriguesvieira
Author

@davidysong I will try, thanks

andreecosta

andreecosta commented on May 18, 2017

@andreecosta

+1 anyone with a solution?

sckoh

sckoh commented on May 18, 2017

@sckoh

+1

lyubo

lyubo commented on May 18, 2017

@lyubo

+1

mnkang89

mnkang89 commented on May 23, 2017

@mnkang89

+1

MSchmidt

MSchmidt commented on May 23, 2017

@MSchmidt

@diegorodriguesvieira did you figure this out yet? What you are trying to accomplish is basically default iOS behaviour and should work out of the box ideally.

faceyspacey

faceyspacey commented on May 24, 2017

@faceyspacey

Here's a concise proposal that will fix this in many other issues:

#1663

61 remaining items

added a commit that references this issue on Oct 26, 2017
toandk

toandk commented on Nov 1, 2017

@toandk

This solution worked for me. Note that if you have 4 screen A, B, C, D and want to back from D to A, you have to call NavigationActions.back with key of B

backToRoute = (navigation, name) => {
    const routes = navigation.state.routes
    for (var i = 0; i < routes.length - 1; i++) {
      if (routes[i].routeName == name) {
        navigation.dispatch(NavigationActions.back({ key: routes[i + 1].key }))
        break
      }
    }
  }
```
vonovak

vonovak commented on Nov 18, 2017

@vonovak
Member

closing since this was fixed by #2520, but feel free to reopen in case the issue persists

eballeste

eballeste commented on Dec 9, 2017

@eballeste

@vonovak #2520 does not work as intended.

After almost giving up on react-navigation I found your example for extending the NavigatorService but it is incomplete, it's missing the return for when there are no nested navigators.

function getRouteWithName(navigationState, name) {
  if (!navigationState) {
    return null;
  }
  const route = navigationState.routes[navigationState.index];

  // dive into nested navigators
  if (route.routes) {
    // NOTE +1 is because goBack accepts from, not to!
    const index = route.routes.findIndex(r => r.routeName === name);
    if (index > -1) {
      return route.routes[index + 1];
    }
    return getRouteWithName(route, name);
  } else {
    const index = navigationState.routes.findIndex(r => r.routeName === name);
    if (index > -1) return navigationState.routes[index + 1];
  }

  return null;
}
dustturtle

dustturtle commented on Jan 11, 2018

@dustturtle

does this issues solved? In iOS we can simply push viewcontrollers by nav just disable the animation.

pisangGoreng

pisangGoreng commented on Jan 19, 2018

@pisangGoreng
  • 1 ..
dustturtle

dustturtle commented on Jan 25, 2018

@dustturtle

welcome to RNRF, easy case for that~

luqmanrom

luqmanrom commented on Feb 2, 2018

@luqmanrom

How is it solved in RNRF @dustturtle

andidev

andidev commented on Feb 18, 2018

@andidev

@luqmanrom it is not solved there as well. RNRF is based on React Navigation.
see aksonov/react-native-router-flux#2713

brentvatne

brentvatne commented on Feb 21, 2018

@brentvatne
Member

can someone please create a new issue for this and include a link to an example reproducing it on https://snack.expo.io or github? please without any superfluous code. I'd be happy to investigate. thanks!

locked and limited conversation to collaborators on Feb 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @MSchmidt@brentvatne@faceyspacey@lyubo@andidev

        Issue actions

          How to reset the navigation stack without animation? · Issue #1493 · react-navigation/react-navigation