Skip to content

Commit b4c6c5a

Browse files
Copilotlstein
andcommitted
Disable drag animation at image list boundaries
Co-authored-by: lstein <[email protected]>
1 parent 37d92e5 commit b4c6c5a

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

invokeai/frontend/web/src/features/gallery/components/ImageViewer/CurrentImagePreview.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import NextPrevItemButtons from 'features/gallery/components/NextPrevItemButtons
88
import { selectShouldShowItemDetails, selectShouldShowProgressInViewer } from 'features/ui/store/uiSelectors';
99
import type { AnimationProps } from 'framer-motion';
1010
import { 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';
1212
import { useImageDTO } from 'services/api/endpoints/images';
1313
import 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

Comments
 (0)