Skip to content

Commit

Permalink
fix: 将offscreenCanvas创建挪至初始化 (#318)
Browse files Browse the repository at this point in the history
Co-authored-by: xuying.xu <xuying.xu@alibaba-inc.com>
  • Loading branch information
tangying1027 and xuying.xu authored Mar 7, 2025
1 parent 16bef46 commit f4fcc19
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/f-my/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ class CanvasImageElement {
class CanvasElement {
constructor(
private canvasContext: IMiniProgramCanvasContext_v1,
private _addCallIdAction: () => void
private _addCallIdAction: () => void,
private offscreenCanvas = (my as any).createOffscreenCanvas
? (my as any).createOffscreenCanvas()
: { requestAnimationFrame: () => {} }
) {

}
Expand All @@ -205,10 +208,8 @@ class CanvasElement {
}
requestAnimationFrame(fn: any) {
const frameFn = bindDrawRunnable(fn, this.canvasContext,this._addCallIdAction);
const offscreenCanvas = (my as any).createOffscreenCanvas
? (my as any).createOffscreenCanvas()
: { requestAnimationFrame: () => {} };
return offscreenCanvas.requestAnimationFrame(() => {

return this.offscreenCanvas.requestAnimationFrame(() => {
frameFn(Date.now());
});
}
Expand Down

0 comments on commit f4fcc19

Please sign in to comment.