Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/core/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const defaults = {
onLoop: noop,
onPause: noop,
onComplete: noop,
onStop: noop,
onRender: noop,
}

Expand Down
4 changes: 4 additions & 0 deletions src/core/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ export const render = (tickable, time, muteCallbacks, internalRender, tickMode)
(isRunningBackwards && tickableAbsoluteTime <= minValue && completed)
)) {
tickable.onComplete(/** @type {CallbackArgument} */(tickable));
tickable.onStop(/** @type {CallbackArgument} */(tickable));
tickable.completed = !isRunningBackwards;
}
// If currentTime is both above 0 and at least equals to duration, handles normal onComplete or infinite loops
Expand All @@ -314,6 +315,7 @@ export const render = (tickable, time, muteCallbacks, internalRender, tickMode)
tickable.completed = true;
if (!muteCallbacks && !(parent && (isRunningBackwards || !parent.began))) {
tickable.onComplete(/** @type {CallbackArgument} */(tickable));
tickable.onStop(/** @type {CallbackArgument} */(tickable));
tickable._resolve(/** @type {CallbackArgument} */(tickable));
}
}
Expand Down Expand Up @@ -366,6 +368,7 @@ export const tick = (tickable, time, muteCallbacks, internalRender, tickMode) =>
// Triggers the onComplete callback on reverse for children on the edges of the timeline
if (!muteCallbacks && childDuration <= minValue && (!childStartTime || childEndTime === tlIterationDuration)) {
child.onComplete(child);
child.onStop(child);
}
}
});
Expand All @@ -390,6 +393,7 @@ export const tick = (tickable, time, muteCallbacks, internalRender, tickMode) =>
tl.completed = true;
if (!muteCallbacks) {
tl.onComplete(/** @type {CallbackArgument} */(tl));
tl.onStop(/** @type {CallbackArgument} */(tl));
tl._resolve(/** @type {CallbackArgument} */(tl));
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/timer/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export class Timer extends Clock {
onComplete,
onLoop,
onPause,
onStop,
onBegin,
onBeforeUpdate,
onUpdate,
Expand Down Expand Up @@ -182,6 +183,8 @@ export class Timer extends Clock {
this.onPause = onPause || timerDefaults.onPause;
/** @type {Callback<this>} */
this.onComplete = onComplete || timerDefaults.onComplete;
/** @type {Callback<this>} */
this.onStop = onStop || timerDefaults.onStop;
/** @type {Number} */
this.iterationDuration = timerDuration; // Duration of one loop
/** @type {Number} */
Expand Down Expand Up @@ -445,6 +448,8 @@ export class Timer extends Clock {
forEachChildren(this, removeTweenSliblings);
}
this._cancelled = 1;
// Call onStop callback when animation is cancelled/interrupted
this.onStop(this);
// Pausing the timer removes it from the engine
return this.pause();
}
Expand Down
2 changes: 2 additions & 0 deletions src/types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export {}
* @property {Callback<Tickable>} [onLoop]
* @property {Callback<Tickable>} [onPause]
* @property {Callback<Tickable>} [onComplete]
* @property {Callback<Tickable>} [onStop]
* @property {Callback<Renderable>} [onRender]
*/

Expand Down Expand Up @@ -167,6 +168,7 @@ export {}
* @property {Callback<T>} [onLoop]
* @property {Callback<T>} [onPause]
* @property {Callback<T>} [onComplete]
* @property {Callback<T>} [onStop]
*/

/**
Expand Down