fix: refine touch handling in PhotoswipeReader to improve swipe detection and pinch gesture management
This commit is contained in:
@@ -154,20 +154,34 @@ export function PhotoswipeReader({ book, pages, onClose, nextBook }: BookReaderP
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
isPinchingRef.current = false;
|
// Un seul doigt - seulement si on n'était pas en train de pinch
|
||||||
touchStartXRef.current = e.touches[0].clientX;
|
// On réinitialise isPinchingRef seulement ici, quand on commence un nouveau geste à 1 doigt
|
||||||
touchStartYRef.current = e.touches[0].clientY;
|
if (e.touches.length === 1) {
|
||||||
|
isPinchingRef.current = false;
|
||||||
|
touchStartXRef.current = e.touches[0].clientX;
|
||||||
|
touchStartYRef.current = e.touches[0].clientY;
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleTouchMove = useCallback((e: TouchEvent) => {
|
||||||
|
// Détecter le pinch pendant le mouvement
|
||||||
|
if (e.touches.length > 1) {
|
||||||
|
isPinchingRef.current = true;
|
||||||
|
touchStartXRef.current = null;
|
||||||
|
touchStartYRef.current = null;
|
||||||
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleTouchEnd = useCallback((e: TouchEvent) => {
|
const handleTouchEnd = useCallback((e: TouchEvent) => {
|
||||||
// Ignorer si c'était un pinch
|
// Si on était en mode pinch, ne JAMAIS traiter le swipe
|
||||||
if (isPinchingRef.current) {
|
if (isPinchingRef.current) {
|
||||||
isPinchingRef.current = false;
|
|
||||||
touchStartXRef.current = null;
|
touchStartXRef.current = null;
|
||||||
touchStartYRef.current = null;
|
touchStartYRef.current = null;
|
||||||
|
// Ne PAS réinitialiser isPinchingRef ici, on le fera au prochain touchstart
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Vérifier qu'on a bien des coordonnées de départ
|
||||||
if (touchStartXRef.current === null || touchStartYRef.current === null) return;
|
if (touchStartXRef.current === null || touchStartYRef.current === null) return;
|
||||||
if (pswpRef.current) return; // Ne pas gérer si Photoswipe est ouvert
|
if (pswpRef.current) return; // Ne pas gérer si Photoswipe est ouvert
|
||||||
|
|
||||||
@@ -183,8 +197,8 @@ export function PhotoswipeReader({ book, pages, onClose, nextBook }: BookReaderP
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Seuil de 100px pour changer de page
|
// Seuil de 50px pour changer de page
|
||||||
if (Math.abs(deltaX) > 100) {
|
if (Math.abs(deltaX) > 50) {
|
||||||
if (deltaX > 0) {
|
if (deltaX > 0) {
|
||||||
// Swipe vers la droite
|
// Swipe vers la droite
|
||||||
if (isRTL) {
|
if (isRTL) {
|
||||||
@@ -231,14 +245,16 @@ export function PhotoswipeReader({ book, pages, onClose, nextBook }: BookReaderP
|
|||||||
|
|
||||||
window.addEventListener("keydown", handleKeyDown);
|
window.addEventListener("keydown", handleKeyDown);
|
||||||
window.addEventListener("touchstart", handleTouchStart);
|
window.addEventListener("touchstart", handleTouchStart);
|
||||||
|
window.addEventListener("touchmove", handleTouchMove);
|
||||||
window.addEventListener("touchend", handleTouchEnd);
|
window.addEventListener("touchend", handleTouchEnd);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener("keydown", handleKeyDown);
|
window.removeEventListener("keydown", handleKeyDown);
|
||||||
window.removeEventListener("touchstart", handleTouchStart);
|
window.removeEventListener("touchstart", handleTouchStart);
|
||||||
|
window.removeEventListener("touchmove", handleTouchMove);
|
||||||
window.removeEventListener("touchend", handleTouchEnd);
|
window.removeEventListener("touchend", handleTouchEnd);
|
||||||
};
|
};
|
||||||
}, [handleNextPage, handlePreviousPage, handleTouchStart, handleTouchEnd, onClose, isRTL, currentPage]);
|
}, [handleNextPage, handlePreviousPage, handleTouchStart, handleTouchMove, handleTouchEnd, onClose, isRTL, currentPage]);
|
||||||
|
|
||||||
// Cleanup - Sync final sans debounce
|
// Cleanup - Sync final sans debounce
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user