Skip to content

Commit

Permalink
changed setCallback() to receive a TweenCallbackHandler instead of a …
Browse files Browse the repository at this point in the history
…TweenCallback instance
  • Loading branch information
xaguzman committed Aug 6, 2014
1 parent 83c7586 commit f8a587f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
13 changes: 6 additions & 7 deletions lib/src/base_tween.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ abstract class BaseTween<T> {
bool _isPaused; // true if pause() was called

// Misc
TweenCallback _callback;
TweenCallbackHandler _callback;
int _callbackTriggers;
Object _userData;

Expand Down Expand Up @@ -141,16 +141,15 @@ abstract class BaseTween<T> {
}

/**
* Sets the [TweenCallback]. By default, it will be fired at the completion of the tween or timeline (event COMPLETE).
* Sets the [TweenCallbackHandler]. By default, it will be fired at the completion of the tween or timeline (event COMPLETE).
* If you want to change this behavior and add more triggers, use the [setCallbackTriggers] method.
*/
void setCallback(TweenCallback callback) {
void setCallback(TweenCallbackHandler callback) {
_callback = callback;
}

/**
* Changes the triggers of the callback. The available triggers, listed as
* members of the [TweenCallback] interface, are:
* Changes the triggers of the callback. The available triggers are:
*
* * [TweenCallback.BEGIN]: right after the delay (if any)
* * [TweenCallback.START]: at each iteration beginning
Expand Down Expand Up @@ -288,7 +287,7 @@ abstract class BaseTween<T> {
}

void callCallback(int type) {
if (_callback != null && (_callbackTriggers & type) > 0) _callback.onEvent(type, this);
if (_callback != null && (_callbackTriggers & type) > 0) _callback(type, this);
}

bool isReverse(int step) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/timeline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class Timeline extends BaseTween<Timeline> {
}

if (!isIterationStep && step < lastStep) {
assert (delta <= 0);
assert (delta <= 0);
num dt = isReverse(lastStep) ? -delta-1 : delta+1;
_children.reversed.forEach( (BaseTween tween) => tween.update(dt));
return;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/tween.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ class Tween extends BaseTween<Tween> {
*
* see [TweenCallback]
*
* [callback] The callback that will be triggered on each iteration start.
* [callback] the function that will be triggered on each iteration start.
*
* Returns The generated Tween.
*/
static Tween callBack(TweenCallback callback) {
static Tween callBack(TweenCallbackHandler callback) {
Tween tween = _pool.get()
.._setup(null, -1, 0)
..setCallback(callback)
Expand Down
8 changes: 4 additions & 4 deletions lib/src/tween_callback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ part of tweenengine;
* Xavier Guzman (dart port)
*/
class TweenCallback {

TweenCallback._();

static const int BEGIN = 0x01;
static const int START = 0x02;
static const int END = 0x04;
Expand All @@ -38,10 +41,7 @@ class TweenCallback {
static const int ANY_FORWARD = 0x0F;
static const int ANY_BACKWARD = 0xF0;
static const int ANY = 0xFF;

///The handler to execute when an event occur in the [Tween] or [Timeline]
CallbackHandler onEvent;
}

///a handler which can take actions when any event occurs on a tween
typedef void CallbackHandler(int type, BaseTween source);
typedef void TweenCallbackHandler(int type, BaseTween source);
7 changes: 3 additions & 4 deletions test/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ main() {
Function expectOnStart = expectAsync1((tween){});
Function expectOnEnd = expectAsync1((tween){});

TweenCallback myCallback = new TweenCallback();
myCallback.onEvent = (type, tween) {
TweenCallbackHandler myCallback = (type, tween) {
switch(type) {
case TweenCallback.BEGIN:
expectOnBegin(tween);
Expand Down Expand Up @@ -159,8 +158,8 @@ main() {
Function expectOnStart = expectAsync1((tween){});
Function expectOnEnd = expectAsync1((tween){});

TweenCallback myCallback = new TweenCallback();
myCallback.onEvent = (type, tween) {

TweenCallbackHandler myCallback = (type, tween) {
switch(type) {
case TweenCallback.BEGIN:
expectOnBegin(tween);
Expand Down

0 comments on commit f8a587f

Please sign in to comment.