Skip to content

Commit 53ec42b

Browse files
committed
fix(阅读器): 添加调试日志并修复触摸事件处理
1 parent 2545cab commit 53ec42b

3 files changed

Lines changed: 33 additions & 11 deletions

File tree

packages/app-expo/assets/reader/reader.html

Lines changed: 10 additions & 10 deletions
Large diffs are not rendered by default.

packages/app-expo/src/screens/ReaderScreen.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,11 @@ export function ReaderScreen({ route, navigation }: Props) {
262262
setToc(items);
263263
},
264264
onSelection: (detail: SelectionEvent) => {
265+
console.log("[ReaderScreen] onSelection callback called:", detail.text);
265266
setSelection(detail);
266267
},
267268
onSelectionCleared: () => {
269+
console.log("[ReaderScreen] onSelectionCleared callback called");
268270
setSelection(null);
269271
},
270272
onTap: () => {
@@ -385,6 +387,7 @@ export function ReaderScreen({ route, navigation }: Props) {
385387

386388
// Lock navigation when selection is active
387389
useEffect(() => {
390+
console.log("[ReaderScreen] selection changed:", !!selection, selection?.text?.substring(0, 20));
388391
if (!webViewReady) return;
389392
bridge.setNavigationLocked(!!selection);
390393
}, [webViewReady, selection]);

packages/foliate-js/paginator.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,17 @@ export class Paginator extends HTMLElement {
827827
});
828828
}
829829
#onTouchStart(e) {
830+
// If navigation is locked (e.g., during text selection), don't track touch
831+
if (this.#navigationLocked) return;
832+
// Also check if there's an active selection in any iframe
833+
// This handles the case where user drags selection handles
834+
const contents = this.getContents?.() ?? [];
835+
for (const { doc } of contents) {
836+
const sel = doc?.getSelection?.();
837+
if (sel && !sel.isCollapsed && sel.toString().trim()) {
838+
return;
839+
}
840+
}
830841
const touch = e.changedTouches[0];
831842
this.#touchState = {
832843
x: touch?.screenX,
@@ -844,7 +855,15 @@ export class Paginator extends HTMLElement {
844855
}
845856
#onTouchMove(e) {
846857
const state = this.#touchState;
847-
if (this.#navigationLocked || state.pinched) return;
858+
if (this.#navigationLocked || state?.pinched) return;
859+
// Also check if there's an active selection (user might be dragging handles)
860+
const contents = this.getContents?.() ?? [];
861+
for (const { doc } of contents) {
862+
const sel = doc?.getSelection?.();
863+
if (sel && !sel.isCollapsed && sel.toString().trim()) {
864+
return;
865+
}
866+
}
848867
state.pinched = globalThis.visualViewport.scale > 1;
849868
if (this.scrolled || state.pinched) return;
850869
if (e.touches.length > 1) {

0 commit comments

Comments
 (0)