Slight efficiency improvement on all page transitions (#9356)
Remove intermediate animation listener
This commit is contained in:
@@ -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(
|
||||
<Listenable>[incomingRouteAnimation, outgoingRouteAnimation]
|
||||
),
|
||||
);
|
||||
super(key: key);
|
||||
|
||||
// When this page is coming in to cover another page.
|
||||
final Animation<FractionalOffset> _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<double> 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<FractionalOffset> _positionAnimation;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new SlideTransition(
|
||||
position: listenable,
|
||||
position: _positionAnimation,
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<double> 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<FractionalOffset> _positionAnimation;
|
||||
final Animation<double> _opacityAnimation;
|
||||
final Widget child;
|
||||
final Animation<double> 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,
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user