Switch Navigator over to using AnimationController
This patch moves Navigator and related code over to using AnimationController.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
library animation;
|
||||
|
||||
export 'src/animation/animated_value.dart';
|
||||
export 'src/animation/animations.dart';
|
||||
export 'src/animation/clamped_simulation.dart';
|
||||
export 'src/animation/curves.dart';
|
||||
export 'src/animation/forces.dart';
|
||||
|
||||
248
packages/flutter/lib/src/animation/animations.dart
Normal file
248
packages/flutter/lib/src/animation/animations.dart
Normal file
@@ -0,0 +1,248 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:ui' show VoidCallback;
|
||||
|
||||
import 'animated_value.dart';
|
||||
import 'listener_helpers.dart';
|
||||
import 'tween.dart';
|
||||
|
||||
class AlwaysCompleteAnimation extends Animated<double> {
|
||||
const AlwaysCompleteAnimation();
|
||||
|
||||
// this performance never changes state
|
||||
void addListener(VoidCallback listener) { }
|
||||
void removeListener(VoidCallback listener) { }
|
||||
void addStatusListener(PerformanceStatusListener listener) { }
|
||||
void removeStatusListener(PerformanceStatusListener listener) { }
|
||||
PerformanceStatus get status => PerformanceStatus.completed;
|
||||
AnimationDirection get direction => AnimationDirection.forward;
|
||||
double get value => 1.0;
|
||||
}
|
||||
|
||||
const AlwaysCompleteAnimation kAlwaysCompleteAnimation = const AlwaysCompleteAnimation();
|
||||
|
||||
class AlwaysDismissedAnimation extends Animated<double> {
|
||||
const AlwaysDismissedAnimation();
|
||||
|
||||
// this performance never changes state
|
||||
void addListener(VoidCallback listener) { }
|
||||
void removeListener(VoidCallback listener) { }
|
||||
void addStatusListener(PerformanceStatusListener listener) { }
|
||||
void removeStatusListener(PerformanceStatusListener listener) { }
|
||||
PerformanceStatus get status => PerformanceStatus.dismissed;
|
||||
AnimationDirection get direction => AnimationDirection.forward;
|
||||
double get value => 0.0;
|
||||
}
|
||||
|
||||
const AlwaysDismissedAnimation kAlwaysDismissedAnimation = const AlwaysDismissedAnimation();
|
||||
|
||||
class ProxyAnimation extends Animated<double>
|
||||
with LazyListenerMixin, LocalPerformanceListenersMixin, LocalPerformanceStatusListenersMixin {
|
||||
ProxyAnimation([Animated<double> animation]) {
|
||||
_masterAnimation = animation;
|
||||
if (_masterAnimation == null) {
|
||||
_status = PerformanceStatus.dismissed;
|
||||
_direction = AnimationDirection.forward;
|
||||
_value = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
PerformanceStatus _status;
|
||||
AnimationDirection _direction;
|
||||
double _value;
|
||||
|
||||
Animated<double> get masterAnimation => _masterAnimation;
|
||||
Animated<double> _masterAnimation;
|
||||
void set masterAnimation(Animated<double> value) {
|
||||
if (value == _masterAnimation)
|
||||
return;
|
||||
if (_masterAnimation != null) {
|
||||
_status = _masterAnimation.status;
|
||||
_direction = _masterAnimation.direction;
|
||||
_value = _masterAnimation.value;
|
||||
if (isListening)
|
||||
didStopListening();
|
||||
}
|
||||
_masterAnimation = value;
|
||||
if (_masterAnimation != null) {
|
||||
if (isListening)
|
||||
didStartListening();
|
||||
if (_value != _masterAnimation.value)
|
||||
notifyListeners();
|
||||
if (_status != _masterAnimation.status)
|
||||
notifyStatusListeners(_masterAnimation.status);
|
||||
_status = null;
|
||||
_direction = null;
|
||||
_value = null;
|
||||
}
|
||||
}
|
||||
|
||||
void didStartListening() {
|
||||
if (_masterAnimation != null) {
|
||||
_masterAnimation.addListener(notifyListeners);
|
||||
_masterAnimation.addStatusListener(notifyStatusListeners);
|
||||
}
|
||||
}
|
||||
|
||||
void didStopListening() {
|
||||
if (_masterAnimation != null) {
|
||||
_masterAnimation.removeListener(notifyListeners);
|
||||
_masterAnimation.removeStatusListener(notifyStatusListeners);
|
||||
}
|
||||
}
|
||||
|
||||
PerformanceStatus get status => _masterAnimation != null ? _masterAnimation.status : _status;
|
||||
AnimationDirection get direction => _masterAnimation != null ? _masterAnimation.direction : _direction;
|
||||
double get value => _masterAnimation != null ? _masterAnimation.value : _value;
|
||||
}
|
||||
|
||||
class ReverseAnimation extends Animated<double>
|
||||
with LazyListenerMixin, LocalPerformanceStatusListenersMixin {
|
||||
ReverseAnimation(this.masterAnimation);
|
||||
|
||||
final Animated<double> masterAnimation;
|
||||
|
||||
void addListener(VoidCallback listener) {
|
||||
didRegisterListener();
|
||||
masterAnimation.addListener(listener);
|
||||
}
|
||||
void removeListener(VoidCallback listener) {
|
||||
masterAnimation.removeListener(listener);
|
||||
didUnregisterListener();
|
||||
}
|
||||
|
||||
void didStartListening() {
|
||||
masterAnimation.addStatusListener(_statusChangeHandler);
|
||||
}
|
||||
|
||||
void didStopListening() {
|
||||
masterAnimation.removeStatusListener(_statusChangeHandler);
|
||||
}
|
||||
|
||||
void _statusChangeHandler(PerformanceStatus status) {
|
||||
notifyStatusListeners(_reverseStatus(status));
|
||||
}
|
||||
|
||||
PerformanceStatus get status => _reverseStatus(masterAnimation.status);
|
||||
AnimationDirection get direction => _reverseDirection(masterAnimation.direction);
|
||||
double get value => 1.0 - masterAnimation.value;
|
||||
|
||||
PerformanceStatus _reverseStatus(PerformanceStatus status) {
|
||||
switch (status) {
|
||||
case PerformanceStatus.forward: return PerformanceStatus.reverse;
|
||||
case PerformanceStatus.reverse: return PerformanceStatus.forward;
|
||||
case PerformanceStatus.completed: return PerformanceStatus.dismissed;
|
||||
case PerformanceStatus.dismissed: return PerformanceStatus.completed;
|
||||
}
|
||||
}
|
||||
|
||||
AnimationDirection _reverseDirection(AnimationDirection direction) {
|
||||
switch (direction) {
|
||||
case AnimationDirection.forward: return AnimationDirection.reverse;
|
||||
case AnimationDirection.reverse: return AnimationDirection.forward;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum _TrainHoppingMode { minimize, maximize }
|
||||
|
||||
/// This animation starts by proxying one animation, but can be given a
|
||||
/// second animation. When their times cross (either because the second is
|
||||
/// going in the opposite direction, or because the one overtakes the other),
|
||||
/// the animation hops over to proxying the second animation, and the second
|
||||
/// animation becomes the new "first" performance.
|
||||
///
|
||||
/// Since this object must track the two animations even when it has no
|
||||
/// listeners of its own, instead of shutting down when all its listeners are
|
||||
/// removed, it exposes a [dispose()] method. Call this method to shut this
|
||||
/// object down.
|
||||
class TrainHoppingAnimation extends Animated<double>
|
||||
with EagerListenerMixin, LocalPerformanceListenersMixin, LocalPerformanceStatusListenersMixin {
|
||||
TrainHoppingAnimation(this._currentTrain, this._nextTrain, { this.onSwitchedTrain }) {
|
||||
assert(_currentTrain != null);
|
||||
if (_nextTrain != null) {
|
||||
if (_currentTrain.value > _nextTrain.value) {
|
||||
_mode = _TrainHoppingMode.maximize;
|
||||
} else {
|
||||
_mode = _TrainHoppingMode.minimize;
|
||||
if (_currentTrain.value == _nextTrain.value) {
|
||||
_currentTrain = _nextTrain;
|
||||
_nextTrain = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
_currentTrain.addStatusListener(_statusChangeHandler);
|
||||
_currentTrain.addListener(_valueChangeHandler);
|
||||
if (_nextTrain != null)
|
||||
_nextTrain.addListener(_valueChangeHandler);
|
||||
assert(_mode != null);
|
||||
}
|
||||
|
||||
Animated<double> get currentTrain => _currentTrain;
|
||||
Animated<double> _currentTrain;
|
||||
Animated<double> _nextTrain;
|
||||
_TrainHoppingMode _mode;
|
||||
|
||||
VoidCallback onSwitchedTrain;
|
||||
|
||||
PerformanceStatus _lastStatus;
|
||||
void _statusChangeHandler(PerformanceStatus status) {
|
||||
assert(_currentTrain != null);
|
||||
if (status != _lastStatus) {
|
||||
notifyListeners();
|
||||
_lastStatus = status;
|
||||
}
|
||||
assert(_lastStatus != null);
|
||||
}
|
||||
|
||||
PerformanceStatus get status => _currentTrain.status;
|
||||
AnimationDirection get direction => _currentTrain.direction;
|
||||
|
||||
double _lastValue;
|
||||
void _valueChangeHandler() {
|
||||
assert(_currentTrain != null);
|
||||
bool hop = false;
|
||||
if (_nextTrain != null) {
|
||||
switch (_mode) {
|
||||
case _TrainHoppingMode.minimize:
|
||||
hop = _nextTrain.value <= _currentTrain.value;
|
||||
break;
|
||||
case _TrainHoppingMode.maximize:
|
||||
hop = _nextTrain.value >= _currentTrain.value;
|
||||
break;
|
||||
}
|
||||
if (hop) {
|
||||
_currentTrain.removeStatusListener(_statusChangeHandler);
|
||||
_currentTrain.removeListener(_valueChangeHandler);
|
||||
_currentTrain = _nextTrain;
|
||||
_nextTrain.addListener(_valueChangeHandler);
|
||||
_statusChangeHandler(_nextTrain.status);
|
||||
}
|
||||
}
|
||||
double newValue = value;
|
||||
if (newValue != _lastValue) {
|
||||
notifyListeners();
|
||||
_lastValue = newValue;
|
||||
}
|
||||
assert(_lastValue != null);
|
||||
if (hop && onSwitchedTrain != null)
|
||||
onSwitchedTrain();
|
||||
}
|
||||
|
||||
double get value => _currentTrain.value;
|
||||
|
||||
/// Frees all the resources used by this performance.
|
||||
/// After this is called, this object is no longer usable.
|
||||
void dispose() {
|
||||
assert(_currentTrain != null);
|
||||
_currentTrain.removeStatusListener(_statusChangeHandler);
|
||||
_currentTrain.removeListener(_valueChangeHandler);
|
||||
_currentTrain = null;
|
||||
if (_nextTrain != null) {
|
||||
_nextTrain.removeListener(_valueChangeHandler);
|
||||
_nextTrain = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,7 +97,7 @@ abstract class Evaluatable<T> {
|
||||
|
||||
T evaluate(Animated<double> animation);
|
||||
|
||||
Animated<T> watch(Animated<double> parent) {
|
||||
Animated<T> animate(Animated<double> parent) {
|
||||
return new _AnimatedEvaluation<T>(parent, this);
|
||||
}
|
||||
}
|
||||
@@ -258,7 +258,11 @@ class _RepeatingSimulation extends Simulation {
|
||||
}
|
||||
|
||||
class CurvedAnimation extends Animated<double> with ProxyAnimatedMixin {
|
||||
CurvedAnimation({ this.parent, this.curve, this.reverseCurve }) {
|
||||
CurvedAnimation({
|
||||
this.parent,
|
||||
this.curve: Curves.linear,
|
||||
this.reverseCurve
|
||||
}) {
|
||||
assert(parent != null);
|
||||
assert(curve != null);
|
||||
parent.addStatusListener(_handleStatusChanged);
|
||||
@@ -373,3 +377,18 @@ class IntTween extends Tween<int> {
|
||||
// the begin and end types by a double, and int * double returns a double.
|
||||
int lerp(double t) => (begin + (end - begin) * t).round();
|
||||
}
|
||||
|
||||
class CurveTween extends Evaluatable<double> {
|
||||
CurveTween({ this.curve });
|
||||
|
||||
Curve curve;
|
||||
|
||||
double evaluate(Animated<double> animation) {
|
||||
double t = animation.value;
|
||||
if (t == 0.0 || t == 1.0) {
|
||||
assert(curve.transform(t).round() == t);
|
||||
return t;
|
||||
}
|
||||
return curve.transform(t);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,41 +129,17 @@ class _ModalBottomSheet extends StatefulComponent {
|
||||
}
|
||||
|
||||
class _ModalBottomSheetState extends State<_ModalBottomSheet> {
|
||||
// TODO(abarth): Delete _controllerPerformanceAdaptor when navigator uses
|
||||
// AnimationController and friends.
|
||||
AnimationController _controllerPerformanceAdaptor;
|
||||
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controllerPerformanceAdaptor = new AnimationController();
|
||||
_updateControllerPerformanceAdaptor();
|
||||
}
|
||||
|
||||
void didUpdateConfig(_ModalBottomSheet oldConfig) {
|
||||
if (config.route.performance != oldConfig.route.performance)
|
||||
_updateControllerPerformanceAdaptor();
|
||||
}
|
||||
|
||||
void _updateControllerPerformanceAdaptor() {
|
||||
Performance performance = config.route.performance;
|
||||
_controllerPerformanceAdaptor
|
||||
..duration = performance.duration
|
||||
..value = performance.progress;
|
||||
if (performance.isAnimating)
|
||||
_controllerPerformanceAdaptor.play(performance.direction);
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return new GestureDetector(
|
||||
onTap: () => Navigator.pop(context),
|
||||
child: new AnimatedBuilder(
|
||||
animation: _controllerPerformanceAdaptor,
|
||||
animation: config.route.animation,
|
||||
builder: (BuildContext context) {
|
||||
return new ClipRect(
|
||||
child: new CustomOneChildLayout(
|
||||
delegate: new _ModalBottomSheetLayout(config.route.performance.progress),
|
||||
delegate: new _ModalBottomSheetLayout(config.route.animation.value),
|
||||
child: new BottomSheet(
|
||||
animationController: _controllerPerformanceAdaptor,
|
||||
animationController: config.route.animation,
|
||||
onClosing: () => Navigator.pop(context),
|
||||
builder: config.route.builder
|
||||
)
|
||||
@@ -191,7 +167,7 @@ class _ModalBottomSheetRoute<T> extends PopupRoute<T> {
|
||||
return BottomSheet.createAnimationController();
|
||||
}
|
||||
|
||||
Widget buildPage(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance) {
|
||||
Widget buildPage(BuildContext context, Animated<double> animation, Animated<double> forwardAnimation) {
|
||||
return new _ModalBottomSheet(route: this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,14 +128,16 @@ class _DialogRoute<T> extends PopupRoute<T> {
|
||||
bool get barrierDismissable => true;
|
||||
Color get barrierColor => Colors.black54;
|
||||
|
||||
Widget buildPage(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance) {
|
||||
Widget buildPage(BuildContext context, Animated<double> animation, Animated<double> forwardAnimation) {
|
||||
return child;
|
||||
}
|
||||
|
||||
Widget buildTransitions(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance, Widget child) {
|
||||
return new OldFadeTransition(
|
||||
performance: performance,
|
||||
opacity: new AnimatedValue<double>(0.0, end: 1.0, curve: Curves.easeOut),
|
||||
Widget buildTransitions(BuildContext context, Animated<double> animation, Animated<double> forwardAnimation, Widget child) {
|
||||
return new FadeTransition(
|
||||
opacity: new CurvedAnimation(
|
||||
parent: animation,
|
||||
curve: Curves.easeOut
|
||||
),
|
||||
child: child
|
||||
);
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ class _DropDownMenu<T> extends StatusTransitionComponent {
|
||||
_DropDownMenu({
|
||||
Key key,
|
||||
_DropDownRoute<T> route
|
||||
}) : route = route, super(key: key, performance: route.performance);
|
||||
}) : route = route, super(key: key, animation: route.animation);
|
||||
|
||||
final _DropDownRoute<T> route;
|
||||
|
||||
@@ -79,16 +79,15 @@ class _DropDownMenu<T> extends StatusTransitionComponent {
|
||||
final double unit = 0.5 / (route.items.length + 1.5);
|
||||
final List<Widget> children = <Widget>[];
|
||||
for (int itemIndex = 0; itemIndex < route.items.length; ++itemIndex) {
|
||||
AnimatedValue<double> opacity;
|
||||
CurvedAnimation opacity;
|
||||
if (itemIndex == route.selectedIndex) {
|
||||
opacity = new AnimatedValue<double>(0.0, end: 1.0, curve: const Interval(0.0, 0.001), reverseCurve: const Interval(0.75, 1.0));
|
||||
opacity = new CurvedAnimation(parent: route.animation, curve: const Interval(0.0, 0.001), reverseCurve: const Interval(0.75, 1.0));
|
||||
} else {
|
||||
final double start = (0.5 + (itemIndex + 1) * unit).clamp(0.0, 1.0);
|
||||
final double end = (start + 1.5 * unit).clamp(0.0, 1.0);
|
||||
opacity = new AnimatedValue<double>(0.0, end: 1.0, curve: new Interval(start, end), reverseCurve: const Interval(0.75, 1.0));
|
||||
opacity = new CurvedAnimation(parent: route.animation, curve: new Interval(start, end), reverseCurve: const Interval(0.75, 1.0));
|
||||
}
|
||||
children.add(new OldFadeTransition(
|
||||
performance: route.performance,
|
||||
children.add(new FadeTransition(
|
||||
opacity: opacity,
|
||||
child: new InkWell(
|
||||
child: new Container(
|
||||
@@ -103,42 +102,45 @@ class _DropDownMenu<T> extends StatusTransitionComponent {
|
||||
));
|
||||
}
|
||||
|
||||
final AnimatedValue<double> menuOpacity = new AnimatedValue<double>(0.0,
|
||||
end: 1.0,
|
||||
final CurvedAnimation opacity = new CurvedAnimation(
|
||||
parent: route.animation,
|
||||
curve: const Interval(0.0, 0.25),
|
||||
reverseCurve: const Interval(0.75, 1.0)
|
||||
);
|
||||
|
||||
final AnimatedValue<double> menuTop = new AnimatedValue<double>(route.rect.top,
|
||||
end: route.rect.top - route.selectedIndex * route.rect.height,
|
||||
curve: const Interval(0.25, 0.5),
|
||||
reverseCurve: const Interval(0.0, 0.001)
|
||||
);
|
||||
final AnimatedValue<double> menuBottom = new AnimatedValue<double>(route.rect.bottom,
|
||||
end: menuTop.end + route.items.length * route.rect.height,
|
||||
final CurvedAnimation resize = new CurvedAnimation(
|
||||
parent: route.animation,
|
||||
curve: const Interval(0.25, 0.5),
|
||||
reverseCurve: const Interval(0.0, 0.001)
|
||||
);
|
||||
|
||||
return new OldFadeTransition(
|
||||
performance: route.performance,
|
||||
opacity: menuOpacity,
|
||||
child: new BuilderTransition(
|
||||
performance: route.performance,
|
||||
variables: <AnimatedValue<double>>[menuTop, menuBottom],
|
||||
final Tween<double> menuTop = new Tween<double>(
|
||||
begin: route.rect.top,
|
||||
end: route.rect.top - route.selectedIndex * route.rect.height
|
||||
);
|
||||
final Tween<double> menuBottom = new Tween<double>(
|
||||
begin: route.rect.bottom,
|
||||
end: menuTop.end + route.items.length * route.rect.height
|
||||
);
|
||||
|
||||
Widget child = new Material(
|
||||
type: MaterialType.transparency,
|
||||
child: new Block(children)
|
||||
);
|
||||
return new FadeTransition(
|
||||
opacity: opacity,
|
||||
child: new AnimatedBuilder(
|
||||
animation: resize,
|
||||
builder: (BuildContext context) {
|
||||
return new CustomPaint(
|
||||
painter: new _DropDownMenuPainter(
|
||||
color: Theme.of(context).canvasColor,
|
||||
elevation: route.elevation,
|
||||
menuTop: menuTop.value,
|
||||
menuBottom: menuBottom.value,
|
||||
menuTop: menuTop.evaluate(resize),
|
||||
menuBottom: menuBottom.evaluate(resize),
|
||||
renderBox: context.findRenderObject()
|
||||
),
|
||||
child: new Material(
|
||||
type: MaterialType.transparency,
|
||||
child: new Block(children)
|
||||
)
|
||||
child: child
|
||||
);
|
||||
}
|
||||
)
|
||||
@@ -190,7 +192,7 @@ class _DropDownRoute<T> extends PopupRoute<_DropDownRouteResult<T>> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildPage(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance) {
|
||||
Widget buildPage(BuildContext context, Animated<double> animation, Animated<double> forwardAnimation) {
|
||||
return new _DropDownMenu(route: this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,20 +40,29 @@ class FloatingActionButton extends StatefulComponent {
|
||||
}
|
||||
|
||||
class _FloatingActionButtonState extends State<FloatingActionButton> {
|
||||
final Performance _childSegue = new Performance(duration: _kChildSegue);
|
||||
Animated<double> _childSegue;
|
||||
AnimationController _childSegueController;
|
||||
|
||||
void initState() {
|
||||
super.initState();
|
||||
_childSegue.play();
|
||||
_childSegueController = new AnimationController(duration: _kChildSegue)
|
||||
..forward();
|
||||
_childSegue = new Tween<double>(
|
||||
begin: -0.125,
|
||||
end: 0.0
|
||||
).animate(new CurvedAnimation(
|
||||
parent: _childSegueController,
|
||||
curve: _kChildSegueInterval
|
||||
));
|
||||
}
|
||||
|
||||
void didUpdateConfig(FloatingActionButton oldConfig) {
|
||||
super.didUpdateConfig(oldConfig);
|
||||
if (Widget.canUpdate(oldConfig.child, config.child) && config.backgroundColor == oldConfig.backgroundColor)
|
||||
return;
|
||||
_childSegue
|
||||
..progress = 0.0
|
||||
..play();
|
||||
_childSegueController
|
||||
..value = 0.0
|
||||
..forward();
|
||||
}
|
||||
|
||||
bool _highlight = false;
|
||||
@@ -87,8 +96,7 @@ class _FloatingActionButtonState extends State<FloatingActionButton> {
|
||||
child: new IconTheme(
|
||||
data: new IconThemeData(color: iconThemeColor),
|
||||
child: new RotationTransition(
|
||||
performance: _childSegue,
|
||||
turns: new AnimatedValue<double>(-0.125, end: 0.0, curve: _kChildSegueInterval),
|
||||
turns: _childSegue,
|
||||
child: config.child
|
||||
)
|
||||
)
|
||||
|
||||
@@ -7,31 +7,32 @@ import 'dart:async';
|
||||
import 'package:flutter/animation.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
class _MaterialPageTransition extends TransitionWithChild {
|
||||
class _MaterialPageTransition extends AnimatedComponent {
|
||||
_MaterialPageTransition({
|
||||
Key key,
|
||||
PerformanceView performance,
|
||||
Widget child
|
||||
}) : super(key: key,
|
||||
performance: performance,
|
||||
child: child);
|
||||
Animated<double> animation,
|
||||
this.child
|
||||
}) : super(
|
||||
key: key,
|
||||
animation: new CurvedAnimation(parent: animation, curve: Curves.easeOut)
|
||||
);
|
||||
|
||||
final AnimatedValue<Point> _position =
|
||||
new AnimatedValue<Point>(const Point(0.0, 75.0), end: Point.origin, curve: Curves.easeOut);
|
||||
final Widget child;
|
||||
|
||||
final AnimatedValue<double> _opacity =
|
||||
new AnimatedValue<double>(0.0, end: 1.0, curve: Curves.easeOut);
|
||||
final Tween<Point> _position = new Tween<Point>(
|
||||
begin: const Point(0.0, 75.0),
|
||||
end: Point.origin
|
||||
);
|
||||
|
||||
Widget buildWithChild(BuildContext context, Widget child) {
|
||||
performance.updateVariable(_position);
|
||||
performance.updateVariable(_opacity);
|
||||
Widget build(BuildContext context) {
|
||||
Point position = _position.evaluate(animation);
|
||||
Matrix4 transform = new Matrix4.identity()
|
||||
..translate(_position.value.x, _position.value.y);
|
||||
..translate(position.x, position.y);
|
||||
return new Transform(
|
||||
transform: transform,
|
||||
// TODO(ianh): tell the transform to be un-transformed for hit testing
|
||||
child: new Opacity(
|
||||
opacity: _opacity.value,
|
||||
opacity: animation.value,
|
||||
child: child
|
||||
)
|
||||
);
|
||||
@@ -56,7 +57,7 @@ class MaterialPageRoute<T> extends PageRoute<T> {
|
||||
Color get barrierColor => null;
|
||||
bool canTransitionFrom(TransitionRoute nextRoute) => false;
|
||||
|
||||
Widget buildPage(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance) {
|
||||
Widget buildPage(BuildContext context, Animated<double> animation, Animated<double> forwardAnimation) {
|
||||
Widget result = builder(context);
|
||||
assert(() {
|
||||
if (result == null)
|
||||
@@ -67,9 +68,9 @@ class MaterialPageRoute<T> extends PageRoute<T> {
|
||||
return result;
|
||||
}
|
||||
|
||||
Widget buildTransitions(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance, Widget child) {
|
||||
Widget buildTransitions(BuildContext context, Animated<double> animation, Animated<double> forwardAnimation, Widget child) {
|
||||
return new _MaterialPageTransition(
|
||||
performance: performance,
|
||||
animation: animation,
|
||||
child: child
|
||||
);
|
||||
}
|
||||
|
||||
@@ -61,9 +61,12 @@ class _PopupMenu<T> extends StatelessComponent {
|
||||
for (int i = 0; i < route.items.length; ++i) {
|
||||
double start = (i + 1) * unit;
|
||||
double end = (start + 1.5 * unit).clamp(0.0, 1.0);
|
||||
children.add(new OldFadeTransition(
|
||||
performance: route.performance,
|
||||
opacity: new AnimatedValue<double>(0.0, end: 1.0, curve: new Interval(start, end)),
|
||||
CurvedAnimation opacity = new CurvedAnimation(
|
||||
parent: route.animation,
|
||||
curve: new Interval(start, end)
|
||||
);
|
||||
children.add(new FadeTransition(
|
||||
opacity: opacity,
|
||||
child: new InkWell(
|
||||
onTap: () => Navigator.pop(context, route.items[i].value),
|
||||
child: route.items[i]
|
||||
@@ -71,38 +74,39 @@ class _PopupMenu<T> extends StatelessComponent {
|
||||
);
|
||||
}
|
||||
|
||||
final AnimatedValue<double> opacity = new AnimatedValue<double>(0.0, end: 1.0, curve: new Interval(0.0, 1.0 / 3.0));
|
||||
final AnimatedValue<double> width = new AnimatedValue<double>(0.0, end: 1.0, curve: new Interval(0.0, unit));
|
||||
final AnimatedValue<double> height = new AnimatedValue<double>(0.0, end: 1.0, curve: new Interval(0.0, unit * route.items.length));
|
||||
final CurveTween opacity = new CurveTween(curve: new Interval(0.0, 1.0 / 3.0));
|
||||
final CurveTween width = new CurveTween(curve: new Interval(0.0, unit));
|
||||
final CurveTween height = new CurveTween(curve: new Interval(0.0, unit * route.items.length));
|
||||
|
||||
return new BuilderTransition(
|
||||
performance: route.performance,
|
||||
variables: <AnimatedValue<double>>[opacity, width, height],
|
||||
Widget child = new ConstrainedBox(
|
||||
constraints: new BoxConstraints(
|
||||
minWidth: _kMenuMinWidth,
|
||||
maxWidth: _kMenuMaxWidth
|
||||
),
|
||||
child: new IntrinsicWidth(
|
||||
stepWidth: _kMenuWidthStep,
|
||||
child: new Block(
|
||||
children,
|
||||
padding: const EdgeDims.symmetric(
|
||||
vertical: _kMenuVerticalPadding
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return new AnimatedBuilder(
|
||||
animation: route.animation,
|
||||
builder: (BuildContext context) {
|
||||
return new Opacity(
|
||||
opacity: opacity.value,
|
||||
opacity: opacity.evaluate(route.animation),
|
||||
child: new Material(
|
||||
type: MaterialType.card,
|
||||
elevation: route.elevation,
|
||||
child: new Align(
|
||||
alignment: const FractionalOffset(1.0, 0.0),
|
||||
widthFactor: width.value,
|
||||
heightFactor: height.value,
|
||||
child: new ConstrainedBox(
|
||||
constraints: new BoxConstraints(
|
||||
minWidth: _kMenuMinWidth,
|
||||
maxWidth: _kMenuMaxWidth
|
||||
),
|
||||
child: new IntrinsicWidth(
|
||||
stepWidth: _kMenuWidthStep,
|
||||
child: new Block(
|
||||
children,
|
||||
padding: const EdgeDims.symmetric(
|
||||
vertical: _kMenuVerticalPadding
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
widthFactor: width.evaluate(route.animation),
|
||||
heightFactor: height.evaluate(route.animation),
|
||||
child: child
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -127,18 +131,18 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
|
||||
return position;
|
||||
}
|
||||
|
||||
PerformanceView createPerformance() {
|
||||
return new CurvedPerformance(
|
||||
super.createPerformance(),
|
||||
Animated<double> createAnimation() {
|
||||
return new CurvedAnimation(
|
||||
parent: super.createAnimation(),
|
||||
reverseCurve: new Interval(0.0, _kMenuCloseIntervalEnd)
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
Duration get transitionDuration => _kMenuDuration;
|
||||
bool get barrierDismissable => true;
|
||||
Color get barrierColor => null;
|
||||
|
||||
Widget buildPage(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance) {
|
||||
Widget buildPage(BuildContext context, Animated<double> animation, Animated<double> forwardAnimation) {
|
||||
return new _PopupMenu(route: this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ class _FloatingActionButtonTransitionState extends State<_FloatingActionButtonTr
|
||||
scale: new Tween<double>(
|
||||
begin: 1.0,
|
||||
end: 0.0
|
||||
).watch(new CurvedAnimation(
|
||||
).animate(new CurvedAnimation(
|
||||
parent: controller,
|
||||
curve: const Interval(0.0, 0.5, curve: Curves.easeIn)
|
||||
)),
|
||||
|
||||
@@ -73,7 +73,7 @@ class _HeroManifest {
|
||||
|
||||
abstract class HeroHandle {
|
||||
bool get alwaysAnimate;
|
||||
_HeroManifest _takeChild(Rect animationArea);
|
||||
_HeroManifest _takeChild(Rect animationArea, Animated<double> currentAnimation);
|
||||
}
|
||||
|
||||
class Hero extends StatefulComponent {
|
||||
@@ -167,7 +167,7 @@ class HeroState extends State<Hero> implements HeroHandle {
|
||||
|
||||
bool get alwaysAnimate => config.alwaysAnimate;
|
||||
|
||||
_HeroManifest _takeChild(Rect animationArea) {
|
||||
_HeroManifest _takeChild(Rect animationArea, Animated<double> currentAnimation) {
|
||||
assert(_mode == _HeroMode.measured || _mode == _HeroMode.taken);
|
||||
final RenderBox renderObject = context.findRenderObject();
|
||||
final Point heroTopLeft = renderObject.localToGlobal(Point.origin);
|
||||
@@ -256,14 +256,14 @@ class _HeroQuestState implements HeroHandle {
|
||||
final RelativeRect targetRect;
|
||||
final int targetTurns;
|
||||
final HeroState targetState;
|
||||
final AnimatedRelativeRectValue currentRect;
|
||||
final AnimatedValue<double> currentTurns;
|
||||
final RelativeRectTween currentRect;
|
||||
final Tween<double> currentTurns;
|
||||
|
||||
bool get alwaysAnimate => true;
|
||||
|
||||
bool get taken => _taken;
|
||||
bool _taken = false;
|
||||
_HeroManifest _takeChild(Rect animationArea) {
|
||||
_HeroManifest _takeChild(Rect animationArea, Animated<double> currentAnimation) {
|
||||
assert(!taken);
|
||||
_taken = true;
|
||||
Set<HeroState> states = sourceStates;
|
||||
@@ -273,18 +273,16 @@ class _HeroQuestState implements HeroHandle {
|
||||
key: key,
|
||||
config: child,
|
||||
sourceStates: states,
|
||||
currentRect: currentRect.value,
|
||||
currentTurns: currentTurns.value
|
||||
currentRect: currentRect.evaluate(currentAnimation),
|
||||
currentTurns: currentTurns.evaluate(currentAnimation)
|
||||
);
|
||||
}
|
||||
|
||||
Widget build(BuildContext context, PerformanceView performance) {
|
||||
Widget build(BuildContext context, Animated<double> animation) {
|
||||
return new PositionedTransition(
|
||||
rect: currentRect,
|
||||
performance: performance,
|
||||
rect: currentRect.animate(animation),
|
||||
child: new RotationTransition(
|
||||
turns: currentTurns,
|
||||
performance: performance,
|
||||
turns: currentTurns.animate(animation),
|
||||
child: new KeyedSubtree(
|
||||
key: key,
|
||||
child: child
|
||||
@@ -317,16 +315,16 @@ class HeroParty {
|
||||
return result;
|
||||
}
|
||||
|
||||
AnimatedRelativeRectValue createAnimatedRelativeRect(RelativeRect begin, RelativeRect end, Curve curve) {
|
||||
return new AnimatedRelativeRectValue(begin, end: end, curve: curve);
|
||||
RelativeRectTween createRectTween(RelativeRect begin, RelativeRect end) {
|
||||
return new RelativeRectTween(begin: begin, end: end);
|
||||
}
|
||||
|
||||
AnimatedValue<double> createAnimatedTurns(double begin, double end, Curve curve) {
|
||||
Tween<double> createTurnsTween(double begin, double end) {
|
||||
assert(end.floor() == end);
|
||||
return new AnimatedValue<double>(begin, end: end, curve: curve);
|
||||
return new Tween<double>(begin: begin, end: end);
|
||||
}
|
||||
|
||||
void animate(Map<Object, HeroHandle> heroesFrom, Map<Object, HeroHandle> heroesTo, Rect animationArea, Curve curve) {
|
||||
void animate(Map<Object, HeroHandle> heroesFrom, Map<Object, HeroHandle> heroesTo, Rect animationArea) {
|
||||
assert(!heroesFrom.containsKey(null));
|
||||
assert(!heroesTo.containsKey(null));
|
||||
|
||||
@@ -346,9 +344,9 @@ class HeroParty {
|
||||
if ((heroPair.from == null && !heroPair.to.alwaysAnimate) ||
|
||||
(heroPair.to == null && !heroPair.from.alwaysAnimate))
|
||||
continue;
|
||||
_HeroManifest from = heroPair.from?._takeChild(animationArea);
|
||||
_HeroManifest from = heroPair.from?._takeChild(animationArea, _currentAnimation);
|
||||
assert(heroPair.to == null || heroPair.to is HeroState);
|
||||
_HeroManifest to = heroPair.to?._takeChild(animationArea);
|
||||
_HeroManifest to = heroPair.to?._takeChild(animationArea, _currentAnimation);
|
||||
assert(from != null || to != null);
|
||||
assert(to == null || to.sourceStates.length == 1);
|
||||
assert(to == null || to.currentTurns.floor() == to.currentTurns);
|
||||
@@ -369,8 +367,8 @@ class HeroParty {
|
||||
targetRect: targetRect,
|
||||
targetTurns: targetTurns.floor(),
|
||||
targetState: targetState,
|
||||
currentRect: createAnimatedRelativeRect(sourceRect, targetRect, curve),
|
||||
currentTurns: createAnimatedTurns(sourceTurns, targetTurns, curve)
|
||||
currentRect: createRectTween(sourceRect, targetRect),
|
||||
currentTurns: createTurnsTween(sourceTurns, targetTurns)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -378,19 +376,19 @@ class HeroParty {
|
||||
_heroes = _newHeroes;
|
||||
}
|
||||
|
||||
PerformanceView _currentPerformance;
|
||||
Animated<double> _currentAnimation;
|
||||
|
||||
void _clearCurrentPerformance() {
|
||||
_currentPerformance?.removeStatusListener(_handleUpdate);
|
||||
_currentPerformance = null;
|
||||
_currentAnimation?.removeStatusListener(_handleUpdate);
|
||||
_currentAnimation = null;
|
||||
}
|
||||
|
||||
void setPerformance(PerformanceView performance) {
|
||||
assert(performance != null || _heroes.length == 0);
|
||||
if (performance != _currentPerformance) {
|
||||
void setAnimation(Animated<double> animation) {
|
||||
assert(animation != null || _heroes.length == 0);
|
||||
if (animation != _currentAnimation) {
|
||||
_clearCurrentPerformance();
|
||||
_currentPerformance = performance;
|
||||
_currentPerformance?.addStatusListener(_handleUpdate);
|
||||
_currentAnimation = animation;
|
||||
_currentAnimation?.addStatusListener(_handleUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -419,7 +417,7 @@ class HeroController extends NavigatorObserver {
|
||||
}
|
||||
|
||||
HeroParty _party;
|
||||
PerformanceView _performance;
|
||||
Animated<double> _animation;
|
||||
PageRoute _from;
|
||||
PageRoute _to;
|
||||
|
||||
@@ -429,11 +427,11 @@ class HeroController extends NavigatorObserver {
|
||||
assert(navigator != null);
|
||||
assert(route != null);
|
||||
if (route is PageRoute) {
|
||||
assert(route.performance != null);
|
||||
assert(route.animation != null);
|
||||
if (previousRoute is PageRoute) // could be null
|
||||
_from = previousRoute;
|
||||
_to = route;
|
||||
_performance = route.performance;
|
||||
_animation = route.animation;
|
||||
_checkForHeroQuest();
|
||||
}
|
||||
}
|
||||
@@ -442,11 +440,11 @@ class HeroController extends NavigatorObserver {
|
||||
assert(navigator != null);
|
||||
assert(route != null);
|
||||
if (route is PageRoute) {
|
||||
assert(route.performance != null);
|
||||
assert(route.animation != null);
|
||||
if (previousRoute is PageRoute) {
|
||||
_to = previousRoute;
|
||||
_from = route;
|
||||
_performance = route.performance;
|
||||
_animation = route.animation;
|
||||
_checkForHeroQuest();
|
||||
}
|
||||
}
|
||||
@@ -454,7 +452,7 @@ class HeroController extends NavigatorObserver {
|
||||
|
||||
void _checkForHeroQuest() {
|
||||
if (_from != null && _to != null && _from != _to) {
|
||||
_to.offstage = _to.performance.status != PerformanceStatus.completed;
|
||||
_to.offstage = _to.animation.status != PerformanceStatus.completed;
|
||||
Scheduler.instance.addPostFrameCallback(_updateQuest);
|
||||
}
|
||||
}
|
||||
@@ -463,7 +461,7 @@ class HeroController extends NavigatorObserver {
|
||||
_removeHeroesFromOverlay();
|
||||
_from = null;
|
||||
_to = null;
|
||||
_performance = null;
|
||||
_animation = null;
|
||||
}
|
||||
|
||||
Rect _getAnimationArea(BuildContext context) {
|
||||
@@ -481,7 +479,7 @@ class HeroController extends NavigatorObserver {
|
||||
|
||||
void _addHeroToOverlay(Widget hero, Object tag, OverlayState overlay) {
|
||||
OverlayEntry entry = new OverlayEntry(builder: (_) => hero);
|
||||
if (_performance.direction == AnimationDirection.forward)
|
||||
if (_animation.direction == AnimationDirection.forward)
|
||||
_to.insertHeroOverlayEntry(entry, tag, overlay);
|
||||
else
|
||||
_from.insertHeroOverlayEntry(entry, tag, overlay);
|
||||
@@ -507,18 +505,21 @@ class HeroController extends NavigatorObserver {
|
||||
Map<Object, HeroHandle> heroesTo = Hero.of(_to.subtreeContext, mostValuableKeys);
|
||||
_to.offstage = false;
|
||||
|
||||
PerformanceView performance = _performance;
|
||||
Animated<double> animation = _animation;
|
||||
Curve curve = Curves.ease;
|
||||
if (performance.status == PerformanceStatus.reverse) {
|
||||
performance = new ReversePerformance(performance);
|
||||
curve = new Interval(performance.progress, 1.0, curve: curve);
|
||||
if (animation.status == PerformanceStatus.reverse) {
|
||||
animation = new ReverseAnimation(animation);
|
||||
curve = new Interval(animation.value, 1.0, curve: curve);
|
||||
}
|
||||
|
||||
_party.animate(heroesFrom, heroesTo, _getAnimationArea(navigator.context), curve);
|
||||
_party.animate(heroesFrom, heroesTo, _getAnimationArea(navigator.context));
|
||||
_removeHeroesFromOverlay();
|
||||
_party.setPerformance(performance);
|
||||
_party.setAnimation(new CurvedAnimation(
|
||||
parent: animation,
|
||||
curve: curve
|
||||
));
|
||||
for (_HeroQuestState hero in _party._heroes) {
|
||||
Widget widget = hero.build(navigator.context, performance);
|
||||
Widget widget = hero.build(navigator.context, animation);
|
||||
_addHeroToOverlay(widget, hero.tag, navigator.overlay);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,38 +43,23 @@ class ModalBarrier extends StatelessComponent {
|
||||
}
|
||||
|
||||
/// Prevents the user from interacting with widgets behind itself.
|
||||
class AnimatedModalBarrier extends StatelessComponent {
|
||||
class AnimatedModalBarrier extends AnimatedComponent {
|
||||
AnimatedModalBarrier({
|
||||
Key key,
|
||||
this.color,
|
||||
this.performance,
|
||||
Animated<Color> color,
|
||||
this.dismissable: true
|
||||
}) : super(key: key);
|
||||
}) : color = color, super(key: key, animation: color);
|
||||
|
||||
/// If non-null, fill the barrier with this color.
|
||||
///
|
||||
/// The barrier will animate this color according to the given [performance].
|
||||
final AnimatedColorValue color;
|
||||
|
||||
/// The performance to use when animating the given [color].
|
||||
final PerformanceView performance;
|
||||
final Animated<Color> color;
|
||||
|
||||
/// Whether touching the barrier will pop the current route off the [Navigator].
|
||||
final bool dismissable;
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return new BuilderTransition(
|
||||
performance: performance,
|
||||
variables: <AnimatedColorValue>[color],
|
||||
builder: (BuildContext context) {
|
||||
return new IgnorePointer(
|
||||
ignoring: performance.status == PerformanceStatus.reverse,
|
||||
child: new ModalBarrier(
|
||||
color: color.value,
|
||||
dismissable: dismissable
|
||||
)
|
||||
);
|
||||
}
|
||||
return new ModalBarrier(
|
||||
color: color.value,
|
||||
dismissable: dismissable
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,11 @@ abstract class PageRoute<T> extends ModalRoute<T> {
|
||||
bool canTransitionTo(TransitionRoute nextRoute) => nextRoute is PageRoute;
|
||||
bool canTransitionFrom(TransitionRoute nextRoute) => nextRoute is PageRoute;
|
||||
|
||||
Performance createPerformanceController() {
|
||||
Performance performance = super.createPerformanceController();
|
||||
AnimationController createAnimationController() {
|
||||
AnimationController controller = super.createAnimationController();
|
||||
if (settings.isInitialRoute)
|
||||
performance.progress = 1.0;
|
||||
return performance;
|
||||
controller.value = 1.0;
|
||||
return controller;
|
||||
}
|
||||
|
||||
/// Subclasses can override this method to customize how heroes are inserted.
|
||||
|
||||
@@ -92,25 +92,25 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
|
||||
Duration get transitionDuration;
|
||||
bool get opaque;
|
||||
|
||||
PerformanceView get performance => _performance;
|
||||
Performance _performanceController;
|
||||
PerformanceView _performance;
|
||||
Animated<double> get animation => _animation;
|
||||
Animated<double> _animation;
|
||||
AnimationController _controller;
|
||||
|
||||
/// Called to create the Performance object that will drive the transitions to
|
||||
/// this route from the previous one, and back to the previous route from this
|
||||
/// one.
|
||||
Performance createPerformanceController() {
|
||||
AnimationController createAnimationController() {
|
||||
Duration duration = transitionDuration;
|
||||
assert(duration != null && duration >= Duration.ZERO);
|
||||
return new Performance(duration: duration, debugLabel: debugLabel);
|
||||
return new AnimationController(duration: duration, debugLabel: debugLabel);
|
||||
}
|
||||
|
||||
/// Called to create the PerformanceView that exposes the current progress of
|
||||
/// the transition controlled by the Performance object created by
|
||||
/// [createPerformanceController()].
|
||||
PerformanceView createPerformance() {
|
||||
assert(_performanceController != null);
|
||||
return _performanceController.view;
|
||||
/// [createAnimationController()].
|
||||
Animated<double> createAnimation() {
|
||||
assert(_controller != null);
|
||||
return _controller.view;
|
||||
}
|
||||
|
||||
T _result;
|
||||
@@ -134,33 +134,33 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
|
||||
}
|
||||
}
|
||||
|
||||
PerformanceView get forwardPerformance => _forwardPerformance;
|
||||
final ProxyPerformance _forwardPerformance = new ProxyPerformance(alwaysDismissedPerformance);
|
||||
Animated<double> get forwardAnimation => _forwardAnimation;
|
||||
final ProxyAnimation _forwardAnimation = new ProxyAnimation(kAlwaysDismissedAnimation);
|
||||
|
||||
void install(OverlayEntry insertionPoint) {
|
||||
_performanceController = createPerformanceController();
|
||||
assert(_performanceController != null);
|
||||
_performance = createPerformance();
|
||||
assert(_performance != null);
|
||||
_controller = createAnimationController();
|
||||
assert(_controller != null);
|
||||
_animation = createAnimation();
|
||||
assert(_animation != null);
|
||||
super.install(insertionPoint);
|
||||
}
|
||||
|
||||
void didPush() {
|
||||
_performance.addStatusListener(handleStatusChanged);
|
||||
_performanceController.forward();
|
||||
_animation.addStatusListener(handleStatusChanged);
|
||||
_controller.forward();
|
||||
super.didPush();
|
||||
}
|
||||
|
||||
void didReplace(Route oldRoute) {
|
||||
if (oldRoute is TransitionRoute)
|
||||
_performanceController.progress = oldRoute._performanceController.progress;
|
||||
_performance.addStatusListener(handleStatusChanged);
|
||||
_controller.value = oldRoute._controller.value;
|
||||
_animation.addStatusListener(handleStatusChanged);
|
||||
super.didReplace(oldRoute);
|
||||
}
|
||||
|
||||
bool didPop(T result) {
|
||||
_result = result;
|
||||
_performanceController.reverse();
|
||||
_controller.reverse();
|
||||
_popCompleter?.complete(_result);
|
||||
return true;
|
||||
}
|
||||
@@ -177,30 +177,30 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
|
||||
|
||||
void _updateForwardPerformance(Route nextRoute) {
|
||||
if (nextRoute is TransitionRoute && canTransitionTo(nextRoute) && nextRoute.canTransitionFrom(this)) {
|
||||
PerformanceView current = _forwardPerformance.masterPerformance;
|
||||
Animated<double> current = _forwardAnimation.masterAnimation;
|
||||
if (current != null) {
|
||||
if (current is TrainHoppingPerformance) {
|
||||
TrainHoppingPerformance newPerformance;
|
||||
newPerformance = new TrainHoppingPerformance(
|
||||
if (current is TrainHoppingAnimation) {
|
||||
TrainHoppingAnimation newPerformance;
|
||||
newPerformance = new TrainHoppingAnimation(
|
||||
current.currentTrain,
|
||||
nextRoute.performance,
|
||||
nextRoute.animation,
|
||||
onSwitchedTrain: () {
|
||||
assert(_forwardPerformance.masterPerformance == newPerformance);
|
||||
assert(newPerformance.currentTrain == nextRoute.performance);
|
||||
_forwardPerformance.masterPerformance = newPerformance.currentTrain;
|
||||
assert(_forwardAnimation.masterAnimation == newPerformance);
|
||||
assert(newPerformance.currentTrain == nextRoute.animation);
|
||||
_forwardAnimation.masterAnimation = newPerformance.currentTrain;
|
||||
newPerformance.dispose();
|
||||
}
|
||||
);
|
||||
_forwardPerformance.masterPerformance = newPerformance;
|
||||
_forwardAnimation.masterAnimation = newPerformance;
|
||||
current.dispose();
|
||||
} else {
|
||||
_forwardPerformance.masterPerformance = new TrainHoppingPerformance(current, nextRoute.performance);
|
||||
_forwardAnimation.masterAnimation = new TrainHoppingAnimation(current, nextRoute.animation);
|
||||
}
|
||||
} else {
|
||||
_forwardPerformance.masterPerformance = nextRoute.performance;
|
||||
_forwardAnimation.masterAnimation = nextRoute.animation;
|
||||
}
|
||||
} else {
|
||||
_forwardPerformance.masterPerformance = alwaysDismissedPerformance;
|
||||
_forwardAnimation.masterAnimation = kAlwaysDismissedAnimation;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,12 +213,12 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
_performanceController.stop();
|
||||
_controller.stop();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
String get debugLabel => '$runtimeType';
|
||||
String toString() => '$runtimeType(performance: $_performanceController)';
|
||||
String toString() => '$runtimeType(animation: $_controller)';
|
||||
}
|
||||
|
||||
class LocalHistoryEntry {
|
||||
@@ -306,8 +306,8 @@ class _ModalScope extends StatefulComponent {
|
||||
class _ModalScopeState extends State<_ModalScope> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
config.route.performance?.addStatusListener(_performanceStatusChanged);
|
||||
config.route.forwardPerformance?.addStatusListener(_performanceStatusChanged);
|
||||
config.route.animation?.addStatusListener(_animationStatusChanged);
|
||||
config.route.forwardAnimation?.addStatusListener(_animationStatusChanged);
|
||||
}
|
||||
|
||||
void didUpdateConfig(_ModalScope oldConfig) {
|
||||
@@ -315,12 +315,12 @@ class _ModalScopeState extends State<_ModalScope> {
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
config.route.performance?.removeStatusListener(_performanceStatusChanged);
|
||||
config.route.forwardPerformance?.removeStatusListener(_performanceStatusChanged);
|
||||
config.route.animation?.removeStatusListener(_animationStatusChanged);
|
||||
config.route.forwardAnimation?.removeStatusListener(_animationStatusChanged);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _performanceStatusChanged(PerformanceStatus status) {
|
||||
void _animationStatusChanged(PerformanceStatus status) {
|
||||
setState(() {
|
||||
// The performances' states are our build state, and they changed already.
|
||||
});
|
||||
@@ -333,7 +333,7 @@ class _ModalScopeState extends State<_ModalScope> {
|
||||
child: new _ModalScopeStatus(
|
||||
route: config.route,
|
||||
isCurrent: config.route.isCurrent,
|
||||
child: config.route.buildPage(context, config.route.performance, config.route.forwardPerformance)
|
||||
child: config.route.buildPage(context, config.route.animation, config.route.forwardAnimation)
|
||||
)
|
||||
);
|
||||
if (config.route.offstage) {
|
||||
@@ -342,11 +342,11 @@ class _ModalScopeState extends State<_ModalScope> {
|
||||
contents = new Focus(
|
||||
key: new GlobalObjectKey(config.route),
|
||||
child: new IgnorePointer(
|
||||
ignoring: config.route.performance?.status == PerformanceStatus.reverse,
|
||||
ignoring: config.route.animation?.status == PerformanceStatus.reverse,
|
||||
child: config.route.buildTransitions(
|
||||
context,
|
||||
config.route.performance,
|
||||
config.route.forwardPerformance,
|
||||
config.route.animation,
|
||||
config.route.forwardAnimation,
|
||||
contents
|
||||
)
|
||||
)
|
||||
@@ -396,8 +396,8 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T
|
||||
// The API for subclasses to override - used by _ModalScope
|
||||
|
||||
ModalPosition getPosition(BuildContext context) => null;
|
||||
Widget buildPage(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance);
|
||||
Widget buildTransitions(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance, Widget child) {
|
||||
Widget buildPage(BuildContext context, Animated<double> animation, Animated<double> forwardAnimation);
|
||||
Widget buildTransitions(BuildContext context, Animated<double> animation, Animated<double> forwardAnimation, Widget child) {
|
||||
return child;
|
||||
}
|
||||
|
||||
@@ -442,17 +442,23 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T
|
||||
Widget barrier;
|
||||
if (barrierColor != null) {
|
||||
assert(barrierColor != _kTransparent);
|
||||
Animated<Color> color = new ColorTween(
|
||||
begin: _kTransparent,
|
||||
end: barrierColor
|
||||
).animate(new CurvedAnimation(
|
||||
parent: animation,
|
||||
curve: Curves.ease
|
||||
));
|
||||
barrier = new AnimatedModalBarrier(
|
||||
color: new AnimatedColorValue(_kTransparent, end: barrierColor, curve: Curves.ease),
|
||||
performance: performance,
|
||||
color: color,
|
||||
dismissable: barrierDismissable
|
||||
);
|
||||
} else {
|
||||
barrier = new ModalBarrier(dismissable: barrierDismissable);
|
||||
}
|
||||
assert(performance.status != PerformanceStatus.dismissed);
|
||||
assert(animation.status != PerformanceStatus.dismissed);
|
||||
return new IgnorePointer(
|
||||
ignoring: performance.status == PerformanceStatus.reverse,
|
||||
ignoring: animation.status == PerformanceStatus.reverse,
|
||||
child: barrier
|
||||
);
|
||||
}
|
||||
@@ -470,7 +476,7 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T
|
||||
_buildModalScope
|
||||
];
|
||||
|
||||
String toString() => '$runtimeType($settings, performance: $_performance)';
|
||||
String toString() => '$runtimeType($settings, animation: $_animation)';
|
||||
}
|
||||
|
||||
/// A modal route that overlays a widget over the current route.
|
||||
|
||||
@@ -9,12 +9,12 @@ import 'framework.dart';
|
||||
abstract class StatusTransitionComponent extends StatefulComponent {
|
||||
StatusTransitionComponent({
|
||||
Key key,
|
||||
this.performance
|
||||
this.animation
|
||||
}) : super(key: key) {
|
||||
assert(performance != null);
|
||||
assert(animation != null);
|
||||
}
|
||||
|
||||
final PerformanceView performance;
|
||||
final Animated<double> animation;
|
||||
|
||||
Widget build(BuildContext context);
|
||||
|
||||
@@ -24,18 +24,18 @@ abstract class StatusTransitionComponent extends StatefulComponent {
|
||||
class _StatusTransitionState extends State<StatusTransitionComponent> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
config.performance.addStatusListener(_performanceStatusChanged);
|
||||
config.animation.addStatusListener(_performanceStatusChanged);
|
||||
}
|
||||
|
||||
void didUpdateConfig(StatusTransitionComponent oldConfig) {
|
||||
if (config.performance != oldConfig.performance) {
|
||||
oldConfig.performance.removeStatusListener(_performanceStatusChanged);
|
||||
config.performance.addStatusListener(_performanceStatusChanged);
|
||||
if (config.animation != oldConfig.animation) {
|
||||
oldConfig.animation.removeStatusListener(_performanceStatusChanged);
|
||||
config.animation.addStatusListener(_performanceStatusChanged);
|
||||
}
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
config.performance.removeStatusListener(_performanceStatusChanged);
|
||||
config.animation.removeStatusListener(_performanceStatusChanged);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
||||
@@ -170,21 +170,19 @@ class ScaleTransition extends AnimatedComponent {
|
||||
}
|
||||
}
|
||||
|
||||
class RotationTransition extends TransitionWithChild {
|
||||
class RotationTransition extends AnimatedComponent {
|
||||
RotationTransition({
|
||||
Key key,
|
||||
this.turns,
|
||||
PerformanceView performance,
|
||||
Widget child
|
||||
}) : super(key: key,
|
||||
performance: performance,
|
||||
child: child);
|
||||
Animated<double> turns,
|
||||
this.child
|
||||
}) : turns = turns, super(key: key, animation: turns);
|
||||
|
||||
final AnimatedValue<double> turns;
|
||||
final Animated<double> turns;
|
||||
final Widget child;
|
||||
|
||||
Widget buildWithChild(BuildContext context, Widget child) {
|
||||
performance.updateVariable(turns);
|
||||
Matrix4 transform = new Matrix4.rotationZ(turns.value * math.PI * 2.0);
|
||||
Widget build(BuildContext context) {
|
||||
double turnsValue = turns.value;
|
||||
Matrix4 transform = new Matrix4.rotationZ(turnsValue * math.PI * 2.0);
|
||||
return new Transform(
|
||||
transform: transform,
|
||||
alignment: const FractionalOffset(0.5, 0.5),
|
||||
@@ -307,9 +305,9 @@ class AlignTransition extends TransitionWithChild {
|
||||
/// This class specializes the interpolation of AnimatedValue<RelativeRect> to
|
||||
/// be appropriate for rectangles that are described in terms of offsets from
|
||||
/// other rectangles.
|
||||
class AnimatedRelativeRectValue extends AnimatedValue<RelativeRect> {
|
||||
AnimatedRelativeRectValue(RelativeRect begin, { RelativeRect end, Curve curve, Curve reverseCurve })
|
||||
: super(begin, end: end, curve: curve, reverseCurve: reverseCurve);
|
||||
class RelativeRectTween extends Tween<RelativeRect> {
|
||||
RelativeRectTween({ RelativeRect begin, RelativeRect end })
|
||||
: super(begin: begin, end: end);
|
||||
|
||||
RelativeRect lerp(double t) => RelativeRect.lerp(begin, end, t);
|
||||
}
|
||||
@@ -320,22 +318,19 @@ class AnimatedRelativeRectValue extends AnimatedValue<RelativeRect> {
|
||||
/// of the performance.
|
||||
///
|
||||
/// Only works if it's the child of a [Stack].
|
||||
class PositionedTransition extends TransitionWithChild {
|
||||
class PositionedTransition extends AnimatedComponent {
|
||||
PositionedTransition({
|
||||
Key key,
|
||||
this.rect,
|
||||
PerformanceView performance,
|
||||
Widget child
|
||||
}) : super(key: key,
|
||||
performance: performance,
|
||||
child: child) {
|
||||
Animated<RelativeRect> rect,
|
||||
this.child
|
||||
}) : rect = rect, super(key: key, animation: rect) {
|
||||
assert(rect != null);
|
||||
}
|
||||
|
||||
final AnimatedRelativeRectValue rect;
|
||||
final Animated<RelativeRect> rect;
|
||||
final Widget child;
|
||||
|
||||
Widget buildWithChild(BuildContext context, Widget child) {
|
||||
performance.updateVariable(rect);
|
||||
Widget build(BuildContext context) {
|
||||
return new Positioned(
|
||||
top: rect.value.top,
|
||||
right: rect.value.right,
|
||||
|
||||
@@ -7,21 +7,22 @@ import 'package:flutter/animation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:test/test.dart' hide TypeMatcher;
|
||||
|
||||
class TestTransition extends TransitionComponent {
|
||||
class TestTransition extends AnimatedComponent {
|
||||
TestTransition({
|
||||
Key key,
|
||||
this.childFirstHalf,
|
||||
this.childSecondHalf,
|
||||
PerformanceView performance
|
||||
}) : super(key: key, performance: performance) {
|
||||
assert(performance != null);
|
||||
Animated<double> animation
|
||||
}) : super(key: key, animation: animation) {
|
||||
assert(animation != null);
|
||||
}
|
||||
|
||||
final Widget childFirstHalf;
|
||||
final Widget childSecondHalf;
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
if (performance.progress >= 0.5)
|
||||
final Animated<double> animation = this.animation;
|
||||
if (animation.value >= 0.5)
|
||||
return childSecondHalf;
|
||||
return childFirstHalf;
|
||||
}
|
||||
@@ -32,7 +33,7 @@ class TestRoute<T> extends PageRoute<T> {
|
||||
final Widget child;
|
||||
Duration get transitionDuration => kMaterialPageRouteTransitionDuration;
|
||||
Color get barrierColor => null;
|
||||
Widget buildPage(BuildContext context, PerformanceView performance, PerformanceView forwardPerformance) {
|
||||
Widget buildPage(BuildContext context, Animated<double> animation, Animated<double> forwardAnimation) {
|
||||
return child;
|
||||
}
|
||||
}
|
||||
@@ -81,12 +82,12 @@ void main() {
|
||||
new TestTransition(
|
||||
childFirstHalf: new Text('A'),
|
||||
childSecondHalf: new Text('B'),
|
||||
performance: route.performance
|
||||
animation: route.animation
|
||||
),
|
||||
new TestTransition(
|
||||
childFirstHalf: new Text('C'),
|
||||
childSecondHalf: new Text('D'),
|
||||
performance: route.forwardPerformance
|
||||
animation: route.forwardAnimation
|
||||
),
|
||||
]
|
||||
);
|
||||
|
||||
@@ -13,18 +13,17 @@ void main() {
|
||||
test('Can animate position data', () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
|
||||
final AnimatedRelativeRectValue rect = new AnimatedRelativeRectValue(
|
||||
new RelativeRect.fromRect(
|
||||
final RelativeRectTween rect = new RelativeRectTween(
|
||||
begin: new RelativeRect.fromRect(
|
||||
new Rect.fromLTRB(10.0, 20.0, 20.0, 30.0),
|
||||
new Rect.fromLTRB(0.0, 10.0, 100.0, 110.0)
|
||||
),
|
||||
end: new RelativeRect.fromRect(
|
||||
new Rect.fromLTRB(80.0, 90.0, 90.0, 100.0),
|
||||
new Rect.fromLTRB(0.0, 10.0, 100.0, 110.0)
|
||||
),
|
||||
curve: Curves.linear
|
||||
)
|
||||
);
|
||||
final Performance performance = new Performance(
|
||||
final AnimationController controller = new AnimationController(
|
||||
duration: const Duration(seconds: 10)
|
||||
);
|
||||
final List<Size> sizes = <Size>[];
|
||||
@@ -46,8 +45,7 @@ void main() {
|
||||
child: new Stack(
|
||||
children: <Widget>[
|
||||
new PositionedTransition(
|
||||
rect: rect,
|
||||
performance: performance,
|
||||
rect: rect.animate(controller),
|
||||
child: new Container(
|
||||
key: key
|
||||
)
|
||||
@@ -58,7 +56,7 @@ void main() {
|
||||
)
|
||||
); // t=0
|
||||
recordMetrics();
|
||||
performance.play();
|
||||
controller.forward();
|
||||
tester.pump(); // t=0 again
|
||||
recordMetrics();
|
||||
tester.pump(const Duration(seconds: 1)); // t=1
|
||||
|
||||
Reference in New Issue
Block a user