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): hold the touch pan off from arming, not just mid-drag

Lincoln Stein833010c4ff2e
diff --git a/invokeai/frontend/webv2/src/workbench/shell/holdToDragSensor.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/shell/holdToDragSensor.browser.test.tsx
index 479e0bb6a0..5ab748b982 100644
--- a/invokeai/frontend/webv2/src/workbench/shell/holdToDragSensor.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/shell/holdToDragSensor.browser.test.tsx
@@ -164,6 +164,42 @@ describe('HoldToDragSensor touch gate', () => {
expect(events.onDragEnd).toHaveBeenCalledTimes(1);
});
+ it('holds the browser pan off from arming onward, but not during the hold', async () => {
+ // The browser's own pan threshold can be tighter than the move tolerance
+ // (Android Chrome starts scrolling around 8px), so from arming onward the
+ // sensor must keep the pan from starting at all; during the hold the pan
+ // must stay available for the native scroll. The handler only reads
+ // `cancelable` and calls `preventDefault()`, so a plain cancelable event
+ // exercises the same path a real TouchEvent takes.
+ const { events, tile } = await renderHarness();
+
+ const touchMove = () => {
+ const event = new Event('touchmove', { bubbles: true, cancelable: true });
+ document.dispatchEvent(event);
+ return event;
+ };
+
+ await interact(() => pointer('pointerdown', tile(), 150, 150));
+
+ // Waiting: the browser must stay free to pan (an early move is a scroll).
+ expect(touchMove().defaultPrevented).toBe(false);
+
+ await wait(HOLD_ELAPSED_MS);
+ expect(tile().getAttribute('data-drag-armed')).toBe('true');
+
+ // Armed: the pan is held off so the scroll-slop cannot steal the drag.
+ expect(touchMove().defaultPrevented).toBe(true);
+
+ await interact(() => pointer('pointermove', document, 170, 150));
+ expect(events.onDragStart).toHaveBeenCalledTimes(1);
+
+ // Active: still held off, as before.
+ expect(touchMove().defaultPrevented).toBe(true);
+
+ // End the gesture so the sensor cannot leak into the next test in this page.
+ await interact(() => pointer('pointerup', document, 170, 150));
+ });
+
it('treats a motionless armed hold that lifts as an ordinary tap', async () => {
// The stock TouchSensor delay constraint activates on the timer alone, so a
// deliberate slow tap selected nothing and the trailing click was swallowed.
diff --git a/invokeai/frontend/webv2/src/workbench/shell/holdToDragSensor.ts b/invokeai/frontend/webv2/src/workbench/shell/holdToDragSensor.ts
index b4d46a2c6a..3420658d54 100644
--- a/invokeai/frontend/webv2/src/workbench/shell/holdToDragSensor.ts
+++ b/invokeai/frontend/webv2/src/workbench/shell/holdToDragSensor.ts
@@ -30,9 +30,12 @@ import { MouseSensor, type Activator, type SensorOptions, type SensorProps } fro
* pen), so a hold gate would hand the armed gesture to the browser's pan
* claim unpredictably.
*
- * Once the drag is active, the sensor holds the browser's pan off with a
- * document-level non-passive `touchmove` listener — pointer events cannot
- * `preventDefault` a pan — so the gesture cannot be stolen mid-drag.
+ * From the moment the hold arms the gate, the sensor holds the browser's pan
+ * off with a document-level non-passive `touchmove` listener — pointer events
+ * cannot `preventDefault` a pan, and the browser's own pan threshold can be
+ * tighter than the move tolerance (Android Chrome starts scrolling around
+ * 8px) — so an armed drag cannot be stolen by the native scroll before it
+ * activates, nor mid-drag afterwards.
*
* Every path through the state machine ends the gesture explicitly
* (`onEnd`/`onCancel`), which is what clears dnd-kit's activation guard; a
@@ -264,9 +267,12 @@ export class HoldToDragSensor {
};
private readonly handleTouchMove = (event: TouchEvent) => {
- // While the drag is live, hold the browser's pan off: pointer events cannot
- // preventDefault a pan, so this is the only thing keeping the gesture.
- if (this.gate === 'active' && event.cancelable) {
+ // From arming onward, hold the browser's pan off: pointer events cannot
+ // preventDefault a pan, and the browser's own pan threshold can be tighter
+ // than the move tolerance (Android Chrome starts scrolling around 8px), so
+ // an armed drag would otherwise be lost to the native scroll the instant
+ // the finger moves.
+ if ((this.gate === 'armed' || this.gate === 'active') && event.cancelable) {
event.preventDefault();
}
};