From f588a6bec7d1f3cb6e409d9e4efc81c201ffd19e Mon Sep 17 00:00:00 2001 From: M-Ray Date: Wed, 25 Sep 2024 10:13:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E5=8A=A8=E7=AB=AF=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E4=BF=AE=E6=94=B9touchAction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/s2-core/src/facet/base-facet.ts | 39 ++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/packages/s2-core/src/facet/base-facet.ts b/packages/s2-core/src/facet/base-facet.ts index 98be71a963..b7430d2981 100644 --- a/packages/s2-core/src/facet/base-facet.ts +++ b/packages/s2-core/src/facet/base-facet.ts @@ -1324,6 +1324,37 @@ export abstract class BaseFacet { } }; + private getTouchAction = (): string[] => { + const { scrollX, scrollY } = this.getScrollOffset(); + const touchActions = []; + + if (this.hRowScrollBar && scrollX === 0) { + touchActions.push('pan-left'); + } + + if (!this.hRowScrollBar) { + touchActions.push('pan-x'); + } + + if (scrollX === this.hScrollBar?.scrollTargetMaxOffset) { + touchActions.push('pan-right'); + } + + if (this.vScrollBar && scrollY === 0) { + touchActions.push('pan-up'); + } + + if (!this.vScrollBar) { + touchActions.push('pan-y'); + } + + if (scrollY === this.vScrollBar?.scrollTargetMaxOffset) { + touchActions.push('pan-down'); + } + + return touchActions; + }; + onWheel = (event: WheelEvent) => { const { interaction } = this.spreadsheet.options; let { deltaX, deltaY, offsetX, offsetY } = event; @@ -1341,6 +1372,14 @@ export abstract class BaseFacet { deltaY = 0; } + if (isMobile()) { + const touchActions = this.getTouchAction(); + const touchActionStr = touchActions.join(' '); + const canvas = this.spreadsheet.getCanvasElement(); + + canvas.style.touchAction = touchActionStr; + } + const [optimizedDeltaX, optimizedDeltaY] = optimizeScrollXY( deltaX, deltaY,