Skip to content
Merged
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
22 changes: 20 additions & 2 deletions packages/f-my/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Component({
this.setCanvasId();
},
didMount() {
this.destroyed = false;
if (!isAppX2CanvasEnv()) {
console.error('当前基础库版本过低,请升级基础库版本到 2.7.0 或以上。');
}
Expand All @@ -75,6 +76,12 @@ Component({
});
},
didUnmount() {
this.destroyed = true;
if (this.renderFrameId != null) {
this.nativeCanvas?.cancelAnimationFrame(this.renderFrameId);
this.renderFrameId = null;
}
Comment thread
huaxiabuluo marked this conversation as resolved.
this.nativeCanvas = null;
const { canvas } = this;
if (!canvas) return;
canvas.destroy();
Expand Down Expand Up @@ -105,6 +112,8 @@ Component({
}

const { width, height } = canvas;
if (this.destroyed) return;
this.nativeCanvas = canvas;
Comment thread
huaxiabuluo marked this conversation as resolved.

const pixelRatio = Math.ceil(getPixelRatio());

Expand All @@ -115,6 +124,9 @@ Component({
height: height * pixelRatio,
},
() => {
if (this.destroyed) {
return;
}
const context = canvas.getContext('2d');
const fCanvas = this.createCanvas({
width,
Expand All @@ -125,8 +137,14 @@ Component({
requestAnimationFrame: canvas.requestAnimationFrame.bind(canvas),
cancelAnimationFrame: canvas.cancelAnimationFrame.bind(canvas),
});
fCanvas.render().catch((error) => {
this.catchError(error);
this.renderFrameId = canvas.requestAnimationFrame(() => {
this.renderFrameId = null;
if (this.destroyed) {
return;
}
fCanvas.render().catch((error) => {
this.catchError(error);
});
});
},
);
Expand Down
Loading