The best way to control Claude Code, Codex and more from any computer or phone
fix(mobile): retain inline image zoom on iOS (#33852)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Alex Southwell committed
Nov 13, 2026 at 11:48 UTC
0465d4a87d0d1571f45c2101f383471325cc29bf
5 files changed
+450
-72
apps/mobile/src/features/threads/ThreadFeed.tsx
+43
-38
@@ -277,6 +277,7 @@ import {
277
ThreadMarkdownImageUnavailable,
278
ThreadMarkdownImageView,
279
} from "./ThreadMarkdownImage";
280
+import { ZoomableImagePressable } from "./ZoomableImagePressable";
281
import { openSettings } from "../settings/settings-navigation";
282
import { useSelectWorkspaceDetail } from "../layout/workspace/useSelectWorkspaceDetail";
283
import { formatMessageTimestamp } from "./messageTimestamp";
@@ -471,6 +472,8 @@ function MessageImage(props: {
472
readonly className: string;
473
readonly maxWidth?: number;
474
readonly height?: number;
475
+ readonly accessibilityLabel: string;
476
+ readonly onPress: () => void;
477
readonly onLoad?: () => void;
478
readonly onError?: () => void;
479
}) {
@@ -485,11 +488,13 @@ function MessageImage(props: {
488
})
489
: null;
490
return (
488
- <ExpoImage
489
- source={props.source}
490
- cachePolicy="memory-disk"
491
+ <ZoomableImagePressable
492
+ accessibilityRole="imagebutton"
493
+ accessibilityLabel={props.accessibilityLabel}
494
+ onPress={props.onPress}
495
style={[
496
imageStyle,
497
+ { overflow: "hidden" },
498
props.maxWidth !== undefined
499
? (displaySize ?? {
500
width: Math.min(props.maxWidth, MARKDOWN_IMAGE_MAX_WIDTH),
@@ -499,13 +504,19 @@ function MessageImage(props: {
504
? { height: props.height }
505
: undefined,
506
]}
502
- contentFit={props.maxWidth === undefined ? "cover" : "contain"}
503
- onLoad={(event) => {
504
- if (props.maxWidth !== undefined) setSize(event.source);
505
- props.onLoad?.();
506
- }}
507
- onError={props.onError}
508
- />
507
+ >
508
+ <ExpoImage
509
+ source={props.source}
510
+ cachePolicy="memory-disk"
511
+ style={{ width: "100%", height: "100%" }}
512
+ contentFit={props.maxWidth === undefined ? "cover" : "contain"}
513
+ onLoad={(event) => {
514
+ if (props.maxWidth !== undefined) setSize(event.source);
515
+ props.onLoad?.();
516
+ }}
517
+ onError={props.onError}
518
+ />
519
+ </ZoomableImagePressable>
520
);
521
}
522
@@ -550,8 +561,12 @@ function MessageAttachmentImage(props: {
561
562
return (
563
<PresentationSource identifier={sourceIdentifier}>
553
- <Pressable
554
- accessibilityRole="imagebutton"
564
+ <MessageImage
565
+ key={props.attachmentId}
566
+ source={assetImageSource(props.environmentId, resource, uri)}
567
+ className={props.className}
568
+ maxWidth={props.maxWidth}
569
+ height={props.height}
570
accessibilityLabel={`Open ${props.name}`}
571
onPress={() =>
572
props.onPressPreview(
@@ -570,22 +585,15 @@ function MessageAttachmentImage(props: {
585
}),
586
)
587
}
573
- >
574
- <MessageImage
575
- source={assetImageSource(props.environmentId, resource, uri)}
576
- className={props.className}
577
- maxWidth={props.maxWidth}
578
- height={props.height}
579
- onLoad={() => {
580
- retriedImage.current = false;
581
- }}
582
- onError={() => {
583
- if (retriedImage.current) return;
584
- retriedImage.current = true;
585
- void refreshAssetUrl();
586
- }}
587
- />
588
- </Pressable>
588
+ onLoad={() => {
589
+ retriedImage.current = false;
590
+ }}
591
+ onError={() => {
592
+ if (retriedImage.current) return;
593
+ retriedImage.current = true;
594
+ void refreshAssetUrl();
595
+ }}
596
+ />
597
</PresentationSource>
598
);
599
}
@@ -960,21 +968,18 @@ function PendingMessageMedia(props: {
968
if (isImageAttachment(attachment)) {
969
const uri = fileBacked ? preview.uri : (attachment.dataUrl ?? attachment.previewUri);
970
return (
963
- <Pressable
964
- accessibilityRole="imagebutton"
971
+ <MessageImage
972
+ key={attachment.id}
973
+ source={uri === null ? undefined : { uri }}
974
+ className={props.className}
975
+ maxWidth={props.maxWidth}
976
+ height={props.height}
977
accessibilityLabel={`Open ${attachment.name}`}
978
onPress={() => {
979
const source = composerImageGallery([attachment])[0];
980
if (source) props.onPressPreview(withGallery(source));
981
}}
970
- >
971
- <MessageImage
972
- source={uri === null ? undefined : { uri }}
973
- className={props.className}
974
- maxWidth={props.maxWidth}
975
- height={props.height}
976
- />
977
- </Pressable>
982
+ />
983
);
984
}
985
if (preview.uri === null) {
apps/mobile/src/features/threads/ThreadMarkdownImage.test.tsx
+201
-6
@@ -3,19 +3,71 @@ import { act } from "react";
3
import { createRoot } from "react-dom/client";
4
import { expect, it, vi } from "vite-plus/test";
5
6
+type HandlerProps = Record<string, ((event: unknown) => void) | undefined>;
7
+type GestureHandlers = Record<string, (event: unknown, manager?: unknown) => void>;
8
+type Transform = [{ translateX: number }, { translateY: number }, { scale: number }];
9
+
10
const harness = vi.hoisted(() => ({
11
failImage: () => {},
12
loadImage: (_event: { source: { width: number; height: number } }) => {},
13
Passthrough: ({ children }: { children?: unknown }) => children,
14
+ pressable: {} as HandlerProps,
15
+ gestures: {} as Record<string, GestureHandlers>,
16
+ contentStyle: () => ({}) as { transform?: Transform },
17
}));
18
12
-vi.mock("react-native", () => ({
13
- Pressable: harness.Passthrough,
14
- StyleSheet: { absoluteFill: {} },
15
- View: ({ children, style }: { children?: ReactNode; style?: unknown }) => (
19
+vi.mock("react-native", () => {
20
+ const View = ({ children, style }: { children?: ReactNode; style?: unknown }) => (
21
<div data-style={JSON.stringify(style)}>{children}</div>
17
- ),
18
-}));
22
+ );
23
+ return {
24
+ Platform: { OS: "ios" },
25
+ Pressable: (props: HandlerProps & { children?: ReactNode; style?: unknown }) => {
26
+ harness.pressable = props;
27
+ return <View style={props.style}>{props.children}</View>;
28
+ },
29
+ StyleSheet: { absoluteFill: {} },
30
+ View,
31
+ };
32
+});
33
+vi.mock("react-native-gesture-handler", () => {
34
+ // Records each gesture's callbacks so a test can drive the worklets with native-shaped events.
35
+ const builder = (kind: string) => () => {
36
+ const handlers: GestureHandlers = {};
37
+ harness.gestures[kind] = handlers;
38
+ const gesture: object = new Proxy(
39
+ {},
40
+ {
41
+ get: (_target, name) => (callback: GestureHandlers[string]) => {
42
+ if (typeof name === "string" && name.startsWith("on")) handlers[name] = callback;
43
+ return gesture;
44
+ },
45
+ },
46
+ );
47
+ return gesture;
48
+ };
49
+ return {
50
+ Gesture: { Pinch: builder("pinch"), Pan: builder("pan"), Simultaneous: () => ({}) },
51
+ GestureDetector: ({ children }: { children?: ReactNode }) => children,
52
+ };
53
+});
54
+vi.mock("react-native-reanimated", async () => {
55
+ const { useState } = await import("react");
56
+ return {
57
+ default: { View: ({ children }: { children?: ReactNode }) => <div>{children}</div> },
58
+ runOnJS: (callback: () => void) => callback,
59
+ // Reads the UI-thread style on demand, as Reanimated would after a gesture frame.
60
+ useAnimatedStyle: (updater: () => { transform?: Transform }) => {
61
+ harness.contentStyle = updater;
62
+ return {};
63
+ },
64
+ useSharedValue: <T,>(initial: T) =>
65
+ useState(() => {
66
+ let value = initial;
67
+ return { get: () => value, set: (next: T) => void (value = next) };
68
+ })[0],
69
+ };
70
+});
71
vi.mock("expo-image", () => ({
72
Image: (props: {
73
onError: () => void;
@@ -203,3 +255,146 @@ it("does not parse an obsolete SVG response after its last reader unmounts", asy
255
registry.dispose();
256
}
257
});
258
+
259
+const zoom = () => {
260
+ const [{ translateX }, { translateY }, { scale }] = harness.contentStyle().transform!;
261
+ // Clamping at fit can yield -0, which is the same position.
262
+ return { scale, x: translateX + 0, y: translateY + 0 };
263
+};
264
+const pinch = (phase: "onStart" | "onUpdate", focalX: number, focalY: number, scale: number) =>
265
+ act(async () => harness.gestures.pinch![phase]!({ focalX, focalY, scale, numberOfPointers: 2 }));
266
+const endPinch = () => act(async () => harness.gestures.pinch!.onFinalize!({}));
267
+const layout = (width: number, height: number) =>
268
+ act(async () => harness.pressable.onLayout?.({ nativeEvent: { layout: { width, height } } }));
269
+const markdownImage = (sourceKey: string, onPressPreview: () => void = () => {}) => (
270
+ <MarkdownImageAvailableWidthContext value={345}>
271
+ <ThreadMarkdownImageView
272
+ uri={`https://example.test/${sourceKey}.png`}
273
+ sourceKey={sourceKey}
274
+ unavailable={false}
275
+ alt={null}
276
+ knownSize={{ width: 1000, height: 585 }}
277
+ onPressPreview={onPressPreview}
278
+ />
279
+ </MarkdownImageAvailableWidthContext>
280
+);
281
+
282
+it("does not open the preview when a touch on the inline image pinches or pans it", async () => {
283
+ (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
284
+ const root = createRoot(document.createElement("div"));
285
+ const onPressPreview = vi.fn();
286
+ const touch = (fingers: number) =>
287
+ act(async () =>
288
+ harness.pressable.onTouchStart?.({
289
+ nativeEvent: { touches: Array.from({ length: fingers }, () => ({})) },
290
+ }),
291
+ );
292
+ const release = () =>
293
+ act(async () => harness.pressable.onPress?.({ nativeEvent: { identifier: 1 } }));
294
+ try {
295
+ await act(async () => root.render(markdownImage("hero", onPressPreview)));
296
+ await touch(1);
297
+ await touch(2);
298
+ await release();
299
+ expect(onPressPreview).not.toHaveBeenCalled();
300
+
301
+ await touch(1);
302
+ await act(async () => harness.gestures.pan!.onStart!({ translationX: 5, translationY: 0 }));
303
+ await release();
304
+ expect(onPressPreview).not.toHaveBeenCalled();
305
+
306
+ await touch(1);
307
+ await release();
308
+ expect(onPressPreview).toHaveBeenCalledOnce();
309
+
310
+ // VoiceOver activation has no touch, so an earlier pinch must not swallow it.
311
+ await touch(2);
312
+ await act(async () => harness.pressable.onPress?.({ nativeEvent: {} }));
313
+ expect(onPressPreview).toHaveBeenCalledTimes(2);
314
+ } finally {
315
+ await act(async () => root.unmount());
316
+ }
317
+});
318
+
319
+it("zooms the inline image around the pinch and keeps it until the source or frame changes", async () => {
320
+ (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
321
+ const root = createRoot(document.createElement("div"));
322
+ const touchPan = () => {
323
+ const manager = { fail: vi.fn() };
324
+ harness.gestures.pan!.onTouchesDown!({}, manager);
325
+ return manager;
326
+ };
327
+ try {
328
+ await act(async () => root.render(markdownImage("a")));
329
+ // The frame center is (172.5, 101); the pinch is off center.
330
+ await layout(345, 202);
331
+ await pinch("onStart", 300, 150, 1);
332
+ await pinch("onUpdate", 300, 150, 2);
333
+ expect(zoom()).toEqual({ scale: 2, x: -127.5, y: -49 });
334
+ await pinch("onUpdate", 280, 140, 2);
335
+ expect(zoom()).toEqual({ scale: 2, x: -147.5, y: -59 });
336
+ await act(async () =>
337
+ harness.gestures.pinch!.onUpdate!({ focalX: 90, focalY: 90, scale: 2, numberOfPointers: 1 }),
338
+ );
339
+ expect(zoom()).toEqual({ scale: 2, x: -147.5, y: -59 });
340
+ await endPinch();
341
+
342
+ await act(async () => harness.loadImage({ source: { width: 1000, height: 585 } }));
343
+ await act(async () => root.render(markdownImage("a")));
344
+ await layout(345, 202);
345
+ expect(zoom()).toEqual({ scale: 2, x: -147.5, y: -59 });
346
+
347
+ await pinch("onStart", 100, 50, 1);
348
+ await pinch("onUpdate", 100, 50, 1.5);
349
+ expect(zoom()).toEqual({ scale: 3, x: -185, y: -63 });
350
+ await pinch("onUpdate", 100, 50, 10);
351
+ expect(zoom().scale).toBe(6);
352
+ await endPinch();
353
+
354
+ const zoomedPan = touchPan();
355
+ await act(async () => harness.gestures.pan!.onStart!({ translationX: 5, translationY: 0 }));
356
+ await act(async () =>
357
+ harness.gestures.pan!.onUpdate!({ translationX: 5000, translationY: -5000 }),
358
+ );
359
+ expect(zoomedPan.fail).not.toHaveBeenCalled();
360
+ expect(zoom()).toEqual({ scale: 6, x: 862.5, y: -505 });
361
+
362
+ await pinch("onStart", 172, 100, 1);
363
+ await pinch("onUpdate", 172, 100, 0.01);
364
+ await endPinch();
365
+ expect(zoom()).toEqual({ scale: 1, x: 0, y: 0 });
366
+ expect(touchPan().fail).toHaveBeenCalledOnce();
367
+
368
+ await pinch("onStart", 300, 150, 1);
369
+ await pinch("onUpdate", 300, 150, 2);
370
+ await endPinch();
371
+ await layout(300, 175);
372
+ expect(zoom()).toEqual({ scale: 1, x: 0, y: 0 });
373
+
374
+ await pinch("onStart", 300, 150, 1);
375
+ await pinch("onUpdate", 300, 150, 2);
376
+ await endPinch();
377
+ await act(async () => root.render(markdownImage("b")));
378
+ expect(zoom()).toEqual({ scale: 1, x: 0, y: 0 });
379
+
380
+ for (const panFirst of [true, false]) {
381
+ await act(async () => root.render(markdownImage(`handoff-${panFirst}`)));
382
+ await layout(300, 200);
383
+ await pinch("onStart", 150, 100, 1);
384
+ await pinch("onUpdate", 150, 100, 2);
385
+ await endPinch();
386
+ await act(async () => harness.gestures.pan!.onStart!({ translationX: 0, translationY: 0 }));
387
+ await pinch("onStart", 150, 100, 1);
388
+ const panUpdate = () =>
389
+ act(async () => harness.gestures.pan!.onUpdate!({ translationX: 10, translationY: 0 }));
390
+ if (panFirst) await panUpdate();
391
+ await pinch("onUpdate", 150, 100, 1.5);
392
+ if (!panFirst) await panUpdate();
393
+ await endPinch();
394
+ await act(async () => harness.gestures.pan!.onUpdate!({ translationX: 20, translationY: 0 }));
395
+ expect(zoom()).toEqual({ scale: 3, x: 10, y: 0 });
396
+ }
397
+ } finally {
398
+ await act(async () => root.unmount());
399
+ }
400
+});
apps/mobile/src/features/threads/ThreadMarkdownImage.tsx
+25
-28
@@ -20,6 +20,7 @@ import { useMediaActions } from "../../state/mediaActions";
20
import type { MediaActionsSource } from "../../lib/mediaActionsSource";
21
import { useAssetUrlState } from "../../state/assets";
22
import { WorkspaceMutationIdContext } from "./workspaceMutationIdContext";
23
+import { ZoomableImagePressable } from "./ZoomableImagePressable";
24
import { assetImageCacheKey } from "../../lib/assetImageSource";
25
import {
26
MARKDOWN_IMAGE_MAX_WIDTH,
@@ -167,7 +168,8 @@ export function ThreadMarkdownImageView(props: {
168
) : (
169
<PresentationSource identifier={sourceIdentifier} style={{ alignSelf: "flex-start" }}>
170
<MediaActionsMenu media={mediaActions}>
170
- <Pressable
171
+ <ZoomableImagePressable
172
+ key={props.sourceKey}
173
accessibilityRole="imagebutton"
174
accessibilityLabel={props.alt ?? "Markdown image"}
175
accessibilityHint={
@@ -184,34 +186,29 @@ export function ThreadMarkdownImageView(props: {
186
}),
187
)
188
}
187
- style={{ alignSelf: "flex-start" }}
189
+ className="overflow-hidden rounded-[10px] bg-md-code-bg"
190
+ style={{ alignSelf: "flex-start", ...frameStyle }}
191
>
189
- <View
190
- className="items-center justify-center overflow-hidden rounded-[10px] bg-md-code-bg"
191
- style={frameStyle}
192
- >
193
- {props.format === "svg" ? (
194
- <ThreadMarkdownSvg ast={svgDocument?.ast ?? null} />
195
- ) : (
196
- <ThreadMarkdownImageRequest
197
- key={props.sourceKey}
198
- uri={props.uri}
199
- cacheKey={props.cacheKey}
200
- onLoad={(size) =>
201
- // Only the first decode counts: later loads report the bitmap
202
- // downsampled for the current frame (969 vs 970 wide), so keeping
203
- // them resizes the frame, which reloads the image, and so on.
204
- setDecoded((current) =>
205
- current?.sourceKey === props.sourceKey
206
- ? current
207
- : { sourceKey: props.sourceKey, size },
208
- )
209
- }
210
- onError={() => setFailure({ uri: props.uri, failed: true })}
211
- />
212
- )}
213
- </View>
214
- </Pressable>
192
+ {props.format === "svg" ? (
193
+ <ThreadMarkdownSvg ast={svgDocument?.ast ?? null} />
194
+ ) : (
195
+ <ThreadMarkdownImageRequest
196
+ uri={props.uri}
197
+ cacheKey={props.cacheKey}
198
+ onLoad={(size) =>
199
+ // Only the first decode counts: later loads report the bitmap
200
+ // downsampled for the current frame (969 vs 970 wide), so keeping
201
+ // them resizes the frame, which reloads the image, and so on.
202
+ setDecoded((current) =>
203
+ current?.sourceKey === props.sourceKey
204
+ ? current
205
+ : { sourceKey: props.sourceKey, size },
206
+ )
207
+ }
208
+ onError={() => setFailure({ uri: props.uri, failed: true })}
209
+ />
210
+ )}
211
+ </ZoomableImagePressable>
212
</MediaActionsMenu>
213
</PresentationSource>
214
)}
apps/mobile/src/features/threads/ZoomableImagePressable.tsx
new
+177
@@ -0,0 +1,177 @@
1
+import { useEffectEvent, useRef, useState, type ComponentProps, type ReactNode } from "react";
2
+import { Platform, Pressable, StyleSheet } from "react-native";
3
+import { Gesture, GestureDetector } from "react-native-gesture-handler";
4
+import Animated, { runOnJS, useAnimatedStyle, useSharedValue } from "react-native-reanimated";
5
+
6
+const MAX_INLINE_ZOOM = 6;
7
+// Below UIScrollView's drag hysteresis, so a zoomed pan wins over the feed scroll.
8
+const ZOOMED_PAN_MIN_DISTANCE = 5;
9
+
10
+type Zoom = { readonly scale: number; readonly x: number; readonly y: number };
11
+type Size = { readonly width: number; readonly height: number };
12
+
13
+const FIT: Zoom = { scale: 1, x: 0, y: 0 };
14
+
15
+/** Keeps the scaled content covering the frame: translation is about the frame center. */
16
+function clampZoom(zoom: Zoom, size: Size): Zoom {
17
+ "worklet";
18
+ const scale = Math.min(Math.max(zoom.scale, 1), MAX_INLINE_ZOOM);
19
+ const maxX = ((scale - 1) * size.width) / 2;
20
+ const maxY = ((scale - 1) * size.height) / 2;
21
+ return {
22
+ scale,
23
+ x: Math.min(Math.max(zoom.x, -maxX), maxX),
24
+ y: Math.min(Math.max(zoom.y, -maxY), maxY),
25
+ };
26
+}
27
+
28
+type ZoomableImagePressableProps = Omit<ComponentProps<typeof Pressable>, "children"> & {
29
+ readonly children: ReactNode;
30
+};
31
+
32
+/**
33
+ * Inline chat image that pinch-zooms in place on iOS. Key it by image source so a
34
+ * new source starts at fit; ordinary rerenders keep the zoom and offset.
35
+ */
36
+export function ZoomableImagePressable(props: ZoomableImagePressableProps) {
37
+ if (Platform.OS !== "ios") return <Pressable {...props} />;
38
+ return <IosZoomableImagePressable {...props} />;
39
+}
40
+
41
+function IosZoomableImagePressable({
42
+ children,
43
+ onTouchStart,
44
+ onPress,
45
+ onLayout,
46
+ ...pressableProps
47
+}: ZoomableImagePressableProps) {
48
+ const gestured = useRef(false);
49
+ const layoutSize = useRef<Size | null>(null);
50
+ const zoom = useSharedValue(FIT);
51
+ const size = useSharedValue<Size>({ width: 0, height: 0 });
52
+ const pinching = useSharedValue(false);
53
+ const pinchStart = useSharedValue({ zoom: FIT, focalX: 0, focalY: 0, scale: 1, pointers: 0 });
54
+ const panStart = useSharedValue({ zoom: FIT, translationX: 0, translationY: 0 });
55
+
56
+ const markGestured = useEffectEvent(() => {
57
+ gestured.current = true;
58
+ });
59
+ const [gesture] = useState(() => {
60
+ // Focal points arrive in the untransformed frame; the transform is about its center.
61
+ const pinch = Gesture.Pinch()
62
+ .onStart((event) => {
63
+ const frame = size.get();
64
+ pinching.set(true);
65
+ pinchStart.set({
66
+ zoom: zoom.get(),
67
+ focalX: event.focalX - frame.width / 2,
68
+ focalY: event.focalY - frame.height / 2,
69
+ scale: event.scale,
70
+ pointers: event.numberOfPointers,
71
+ });
72
+ runOnJS(markGestured)();
73
+ })
74
+ .onUpdate((event) => {
75
+ const frame = size.get();
76
+ const start = pinchStart.get();
77
+ const focalX = event.focalX - frame.width / 2;
78
+ const focalY = event.focalY - frame.height / 2;
79
+ if (event.numberOfPointers !== start.pointers) {
80
+ // A lifted or added finger jumps the focal point; continue from here instead.
81
+ pinchStart.set({
82
+ zoom: zoom.get(),
83
+ focalX,
84
+ focalY,
85
+ scale: event.scale,
86
+ pointers: event.numberOfPointers,
87
+ });
88
+ return;
89
+ }
90
+ const scale = Math.min(
91
+ Math.max((start.zoom.scale * event.scale) / start.scale, 1),
92
+ MAX_INLINE_ZOOM,
93
+ );
94
+ // Keep the content point that started under the fingers under them.
95
+ const contentX = (start.focalX - start.zoom.x) / start.zoom.scale;
96
+ const contentY = (start.focalY - start.zoom.y) / start.zoom.scale;
97
+ zoom.set(
98
+ clampZoom({ scale, x: focalX - scale * contentX, y: focalY - scale * contentY }, frame),
99
+ );
100
+ })
101
+ .onFinalize(() => {
102
+ panStart.set({ ...panStart.get(), zoom: zoom.get() });
103
+ pinching.set(false);
104
+ });
105
+ const pan = Gesture.Pan()
106
+ .minDistance(ZOOMED_PAN_MIN_DISTANCE)
107
+ .onTouchesDown((_event, manager) => {
108
+ // At fit, a one-finger drag belongs to the feed.
109
+ if (zoom.get().scale <= 1) manager.fail();
110
+ })
111
+ .onStart((event) => {
112
+ panStart.set({
113
+ zoom: zoom.get(),
114
+ translationX: event.translationX,
115
+ translationY: event.translationY,
116
+ });
117
+ runOnJS(markGestured)();
118
+ })
119
+ .onUpdate((event) => {
120
+ if (pinching.get()) {
121
+ // The pinch owns the transform; resume panning from wherever it leaves it.
122
+ panStart.set({
123
+ zoom: zoom.get(),
124
+ translationX: event.translationX,
125
+ translationY: event.translationY,
126
+ });
127
+ return;
128
+ }
129
+ const start = panStart.get();
130
+ zoom.set(
131
+ clampZoom(
132
+ {
133
+ scale: start.zoom.scale,
134
+ x: start.zoom.x + event.translationX - start.translationX,
135
+ y: start.zoom.y + event.translationY - start.translationY,
136
+ },
137
+ size.get(),
138
+ ),
139
+ );
140
+ });
141
+ return Gesture.Simultaneous(pinch, pan);
142
+ });
143
+ const contentStyle = useAnimatedStyle(() => {
144
+ const { scale, x, y } = zoom.get();
145
+ return { transform: [{ translateX: x }, { translateY: y }, { scale }] };
146
+ });
147
+
148
+ return (
149
+ <GestureDetector gesture={gesture}>
150
+ <Pressable
151
+ {...pressableProps}
152
+ onTouchStart={(event) => {
153
+ gestured.current = event.nativeEvent.touches.length > 1;
154
+ onTouchStart?.(event);
155
+ }}
156
+ onPress={(event) => {
157
+ // Accessibility activation carries no touch identifier and no gesture.
158
+ if (typeof event.nativeEvent.identifier === "number" && gestured.current) return;
159
+ onPress?.(event);
160
+ }}
161
+ onLayout={(event) => {
162
+ const { width, height } = event.nativeEvent.layout;
163
+ const previous = layoutSize.current;
164
+ if (previous?.width !== width || previous?.height !== height) {
165
+ // The old offsets no longer fit the new frame, so a resize starts over at fit.
166
+ layoutSize.current = { width, height };
167
+ size.set({ width, height });
168
+ zoom.set(FIT);
169
+ }
170
+ onLayout?.(event);
171
+ }}
172
+ >
173
+ <Animated.View style={[StyleSheet.absoluteFill, contentStyle]}>{children}</Animated.View>
174
+ </Pressable>
175
+ </GestureDetector>
176
+ );
177
+}
apps/mobile/src/lib/filePreview.test.ts
+4
@@ -297,6 +297,10 @@ vi.mock("../features/threads/ThreadMarkdownImage", async () => {
297
const { createContext } = await import("react");
298
return { MarkdownImageAvailableWidthContext: createContext(390) };
299
});
300
+vi.mock("../features/threads/ZoomableImagePressable", async () => {
301
+ const { Pressable } = await import("react-native");
302
+ return { ZoomableImagePressable: Pressable };
303
+});
304
vi.mock("../features/review/ReviewCommentCard", () => ({ useReviewCommentColors: () => ({}) }));
305
vi.mock("../features/prompt-links/prompt-link-actions", () => ({}));
306
vi.mock("@react-navigation/elements", async () => {