From 623e96e4c3455081473a68dacbdeed321a791562 Mon Sep 17 00:00:00 2001 From: Michiel van der Geest Date: Tue, 15 Oct 2024 14:50:54 +0200 Subject: [PATCH] Added onTick event to animations. --- src/core/animations/CoreAnimation.ts | 4 ++++ src/core/animations/CoreAnimationController.ts | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/src/core/animations/CoreAnimation.ts b/src/core/animations/CoreAnimation.ts index af78737d..72879711 100644 --- a/src/core/animations/CoreAnimation.ts +++ b/src/core/animations/CoreAnimation.ts @@ -326,6 +326,10 @@ export class CoreAnimation extends EventEmitter { } } + if (this.progress < 1) { + this.emit('tick', {}); + } + if (this.progress === 1) { this.emit('finished', {}); } diff --git a/src/core/animations/CoreAnimationController.ts b/src/core/animations/CoreAnimationController.ts index ff424a9e..187456b2 100644 --- a/src/core/animations/CoreAnimationController.ts +++ b/src/core/animations/CoreAnimationController.ts @@ -50,6 +50,7 @@ export class CoreAnimationController // Bind event handlers this.onAnimating = this.onAnimating.bind(this); this.onFinished = this.onFinished.bind(this); + this.onTick = this.onTick.bind(this); } start(): IAnimationController { @@ -93,6 +94,7 @@ export class CoreAnimationController // Hook up event listeners this.animation.once('finished', this.onFinished); this.animation.on('animating', this.onAnimating); + this.animation.on('tick', this.onTick); // Then register the animation this.manager.registerAnimation(this.animation); } @@ -103,6 +105,7 @@ export class CoreAnimationController // Then unhook event listeners this.animation.off('finished', this.onFinished); this.animation.off('animating', this.onAnimating); + this.animation.off('tick', this.onTick); } private makeStoppedPromise(): void { @@ -142,4 +145,8 @@ export class CoreAnimationController this.state = 'running'; this.emit('animating', this); } + + private onTick(this: CoreAnimationController): void { + this.emit('tick'); + } }