diff --git a/packages/s2-core/src/facet/base-facet.ts b/packages/s2-core/src/facet/base-facet.ts index 440fffcd59..b48ae22f58 100644 --- a/packages/s2-core/src/facet/base-facet.ts +++ b/packages/s2-core/src/facet/base-facet.ts @@ -1425,6 +1425,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; @@ -1442,6 +1473,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,