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

Unified Diff: sky/sdk/lib/animation/animation_performance.dart

Issue 1241703003: Use AnimationVariables to drive PopupMenu animation (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: adjustedTime moar 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 | « no previous file | sky/sdk/lib/widgets/popup_menu.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/sdk/lib/animation/animation_performance.dart
diff --git a/sky/sdk/lib/animation/animation_performance.dart b/sky/sdk/lib/animation/animation_performance.dart
index 7b7a96e5f70b19d7527c079bd17f747ce8990dc9..9f13a3553aebcb1429df3a41bf698aa7cc247f43 100644
--- a/sky/sdk/lib/animation/animation_performance.dart
+++ b/sky/sdk/lib/animation/animation_performance.dart
@@ -10,23 +10,41 @@ abstract class AnimatedVariable {
String toString();
}
+class Interval {
+ final double start;
+ final double end;
+
+ double adjustTime(double t) {
+ return ((t - start) / (end - start)).clamp(0.0, 1.0);
+ }
+
+ Interval(this.start, this.end) {
+ assert(start >= 0.0);
+ assert(start <= 1.0);
+ assert(end >= 0.0);
+ assert(end <= 1.0);
+ }
+}
+
class AnimatedType<T extends dynamic> extends AnimatedVariable {
- AnimatedType(this.begin, { this.end, this.curve: linear }) {
+ AnimatedType(this.begin, { this.end, this.interval, this.curve: linear }) {
value = begin;
}
T value;
T begin;
T end;
+ Interval interval;
Curve curve;
void setFraction(double t) {
if (end != null) {
- if (t == 1.0) {
+ double adjustedTime = interval == null ? t : interval.adjustTime(t);
+ if (adjustedTime == 1.0) {
value = end;
} else {
// TODO(mpcomplete): Reverse the timeline and curve.
- value = begin + (end - begin) * curve.transform(t);
+ value = begin + (end - begin) * curve.transform(adjustedTime);
}
}
}
« no previous file with comments | « no previous file | sky/sdk/lib/widgets/popup_menu.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698