Skip to content

Commit

Permalink
fix: release unused loop animation
Browse files Browse the repository at this point in the history
  • Loading branch information
purpose committed Jan 7, 2025
1 parent f58258d commit 8952268
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion packages/vgrammar-core/src/graph/animation/animate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ export class Animate implements IAnimate {
);
});
if (needStopAnimation) {
// do not clear exit element in case it will animate
this.clearElementAnimation(element, false);
}
// clear animations for exit elements
else if (element.diffState === DiffState.exit) {
this.clearElementAnimation(element, false);
}
});
Expand Down Expand Up @@ -297,6 +300,16 @@ export class Animate implements IAnimate {
elementCount: animatedElements.length,
elementIndex: 0
};
// clear animator with same state
animatedElements.forEach(element => {
(this.animators.get(config.state) ?? [])
.filter(animator => animator.element === element && animator.animationOptions.id === config.id)
.forEach(animator => {
animator.stop(null, false);
this.handleAnimatorEnd(animator, false);
});
});
// run animator
animatedElements.forEach((element, index) => {
animationParameters.elementIndex = index;
// add animation parameter into parameters
Expand Down
2 changes: 1 addition & 1 deletion packages/vgrammar-core/src/graph/animation/animator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class Animator implements IAnimator {
return this;
}

stop(stopState: 'start' | 'end' = 'end', invokeCallback: boolean = true): this {
stop(stopState?: 'start' | 'end', invokeCallback: boolean = true): this {
// FIXME: wait for VRender to fix 'end' parameter
this.runnings.forEach(running => running.stop(stopState));
this.animationEnd(invokeCallback);
Expand Down

0 comments on commit 8952268

Please sign in to comment.