Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix(gallery): require a sustained touch to drag, so touch can scroll the gallery

Lincoln Stein047d1c04eed2
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryThumbnail.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryThumbnail.tsx
index 4c5cd46b4f..fa0cea4466 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryThumbnail.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryThumbnail.tsx
@@ -18,9 +18,21 @@ const THUMBNAIL_HOVER_CSS = {
'&:hover .gallery-thumb-overlay, &:focus-within .gallery-thumb-overlay': { opacity: 1 },
} as const;
+/**
+ * The tile while its image is being dragged: desaturated, the visible half of
+ * the touch drag cue. The other half is the portalled drag preview, which
+ * carries the same desaturation so the change is visible under a finger that
+ * has not moved yet — the moment the drag hold completes.
+ */
+const THUMBNAIL_DRAG_CSS = {
+ ...THUMBNAIL_HOVER_CSS,
+ filter: 'saturate(0.4)',
+} as const;
+
const PREVIEW_IMAGE_STYLE = {
borderRadius: '0.375rem',
boxShadow: '0 8px 24px rgb(0 0 0 / 45%)',
+ filter: 'saturate(0.4)',
height: '100%',
objectFit: 'cover',
width: '100%',
@@ -161,14 +173,18 @@ const GalleryThumbnail = ({
borderColor={isSelected || isCompared ? 'accent.solid' : 'border.subtle'}
borderWidth="2px"
boxShadow={isCompared ? 'inset 0 0 0 1px {colors.accent.solid}' : undefined}
- css={THUMBNAIL_HOVER_CSS}
+ css={isDragging ? THUMBNAIL_DRAG_CSS : THUMBNAIL_HOVER_CSS}
minW="0"
opacity={isDragging ? 0.4 : undefined}
overflow="hidden"
position="relative"
role="listitem"
rounded="md"
- touchAction="none"
+ // Pan, don't drag: `none` would hand every touch-drag to the drag
+ // sensor before the browser could scroll the grid. Allowing the pan
+ // lets a moving finger scroll (the sensor detaches on touchcancel);
+ // dragging still works via the TouchSensor's hold delay.
+ touchAction="pan-y"
w="full"
onContextMenu={handleContextMenu}
>
diff --git a/invokeai/frontend/webv2/src/workbench/shell/WorkbenchShell.tsx b/invokeai/frontend/webv2/src/workbench/shell/WorkbenchShell.tsx
index e80c6c619a..961a5cecaa 100644
--- a/invokeai/frontend/webv2/src/workbench/shell/WorkbenchShell.tsx
+++ b/invokeai/frontend/webv2/src/workbench/shell/WorkbenchShell.tsx
@@ -3,7 +3,8 @@ import {
DndContext,
DragOverlay,
KeyboardSensor,
- PointerSensor,
+ MouseSensor,
+ TouchSensor,
useSensor,
useSensors,
type DragEndEvent,
@@ -60,6 +61,21 @@ const DND_MODIFIERS = [restrictToWindowEdges];
* scrolls from afar are prevented by the visibility check inside
* widgetCollisionDetection, not by shrinking zones.
*/
+/**
+ * Touch drags activate only after a sustained hold: a `PointerSensor` with a
+ * distance constraint claims a touch-drag at 6px, which makes every
+ * scrollable surface of draggable items (the gallery grid, the filmstrip)
+ * unscrollable by touch — the drag wins the gesture before the browser can
+ * pan. The `TouchSensor`'s delay constraint leaves the gesture alone while
+ * the hold is pending (its touchmove listener does not preventDefault until
+ * activated), so an early move pans the surface and the sensor detaches on
+ * `touchcancel`; a hold that outlasts the delay — moving no more than
+ * `TOUCH_DRAG_MOVE_TOLERANCE_PX` — activates the drag, which then owns the
+ * gesture. Mouse pointers keep the immediate distance activation.
+ */
+const TOUCH_DRAG_HOLD_DELAY_MS = 400;
+const TOUCH_DRAG_MOVE_TOLERANCE_PX = 10;
+
const DND_AUTO_SCROLL = { acceleration: 5 };
export const WorkbenchShell = () => {
@@ -71,7 +87,10 @@ export const WorkbenchShell = () => {
const rightRegion = useActiveProjectSelector((project) => project.widgetRegions.right);
const placementProject = useActiveProjectSelector(getWidgetPlacementProject, areWidgetPlacementProjectsEqual);
const sensors = useSensors(
- useSensor(PointerSensor, { activationConstraint: { distance: 6 } }),
+ useSensor(MouseSensor, { activationConstraint: { distance: 6 } }),
+ useSensor(TouchSensor, {
+ activationConstraint: { delay: TOUCH_DRAG_HOLD_DELAY_MS, tolerance: TOUCH_DRAG_MOVE_TOLERANCE_PX },
+ }),
useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates })
);
const [activeDrag, setActiveDrag] = useState<ActiveWidgetDrag | null>(null);
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFilmstrip.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFilmstrip.tsx
index 673395ffa0..7b9efcc7b1 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFilmstrip.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFilmstrip.tsx
@@ -91,7 +91,7 @@ const FilmstripThumb = ({
const itemRef = useMemo(() => toGalleryItemRef(item), [item]);
const dragData = useMemo(() => getGalleryItemDragData([itemRef]), [itemRef]);
const thumbnailSrc = item.thumbnailUrl || (item.kind === 'image' ? item.fullUrl : null);
- const { listeners, setNodeRef } = useDraggable({
+ const { isDragging, listeners, setNodeRef } = useDraggable({
data: dragData,
id: getGalleryItemDragId(itemRef, 'preview-filmstrip'),
});
@@ -119,12 +119,17 @@ const FilmstripThumb = ({
borderColor={isSelected ? 'accent.solid' : 'border.subtle'}
borderWidth="2px"
boxSize={size}
+ css={isDragging ? FILMSTRIP_THUMB_DRAG_CSS : undefined}
cursor="pointer"
flexShrink={0}
+ opacity={isDragging ? 0.4 : undefined}
overflow="hidden"
position="relative"
rounded="sm"
- touchAction="none"
+ // Pan, don't drag: the strip scrolls horizontally, so a moving finger
+ // must scroll it (the drag sensor detaches on touchcancel); dragging
+ // still works via the TouchSensor's hold delay.
+ touchAction="pan-x"
onClick={handleClick}
>
{thumbnailSrc ? (
@@ -138,6 +143,9 @@ const FilmstripThumb = ({
const FILMSTRIP_CONTAIN_CSS = { contain: 'inline-size' } as const;
+/** Same touch drag cue as the gallery grid: the source thumb desaturates while dragged. */
+const FILMSTRIP_THUMB_DRAG_CSS = { filter: 'saturate(0.4)' } as const;
+
// The thumb row centers itself with `h="full"`, which needs the content
// wrapper to actually span the viewport height rather than shrink to it.
const FILMSTRIP_CONTENT_PROPS = { h: 'full' } as const;