From f901d2ee59c0847ac5a31db4c19c249b63038c29 Mon Sep 17 00:00:00 2001 From: linwrui Date: Fri, 8 Nov 2024 11:00:50 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20hdAdapter=20=E9=94=80=E6=AF=81?= =?UTF-8?q?=E5=90=8E=E6=B7=BB=E5=8A=A0=20destroyed=20=E6=A0=87=E8=AF=86?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8D=E5=9B=A0=20resize=20=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E5=BC=82=E6=AD=A5=E5=A4=84=E7=90=86=E5=99=A8?= =?UTF-8?q?=E5=9C=A8=E6=89=A7=E8=A1=8C=E6=97=B6=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/s2-core/src/ui/hd-adapter/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/s2-core/src/ui/hd-adapter/index.ts b/packages/s2-core/src/ui/hd-adapter/index.ts index 9d326b9bbb..be9a8adc12 100644 --- a/packages/s2-core/src/ui/hd-adapter/index.ts +++ b/packages/s2-core/src/ui/hd-adapter/index.ts @@ -21,6 +21,8 @@ export class HdAdapter { private zoomOffsetLeft: number | undefined; + private destroyed: boolean = false + constructor(spreadsheet: SpreadSheet) { this.spreadsheet = spreadsheet; } @@ -31,6 +33,7 @@ export class HdAdapter { }; public destroy = () => { + this.destroyed = true this.removeDevicePixelRatioListener(); this.removeDeviceZoomListener(); }; @@ -118,7 +121,7 @@ export class HdAdapter { const currentRatio = Math.ceil(ratio); const lastRatio = container.getConfig().devicePixelRatio ?? 1; - if (lastRatio === currentRatio || !canvas) { + if (this.destroyed || lastRatio === currentRatio || !canvas) { return; } @@ -130,6 +133,9 @@ export class HdAdapter { }; private renderByZoomScale = debounce(async (event: Event) => { + if (this.destroyed) { + return + } const target = event.target as VisualViewport; const ratio = Math.ceil(target?.scale); From ecb82e83eecdf94055bb4c2e4f0dac59aab125d6 Mon Sep 17 00:00:00 2001 From: linwrui Date: Fri, 8 Nov 2024 14:29:02 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20renderByDevicePixelRatio=20=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E4=B8=AD=E7=9A=84=E9=94=80=E6=AF=81=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E6=8F=90=E5=89=8D=E5=88=B0=20L#116=20?= =?UTF-8?q?=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/s2-core/src/ui/hd-adapter/index.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/s2-core/src/ui/hd-adapter/index.ts b/packages/s2-core/src/ui/hd-adapter/index.ts index be9a8adc12..438e438cff 100644 --- a/packages/s2-core/src/ui/hd-adapter/index.ts +++ b/packages/s2-core/src/ui/hd-adapter/index.ts @@ -21,7 +21,7 @@ export class HdAdapter { private zoomOffsetLeft: number | undefined; - private destroyed: boolean = false + private destroyed: boolean = false; constructor(spreadsheet: SpreadSheet) { this.spreadsheet = spreadsheet; @@ -33,7 +33,7 @@ export class HdAdapter { }; public destroy = () => { - this.destroyed = true + this.destroyed = true; this.removeDevicePixelRatioListener(); this.removeDeviceZoomListener(); }; @@ -113,6 +113,10 @@ export class HdAdapter { private renderByDevicePixelRatio = async ( ratio = window.devicePixelRatio, ) => { + if (this.destroyed) { + return; + } + const { container, options: { width, height }, @@ -121,7 +125,7 @@ export class HdAdapter { const currentRatio = Math.ceil(ratio); const lastRatio = container.getConfig().devicePixelRatio ?? 1; - if (this.destroyed || lastRatio === currentRatio || !canvas) { + if (lastRatio === currentRatio || !canvas) { return; } @@ -134,8 +138,9 @@ export class HdAdapter { private renderByZoomScale = debounce(async (event: Event) => { if (this.destroyed) { - return + return; } + const target = event.target as VisualViewport; const ratio = Math.ceil(target?.scale); From da484bb7ed86d8a5929a2c6582200333abb25b3d Mon Sep 17 00:00:00 2001 From: linwrui Date: Fri, 8 Nov 2024 14:50:56 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20spreadsheet.destroyed=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=20public?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/s2-core/src/sheet-type/spread-sheet.ts | 2 +- packages/s2-core/src/ui/hd-adapter/index.ts | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/s2-core/src/sheet-type/spread-sheet.ts b/packages/s2-core/src/sheet-type/spread-sheet.ts index cecf97dd5e..b1991c8938 100644 --- a/packages/s2-core/src/sheet-type/spread-sheet.ts +++ b/packages/s2-core/src/sheet-type/spread-sheet.ts @@ -98,7 +98,7 @@ export abstract class SpreadSheet extends EE { /** * 表格是否已销毁 */ - private destroyed = false; + public destroyed = false; protected abstract bindEvents(): void; diff --git a/packages/s2-core/src/ui/hd-adapter/index.ts b/packages/s2-core/src/ui/hd-adapter/index.ts index 438e438cff..9bb2dac7b1 100644 --- a/packages/s2-core/src/ui/hd-adapter/index.ts +++ b/packages/s2-core/src/ui/hd-adapter/index.ts @@ -21,8 +21,6 @@ export class HdAdapter { private zoomOffsetLeft: number | undefined; - private destroyed: boolean = false; - constructor(spreadsheet: SpreadSheet) { this.spreadsheet = spreadsheet; } @@ -33,7 +31,6 @@ export class HdAdapter { }; public destroy = () => { - this.destroyed = true; this.removeDevicePixelRatioListener(); this.removeDeviceZoomListener(); }; @@ -113,7 +110,7 @@ export class HdAdapter { private renderByDevicePixelRatio = async ( ratio = window.devicePixelRatio, ) => { - if (this.destroyed) { + if (this.spreadsheet.destroyed) { return; } @@ -137,7 +134,7 @@ export class HdAdapter { }; private renderByZoomScale = debounce(async (event: Event) => { - if (this.destroyed) { + if (this.spreadsheet.destroyed) { return; }