[Navigator] Animated replace
See original GitHub issueI often find myself wanting to “replace” a route i.e not adding to the history yet have the route change animate.
In iOS I would do something like this.
[navigationController popToRootViewControllerAnimated:NO];
[navigationController pushViewController:someOtherViewController animated:YES];
Maybe this is related to issue #1953 I think I would prefer an api where we could do
replace(route, animated);
push(route, animated);
Issue Analytics
- State:
- Created 8 years ago
- Reactions:4
- Comments:27 (10 by maintainers)
Top Results From Across the Web
How to change navigation animation using Flutter
You can achieve this by using CupertinoPageRoute. Please check the below code. import 'package:flutter/material.dart'; import 'package:flutter/ ...
Read more >Animate a page route transition - Flutter documentation
To help, PageRouteBuilder provides an Animation object. This Animation can be used with Tween and Curve objects to customize the transition animation.
Read more >navigation.replace animation with 2.0.x · Issue #7031 - GitHub
Resolved with the following work around: Pass a route param animate: false when going to this screen with a .replace call. Then on...
Read more >Stack Navigator | React Navigation
If you specify a custom header, React Navigation will change it to screen automatically so that the header animated along with the screen...
Read more >Custom Animated Transition in React Navigation with Stack ...
In this video, we create Custom Animated Transition in React Navigation with Stack Navigator (aka shared transition).
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have tried all of these solutions above but all didn’t work. So I had to check the Navigator source code while coded on my own. Finally after solving some problems such as flashing and animating, not working at all, replacing without animation though I have written the code, I got the solution.
These are my code below. Most of them are copied from Navigator source code. What I did is just combine them in a right way. Um…of course, they still can be optimized. And they too much hard to understand. Trust me, I won’t understand after tonight. But it works. It’s enough. BTW, my RN is 0.27.
After defining that in prototype, you can use it anywhere you want. Just like
navigator.replaceWithAnimation(route);
Inspired by the suggestion from @grabbou, I am now using this workaround:
Note the overwrites of
replace()
andpop()
. pop will skip all routes that have been replaced.