fix: review fullscreen and touch

This commit is contained in:
Julien Froidefond
2025-02-16 23:08:57 +01:00
parent 86529d4994
commit 54115ac9cc
3 changed files with 7 additions and 16 deletions

View File

@@ -142,23 +142,11 @@ export function BookReader({ book, pages, onClose }: BookReaderProps) {
// Effet pour gérer le fullscreen // Effet pour gérer le fullscreen
useEffect(() => { useEffect(() => {
const enterFullscreen = async () => {
try {
if (readerRef.current && !isFullscreen) {
await readerRef.current.requestFullscreen();
setIsFullscreen(true);
}
} catch (error) {
console.error("Erreur lors du passage en plein écran:", error);
}
};
const handleFullscreenChange = () => { const handleFullscreenChange = () => {
setIsFullscreen(!!document.fullscreenElement); setIsFullscreen(!!document.fullscreenElement);
}; };
document.addEventListener("fullscreenchange", handleFullscreenChange); document.addEventListener("fullscreenchange", handleFullscreenChange);
enterFullscreen();
return () => { return () => {
document.removeEventListener("fullscreenchange", handleFullscreenChange); document.removeEventListener("fullscreenchange", handleFullscreenChange);

View File

@@ -25,10 +25,10 @@ export const ControlButtons = ({
}: ControlButtonsProps) => { }: ControlButtonsProps) => {
return ( return (
<> <>
{/* Bouton mode double page */} {/* Boutons de contrôle */}
<div <div
className={cn( className={cn(
"absolute top-4 left-4 z-30 flex items-center gap-2 transition-all duration-300", "absolute top-4 left-1/2 -translate-x-1/2 z-30 flex items-center gap-2 transition-all duration-300",
showControls ? "opacity-100" : "opacity-0 pointer-events-none" showControls ? "opacity-100" : "opacity-0 pointer-events-none"
)} )}
> >

View File

@@ -20,6 +20,7 @@ export const usePageNavigation = ({
const [imageError, setImageError] = useState(false); const [imageError, setImageError] = useState(false);
const timeoutRef = useRef<NodeJS.Timeout | null>(null); const timeoutRef = useRef<NodeJS.Timeout | null>(null);
const touchStartXRef = useRef<number | null>(null); const touchStartXRef = useRef<number | null>(null);
const touchStartYRef = useRef<number | null>(null);
const currentPageRef = useRef(currentPage); const currentPageRef = useRef(currentPage);
useEffect(() => { useEffect(() => {
@@ -94,16 +95,17 @@ export const usePageNavigation = ({
const handleTouchStart = useCallback((event: TouchEvent) => { const handleTouchStart = useCallback((event: TouchEvent) => {
touchStartXRef.current = event.touches[0].clientX; touchStartXRef.current = event.touches[0].clientX;
touchStartYRef.current = event.touches[0].clientY;
}, []); }, []);
const handleTouchEnd = useCallback( const handleTouchEnd = useCallback(
(event: TouchEvent) => { (event: TouchEvent) => {
if (touchStartXRef.current === null) return; if (touchStartXRef.current === null || touchStartYRef.current === null) return;
const touchEndX = event.changedTouches[0].clientX; const touchEndX = event.changedTouches[0].clientX;
const touchEndY = event.changedTouches[0].clientY; const touchEndY = event.changedTouches[0].clientY;
const deltaX = touchEndX - touchStartXRef.current; const deltaX = touchEndX - touchStartXRef.current;
const deltaY = Math.abs(touchEndY - event.touches[0].clientY); const deltaY = Math.abs(touchEndY - touchStartYRef.current);
const minSwipeDistance = 50; const minSwipeDistance = 50;
if (deltaY > Math.abs(deltaX)) return; if (deltaY > Math.abs(deltaX)) return;
@@ -117,6 +119,7 @@ export const usePageNavigation = ({
} }
touchStartXRef.current = null; touchStartXRef.current = null;
touchStartYRef.current = null;
}, },
[handlePreviousPage, handleNextPage] [handlePreviousPage, handleNextPage]
); );