Skip to content

Commit

Permalink
feat: offscreenCanvas代替setTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
xuying.xu committed Feb 18, 2025
1 parent 75070c1 commit d1e6e3e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/f-my/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,13 @@ class CanvasElement {
return new CanvasImageElement(url, this.canvasContext, this._addCallIdAction);
}
requestAnimationFrame(fn: any) {
const frameFn = bindDrawRunnable(fn, this.canvasContext, this._addCallIdAction);
return setTimeout(function () {
const frameFn = bindDrawRunnable(fn, this.canvasContext,this._addCallIdAction);
const offscreenCanvas = (my as any).createOffscreenCanvas
? (my as any).createOffscreenCanvas()
: { requestAnimationFrame: () => {} };
return offscreenCanvas.requestAnimationFrame(() => {
frameFn(Date.now());
}, 16);
});
}
cancelAnimationFrame(tid: any) {
return clearTimeout(tid);
Expand Down

0 comments on commit d1e6e3e

Please sign in to comment.