From da34ae654f4dfc03f595169b6b90cca8de4c4a69 Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Fri, 19 Aug 2016 17:18:42 -0700 Subject: [PATCH] Ease Material route animations redux (#5509) --- packages/flutter/lib/src/widgets/heroes.dart | 13 +++--- packages/flutter/test/widget/heroes_test.dart | 41 ++++++++++++++++++- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/packages/flutter/lib/src/widgets/heroes.dart b/packages/flutter/lib/src/widgets/heroes.dart index a4ce350920..6820b34971 100644 --- a/packages/flutter/lib/src/widgets/heroes.dart +++ b/packages/flutter/lib/src/widgets/heroes.dart @@ -447,7 +447,7 @@ class HeroController extends NavigatorObserver { if (previousRoute is PageRoute) // could be null _from = previousRoute; _to = route; - _animation = new CurvedAnimation(parent: route.animation, curve: Curves.fastOutSlowIn); + _animation = route.animation; _checkForHeroQuest(); } } @@ -461,7 +461,7 @@ class HeroController extends NavigatorObserver { if (previousRoute is PageRoute) { _to = previousRoute; _from = route; - _animation = new CurvedAnimation(parent: route.animation, curve: Curves.fastOutSlowIn); + _animation = route.animation; _checkForHeroQuest(); } } @@ -516,19 +516,18 @@ class HeroController extends NavigatorObserver { Map heroesTo = Hero.of(_to.subtreeContext); _to.offstage = false; - Animation animation = _animation; + Animation animation = _animation; // The route's animation. Curve curve = Curves.fastOutSlowIn; if (animation.status == AnimationStatus.reverse) { animation = new ReverseAnimation(animation); curve = new Interval(animation.value, 1.0, curve: curve); } + animation = new CurvedAnimation(parent: animation, curve: curve); _party.animate(heroesFrom, heroesTo, _getAnimationArea(navigator.context)); _removeHeroesFromOverlay(); - _party.setAnimation(new CurvedAnimation( - parent: animation, - curve: curve - )); + _party.setAnimation(animation); + for (_HeroQuestState hero in _party._heroes) { hero.overlayEntry = _addHeroToOverlay( (BuildContext context) => hero.build(navigator.context, animation), diff --git a/packages/flutter/test/widget/heroes_test.dart b/packages/flutter/test/widget/heroes_test.dart index 029dc4910f..f70cc29850 100644 --- a/packages/flutter/test/widget/heroes_test.dart +++ b/packages/flutter/test/widget/heroes_test.dart @@ -177,6 +177,46 @@ void main() { 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 { List log = []; @@ -246,5 +286,4 @@ void main() { await tester.tap(find.text('bar')); expect(log, equals(['bar'])); }); - }