| Index: sky/examples/fn/widgets/drawer.dart
|
| diff --git a/sky/examples/fn/widgets/drawer.dart b/sky/examples/fn/widgets/drawer.dart
|
| index 8e210d8eb7064aec7a2ff281e02236421dc81c60..8f36d182455a0a51457e73afaca04a52e32f7897 100644
|
| --- a/sky/examples/fn/widgets/drawer.dart
|
| +++ b/sky/examples/fn/widgets/drawer.dart
|
| @@ -6,39 +6,34 @@ const double _kBaseSettleDurationMS = 246.0;
|
| const double _kMaxSettleDurationMS = 600.0;
|
| const Cubic _kAnimationCurve = easeOut;
|
|
|
| -class DrawerAnimation {
|
| +class DrawerAnimation extends Animation {
|
|
|
| - Stream<double> get onPositionChanged => _controller.stream;
|
| + Stream<double> get onPositionChanged => onValueChanged;
|
|
|
| - StreamController _controller;
|
| - AnimationGenerator _animation;
|
| - double _position;
|
| - bool get _isAnimating => _animation != null;
|
| - bool get _isMostlyClosed => _position <= -_kWidth / 2;
|
| + bool get _isMostlyClosed => value <= -_kWidth / 2;
|
|
|
| DrawerAnimation() {
|
| - _controller = new StreamController(sync: true);
|
| - _setPosition(-_kWidth);
|
| + value = -_kWidth;
|
| }
|
|
|
| void toggle(_) => _isMostlyClosed ? _open() : _close();
|
|
|
| void handleMaskTap(_) => _close();
|
|
|
| - void handlePointerDown(_) => _cancelAnimation();
|
| + void handlePointerDown(_) => stop();
|
|
|
| void handlePointerMove(sky.PointerEvent event) {
|
| - assert(_animation == null);
|
| - _setPosition(_position + event.dx);
|
| + assert(!isAnimating);
|
| + value = math.min(0.0, math.max(value + event.dx, -_kWidth));
|
| }
|
|
|
| void handlePointerUp(_) {
|
| - if (!_isAnimating)
|
| + if (!isAnimating)
|
| _settle();
|
| }
|
|
|
| void handlePointerCancel(_) {
|
| - if (!_isAnimating)
|
| + if (!isAnimating)
|
| _settle();
|
| }
|
|
|
| @@ -48,35 +43,12 @@ class DrawerAnimation {
|
|
|
| void _settle() => _isMostlyClosed ? _close() : _open();
|
|
|
| - void _setPosition(double value) {
|
| - _position = math.min(0.0, math.max(value, -_kWidth));
|
| - _controller.add(_position);
|
| - }
|
| -
|
| - void _cancelAnimation() {
|
| - if (_animation != null) {
|
| - _animation.cancel();
|
| - _animation = null;
|
| - }
|
| - }
|
| -
|
| - void _animate(double duration, double begin, double end, Curve curve) {
|
| - _cancelAnimation();
|
| -
|
| - _animation = new AnimationGenerator(duration, begin: begin, end: end,
|
| - curve: curve);
|
| -
|
| - _animation.onTick.listen(_setPosition, onDone: () {
|
| - _animation = null;
|
| - });
|
| - }
|
| -
|
| void _animateToPosition(double targetPosition) {
|
| - double distance = (targetPosition - _position).abs();
|
| + double distance = (targetPosition - value).abs();
|
| if (distance != 0) {
|
| double targetDuration = distance / _kWidth * _kBaseSettleDurationMS;
|
| double duration = math.min(targetDuration, _kMaxSettleDurationMS);
|
| - _animate(duration, _position, targetPosition, _kAnimationCurve);
|
| + animateTo(targetPosition, duration, curve: _kAnimationCurve);
|
| }
|
| }
|
|
|
| @@ -87,10 +59,10 @@ class DrawerAnimation {
|
| return;
|
|
|
| double targetPosition = direction < 0.0 ? -_kWidth : 0.0;
|
| - double distance = (targetPosition - _position).abs();
|
| + double distance = (targetPosition - value).abs();
|
| double duration = distance / velocityX;
|
|
|
| - _animate(duration, _position, targetPosition, linear);
|
| + animateTo(targetPosition, duration, curve: linear);
|
| }
|
| }
|
|
|
|
|