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.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(webv2): keep video preview swipes from snapping back on tablets
Lincoln Steine8600b93d609
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrame.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrame.tsxindex 6811fac440..b0b52af7cb 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrame.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrame.tsx@@ -835,8 +835,10 @@ const PreviewVideo = ({fill="flex"padding={padding}paddingBottom={paddingBottom}- // Horizontal travel is the swipe's; without a swipe the browser keeps its native gestures.- touchAction={swipeNavigation ? 'pan-y pinch-zoom' : undefined}+ // One-finger travel is the swipe's, exactly as on the image stage: any native pan left available here lets the+ // browser (or the player's own controls) claim a swipe midway and cancel it. Without a swipe the browser keeps+ // its native gestures.+ touchAction={swipeNavigation ? 'none' : undefined}onPointerDown={swipeNavigation ? handleStagePointerDown : undefined}><FittedFramediff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrameSwipe.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrameSwipe.browser.test.tsxindex 9674dd3805..5925b066e3 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrameSwipe.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrameSwipe.browser.test.tsx@@ -458,6 +458,25 @@ describe('PreviewFrame touch swipe', () => {expect(carousel.onNavigate).not.toHaveBeenCalled();});+ it('completes a video swipe that the browser or the player cancels midway', async () => {+ const carousel = await renderCarousel({ items: [makeItem('red'), makeItem('clip', 'video'), makeItem('blue')] });+ const video = carousel.media();+ const y = video.getBoundingClientRect().top + 20;+ const base = performance.now();++ // Nothing native is left to claim one-finger travel on the stage.+ expect(getComputedStyle(carousel.content().parentElement!).touchAction).toBe('none');++ await interact(() => touch('pointerdown', video, 200, y, base), 0);+ await interact(() => touch('pointermove', document, 170, y, base + 16), 0);+ await interact(() => touch('pointermove', document, 140, y, base + 32), 0);+ // The cancel arrives well after the last move; the flick it interrupted still counts.+ await interact(() => touch('pointercancel', document, 140, y, base + 400), 0);+ await vi.waitFor(() => expect(carousel.media().getAttribute('alt')).toBe('blue'));++ expect(carousel.onNavigate).toHaveBeenCalledExactlyOnceWith(1);+ });+it('swipes a video from its picture but leaves the native control bar alone', async () => {const carousel = await renderCarousel({ items: [makeItem('red'), makeItem('clip', 'video'), makeItem('blue')] });const video = carousel.media();diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/usePreviewSwipe.ts b/invokeai/frontend/webv2/src/workbench/widgets/preview/usePreviewSwipe.tsindex 5d27457211..bbb1589995 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/usePreviewSwipe.ts+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/usePreviewSwipe.ts@@ -295,19 +295,19 @@ export const usePreviewSwipe = ({return;}- if (gesture.phase !== 'tracking' || event.type === 'pointercancel') {- if (gesture.phase === 'tracking') {- settleTo(0, RETURN_MS);- } else {- restoreIfStranded();- }-+ if (gesture.phase !== 'tracking') {+ restoreIfStranded();return;}- release(gesture, event.timeStamp);+ // A cancel means the browser or a native control took the touch over mid-swipe, not that the user changed their+ // mind: decide it like a lift at the last move, so a swipe that was clearly going somewhere still gets there.+ release(+ gesture,+ event.type === 'pointercancel' ? (gesture.samples.at(-1)?.time ?? event.timeStamp) : event.timeStamp+ );},- [release, restoreIfStranded, settleTo]+ [release, restoreIfStranded]);// Document-level so a finger that leaves the stage still moves and releases the track.