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

Unified Diff: sky/sdk/lib/widgets/toggleable.dart

Issue 1226143010: Port Toggleable to the new animation system (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: typo Created 5 years, 5 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 | « sky/sdk/lib/widgets/switch.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/sdk/lib/widgets/toggleable.dart
diff --git a/sky/sdk/lib/widgets/toggleable.dart b/sky/sdk/lib/widgets/toggleable.dart
index e6fac38ab4e640ba56dbab3b1ea257db022e9110..10162678d057521e2dc9663595b345f298e647fb 100644
--- a/sky/sdk/lib/widgets/toggleable.dart
+++ b/sky/sdk/lib/widgets/toggleable.dart
@@ -4,14 +4,14 @@
import 'dart:sky' as sky;
-import '../animation/animated_value.dart';
+import '../animation/animation_performance.dart';
import '../animation/curves.dart';
import 'animated_component.dart';
import 'basic.dart';
typedef void ValueChanged(value);
-const double _kCheckDuration = 200.0;
+const Duration _kCheckDuration = const Duration(milliseconds: 200);
abstract class Toggleable extends AnimatedComponent {
@@ -20,25 +20,32 @@ abstract class Toggleable extends AnimatedComponent {
this.value,
this.onChanged
}) : super(key: key) {
- toggleAnimation = new AnimatedValue(value ? 1.0 : 0.0);
- watch(toggleAnimation);
+ position = new AnimatedType<double>(0.0, end: 1.0);
+ performance = new AnimationPerformance()
+ ..variable = position
+ ..duration = _kCheckDuration
+ ..progress = value ? 1.0 : 0.0;
+ watchPerformance(performance);
}
bool value;
- AnimatedValue toggleAnimation;
ValueChanged onChanged;
+ AnimatedType<double> position;
+ AnimationPerformance performance;
+
void syncFields(Toggleable source) {
onChanged = source.onChanged;
if (value != source.value) {
value = source.value;
- double targetValue = value ? 1.0 : 0.0;
- double difference = (toggleAnimation.value - targetValue).abs();
- if (difference > 0) {
- toggleAnimation.stop();
- double t = difference * duration;
- Curve curve = targetValue > toggleAnimation.value ? curveUp : curveDown;
- toggleAnimation.animateTo(targetValue, t, curve: curve);
+ // TODO(abarth): Setting the curve on the position means there's a
+ // discontinuity when we reverse the timeline.
+ if (value) {
+ position.curve = curveUp;
+ performance.play();
+ } else {
+ position.curve = curveDown;
+ performance.reverse();
}
}
super.syncFields(source);
@@ -65,7 +72,7 @@ abstract class Toggleable extends AnimatedComponent {
width: size.width,
height: size.height,
child: new CustomPaint(
- token: toggleAnimation.value,
+ token: position.value,
callback: customPaintCallback
)
),
« no previous file with comments | « sky/sdk/lib/widgets/switch.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698