From 4e16b9db294241bd097fccc7548ec2f525268fd4 Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Thu, 21 Dec 2017 15:02:03 -0800 Subject: [PATCH] Attempt a less invasive way to disable fading. (#13733) Hopefully this will fix the performance regression in https://github.com/flutter/flutter/pull/13680 but with an easier way to flip the switch. --- packages/flutter/lib/src/material/page.dart | 14 ++++++++++++-- packages/flutter/test/material/page_test.dart | 4 ++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/flutter/lib/src/material/page.dart b/packages/flutter/lib/src/material/page.dart index 40e40de6fe8..54a2849ff5a 100644 --- a/packages/flutter/lib/src/material/page.dart +++ b/packages/flutter/lib/src/material/page.dart @@ -18,16 +18,17 @@ final Tween _kBottomUpTween = new Tween( class _MountainViewPageTransition extends StatelessWidget { _MountainViewPageTransition({ Key key, + @required bool fade, @required Animation routeAnimation, @required this.child, }) : _positionAnimation = _kBottomUpTween.animate(new CurvedAnimation( parent: routeAnimation, // The route's linear 0.0 - 1.0 animation. curve: Curves.fastOutSlowIn, )), - _opacityAnimation = new CurvedAnimation( + _opacityAnimation = fade ? new CurvedAnimation( parent: routeAnimation, curve: Curves.easeIn, // Eyeballed from other Material apps. - ), + ) : const AlwaysStoppedAnimation(1.0), super(key: key); final Animation _positionAnimation; @@ -83,6 +84,14 @@ class MaterialPageRoute extends PageRoute { assert(opaque); } + /// Turns on the fading of routes during page transitions. + /// + /// This is currently disabled by default because of performance issues on + /// low-end phones. Eventually these issues will be resolved and this flag + /// will be removed. + @Deprecated('This flag will eventually be removed once the performance issues are resolved. See: https://github.com/flutter/flutter/issues/13736') + static bool debugEnableFadingRoutes = false; + /// Builds the primary contents of the route. final WidgetBuilder builder; @@ -159,6 +168,7 @@ class MaterialPageRoute extends PageRoute { return new _MountainViewPageTransition( routeAnimation: animation, child: child, + fade: debugEnableFadingRoutes, // ignore: deprecated_member_use ); } } diff --git a/packages/flutter/test/material/page_test.dart b/packages/flutter/test/material/page_test.dart index 5841beb628c..143951ecc66 100644 --- a/packages/flutter/test/material/page_test.dart +++ b/packages/flutter/test/material/page_test.dart @@ -40,7 +40,7 @@ void main() { // Animation begins 3/4 of the way up the page. expect(widget2TopLeft.dy < widget2Size.height / 4.0, true); // Animation starts with page 2 being near transparent. - expect(widget2Opacity.opacity < 0.01, true); + expect(widget2Opacity.opacity < 0.01, MaterialPageRoute.debugEnableFadingRoutes); // ignore: deprecated_member_use await tester.pump(const Duration(milliseconds: 300)); @@ -59,7 +59,7 @@ void main() { // Page 2 starts to move down. expect(widget1TopLeft.dy < widget2TopLeft.dy, true); // Page 2 starts to lose opacity. - expect(widget2Opacity.opacity < 1.0, true); + expect(widget2Opacity.opacity < 1.0, MaterialPageRoute.debugEnableFadingRoutes); // ignore: deprecated_member_use await tester.pump(const Duration(milliseconds: 300));