Skip to content

Commit

Permalink
perf(web): update currentFrame precision for perf (#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
theashraf authored Jan 3, 2025
1 parent 49b1bf5 commit 8ef9888
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-hats-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lottiefiles/dotlottie-web': minor
---

perf(web): update currentFrame precision for perf
16 changes: 9 additions & 7 deletions packages/web/src/dotlottie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export class DotLottie {

this._eventManager.dispatch({
type: 'frame',
currentFrame: this._dotLottieCore.currentFrame(),
currentFrame: this.currentFrame,
});

this._render();
Expand Down Expand Up @@ -405,7 +405,9 @@ export class DotLottie {
}

public get currentFrame(): number {
return this._dotLottieCore?.currentFrame() ?? 0;
if (!this._dotLottieCore) return 0;

return Math.round(this._dotLottieCore.currentFrame() * 100) / 100;
}

public get loopCount(): number {
Expand Down Expand Up @@ -489,7 +491,7 @@ export class DotLottie {

this._eventManager.dispatch({
type: 'render',
currentFrame: this._dotLottieCore.currentFrame(),
currentFrame: this.currentFrame,
});

return true;
Expand All @@ -501,14 +503,14 @@ export class DotLottie {
private _draw(): void {
if (this._dotLottieCore === null || this._context === null || !this._dotLottieCore.isPlaying()) return;

const nextFrame = this._dotLottieCore.requestFrame();
const nextFrame = Math.round(this._dotLottieCore.requestFrame() * 100) / 100;

const updated = this._dotLottieCore.setFrame(nextFrame);

if (updated) {
this._eventManager.dispatch({
type: 'frame',
currentFrame: this._dotLottieCore.currentFrame(),
currentFrame: this.currentFrame,
});

const rendered = this._render();
Expand Down Expand Up @@ -573,7 +575,7 @@ export class DotLottie {
const ok = this._dotLottieCore.stop();

if (ok) {
this._eventManager.dispatch({ type: 'frame', currentFrame: this._dotLottieCore.currentFrame() });
this._eventManager.dispatch({ type: 'frame', currentFrame: this.currentFrame });

this._render();

Expand All @@ -589,7 +591,7 @@ export class DotLottie {
const ok = this._dotLottieCore.seek(frame);

if (ok) {
this._eventManager.dispatch({ type: 'frame', currentFrame: this._dotLottieCore.currentFrame() });
this._eventManager.dispatch({ type: 'frame', currentFrame: this.currentFrame });

this._render();
}
Expand Down

0 comments on commit 8ef9888

Please sign in to comment.