Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 移动端动态修改touchAction #2908

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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;
Expand All @@ -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,
Expand Down
Loading