@@ -8,7 +8,7 @@ import NextPrevItemButtons from 'features/gallery/components/NextPrevItemButtons
88import { selectShouldShowItemDetails , selectShouldShowProgressInViewer } from 'features/ui/store/uiSelectors' ;
99import type { AnimationProps } from 'framer-motion' ;
1010import { animate , AnimatePresence , motion , useMotionValue } from 'framer-motion' ;
11- import { memo , useCallback , useEffect , useRef , useState } from 'react' ;
11+ import { memo , useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
1212import { useImageDTO } from 'services/api/endpoints/images' ;
1313import type { ImageDTO } from 'services/api/types' ;
1414
@@ -28,7 +28,7 @@ export const CurrentImagePreview = memo(({ imageDTO }: { imageDTO: ImageDTO | nu
2828 const { onLoadImage, $progressEvent, $progressImage } = useImageViewerContext ( ) ;
2929 const progressEvent = useStore ( $progressEvent ) ;
3030 const progressImage = useStore ( $progressImage ) ;
31- const { onDragEnd, previousImageName, nextImageName } = useSwipeNavigation ( ) ;
31+ const { onDragEnd, previousImageName, nextImageName, canNavigatePrevious , canNavigateNext } = useSwipeNavigation ( ) ;
3232
3333 // Get adjacent images for swipe preview
3434 const previousImageDTO = useImageDTO ( previousImageName ) ;
@@ -79,6 +79,15 @@ export const CurrentImagePreview = memo(({ imageDTO }: { imageDTO: ImageDTO | nu
7979 [ onDragEnd , dragX ]
8080 ) ;
8181
82+ // Set drag constraints based on navigation boundaries
83+ // Prevent dragging past the first/last image
84+ const dragConstraints = useMemo ( ( ) => {
85+ return {
86+ left : canNavigateNext ? undefined : 0 , // Prevent dragging left if can't go to next
87+ right : canNavigatePrevious ? undefined : 0 , // Prevent dragging right if can't go to previous
88+ } ;
89+ } , [ canNavigatePrevious , canNavigateNext ] ) ;
90+
8291 return (
8392 < Box
8493 onMouseOver = { onMouseOver }
@@ -92,6 +101,7 @@ export const CurrentImagePreview = memo(({ imageDTO }: { imageDTO: ImageDTO | nu
92101 < Box
93102 as = { motion . div }
94103 drag = { imageDTO ? 'x' : false }
104+ dragConstraints = { dragConstraints }
95105 dragElastic = { 0.1 }
96106 dragMomentum = { false }
97107 onDragEnd = { handleDragEnd }
0 commit comments