From 819bb539f17dcd84e21ffb128d9c87a5cbbb263f Mon Sep 17 00:00:00 2001 From: xster Date: Wed, 12 Apr 2017 16:25:12 -0700 Subject: [PATCH] Slight efficiency improvement on all page transitions (#9356) Remove intermediate animation listener --- packages/flutter/lib/src/cupertino/page.dart | 45 ++++++++------------ packages/flutter/lib/src/material/page.dart | 45 ++++++++++---------- 2 files changed, 41 insertions(+), 49 deletions(-) diff --git a/packages/flutter/lib/src/cupertino/page.dart b/packages/flutter/lib/src/cupertino/page.dart index b1ae0fa58d..e1a16bd5e3 100644 --- a/packages/flutter/lib/src/cupertino/page.dart +++ b/packages/flutter/lib/src/cupertino/page.dart @@ -20,14 +20,17 @@ final FractionalOffsetTween _kMiddleLeftTween = new FractionalOffsetTween( end: const FractionalOffset(-1.0/3.0, 0.0), ); +// Fractional offset from offscreen below to fully on screen. +final FractionalOffsetTween _kBottomUpTween = new FractionalOffsetTween( + begin: FractionalOffset.bottomLeft, + end: FractionalOffset.topLeft, +); + /// Provides the native iOS page transition animation. /// -/// Takes in a page widget and a route animation from a [TransitionRoute] and produces an -/// AnimatedWidget wrapping that animates the page transition. -/// /// The page slides in from the right and exits in reverse. It also shifts to the left in /// a parallax motion when another page enters to cover it. -class CupertinoPageTransition extends AnimatedWidget { +class CupertinoPageTransition extends StatelessWidget { CupertinoPageTransition({ Key key, // Linear route animation from 0.0 to 1.0 when this screen is being pushed. @@ -55,13 +58,7 @@ class CupertinoPageTransition extends AnimatedWidget { reverseCurve: Curves.easeIn, ) ), - super( - key: key, - // Trigger a rebuild whenever any of the 2 animation route happens. - listenable: new Listenable.merge( - [incomingRouteAnimation, outgoingRouteAnimation] - ), - ); + super(key: key); // When this page is coming in to cover another page. final Animation _incomingPositionAnimation; @@ -91,32 +88,26 @@ class CupertinoPageTransition extends AnimatedWidget { /// Transitions used for summoning fullscreen dialogs in iOS such as creating a new /// calendar event etc by bringing in the next screen from the bottom. -class CupertinoFullscreenDialogTransition extends AnimatedWidget { +class CupertinoFullscreenDialogTransition extends StatelessWidget { CupertinoFullscreenDialogTransition({ Key key, @required Animation animation, @required this.child, - }) : super( - key: key, - listenable: _kBottomUpTween.animate( - new CurvedAnimation( - parent: animation, - curve: Curves.easeInOut, - ) - ), - ); - - static final FractionalOffsetTween _kBottomUpTween = new FractionalOffsetTween( - begin: FractionalOffset.bottomLeft, - end: FractionalOffset.topLeft, - ); + }) : _positionAnimation = _kBottomUpTween.animate( + new CurvedAnimation( + parent: animation, + curve: Curves.easeInOut, + ) + ), + super(key: key); + final Animation _positionAnimation; final Widget child; @override Widget build(BuildContext context) { return new SlideTransition( - position: listenable, + position: _positionAnimation, child: child, ); } diff --git a/packages/flutter/lib/src/material/page.dart b/packages/flutter/lib/src/material/page.dart index e99cf5179d..f72a463bf7 100644 --- a/packages/flutter/lib/src/material/page.dart +++ b/packages/flutter/lib/src/material/page.dart @@ -3,43 +3,44 @@ // found in the LICENSE file. import 'package:flutter/cupertino.dart'; -import 'package:flutter/foundation.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; import 'theme.dart'; +// Fractional offset from 1/4 screen below the top to fully on screen. +final FractionalOffsetTween _kBottomUpTween = new FractionalOffsetTween( + begin: const FractionalOffset(0.0, 0.25), + end: FractionalOffset.topLeft +); + // Used for Android and Fuchsia. -class _MountainViewPageTransition extends AnimatedWidget { +class _MountainViewPageTransition extends StatelessWidget { _MountainViewPageTransition({ Key key, - this.routeAnimation, - this.child, - }) : super( - key: key, - listenable: _kTween.animate(new CurvedAnimation( - parent: routeAnimation, // The route's linear 0.0 - 1.0 animation. - curve: Curves.fastOutSlowIn - ) - )); - - static final FractionalOffsetTween _kTween = new FractionalOffsetTween( - begin: const FractionalOffset(0.0, 0.25), - end: FractionalOffset.topLeft - ); + @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( + parent: routeAnimation, + curve: Curves.easeIn, // Eyeballed from other Material apps. + ), + super(key: key); + final Animation _positionAnimation; + final Animation _opacityAnimation; final Widget child; - final Animation routeAnimation; @override Widget build(BuildContext context) { // TODO(ianh): tell the transform to be un-transformed for hit testing return new SlideTransition( - position: listenable, + position: _positionAnimation, child: new FadeTransition( - opacity: new CurvedAnimation( - parent: routeAnimation, - curve: Curves.easeIn, // Eyeballed from other Material apps. - ), + opacity: _opacityAnimation, child: child, ), );