Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Keep the mobile inbox open while scrolling

Daniel9884c69a7298
diff --git a/app/src/layout/dock/Inbox.ts b/app/src/layout/dock/Inbox.ts
index 989d85ea95..457a756687 100644
--- a/app/src/layout/dock/Inbox.ts
+++ b/app/src/layout/dock/Inbox.ts
@@ -48,8 +48,8 @@ export class Inbox extends Model {
<div class="fn__loading fn__none">
<img width="64px" src="/stage/loading-pure.svg"></div>
</div>
-<div class="fn__flex-1 fn__none inboxDetails fn__flex-column" style="min-height: auto;background-color: var(--b3-theme-background)"></div>
-<div class="fn__flex-1"></div>`;
+<div class="fn__flex-1 fn__none inboxDetails fn__flex-column" data-prevent-swipe style="min-height: auto;background-color: var(--b3-theme-background)"></div>
+<div class="fn__flex-1" data-prevent-swipe></div>`;
/// #else
this.element.classList.add("fn__flex-column", "file-tree", "sy__inbox", "dockPanel");
this.element.innerHTML = `<div class="block__icons">
diff --git a/app/src/mobile/util/touch.ts b/app/src/mobile/util/touch.ts
index 3eabe56ba8..c4d1993e34 100644
--- a/app/src/mobile/util/touch.ts
+++ b/app/src/mobile/util/touch.ts
@@ -15,6 +15,7 @@ import {Constants} from "../../constants";
import {getEmbedChildOperationContext} from "../../protyle/wysiwyg/getBlock";
import {backModel} from "../menu/model";
import {hasVisibleSelectionText, shouldRestoreLongPressSelection} from "./touchSelection";
+import {getTouchAxis} from "./touchGesture";
let clientX: number;
let clientY: number;
@@ -197,6 +198,9 @@ export const handleTouchEnd = (event: TouchEvent) => {
clientX = null;
// 有些事件不经过 touchmove
+ if (!firstXY) {
+ return;
+ }
const isXScroll = Math.abs(xDiff) > Math.abs(yDiff);
const modelElement = hasClosestByAttribute(target, "id", "model", true);
if (modelElement) {
@@ -296,6 +300,12 @@ export const handleTouchStart = (event: TouchEvent) => {
activeBlur();
return;
}
+ // 可滚动面板内容优先处理原生滚动,避免斜向滑动触发侧栏关闭
+ if (hasClosestByAttribute(target, "data-prevent-swipe", null, true)) {
+ clientX = null;
+ clientY = null;
+ return;
+ }
// 存在其他拖拽元素时
const otherTouchElement = hasClosestByClassName(target, "b3-chip");
if ((otherTouchElement && otherTouchElement.parentElement.classList.contains("b3-chips__doctag")) ||
@@ -319,6 +329,7 @@ export const handleTouchStart = (event: TouchEvent) => {
yDiff = undefined;
lastClientX = undefined;
firstXY = undefined;
+ previousClientX = undefined;
if (isIPhone() ||
(event.touches[0].clientX > 8 && event.touches[0].clientX < window.innerWidth - 8)) {
clientX = event.touches[0].clientX;
@@ -421,16 +432,13 @@ export const handleTouchMove = (event: TouchEvent) => {
xDiff = Math.floor(clientX - event.touches[0].clientX);
yDiff = Math.floor(clientY - event.touches[0].clientY);
- if (!firstDirection) {
- firstDirection = xDiff > 0 ? "toLeft" : "toRight";
- }
// 上下滚动防止左右滑动
if (!firstXY) {
- if (Math.abs(xDiff) > Math.abs(yDiff)) {
- firstXY = "x";
- } else {
- firstXY = "y";
+ firstXY = getTouchAxis(xDiff, yDiff, Constants.SIZE_DRAG_THRESHOLD);
+ if (!firstXY) {
+ return;
}
+ firstDirection = xDiff > 0 ? "toLeft" : "toRight";
if (firstXY === "x") {
if ((hasClosestByAttribute(target, "id", "menu") && firstDirection === "toLeft") ||
(hasClosestByAttribute(target, "id", "sidebar") && firstDirection === "toRight")) {
diff --git a/app/src/mobile/util/touchGesture.test.ts b/app/src/mobile/util/touchGesture.test.ts
new file mode 100644
index 0000000000..a6652f46a9
--- /dev/null
+++ b/app/src/mobile/util/touchGesture.test.ts
@@ -0,0 +1,15 @@
+import {describe, it} from "node:test";
+import * as assert from "node:assert/strict";
+import {getTouchAxis} from "./touchGesture";
+
+describe("mobile touch gesture", () => {
+ it("waits for the drag threshold before locking the gesture axis", () => {
+ assert.equal(getTouchAxis(1, 0, 5), undefined);
+ assert.equal(getTouchAxis(1, 12, 5), "y");
+ });
+
+ it("locks gestures to their dominant axis", () => {
+ assert.equal(getTouchAxis(12, 4, 5), "x");
+ assert.equal(getTouchAxis(4, 12, 5), "y");
+ });
+});
diff --git a/app/src/mobile/util/touchGesture.ts b/app/src/mobile/util/touchGesture.ts
new file mode 100644
index 0000000000..3a0e605e3e
--- /dev/null
+++ b/app/src/mobile/util/touchGesture.ts
@@ -0,0 +1,8 @@
+export type TouchAxis = "x" | "y";
+
+export const getTouchAxis = (xDiff: number, yDiff: number, threshold: number): TouchAxis | undefined => {
+ if (Math.max(Math.abs(xDiff), Math.abs(yDiff)) < threshold) {
+ return;
+ }
+ return Math.abs(xDiff) > Math.abs(yDiff) ? "x" : "y";
+};