fix: ensure transitions properly cancel on completion ()

pull/9783/head
Dominic Gannaway 1 year ago committed by GitHub
parent ef158ff729
commit 25abca78b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: ensure transitions properly cancel on completion

@ -177,10 +177,13 @@ class TickAnimation {
} }
cancel() { cancel() {
const t = this.#reversed ? 1 : 0;
active_tick_animations.delete(this); active_tick_animations.delete(this);
const current = this.#current / this.#duration;
if (current > 0 && current < 1) {
const t = this.#reversed ? 1 : 0;
this.#tick_fn(t, 1 - t); this.#tick_fn(t, 1 - t);
} }
}
finish() { finish() {
active_tick_animations.delete(this); active_tick_animations.delete(this);
@ -322,7 +325,7 @@ function create_transition(dom, init, direction, effect) {
animation.onfinish = () => { animation.onfinish = () => {
const is_outro = curr_direction === 'out'; const is_outro = curr_direction === 'out';
/** @type {Animation | TickAnimation} */ (animation).pause(); /** @type {Animation | TickAnimation} */ (animation).cancel();
if (is_outro) { if (is_outro) {
run_all(subs); run_all(subs);
subs = []; subs = [];

@ -102,16 +102,18 @@ class Animation {
} }
finish() { finish() {
this.onfinish();
this.currentTime = this.#reversed ? 0 : this.#duration; this.currentTime = this.#reversed ? 0 : this.#duration;
if (this.#reversed) { if (this.#reversed) {
raf.animations.delete(this); raf.animations.delete(this);
} }
this.onfinish();
} }
cancel() { cancel() {
this.#paused = true;
if (this.currentTime > 0 && this.currentTime < this.#duration) {
this._applyKeyFrame(this.#reversed ? this.#keyframes.length - 1 : 0); this._applyKeyFrame(this.#reversed ? this.#keyframes.length - 1 : 0);
raf.animations.delete(this); }
} }
pause() { pause() {

Loading…
Cancel
Save