Skip to content

Commit

Permalink
🎨
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Apr 2, 2024
1 parent cf40a99 commit f5b7def
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions app/src/mobile/util/touch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let xDiff: number;
let yDiff: number;
let time: number;
let firstDirection: "toLeft" | "toRight";
let firstXY: "x" | "y";
let lastClientX: number; // 和起始方向不一致时,记录最后一次的 clientX
let scrollBlock: boolean;

Expand Down Expand Up @@ -143,6 +144,7 @@ export const handleTouchStart = (event: TouchEvent) => {
xDiff = undefined;
yDiff = undefined;
lastClientX = undefined;
firstXY = undefined;
if (isIPhone() ||
(event.touches[0].clientX > 8 && event.touches[0].clientX < window.innerWidth - 8)) {
clientX = event.touches[0].clientX;
Expand All @@ -167,7 +169,7 @@ export const handleTouchMove = (event: TouchEvent) => {
(window.siyuan.mobile.editor && !window.siyuan.mobile.editor.protyle.toolbar.subElement.classList.contains("fn__none")) ||
hasClosestByClassName(target, "keyboard") ||
hasClosestByClassName(target, "viewer-container") ||
hasClosestByAttribute(target, "id", "commonMenu")
hasClosestByAttribute(target, "id", "commonMenu") || firstXY === "y"
) {
return;
}
Expand All @@ -181,14 +183,24 @@ export const handleTouchMove = (event: TouchEvent) => {

xDiff = Math.floor(clientX - event.touches[0].clientX);
yDiff = Math.floor(clientY - event.touches[0].clientY);
// 上下滚动防止左右滑动
if (Math.abs(xDiff) < Math.abs(yDiff) && sideMaskElement.classList.contains("fn__none")) {
clientX = null;
return;
}
if (!firstDirection) {
firstDirection = xDiff > 0 ? "toLeft" : "toRight";
}
// 上下滚动防止左右滑动
if (!firstXY) {
if (Math.abs(xDiff) > Math.abs(yDiff)) {
firstXY = "x"
} else {
firstXY = "y"
}
if (firstXY === "x") {
if ((hasClosestByAttribute(target, "id", "menu") && firstDirection === "toLeft") ||
(hasClosestByAttribute(target, "id", "sidebar") && firstDirection === "toRight")) {
firstXY = "y"
yDiff = undefined
}
}
}
if (previousClientX) {
if (firstDirection === "toRight") {
if (previousClientX > event.touches[0].clientX) {
Expand Down

0 comments on commit f5b7def

Please sign in to comment.