Skip to content

Commit

Permalink
fix: 移动端动态修改touchAction
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Ray committed Sep 25, 2024
1 parent c35bc03 commit f588a6b
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions packages/s2-core/src/facet/base-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down

0 comments on commit f588a6b

Please sign in to comment.