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

Side by Side Diff: sky/sdk/lib/animation/animation_performance.dart

Issue 1223073002: AnimatedContainer: generalized Container widget that handles animating values (Closed) Base URL: git@github.com:/domokit/mojo.git@master
Patch Set: . 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 import 'animated_value.dart'; 5 import 'animated_value.dart';
6 import 'curves.dart'; 6 import 'curves.dart';
7 7
8 // TODO(mpcomplete): merge this stuff with AnimatedValue somehow. We shouldn't 8 // TODO(mpcomplete): merge this stuff with AnimatedValue somehow. We shouldn't
9 // have 2 different ways to animate values. 9 // have 2 different ways to animate values.
10 abstract class AnimatedVariable { 10 abstract class AnimatedVariable {
11 void setFraction(double t); 11 void setFraction(double t);
12 } 12 }
13 13
14 class AnimatedType<T extends dynamic> extends AnimatedVariable { 14 class AnimatedType<T extends dynamic> extends AnimatedVariable {
15 T value; 15 T value;
16 final T begin, end; 16 T begin, end;
17 final Curve curve; 17 final Curve curve;
18 18
19 AnimatedType(this.begin, this.end, {this.curve: linear}) { 19 AnimatedType(this.begin, {this.end, this.curve: linear}) {
20 value = begin; 20 value = begin;
21 } 21 }
22 22
23 void setFraction(double t) { 23 void setFraction(double t) {
24 // TODO(mpcomplete): Reverse the timeline and curve. 24 if (end != null) {
25 value = begin + (end - begin) * curve.transform(t); 25 // TODO(mpcomplete): Reverse the timeline and curve.
26 value = begin + (end - begin) * curve.transform(t);
27 }
26 } 28 }
27 } 29 }
28 30
29 // This class manages a "performance" - a collection of values that change 31 // This class manages a "performance" - a collection of values that change
30 // based on a timeline. For example, a performance may handle an animation 32 // based on a timeline. For example, a performance may handle an animation
31 // of a menu opening by sliding and fading in (changing Y value and opacity) 33 // of a menu opening by sliding and fading in (changing Y value and opacity)
32 // over .5 seconds. The performance can move forwards (present) or backwards 34 // over .5 seconds. The performance can move forwards (present) or backwards
33 // (dismiss). A consumer may also take direct control of the timeline by 35 // (dismiss). A consumer may also take direct control of the timeline by
34 // manipulating |progress|, or |fling| the timeline causing a physics-based 36 // manipulating |progress|, or |fling| the timeline causing a physics-based
35 // simulation to take over the progression. 37 // simulation to take over the progression.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 // time. 82 // time.
81 void fling({double velocity: 1.0}) { 83 void fling({double velocity: 1.0}) {
82 double target = velocity.sign < 0.0 ? 0.0 : 1.0; 84 double target = velocity.sign < 0.0 ? 0.0 : 1.0;
83 double distance = (target - timeline.value).abs(); 85 double distance = (target - timeline.value).abs();
84 double duration = distance / velocity.abs(); 86 double duration = distance / velocity.abs();
85 87
86 if (distance > 0.0) 88 if (distance > 0.0)
87 timeline.animateTo(target, duration, curve: linear); 89 timeline.animateTo(target, duration, curve: linear);
88 } 90 }
89 } 91 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698