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

How to reset the navigation stack without animation? #1493

Closed
diegorodriguesvieira opened this issue May 12, 2017 · 59 comments
Closed

How to reset the navigation stack without animation? #1493

diegorodriguesvieira opened this issue May 12, 2017 · 59 comments

Comments

@diegorodriguesvieira
Copy link

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);
@diegorodriguesvieira diegorodriguesvieira changed the title Hot to reset the navigation stack without animation? How to reset the navigation stack without animation? May 12, 2017
@turnipdabeets
Copy link

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

@davidysong
Copy link

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
Copy link

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

@LaurensLang
Copy link

LaurensLang commented May 17, 2017

@diegorodriguesvieira i don't understand?

@diegorodriguesvieira
Copy link
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
Copy link
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
Copy link
Author

@davidysong I will try, thanks

@andreecosta
Copy link

+1 anyone with a solution?

@sckoh
Copy link

sckoh commented May 18, 2017

+1

2 similar comments
@lyubo
Copy link

lyubo commented May 18, 2017

+1

@mnkang89
Copy link

+1

@MSchmidt
Copy link

@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
Copy link

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

#1663

@binzailani3136
Copy link

binzailani3136 commented Jun 3, 2017

I've really similar issue.
My navigation structure is like below

TabNavigator
---Tab1(StackNavigator)
--------Screen1
----------Screen2
---Tab2
---Tab3

The problem is - when first land on Tab1, it shows Screen1 and I can navigate to Screen2.
And then I go to Tab2 and I go back Tab1 again and reset the Tab1's StackNavigator to show Screen1(First page of Tab1) because Tab1's current page is Screen2.
Reset works but when I am doing reset, it shows transition animation of back transition Screen2->Screen1
I really want to remove this back transition animation when resetting Tab1's StackNavigator.
Is there any workaround of this issue?

I've spent so much time to solve this issue and googled a lot.
But no appropriate answers about this issue.
Some one answered that we can use transitionConfig option but if we remove animation by this option, the animation of navigate action also removed.
Such as Screen1->Screen2 animation also removed because transitionConfig is set on StacNavigator of Tab1 and this config removes all animation of Tab1's StackNavigator.

I want to show animation when navigating and only want to remove animation when resetting.
Any kind of answers will be appreciated.
Thanks

@cccRaim
Copy link

cccRaim commented Jun 30, 2017

+1
When I want to backward more than 1 screen, the animation is "5-4-3-2-1", but I just want "5-1"

@jamesone
Copy link

jamesone commented Jul 6, 2017

@diegorodriguesvieira Did you find a workaround for this?

@diegorodriguesvieira
Copy link
Author

Hello @jamesone, unfortunately I have not found any workaround yet...

@NSShentu
Copy link

@diegorodriguesvieira @jamesone
i also get the same problem. So if you have any workaround pelase tell me .

@NSShentu
Copy link

@cccRaim 中间页面的闪屏怎么去掉,,,你有方法吗?

@rajsuvariya
Copy link

Has anyone found any solution for this issue?

@NSShentu
Copy link

@rajsuvariya yeah~ I change some project code then it work fine. You can check this https://github.com/gorokhovich/react-navigation/commit/30e6d0cc73406e7697f5b846a3a7c6a1ddca9862

@rajsuvariya
Copy link

@NSShentu sorry I am not able to understand anything from the link. Can you provide code for removing animations?

@NSShentu
Copy link

@rajsuvariya
+

  • // work around for flashing scenes
  • let k = null;
  • let v = null;
  • staleScenes.forEach(scene => {
  • let {key} = scene;
  • k = key;
  • v = scene;
  • });
  • newStaleScenes = k && v ? new Map([[k, v]]) : new Map();
  • newStaleScenes.forEach(mergeScene);
  • // staleScenes.forEach(mergeScene);
  • // work around end

use the + code replace the function:
staleScenes.forEach(mergeScene);
in src/views/ScenesReducer.js file

@rajsuvariya
Copy link

@NSShentu Thanks it solved the issue

@acahir
Copy link

acahir commented Jul 27, 2017

Same issue. From the reactions on this issue, it sounds like most would assume a single transition animation on a reset should be the default.

@NSShentu are you going to submit a PR?

@rishabhbhatia
Copy link

+1

@rishabhbhatia
Copy link

@NSShentu your code works, but it gives black screen for a second. any solution?

@evollu
Copy link

evollu commented Sep 18, 2017

My temporary solution is creating a custom action Navigation/ROOT and do a init followed by reset. In that case there is no animation.

and my reducer looks like

export const reducer = (state, action: any = {}) => {
  let newState;
  if (action.type === 'Navigation/ROOT') {
    newState = AppNavigator.router.getStateForAction(NavigationActions.reset({
      index: 0,
      actions: [
        NavigationActions.navigate({ routeName: action.routeName })
      ]
    }), AppNavigator.router.getStateForAction(NavigationActions.init()));
  } else {
    newState = AppNavigator.router.getStateForAction(action, state);
  }
  return newState || state;
}

@etaiklein
Copy link

etaiklein commented Sep 20, 2017

@evollu this ended up overwriting my Home routename (though it may be more related to my setup).

This solution worked for my personal setup:

export const reducer = (state, action: any = {}) => {
  let newState;
  if (action.type === 'Navigation/ROOT') {
    // fully reset routes to initial state
    newState = AppNavigator.router.getStateForAction(NavigationActions.init());
    // put me back on my last tab
    newState.routes[0].index = TabHomeRoutes.indexOf(action.routeName);
  } else {
    newState = AppNavigator.router.getStateForAction(action, state);
  }
  return newState || state;
}

94cstyles added a commit to 94cstyles/react-navigation that referenced this issue Sep 27, 2017
94cstyles added a commit to 94cstyles/react-navigation that referenced this issue Sep 27, 2017
mcadelago pushed a commit to mcadelago/react-navigation that referenced this issue Oct 3, 2017
@rodrigooler
Copy link

+1

2 similar comments
@omeraplak
Copy link

+1

@dale-french
Copy link

+1

94cstyles added a commit to 94cstyles/react-navigation that referenced this issue Oct 19, 2017
94cstyles added a commit to 94cstyles/react-navigation that referenced this issue Oct 23, 2017
vonovak pushed a commit that referenced this issue Oct 26, 2017
* Fix animation (#1493)

* Rewrite the file animatedInterpolate.js. To increase readability.

* Rename the variable, To increase readability.

* minor renaming
@toandk
Copy link

toandk commented Nov 1, 2017

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
Copy link
Member

vonovak commented Nov 18, 2017

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

@vonovak vonovak closed this as completed Nov 18, 2017
@eballeste
Copy link

eballeste commented Dec 9, 2017

@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
Copy link

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

@pisangGoreng
Copy link

  • 1 ..

@dustturtle
Copy link

welcome to RNRF, easy case for that~

@luqmanrom
Copy link

How is it solved in RNRF @dustturtle

@andidev
Copy link

andidev commented Feb 18, 2018

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

@brentvatne
Copy link
Member

brentvatne commented Feb 21, 2018

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!

@react-navigation react-navigation locked and limited conversation to collaborators Feb 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests