Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Unified Diff: sky/examples/fn/widgets/drawer.dart

Issue 994143002: Add initialDelay to AnimationGenerator and add Animation class (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: cr comments Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sky/framework/animation/generator.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
}
« no previous file with comments | « no previous file | sky/framework/animation/generator.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698