| OLD | NEW |
| 1 Animation API | 1 Animation API |
| 2 ============= | 2 ============= |
| 3 | 3 |
| 4 (This is very incomplete, because it's all expected to be in the | 4 ```dart |
| 5 framework, not the platform.) | 5 typedef void TimerCallback(); |
| 6 | 6 |
| 7 ```javascript | 7 class AnimationTimer extends Timer { |
| 8 external factory whenIdle(TimerCallback callback, { double budget: 1.0 }); |
| 9 // calls callback next time the system is idle |
| 10 // - if budget is in the range 0.0 < budget <= 1.0, then callback is |
| 11 // guaranteed to have that many milliseconds before being killed |
| 12 // - if budget <= 0.0, then the callback could be killed [at any time](script.
md). |
| 13 // - if budget > 1.0, then it is treated as 1.0. |
| 8 | 14 |
| 9 dictionary EasingFunctionSettings { | 15 external factory beforePaint(TimerCallback callback, { int priority: 0 }); |
| 10 Float duration; // required | 16 // runs this timeout before this frame's layout/paint phases begin |
| 11 Callback? completionCallback = null; | 17 external factory nextFrame(TimerCallback callback, { int priority: 0 }); |
| 12 } | 18 // runs this timeout right away |
| 13 | 19 |
| 14 abstract class EasingFunction { | 20 // for beforePaint and nextFrame, the callbacks are first sorted by |
| 15 abstract constructor (EasingFunctionSettings settings); | 21 // priority, and then run in decreasing order of priority, |
| 16 abstract Float getFactor(Float time); | 22 // tie-breaking by registration time, earliest first. |
| 17 // calls completionCallback if time >= duration | 23 |
| 18 // then returns a number ostensibly in the range 0.0 to 1.0 | 24 // once there is no more time for callbacks this frame, the Timers |
| 19 // (but it could in practice go outside this range, e.g. for | 25 // are all canceled, so isActive will become false |
| 20 // animation styles that overreach then come back) | 26 |
| 21 } | 27 } |
| 22 ``` | 28 ``` |
| 23 | 29 |
| 24 | 30 |
| 31 Easing Functions |
| 32 ---------------- |
| 33 |
| 34 ```dart |
| 35 // part of the framework, not sky:core |
| 36 |
| 37 typedef void AnimationCallback(); |
| 38 |
| 39 abstract class EasingFunction { |
| 40 EasingFunction({double duration: 0.0, AnimationCallback completionCallback: nu
ll }); |
| 41 double getFactor(Float time); |
| 42 // calls completionCallback if time >= duration |
| 43 // then returns a number ostensibly in the range 0.0 to 1.0 |
| 44 // (but it could in practice go outside this range, e.g. for |
| 45 // animation styles that overreach then come back) |
| 46 } |
| 47 ``` |
| 48 |
| 25 If you want to have two animations simultaneously, e.g. two | 49 If you want to have two animations simultaneously, e.g. two |
| 26 transforms, then you can add to the RenderNode's overrideStyles a | 50 transforms, then you can add to the RenderNode's overrideStyles a |
| 27 StyleValue that combines other StyleValues, e.g. a | 51 StyleValue that combines other StyleValues, e.g. a |
| 28 "TransformStyleValueCombinerStyleValue", and then add to it the | 52 "TransformStyleValueCombinerStyleValue", and then add to it the |
| 29 regular animated StyleValues, e.g. multiple | 53 regular animated StyleValues, e.g. multiple |
| 30 "AnimatedTransformStyleValue" objects. A framework API could make | 54 "AnimatedTransformStyleValue" objects. A framework API could make |
| 31 setting all that up easy, given the right underlying StyleValue | 55 setting all that up easy, given the right underlying StyleValue |
| 32 classes. | 56 classes. |
| OLD | NEW |