From ef880695d5525243e20567ae005a18ee7d989beb Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Sun, 6 Sep 2015 15:38:26 -0700 Subject: [PATCH] Introduce package:sky/animation.dart Move the animation libraries into src/animation and change importers to use package:sky/animation.dart. Also, move scheduler.dart into the animation library so that the animation library can be self-contained. --- examples/fitness/lib/main.dart | 1 + examples/rendering/spinning_flex.dart | 2 +- examples/stocks/lib/main.dart | 1 + examples/widgets/card_collection.dart | 1 + examples/widgets/pageable_list.dart | 1 + examples/widgets/progress_indicator.dart | 4 +- examples/widgets/spinning_mixed.dart | 2 +- sky/packages/sky/lib/README.md | 31 +++--- sky/packages/sky/lib/animation.dart | 19 ++++ sky/packages/sky/lib/animation/direction.dart | 8 -- sky/packages/sky/lib/base/debug.dart | 3 - sky/packages/sky/lib/base/scheduler.dart | 88 ----------------- sky/packages/sky/lib/painting/README.md | 4 +- .../sky/lib/painting/radial_reaction.dart | 4 +- .../sky/lib/{ => src}/animation/README.md | 2 +- .../animation/animated_simulation.dart | 2 +- .../{ => src}/animation/animated_value.dart | 8 +- .../animation/animation_performance.dart | 9 +- .../sky/lib/{ => src}/animation/curves.dart | 18 ---- .../sky/lib/{ => src}/animation/forces.dart | 9 +- .../sky/lib/src/animation/scheduler.dart | 95 +++++++++++++++++++ .../{ => src}/animation/scroll_behavior.dart | 0 .../sky/lib/{ => src}/animation/timeline.dart | 3 +- sky/packages/sky/lib/src/rendering/README.md | 10 +- .../sky/lib/src/rendering/object.dart | 2 +- .../sky/lib/src/rendering/sky_binding.dart | 5 +- .../sky/lib/src/rendering/toggleable.dart | 4 +- sky/packages/sky/lib/src/rendering/view.dart | 2 +- sky/packages/sky/lib/src/widgets/README.md | 10 +- .../lib/src/widgets/animated_component.dart | 2 +- .../lib/src/widgets/animated_container.dart | 4 +- sky/packages/sky/lib/src/widgets/dialog.dart | 3 +- .../sky/lib/src/widgets/dismissable.dart | 4 +- sky/packages/sky/lib/src/widgets/drawer.dart | 6 +- .../sky/lib/src/widgets/framework.dart | 2 +- .../sky/lib/src/widgets/ink_well.dart | 8 +- .../sky/lib/src/widgets/mimic_overlay.dart | 4 +- .../sky/lib/src/widgets/navigator.dart | 4 +- .../sky/lib/src/widgets/popup_menu.dart | 5 +- .../lib/src/widgets/progress_indicator.dart | 4 +- .../sky/lib/src/widgets/scrollable.dart | 6 +- .../sky/lib/src/widgets/snack_bar.dart | 6 +- sky/packages/sky/lib/src/widgets/tabs.dart | 9 +- .../sky/lib/src/widgets/transitions.dart | 5 +- .../{base => animation}/scheduler_test.dart | 2 +- sky/unit/test/widget/widget_tester.dart | 2 +- skysprites/lib/skysprites.dart | 3 +- 47 files changed, 193 insertions(+), 234 deletions(-) create mode 100644 sky/packages/sky/lib/animation.dart delete mode 100644 sky/packages/sky/lib/animation/direction.dart delete mode 100644 sky/packages/sky/lib/base/scheduler.dart rename sky/packages/sky/lib/{ => src}/animation/README.md (51%) rename sky/packages/sky/lib/{ => src}/animation/animated_simulation.dart (97%) rename sky/packages/sky/lib/{ => src}/animation/animated_value.dart (94%) rename sky/packages/sky/lib/{ => src}/animation/animation_performance.dart (96%) rename sky/packages/sky/lib/{ => src}/animation/curves.dart (91%) rename sky/packages/sky/lib/{ => src}/animation/forces.dart (87%) create mode 100644 sky/packages/sky/lib/src/animation/scheduler.dart rename sky/packages/sky/lib/{ => src}/animation/scroll_behavior.dart (100%) rename sky/packages/sky/lib/{ => src}/animation/timeline.dart (97%) rename sky/unit/test/{base => animation}/scheduler_test.dart (95%) diff --git a/examples/fitness/lib/main.dart b/examples/fitness/lib/main.dart index a4d40d1b2ac..740ac9e79cf 100644 --- a/examples/fitness/lib/main.dart +++ b/examples/fitness/lib/main.dart @@ -5,6 +5,7 @@ library fitness; import 'package:playfair/playfair.dart' as playfair; +import 'package:sky/animation.dart'; import 'package:sky/painting/text_style.dart'; import 'package:sky/theme/colors.dart' as colors; import 'package:sky/widgets.dart'; diff --git a/examples/rendering/spinning_flex.dart b/examples/rendering/spinning_flex.dart index d217c325a60..b2fc6e894f8 100644 --- a/examples/rendering/spinning_flex.dart +++ b/examples/rendering/spinning_flex.dart @@ -4,7 +4,7 @@ import 'dart:sky' as sky; -import 'package:sky/base/scheduler.dart' as scheduler; +import 'package:sky/animation.dart'; import 'package:sky/rendering.dart'; import 'solid_color_box.dart'; diff --git a/examples/stocks/lib/main.dart b/examples/stocks/lib/main.dart index ba81c856ac6..1962baa424f 100644 --- a/examples/stocks/lib/main.dart +++ b/examples/stocks/lib/main.dart @@ -9,6 +9,7 @@ import 'dart:sky' as sky; import 'package:sky/theme/colors.dart' as colors; import 'package:sky/theme/typography.dart' as typography; +import 'package:sky/animation.dart'; import 'package:sky/widgets.dart'; import 'stock_data.dart'; diff --git a/examples/widgets/card_collection.dart b/examples/widgets/card_collection.dart index b81da2807c5..a0bbb3cd03d 100644 --- a/examples/widgets/card_collection.dart +++ b/examples/widgets/card_collection.dart @@ -4,6 +4,7 @@ import 'package:sky/theme/colors.dart' as colors; import 'package:sky/theme/typography.dart' as typography; +import 'package:sky/animation.dart'; import 'package:sky/widgets.dart'; class CardModel { diff --git a/examples/widgets/pageable_list.dart b/examples/widgets/pageable_list.dart index 881cff51071..a62630698af 100644 --- a/examples/widgets/pageable_list.dart +++ b/examples/widgets/pageable_list.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'package:sky/theme/colors.dart'; +import 'package:sky/animation.dart'; import 'package:sky/widgets.dart'; class CardModel { diff --git a/examples/widgets/progress_indicator.dart b/examples/widgets/progress_indicator.dart index a9be0488044..1adc5dd2285 100644 --- a/examples/widgets/progress_indicator.dart +++ b/examples/widgets/progress_indicator.dart @@ -2,9 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:sky/animation/animation_performance.dart'; -import 'package:sky/animation/animated_value.dart'; -import 'package:sky/animation/curves.dart'; +import 'package:sky/animation.dart'; import 'package:sky/theme/colors.dart' as colors; import 'package:sky/widgets.dart'; diff --git a/examples/widgets/spinning_mixed.dart b/examples/widgets/spinning_mixed.dart index 44a20b37532..2a2463bf55a 100644 --- a/examples/widgets/spinning_mixed.dart +++ b/examples/widgets/spinning_mixed.dart @@ -4,7 +4,7 @@ import 'dart:sky' as sky; -import 'package:sky/base/scheduler.dart' as scheduler; +import 'package:sky/animation.dart'; import 'package:sky/rendering.dart'; import 'package:sky/widgets.dart'; diff --git a/sky/packages/sky/lib/README.md b/sky/packages/sky/lib/README.md index c52ef87186d..1b27173276c 100644 --- a/sky/packages/sky/lib/README.md +++ b/sky/packages/sky/lib/README.md @@ -5,31 +5,30 @@ Sky and Sky's SDK are designed as layered frameworks, where each layer depends on the ones below it but could be replaced wholesale. The bottom-most layer is the Sky Platform, which is exposed to Dart -code as [various ```dart:``` packages](https://api.dartlang.org/), -including ```dart:sky```. +code as [various `dart:` packages](https://api.dartlang.org/), +including `dart:sky`. The [base/](base/) directory contains libraries that extend these core APIs to provide base classes for tree structures ([base/node.dart](base/node.dart)), hit testing -([base/hit_test.dart](base/hit_test.dart)), debugging -([base/debug.dart](base/debug.dart)), and task scheduling -([base/scheduler.dart](base/scheduler.dart)). +([base/hit_test.dart](base/hit_test.dart)), and debugging +([base/debug.dart](base/debug.dart)). -Above this are the files in the [animation/](animation/) directory, -which provide core primitives for animating values, and in the [gestures/](gestures/) +Above this layer is the [animation](animation.dart) library, +which provides core animation primitives, and the [gestures/](gestures/) directory, which define a gesture recognition and disambiguation system. The next layer consists of the files in the [painting/](painting/) directory, which provide APIs related to drawing graphics. Some of the code here -uses the [animation/](animation/) utilities mentioned above. +uses the [animation](animation.dart) utilities mentioned above. Layout primitives are provided in the next layer, found in the -[rendering/](rendering/) directory. They use ```dart:sky``` and the -APIs exposed in painting/ to provide a retained-mode layout and +[rendering](rendering.dart) library. They use `dart:sky` and the +APIs exposed in [painting/](painting/) to provide a retained-mode layout and rendering model for applications or documents. -Widgets are provided by the files in the [widgets/](widgets/) -directory, using a reactive framework. They use data given in the +Widgets are provided by the files in the [widgets](widgets.dart) +library, using a reactive framework. They use data given in the [theme/](theme/) directory to select styles consistent with Material Design. @@ -38,18 +37,18 @@ anything that uses the Mojo IPC mechanism, typically as part of wrapping host operating system features. Some of those Host APIs are implemented in the host system's preferred language. -Here is a diagram summarising all this: +Here is a diagram summarizing all this: +-----------------------------+ ------ | YOUR APP | | +----------------------+---+ - | | widgets/ (theme/) | | + | | widgets (theme/) | | | ++---------------------++ | - | | rendering/ | | Dart + | | rendering | | Dart | |---------+------------+ | | | | painting/ | | +-+ +------------+ | - | gestures/ | animation/ | | + | gestures/ | animation | | +-----------+---+--------+ | | base/ | mojo/ | +------------+--+-+----+------+ ------- diff --git a/sky/packages/sky/lib/animation.dart b/sky/packages/sky/lib/animation.dart new file mode 100644 index 00000000000..6a8b2869b20 --- /dev/null +++ b/sky/packages/sky/lib/animation.dart @@ -0,0 +1,19 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// The Sky animation engine. +/// +/// This library includes and re-exports all Sky animation classes. +library animation; + +export 'package:sky/src/rendering/auto_layout.dart'; + +export 'src/animation/animated_simulation.dart'; +export 'src/animation/animated_value.dart'; +export 'src/animation/animation_performance.dart'; +export 'src/animation/curves.dart'; +export 'src/animation/forces.dart'; +export 'src/animation/scheduler.dart'; +export 'src/animation/scroll_behavior.dart'; +export 'src/animation/timeline.dart'; diff --git a/sky/packages/sky/lib/animation/direction.dart b/sky/packages/sky/lib/animation/direction.dart deleted file mode 100644 index 1a72ed771f9..00000000000 --- a/sky/packages/sky/lib/animation/direction.dart +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -enum Direction { - forward, - reverse -} diff --git a/sky/packages/sky/lib/base/debug.dart b/sky/packages/sky/lib/base/debug.dart index ae396dfd492..53e02ae9d91 100644 --- a/sky/packages/sky/lib/base/debug.dart +++ b/sky/packages/sky/lib/base/debug.dart @@ -40,6 +40,3 @@ const sky.Color debugPaintLayerBordersColor = const sky.Color(0xFFFF9800); /// Causes RenderObjects to paint warnings when painting outside their bounds. bool debugPaintBoundsEnabled = false; - -/// Slows down animations by this factor to help in development. -double timeDilation = 1.0; diff --git a/sky/packages/sky/lib/base/scheduler.dart b/sky/packages/sky/lib/base/scheduler.dart deleted file mode 100644 index c0e0ecea8a8..00000000000 --- a/sky/packages/sky/lib/base/scheduler.dart +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:collection'; -import 'dart:sky' as sky; - -import 'package:sky/base/debug.dart'; - -/// A callback from the scheduler -/// -/// The timeStamp is the number of milliseconds since the beginning of the -/// scheduler's epoch. Use timeStamp to determine how far to advance animation -/// timelines so that all the animations in the system are synchronized to a -/// common time base. -typedef void SchedulerCallback(double timeStamp); - -bool _haveScheduledVisualUpdate = false; -int _nextCallbackId = 1; - -final List _persistentCallbacks = new List(); -Map _transientCallbacks = new LinkedHashMap(); -final Set _removedIds = new Set(); - -/// Called by the engine to produce a new frame. -/// -/// This function first calls all the callbacks registered by -/// [requestAnimationFrame] and then calls all the callbacks registered by -/// [addPersistentFrameCallback], which typically drive the rendering pipeline. -void beginFrame(double timeStamp) { - timeStamp /= timeDilation; - - _haveScheduledVisualUpdate = false; - - Map callbacks = _transientCallbacks; - _transientCallbacks = new Map(); - - callbacks.forEach((id, callback) { - if (!_removedIds.contains(id)) - callback(timeStamp); - }); - _removedIds.clear(); - - for (SchedulerCallback callback in _persistentCallbacks) - callback(timeStamp); -} - -/// Registers [beginFrame] callback with the engine. -void init() { - sky.view.setFrameCallback(beginFrame); -} - -/// Call callback every frame. -void addPersistentFrameCallback(SchedulerCallback callback) { - _persistentCallbacks.add(callback); -} - -/// Schedule a callback for the next frame. -/// -/// The callback will be run prior to flushing the main rendering pipeline. -/// Typically, requestAnimationFrame is used to throttle writes into the -/// rendering pipeline until the system is ready to accept a new frame. For -/// example, if you wanted to tick through an animation, you should use -/// requestAnimation frame to determine when to tick the animation. The callback -/// is passed a timeStamp that you can use to determine how far along the -/// timeline to advance your animation. -/// -/// Returns an id that can be used to unschedule this callback. -int requestAnimationFrame(SchedulerCallback callback) { - int id = _nextCallbackId++; - _transientCallbacks[id] = callback; - ensureVisualUpdate(); - return id; -} - -/// Cancel the callback identified by id. -void cancelAnimationFrame(int id) { - _transientCallbacks.remove(id); - _removedIds.add(id); -} - -/// Ensure that a frame will be produced after this function is called. -void ensureVisualUpdate() { - if (_haveScheduledVisualUpdate) - return; - sky.view.scheduleFrame(); - _haveScheduledVisualUpdate = true; -} diff --git a/sky/packages/sky/lib/painting/README.md b/sky/packages/sky/lib/painting/README.md index 64967d7d8f0..ed05e995f64 100644 --- a/sky/packages/sky/lib/painting/README.md +++ b/sky/packages/sky/lib/painting/README.md @@ -1,3 +1,3 @@ This directory contains painting-related libraries that only depend on -core Dart libraries, ../base/*, and ../animation/*. Note that -../animation/* depends on the Newton Dart library also. +core Dart libraries, `../base/*`, and [animation.dart](../animation.dart). Note +that [animation.dart](../animation.dart) depends on the Newton Dart library. diff --git a/sky/packages/sky/lib/painting/radial_reaction.dart b/sky/packages/sky/lib/painting/radial_reaction.dart index 69663d00b12..0e4aa0034c9 100644 --- a/sky/packages/sky/lib/painting/radial_reaction.dart +++ b/sky/packages/sky/lib/painting/radial_reaction.dart @@ -6,9 +6,7 @@ import 'dart:async'; import 'dart:sky' as sky; import 'dart:sky' show Point, Offset, Color, Paint; -import 'package:sky/animation/animated_value.dart'; -import 'package:sky/animation/animation_performance.dart'; -import 'package:sky/animation/curves.dart'; +import 'package:sky/animation.dart'; const Duration _kShowDuration = const Duration(milliseconds: 300); const Duration _kHideDuration = const Duration(milliseconds: 200); diff --git a/sky/packages/sky/lib/animation/README.md b/sky/packages/sky/lib/src/animation/README.md similarity index 51% rename from sky/packages/sky/lib/animation/README.md rename to sky/packages/sky/lib/src/animation/README.md index 55f96cae9ef..6b2ebb3a0aa 100644 --- a/sky/packages/sky/lib/animation/README.md +++ b/sky/packages/sky/lib/src/animation/README.md @@ -1,2 +1,2 @@ This directory contains animation-related libraries that only depend -on core Dart libraries, the Newton Dart library, and ../base/*. +on core Dart libraries and the Newton Dart library. diff --git a/sky/packages/sky/lib/animation/animated_simulation.dart b/sky/packages/sky/lib/src/animation/animated_simulation.dart similarity index 97% rename from sky/packages/sky/lib/animation/animated_simulation.dart rename to sky/packages/sky/lib/src/animation/animated_simulation.dart index b3278e20762..18ce06fc88e 100644 --- a/sky/packages/sky/lib/animation/animated_simulation.dart +++ b/sky/packages/sky/lib/src/animation/animated_simulation.dart @@ -5,7 +5,7 @@ import 'dart:async'; import 'package:newton/newton.dart'; -import 'package:sky/base/scheduler.dart' as scheduler; +import 'package:sky/src/animation/scheduler.dart'; const double _kSecondsPerMillisecond = 1000.0; diff --git a/sky/packages/sky/lib/animation/animated_value.dart b/sky/packages/sky/lib/src/animation/animated_value.dart similarity index 94% rename from sky/packages/sky/lib/animation/animated_value.dart rename to sky/packages/sky/lib/src/animation/animated_value.dart index 02cc3b3b8c3..7f9877d911c 100644 --- a/sky/packages/sky/lib/animation/animated_value.dart +++ b/sky/packages/sky/lib/src/animation/animated_value.dart @@ -4,10 +4,12 @@ import "dart:sky"; -import 'package:sky/animation/curves.dart'; -import 'package:sky/animation/direction.dart'; +import 'package:sky/src/animation/curves.dart'; -export 'package:sky/animation/curves.dart' show Interval; +enum Direction { + forward, + reverse +} abstract class AnimatedVariable { void setProgress(double t, Direction direction); diff --git a/sky/packages/sky/lib/animation/animation_performance.dart b/sky/packages/sky/lib/src/animation/animation_performance.dart similarity index 96% rename from sky/packages/sky/lib/animation/animation_performance.dart rename to sky/packages/sky/lib/src/animation/animation_performance.dart index 700f572cdc3..af0c1744590 100644 --- a/sky/packages/sky/lib/animation/animation_performance.dart +++ b/sky/packages/sky/lib/src/animation/animation_performance.dart @@ -4,12 +4,9 @@ import 'dart:async'; -import 'package:sky/animation/animated_value.dart'; -import 'package:sky/animation/direction.dart'; -import 'package:sky/animation/forces.dart'; -import 'package:sky/animation/timeline.dart'; - -export 'package:sky/animation/direction.dart' show Direction; +import 'package:sky/src/animation/animated_value.dart'; +import 'package:sky/src/animation/forces.dart'; +import 'package:sky/src/animation/timeline.dart'; enum AnimationStatus { dismissed, // stoped at 0 diff --git a/sky/packages/sky/lib/animation/curves.dart b/sky/packages/sky/lib/src/animation/curves.dart similarity index 91% rename from sky/packages/sky/lib/animation/curves.dart rename to sky/packages/sky/lib/src/animation/curves.dart index b16c1388e49..5e9cb6892e1 100644 --- a/sky/packages/sky/lib/animation/curves.dart +++ b/sky/packages/sky/lib/src/animation/curves.dart @@ -39,22 +39,6 @@ class Interval implements Curve { } } -class ParabolicFall implements Curve { - const ParabolicFall(); - - double transform(double t) { - return -t*t + 1; - } -} - -class ParabolicRise implements Curve { - const ParabolicRise(); - - double transform(double t) { - return -(t-1)*(t-1) + 1; - } -} - class Cubic implements Curve { final double a; final double b; @@ -162,8 +146,6 @@ const Cubic ease = const Cubic(0.25, 0.1, 0.25, 1.0); const Cubic easeIn = const Cubic(0.42, 0.0, 1.0, 1.0); const Cubic easeOut = const Cubic(0.0, 0.0, 0.58, 1.0); const Cubic easeInOut = const Cubic(0.42, 0.0, 0.58, 1.0); -const ParabolicRise parabolicRise = const ParabolicRise(); -const ParabolicFall parabolicFall = const ParabolicFall(); const BounceInCurve bounceIn = const BounceInCurve(); const BounceOutCurve bounceOut = const BounceOutCurve(); const BounceInOutCurve bounceInOut = const BounceInOutCurve(); diff --git a/sky/packages/sky/lib/animation/forces.dart b/sky/packages/sky/lib/src/animation/forces.dart similarity index 87% rename from sky/packages/sky/lib/animation/forces.dart rename to sky/packages/sky/lib/src/animation/forces.dart index 6353c8afc43..8c57978015f 100644 --- a/sky/packages/sky/lib/animation/forces.dart +++ b/sky/packages/sky/lib/src/animation/forces.dart @@ -6,22 +6,25 @@ import 'package:newton/newton.dart'; // Base class for creating Simulations for the animation Timeline. abstract class Force { + const Force(); + Simulation release(double position, double velocity); } class SpringForce extends Force { - SpringForce(this.spring, { this.left: 0.0, this.right: 1.0 }); + const SpringForce(this.spring, { this.left: 0.0, this.right: 1.0 }); final SpringDescription spring; // Where to put the spring's resting point when releasing left or right, // respectively. - final double left, right; + final double left; + final double right; // We overshoot the target by this distance, but stop the simulation when // the spring gets within this distance (regardless of how fast it's moving). // This causes the spring to settle a bit faster than it otherwise would. - static final Tolerance tolerance = new Tolerance( + static const Tolerance tolerance = const Tolerance( velocity: double.INFINITY, distance: 0.01 ); diff --git a/sky/packages/sky/lib/src/animation/scheduler.dart b/sky/packages/sky/lib/src/animation/scheduler.dart new file mode 100644 index 00000000000..999ba890082 --- /dev/null +++ b/sky/packages/sky/lib/src/animation/scheduler.dart @@ -0,0 +1,95 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:collection'; +import 'dart:sky' as sky; + +/// Slows down animations by this factor to help in development. +double timeDilation = 1.0; + +/// A callback from the scheduler +/// +/// The timeStamp is the number of milliseconds since the beginning of the +/// scheduler's epoch. Use timeStamp to determine how far to advance animation +/// timelines so that all the animations in the system are synchronized to a +/// common time base. +typedef void SchedulerCallback(double timeStamp); + +/// Schedules callbacks to run in concert with the engine's animation system +class Scheduler { + /// Requires clients to use the [scheduler] singleton + Scheduler._() { + sky.view.setFrameCallback(beginFrame); + } + + bool _haveScheduledVisualUpdate = false; + int _nextCallbackId = 1; + + final List _persistentCallbacks = new List(); + Map _transientCallbacks = new LinkedHashMap(); + final Set _removedIds = new Set(); + + /// Called by the engine to produce a new frame. + /// + /// This function first calls all the callbacks registered by + /// [requestAnimationFrame] and then calls all the callbacks registered by + /// [addPersistentFrameCallback], which typically drive the rendering pipeline. + void beginFrame(double timeStamp) { + timeStamp /= timeDilation; + + _haveScheduledVisualUpdate = false; + + Map callbacks = _transientCallbacks; + _transientCallbacks = new Map(); + + callbacks.forEach((id, callback) { + if (!_removedIds.contains(id)) + callback(timeStamp); + }); + _removedIds.clear(); + + for (SchedulerCallback callback in _persistentCallbacks) + callback(timeStamp); + } + + /// Call callback every frame. + void addPersistentFrameCallback(SchedulerCallback callback) { + _persistentCallbacks.add(callback); + } + + /// Schedule a callback for the next frame. + /// + /// The callback will be run prior to flushing the main rendering pipeline. + /// Typically, requestAnimationFrame is used to throttle writes into the + /// rendering pipeline until the system is ready to accept a new frame. For + /// example, if you wanted to tick through an animation, you should use + /// requestAnimation frame to determine when to tick the animation. The callback + /// is passed a timeStamp that you can use to determine how far along the + /// timeline to advance your animation. + /// + /// Returns an id that can be used to unschedule this callback. + int requestAnimationFrame(SchedulerCallback callback) { + int id = _nextCallbackId++; + _transientCallbacks[id] = callback; + ensureVisualUpdate(); + return id; + } + + /// Cancel the callback identified by id. + void cancelAnimationFrame(int id) { + _transientCallbacks.remove(id); + _removedIds.add(id); + } + + /// Ensure that a frame will be produced after this function is called. + void ensureVisualUpdate() { + if (_haveScheduledVisualUpdate) + return; + sky.view.scheduleFrame(); + _haveScheduledVisualUpdate = true; + } +} + +/// A singleton instance of Scheduler to coordinate all the callbacks. +final Scheduler scheduler = new Scheduler._(); diff --git a/sky/packages/sky/lib/animation/scroll_behavior.dart b/sky/packages/sky/lib/src/animation/scroll_behavior.dart similarity index 100% rename from sky/packages/sky/lib/animation/scroll_behavior.dart rename to sky/packages/sky/lib/src/animation/scroll_behavior.dart diff --git a/sky/packages/sky/lib/animation/timeline.dart b/sky/packages/sky/lib/src/animation/timeline.dart similarity index 97% rename from sky/packages/sky/lib/animation/timeline.dart rename to sky/packages/sky/lib/src/animation/timeline.dart index 33073493f6a..294c918930d 100644 --- a/sky/packages/sky/lib/animation/timeline.dart +++ b/sky/packages/sky/lib/src/animation/timeline.dart @@ -5,7 +5,8 @@ import 'dart:async'; import 'package:newton/newton.dart'; -import 'package:sky/animation/animated_simulation.dart'; + +import 'package:sky/src/animation/animated_simulation.dart'; // Simple simulation that linearly varies from |begin| to |end| over |duration|. class TweenSimulation extends Simulation { diff --git a/sky/packages/sky/lib/src/rendering/README.md b/sky/packages/sky/lib/src/rendering/README.md index 91ba8a2ab9b..ff864f2d00b 100644 --- a/sky/packages/sky/lib/src/rendering/README.md +++ b/sky/packages/sky/lib/src/rendering/README.md @@ -372,8 +372,8 @@ This can be quite useful in figuring out exactly what is going on when working with the render tree. ```dart -import 'package:sky/src/rendering/sky_binding.dart'; -import 'package:sky/base/scheduler.dart' as scheduler; +import 'package:sky/animation.dart'; +import 'package:sky/rendering.dart'; scheduler.addPersistentFrameCallback((_) { SkyBinding.instance.debugDumpRenderTree(); @@ -384,6 +384,6 @@ scheduler.addPersistentFrameCallback((_) { Dependencies ------------ - * [`package:sky/base`](../base) - * [`package:sky/mojo`](../mojo) - * [`package:sky/animation`](../mojo) + * [`package:sky/base`](../../base) + * [`package:sky/mojo`](../../mojo) + * [`package:sky/animation.dart`](../../animation.dart) diff --git a/sky/packages/sky/lib/src/rendering/object.dart b/sky/packages/sky/lib/src/rendering/object.dart index 0977c1f3ec5..886769038d4 100644 --- a/sky/packages/sky/lib/src/rendering/object.dart +++ b/sky/packages/sky/lib/src/rendering/object.dart @@ -6,10 +6,10 @@ import 'dart:math' as math; import 'dart:sky' as sky; import 'dart:sky' show Point, Offset, Size, Rect, Color, Paint, Path; +import 'package:sky/animation.dart'; import 'package:sky/base/debug.dart'; import 'package:sky/base/hit_test.dart'; import 'package:sky/base/node.dart'; -import 'package:sky/base/scheduler.dart' as scheduler; import 'package:sky/src/rendering/layer.dart'; import 'package:vector_math/vector_math.dart'; diff --git a/sky/packages/sky/lib/src/rendering/sky_binding.dart b/sky/packages/sky/lib/src/rendering/sky_binding.dart index bb714d584fd..d5ce39530a9 100644 --- a/sky/packages/sky/lib/src/rendering/sky_binding.dart +++ b/sky/packages/sky/lib/src/rendering/sky_binding.dart @@ -4,9 +4,9 @@ import 'dart:sky' as sky; -import 'package:sky/base/pointer_router.dart'; +import 'package:sky/animation.dart'; import 'package:sky/base/hit_test.dart'; -import 'package:sky/base/scheduler.dart' as scheduler; +import 'package:sky/base/pointer_router.dart'; import 'package:sky/gestures/arena.dart'; import 'package:sky/src/rendering/box.dart'; import 'package:sky/src/rendering/object.dart'; @@ -45,7 +45,6 @@ class SkyBinding extends HitTestTarget { sky.view.setEventCallback(_handleEvent); sky.view.setMetricsChangedCallback(_handleMetricsChanged); - scheduler.init(); if (renderViewOverride == null) { _renderView = new RenderView(child: root); _renderView.attach(); diff --git a/sky/packages/sky/lib/src/rendering/toggleable.dart b/sky/packages/sky/lib/src/rendering/toggleable.dart index c42d1d82012..71673f933d4 100644 --- a/sky/packages/sky/lib/src/rendering/toggleable.dart +++ b/sky/packages/sky/lib/src/rendering/toggleable.dart @@ -4,9 +4,7 @@ import 'dart:sky' as sky; -import 'package:sky/animation/animated_value.dart'; -import 'package:sky/animation/animation_performance.dart'; -import 'package:sky/animation/curves.dart'; +import 'package:sky/animation.dart'; import 'package:sky/src/rendering/box.dart'; import 'package:sky/src/rendering/object.dart'; import 'package:sky/src/rendering/proxy_box.dart'; diff --git a/sky/packages/sky/lib/src/rendering/view.dart b/sky/packages/sky/lib/src/rendering/view.dart index 0292be3ef4f..943f0957f4b 100644 --- a/sky/packages/sky/lib/src/rendering/view.dart +++ b/sky/packages/sky/lib/src/rendering/view.dart @@ -4,7 +4,7 @@ import 'dart:sky' as sky; -import 'package:sky/base/scheduler.dart' as scheduler; +import 'package:sky/animation.dart'; import 'package:sky/src/rendering/layer.dart'; import 'package:sky/src/rendering/object.dart'; import 'package:sky/src/rendering/box.dart'; diff --git a/sky/packages/sky/lib/src/widgets/README.md b/sky/packages/sky/lib/src/widgets/README.md index 3deaa763df2..0fcb964681f 100644 --- a/sky/packages/sky/lib/src/widgets/README.md +++ b/sky/packages/sky/lib/src/widgets/README.md @@ -500,8 +500,8 @@ Dependencies ------------ * `package:vector_math` - * [`package:sky/animation`](../animation) - * [`package:sky/base`](../base) - * [`package:sky/painting`](../painting) - * [`package:sky/rendering`](../rendering) - * [`package:sky/theme`](../theme) + * [`package:sky/animation.dart`](../../animation.dart) + * [`package:sky/base`](../../base) + * [`package:sky/painting`](../../painting) + * [`package:sky/rendering.dart`](../../rendering.dart) + * [`package:sky/theme`](../../theme) diff --git a/sky/packages/sky/lib/src/widgets/animated_component.dart b/sky/packages/sky/lib/src/widgets/animated_component.dart index 2088a4d6a1f..f23d884fd33 100644 --- a/sky/packages/sky/lib/src/widgets/animated_component.dart +++ b/sky/packages/sky/lib/src/widgets/animated_component.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:sky/animation/animation_performance.dart'; +import 'package:sky/animation.dart'; import 'package:sky/src/widgets/framework.dart'; abstract class AnimatedComponent extends StatefulComponent { diff --git a/sky/packages/sky/lib/src/widgets/animated_container.dart b/sky/packages/sky/lib/src/widgets/animated_container.dart index a2db6bb20a5..744f1b65273 100644 --- a/sky/packages/sky/lib/src/widgets/animated_container.dart +++ b/sky/packages/sky/lib/src/widgets/animated_container.dart @@ -5,9 +5,7 @@ import 'dart:sky' as sky; import 'package:vector_math/vector_math.dart'; -import 'package:sky/animation/animated_value.dart'; -import 'package:sky/animation/animation_performance.dart'; -import 'package:sky/animation/curves.dart'; +import 'package:sky/animation.dart'; import 'package:sky/painting/box_painter.dart'; import 'package:sky/src/widgets/animated_component.dart'; import 'package:sky/src/widgets/basic.dart'; diff --git a/sky/packages/sky/lib/src/widgets/dialog.dart b/sky/packages/sky/lib/src/widgets/dialog.dart index 2db1f1cebc1..713b63577c3 100644 --- a/sky/packages/sky/lib/src/widgets/dialog.dart +++ b/sky/packages/sky/lib/src/widgets/dialog.dart @@ -4,8 +4,7 @@ import 'dart:async'; -import 'package:sky/animation/animated_value.dart'; -import 'package:sky/animation/curves.dart'; +import 'package:sky/animation.dart'; import 'package:sky/theme/colors.dart' as colors; import 'package:sky/src/widgets/basic.dart'; import 'package:sky/src/widgets/default_text_style.dart'; diff --git a/sky/packages/sky/lib/src/widgets/dismissable.dart b/sky/packages/sky/lib/src/widgets/dismissable.dart index a84827572d7..7425cdb0a9a 100644 --- a/sky/packages/sky/lib/src/widgets/dismissable.dart +++ b/sky/packages/sky/lib/src/widgets/dismissable.dart @@ -4,9 +4,7 @@ import 'dart:sky' as sky; -import 'package:sky/animation/animated_value.dart'; -import 'package:sky/animation/animation_performance.dart'; -import 'package:sky/animation/curves.dart'; +import 'package:sky/animation.dart'; import 'package:sky/src/widgets/basic.dart'; import 'package:sky/src/widgets/transitions.dart'; import 'package:sky/src/widgets/framework.dart'; diff --git a/sky/packages/sky/lib/src/widgets/drawer.dart b/sky/packages/sky/lib/src/widgets/drawer.dart index feb2a029660..d6f3ce6ea2e 100644 --- a/sky/packages/sky/lib/src/widgets/drawer.dart +++ b/sky/packages/sky/lib/src/widgets/drawer.dart @@ -5,9 +5,7 @@ import 'dart:async'; import 'dart:sky' as sky; -import 'package:sky/animation/animated_value.dart'; -import 'package:sky/animation/animation_performance.dart'; -import 'package:sky/animation/forces.dart'; +import 'package:sky/animation.dart'; import 'package:sky/theme/colors.dart' as colors; import 'package:sky/theme/shadows.dart'; import 'package:sky/src/widgets/animated_container.dart'; @@ -19,8 +17,6 @@ import 'package:sky/src/widgets/scrollable.dart'; import 'package:sky/src/widgets/theme.dart'; import 'package:sky/src/widgets/transitions.dart'; -export 'package:sky/animation/animation_performance.dart' show AnimationStatus; - // TODO(eseidel): Draw width should vary based on device size: // http://www.google.com/design/spec/layout/structure.html#structure-side-nav diff --git a/sky/packages/sky/lib/src/widgets/framework.dart b/sky/packages/sky/lib/src/widgets/framework.dart index c565530574e..167146c25fb 100644 --- a/sky/packages/sky/lib/src/widgets/framework.dart +++ b/sky/packages/sky/lib/src/widgets/framework.dart @@ -6,8 +6,8 @@ import 'dart:async'; import 'dart:collection'; import 'dart:sky' as sky; +import 'package:sky/animation.dart'; import 'package:sky/base/hit_test.dart'; -import 'package:sky/base/scheduler.dart' as scheduler; import 'package:sky/mojo/activity.dart'; import 'package:sky/src/rendering/box.dart'; import 'package:sky/src/rendering/object.dart'; diff --git a/sky/packages/sky/lib/src/widgets/ink_well.dart b/sky/packages/sky/lib/src/widgets/ink_well.dart index 584491212c9..503956610d5 100644 --- a/sky/packages/sky/lib/src/widgets/ink_well.dart +++ b/sky/packages/sky/lib/src/widgets/ink_well.dart @@ -5,12 +5,8 @@ import 'dart:math' as math; import 'dart:sky' as sky; -import 'package:sky/animation/animated_value.dart'; -import 'package:sky/animation/animation_performance.dart'; -import 'package:sky/animation/curves.dart'; -import 'package:sky/src/rendering/box.dart'; -import 'package:sky/src/rendering/object.dart'; -import 'package:sky/src/rendering/proxy_box.dart'; +import 'package:sky/animation.dart'; +import 'package:sky/rendering.dart'; import 'package:sky/src/widgets/basic.dart'; import 'package:sky/src/widgets/framework.dart'; diff --git a/sky/packages/sky/lib/src/widgets/mimic_overlay.dart b/sky/packages/sky/lib/src/widgets/mimic_overlay.dart index f4958d6ab01..9c7c742db31 100644 --- a/sky/packages/sky/lib/src/widgets/mimic_overlay.dart +++ b/sky/packages/sky/lib/src/widgets/mimic_overlay.dart @@ -2,9 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:sky/animation/animated_value.dart'; -import 'package:sky/animation/animation_performance.dart'; -import 'package:sky/animation/curves.dart'; +import 'package:sky/animation.dart'; import 'package:sky/src/widgets/animated_component.dart'; import 'package:sky/src/widgets/basic.dart'; import 'package:sky/src/widgets/framework.dart'; diff --git a/sky/packages/sky/lib/src/widgets/navigator.dart b/sky/packages/sky/lib/src/widgets/navigator.dart index 8fa3a1107ff..07e97a7732c 100644 --- a/sky/packages/sky/lib/src/widgets/navigator.dart +++ b/sky/packages/sky/lib/src/widgets/navigator.dart @@ -2,9 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:sky/animation/animated_value.dart'; -import 'package:sky/animation/animation_performance.dart'; -import 'package:sky/animation/curves.dart'; +import 'package:sky/animation.dart'; import 'package:sky/src/widgets/basic.dart'; import 'package:sky/src/widgets/focus.dart'; import 'package:sky/src/widgets/framework.dart'; diff --git a/sky/packages/sky/lib/src/widgets/popup_menu.dart b/sky/packages/sky/lib/src/widgets/popup_menu.dart index f08d7b7d97c..49185d08cd5 100644 --- a/sky/packages/sky/lib/src/widgets/popup_menu.dart +++ b/sky/packages/sky/lib/src/widgets/popup_menu.dart @@ -4,8 +4,7 @@ import 'dart:sky' as sky; -import 'package:sky/animation/animated_value.dart'; -import 'package:sky/animation/animation_performance.dart'; +import 'package:sky/animation.dart'; import 'package:sky/painting/box_painter.dart'; import 'package:sky/theme/colors.dart'; import 'package:sky/theme/shadows.dart'; @@ -16,8 +15,6 @@ import 'package:sky/src/widgets/popup_menu_item.dart'; import 'package:sky/src/widgets/scrollable.dart'; import 'package:sky/src/widgets/transitions.dart'; -export 'package:sky/animation/animation_performance.dart' show AnimationStatus; - const Duration _kMenuDuration = const Duration(milliseconds: 300); double _kMenuCloseIntervalEnd = 2.0 / 3.0; const double _kMenuWidthStep = 56.0; diff --git a/sky/packages/sky/lib/src/widgets/progress_indicator.dart b/sky/packages/sky/lib/src/widgets/progress_indicator.dart index 3688e43d400..6a7b683411f 100644 --- a/sky/packages/sky/lib/src/widgets/progress_indicator.dart +++ b/sky/packages/sky/lib/src/widgets/progress_indicator.dart @@ -5,9 +5,7 @@ import 'dart:math' as math; import 'dart:sky' as sky; -import 'package:sky/animation/animation_performance.dart'; -import 'package:sky/animation/animated_value.dart'; -import 'package:sky/animation/curves.dart'; +import 'package:sky/animation.dart'; import 'package:sky/src/widgets/basic.dart'; import 'package:sky/src/widgets/theme.dart'; import 'package:sky/src/widgets/framework.dart'; diff --git a/sky/packages/sky/lib/src/widgets/scrollable.dart b/sky/packages/sky/lib/src/widgets/scrollable.dart index 6789534cd09..b803fa55eab 100644 --- a/sky/packages/sky/lib/src/widgets/scrollable.dart +++ b/sky/packages/sky/lib/src/widgets/scrollable.dart @@ -7,11 +7,7 @@ import 'dart:math' as math; import 'dart:sky' as sky; import 'package:newton/newton.dart'; -import 'package:sky/animation/animated_simulation.dart'; -import 'package:sky/animation/animated_value.dart'; -import 'package:sky/animation/animation_performance.dart'; -import 'package:sky/animation/curves.dart'; -import 'package:sky/animation/scroll_behavior.dart'; +import 'package:sky/animation.dart'; import 'package:sky/gestures/constants.dart'; import 'package:sky/src/rendering/box.dart'; import 'package:sky/src/rendering/viewport.dart'; diff --git a/sky/packages/sky/lib/src/widgets/snack_bar.dart b/sky/packages/sky/lib/src/widgets/snack_bar.dart index 2e5a521a94e..eae0ae8920f 100644 --- a/sky/packages/sky/lib/src/widgets/snack_bar.dart +++ b/sky/packages/sky/lib/src/widgets/snack_bar.dart @@ -3,9 +3,7 @@ // found in the LICENSE file. -import 'package:sky/animation/animated_value.dart'; -import 'package:sky/animation/animation_performance.dart'; -import 'package:sky/animation/curves.dart'; +import 'package:sky/animation.dart'; import 'package:sky/painting/text_style.dart'; import 'package:sky/theme/typography.dart' as typography; import 'package:sky/src/widgets/basic.dart'; @@ -16,8 +14,6 @@ import 'package:sky/src/widgets/material.dart'; import 'package:sky/src/widgets/theme.dart'; import 'package:sky/src/widgets/transitions.dart'; -export 'package:sky/animation/animation_performance.dart' show AnimationStatus; - typedef void SnackBarDismissedCallback(); const Duration _kSlideInDuration = const Duration(milliseconds: 200); diff --git a/sky/packages/sky/lib/src/widgets/tabs.dart b/sky/packages/sky/lib/src/widgets/tabs.dart index 804efe3ad75..3a3d8fce7d9 100644 --- a/sky/packages/sky/lib/src/widgets/tabs.dart +++ b/sky/packages/sky/lib/src/widgets/tabs.dart @@ -6,14 +6,9 @@ import 'dart:math' as math; import 'dart:sky' as sky; import 'package:newton/newton.dart'; -import 'package:sky/animation/animation_performance.dart'; -import 'package:sky/animation/animated_value.dart'; -import 'package:sky/animation/curves.dart'; -import 'package:sky/animation/scroll_behavior.dart'; +import 'package:sky/animation.dart'; import 'package:sky/painting/text_style.dart'; -import 'package:sky/src/rendering/box.dart'; -import 'package:sky/src/rendering/object.dart'; -import 'package:sky/src/rendering/viewport.dart'; +import 'package:sky/rendering.dart'; import 'package:sky/theme/colors.dart' as colors; import 'package:sky/theme/typography.dart' as typography; import 'package:sky/src/widgets/basic.dart'; diff --git a/sky/packages/sky/lib/src/widgets/transitions.dart b/sky/packages/sky/lib/src/widgets/transitions.dart index d94a6b721fa..35e431ef61f 100644 --- a/sky/packages/sky/lib/src/widgets/transitions.dart +++ b/sky/packages/sky/lib/src/widgets/transitions.dart @@ -2,14 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:sky/animation/animated_value.dart'; -import 'package:sky/animation/animation_performance.dart'; +import 'package:sky/animation.dart'; import 'package:sky/src/widgets/animated_component.dart'; import 'package:sky/src/widgets/basic.dart'; import 'package:sky/src/widgets/framework.dart'; import 'package:vector_math/vector_math.dart'; -export 'package:sky/animation/direction.dart' show Direction; +export 'package:sky/animation.dart' show Direction; // A helper class to anchor widgets to one another. Pass an instance of this to // a Transition, then use the build() method to create a child with the same diff --git a/sky/unit/test/base/scheduler_test.dart b/sky/unit/test/animation/scheduler_test.dart similarity index 95% rename from sky/unit/test/base/scheduler_test.dart rename to sky/unit/test/animation/scheduler_test.dart index a49379734ce..380de02bb3e 100644 --- a/sky/unit/test/base/scheduler_test.dart +++ b/sky/unit/test/animation/scheduler_test.dart @@ -1,4 +1,4 @@ -import 'package:sky/base/scheduler.dart' as scheduler; +import 'package:sky/animation.dart'; import 'package:test/test.dart'; void main() { diff --git a/sky/unit/test/widget/widget_tester.dart b/sky/unit/test/widget/widget_tester.dart index ae1da3f2d46..356f45b3074 100644 --- a/sky/unit/test/widget/widget_tester.dart +++ b/sky/unit/test/widget/widget_tester.dart @@ -1,8 +1,8 @@ import 'dart:sky' as sky; +import 'package:sky/animation.dart'; import 'package:sky/rendering.dart'; import 'package:sky/widgets.dart'; -import 'package:sky/base/scheduler.dart' as scheduler; import '../engine/mock_events.dart'; diff --git a/skysprites/lib/skysprites.dart b/skysprites/lib/skysprites.dart index 3bb57b1d2f4..9d300e7f5c7 100644 --- a/skysprites/lib/skysprites.dart +++ b/skysprites/lib/skysprites.dart @@ -11,8 +11,7 @@ import 'dart:typed_data'; import 'dart:sky'; import 'package:mojo/core.dart'; -import 'package:sky/animation/curves.dart'; -import 'package:sky/base/scheduler.dart' as scheduler; +import 'package:sky/animation.dart'; import 'package:sky/mojo/asset_bundle.dart'; import 'package:sky/mojo/shell.dart' as shell; import 'package:sky/painting/text_painter.dart';