Skip to content

Commit

Permalink
fix(web): address canvas resizing issue in DotLottieWorker after tran…
Browse files Browse the repository at this point in the history
…sferControlToOffscreen() (#330)

* fix(web): address canvas resizing issue in DotLottieWorker after transferControlToOffscreen()
  • Loading branch information
theashraf authored Aug 20, 2024
1 parent d91ee4f commit 8e6f572
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-seahorses-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lottiefiles/dotlottie-web': patch
---

fix(web): address canvas resizing issue in DotLottieWorker after transferControlToOffscreen()
10 changes: 10 additions & 0 deletions apps/dotlottie-web-example/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ app.innerHTML = `
<button id="start_sm">Start State Machine</button>
<button id="end_sm">End State Machine</button>
</div>
<div>
<button id="resize" class="control-button">Resize</button>
</div>
</div>
</div>
`;
Expand Down Expand Up @@ -229,6 +233,8 @@ fetch(
const alignSelect = document.getElementById('align') as HTMLSelectElement;
const stateMachinesSelect = document.getElementById('states') as HTMLSelectElement;

const resizeButton = document.getElementById('resize') as HTMLButtonElement;

let animationIdx = 0;

nextAnimationButton.addEventListener('click', () => {
Expand All @@ -247,6 +253,10 @@ fetch(
}
});

resizeButton.addEventListener('click', () => {
dotLottie.resize();
});

freezeButton.addEventListener('click', () => {
dotLottie.freeze();
});
Expand Down
3 changes: 0 additions & 3 deletions packages/web/src/worker/dotlottie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,6 @@ export class DotLottieWorker {

const { height, width } = getCanvasSize(this._canvas);

this._canvas.width = width;
this._canvas.height = height;

await this._sendMessage('resize', { height, instanceId: this._id, width });
await this._updateDotLottieInstanceState();
}
Expand Down

0 comments on commit 8e6f572

Please sign in to comment.