diff --git a/packages/s2-core/src/facet/base-facet.ts b/packages/s2-core/src/facet/base-facet.ts index e1477dd87d..f9724e45db 100644 --- a/packages/s2-core/src/facet/base-facet.ts +++ b/packages/s2-core/src/facet/base-facet.ts @@ -1331,6 +1331,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; @@ -1348,6 +1379,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,