Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(web): update nextFrame precision for perf #440

Merged
merged 1 commit into from
Jan 3, 2025
Merged
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
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
Loading