Commit 819bb539 authored by xster's avatar xster Committed by GitHub

Slight efficiency improvement on all page transitions (#9356)

Remove intermediate animation listener
parent 9f34e2e4
...@@ -20,14 +20,17 @@ final FractionalOffsetTween _kMiddleLeftTween = new FractionalOffsetTween( ...@@ -20,14 +20,17 @@ final FractionalOffsetTween _kMiddleLeftTween = new FractionalOffsetTween(
end: const FractionalOffset(-1.0/3.0, 0.0), 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. /// 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 /// 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. /// a parallax motion when another page enters to cover it.
class CupertinoPageTransition extends AnimatedWidget { class CupertinoPageTransition extends StatelessWidget {
CupertinoPageTransition({ CupertinoPageTransition({
Key key, Key key,
// Linear route animation from 0.0 to 1.0 when this screen is being pushed. // Linear route animation from 0.0 to 1.0 when this screen is being pushed.
...@@ -55,13 +58,7 @@ class CupertinoPageTransition extends AnimatedWidget { ...@@ -55,13 +58,7 @@ class CupertinoPageTransition extends AnimatedWidget {
reverseCurve: Curves.easeIn, reverseCurve: Curves.easeIn,
) )
), ),
super( super(key: key);
key: key,
// Trigger a rebuild whenever any of the 2 animation route happens.
listenable: new Listenable.merge(
<Listenable>[incomingRouteAnimation, outgoingRouteAnimation]
),
);
// When this page is coming in to cover another page. // When this page is coming in to cover another page.
final Animation<FractionalOffset> _incomingPositionAnimation; final Animation<FractionalOffset> _incomingPositionAnimation;
...@@ -91,32 +88,26 @@ class CupertinoPageTransition extends AnimatedWidget { ...@@ -91,32 +88,26 @@ class CupertinoPageTransition extends AnimatedWidget {
/// Transitions used for summoning fullscreen dialogs in iOS such as creating a new /// 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. /// calendar event etc by bringing in the next screen from the bottom.
class CupertinoFullscreenDialogTransition extends AnimatedWidget { class CupertinoFullscreenDialogTransition extends StatelessWidget {
CupertinoFullscreenDialogTransition({ CupertinoFullscreenDialogTransition({
Key key, Key key,
@required Animation<double> animation, @required Animation<double> animation,
@required this.child, @required this.child,
}) : super( }) : _positionAnimation = _kBottomUpTween.animate(
key: key, new CurvedAnimation(
listenable: _kBottomUpTween.animate( parent: animation,
new CurvedAnimation( curve: Curves.easeInOut,
parent: animation, )
curve: Curves.easeInOut, ),
) super(key: key);
),
); final Animation<FractionalOffset> _positionAnimation;
static final FractionalOffsetTween _kBottomUpTween = new FractionalOffsetTween(
begin: FractionalOffset.bottomLeft,
end: FractionalOffset.topLeft,
);
final Widget child; final Widget child;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new SlideTransition( return new SlideTransition(
position: listenable, position: _positionAnimation,
child: child, child: child,
); );
} }
......
...@@ -3,43 +3,44 @@ ...@@ -3,43 +3,44 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'theme.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. // Used for Android and Fuchsia.
class _MountainViewPageTransition extends AnimatedWidget { class _MountainViewPageTransition extends StatelessWidget {
_MountainViewPageTransition({ _MountainViewPageTransition({
Key key, Key key,
this.routeAnimation, @required Animation<double> routeAnimation,
this.child, @required this.child,
}) : super( }) : _positionAnimation = _kBottomUpTween.animate(new CurvedAnimation(
key: key, parent: routeAnimation, // The route's linear 0.0 - 1.0 animation.
listenable: _kTween.animate(new CurvedAnimation( curve: Curves.fastOutSlowIn,
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.
),
static final FractionalOffsetTween _kTween = new FractionalOffsetTween( super(key: key);
begin: const FractionalOffset(0.0, 0.25),
end: FractionalOffset.topLeft final Animation<FractionalOffset> _positionAnimation;
); final Animation<double> _opacityAnimation;
final Widget child; final Widget child;
final Animation<double> routeAnimation;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// TODO(ianh): tell the transform to be un-transformed for hit testing // TODO(ianh): tell the transform to be un-transformed for hit testing
return new SlideTransition( return new SlideTransition(
position: listenable, position: _positionAnimation,
child: new FadeTransition( child: new FadeTransition(
opacity: new CurvedAnimation( opacity: _opacityAnimation,
parent: routeAnimation,
curve: Curves.easeIn, // Eyeballed from other Material apps.
),
child: child, child: child,
), ),
); );
......
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