Commit da34ae65 authored by Hans Muller's avatar Hans Muller Committed by GitHub

Ease Material route animations redux (#5509)

parent 789bfa42
...@@ -447,7 +447,7 @@ class HeroController extends NavigatorObserver { ...@@ -447,7 +447,7 @@ class HeroController extends NavigatorObserver {
if (previousRoute is PageRoute<dynamic>) // could be null if (previousRoute is PageRoute<dynamic>) // could be null
_from = previousRoute; _from = previousRoute;
_to = route; _to = route;
_animation = new CurvedAnimation(parent: route.animation, curve: Curves.fastOutSlowIn); _animation = route.animation;
_checkForHeroQuest(); _checkForHeroQuest();
} }
} }
...@@ -461,7 +461,7 @@ class HeroController extends NavigatorObserver { ...@@ -461,7 +461,7 @@ class HeroController extends NavigatorObserver {
if (previousRoute is PageRoute<dynamic>) { if (previousRoute is PageRoute<dynamic>) {
_to = previousRoute; _to = previousRoute;
_from = route; _from = route;
_animation = new CurvedAnimation(parent: route.animation, curve: Curves.fastOutSlowIn); _animation = route.animation;
_checkForHeroQuest(); _checkForHeroQuest();
} }
} }
...@@ -516,19 +516,18 @@ class HeroController extends NavigatorObserver { ...@@ -516,19 +516,18 @@ class HeroController extends NavigatorObserver {
Map<Object, HeroHandle> heroesTo = Hero.of(_to.subtreeContext); Map<Object, HeroHandle> heroesTo = Hero.of(_to.subtreeContext);
_to.offstage = false; _to.offstage = false;
Animation<double> animation = _animation; Animation<double> animation = _animation; // The route's animation.
Curve curve = Curves.fastOutSlowIn; Curve curve = Curves.fastOutSlowIn;
if (animation.status == AnimationStatus.reverse) { if (animation.status == AnimationStatus.reverse) {
animation = new ReverseAnimation(animation); animation = new ReverseAnimation(animation);
curve = new Interval(animation.value, 1.0, curve: curve); curve = new Interval(animation.value, 1.0, curve: curve);
} }
animation = new CurvedAnimation(parent: animation, curve: curve);
_party.animate(heroesFrom, heroesTo, _getAnimationArea(navigator.context)); _party.animate(heroesFrom, heroesTo, _getAnimationArea(navigator.context));
_removeHeroesFromOverlay(); _removeHeroesFromOverlay();
_party.setAnimation(new CurvedAnimation( _party.setAnimation(animation);
parent: animation,
curve: curve
));
for (_HeroQuestState hero in _party._heroes) { for (_HeroQuestState hero in _party._heroes) {
hero.overlayEntry = _addHeroToOverlay( hero.overlayEntry = _addHeroToOverlay(
(BuildContext context) => hero.build(navigator.context, animation), (BuildContext context) => hero.build(navigator.context, animation),
......
...@@ -177,6 +177,46 @@ void main() { ...@@ -177,6 +177,46 @@ void main() {
await tester.pump(new Duration(seconds: 1)); await tester.pump(new Duration(seconds: 1));
}); });
testWidgets('Heroes animation is fastOutSlowIn', (WidgetTester tester) async {
await tester.pumpWidget(new MaterialApp(routes: routes));
await tester.tap(find.text('two'));
await tester.pump(); // begin navigation
// Expect the height of the secondKey Hero to vary from 100 to 150
// over duration and according to curve.
final Duration duration = const Duration(milliseconds: 300);
final Curve curve = Curves.fastOutSlowIn;
final double initialHeight = tester.getSize(find.byKey(firstKey)).height;
final double finalHeight = tester.getSize(find.byKey(secondKey)).height;
final double deltaHeight = finalHeight - initialHeight;
final double epsilon = 0.001;
await tester.pump(duration * 0.25);
expect(
tester.getSize(find.byKey(secondKey)).height,
closeTo(curve.transform(0.25) * deltaHeight + initialHeight, epsilon)
);
await tester.pump(duration * 0.25);
expect(
tester.getSize(find.byKey(secondKey)).height,
closeTo(curve.transform(0.50) * deltaHeight + initialHeight, epsilon)
);
await tester.pump(duration * 0.25);
expect(
tester.getSize(find.byKey(secondKey)).height,
closeTo(curve.transform(0.75) * deltaHeight + initialHeight, epsilon)
);
await tester.pump(duration * 0.25);
expect(
tester.getSize(find.byKey(secondKey)).height,
closeTo(curve.transform(1.0) * deltaHeight + initialHeight, epsilon)
);
});
testWidgets('Heroes are not interactive', (WidgetTester tester) async { testWidgets('Heroes are not interactive', (WidgetTester tester) async {
List<String> log = <String>[]; List<String> log = <String>[];
...@@ -246,5 +286,4 @@ void main() { ...@@ -246,5 +286,4 @@ void main() {
await tester.tap(find.text('bar')); await tester.tap(find.text('bar'));
expect(log, equals(<String>['bar'])); expect(log, equals(<String>['bar']));
}); });
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment