The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
fix(mobile): a missing image no longer stops its gallery opening on Android (#39128)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Wout Stiens committed
Nov 19, 2026 at 15:25 UTC
60c69524304c33994bef76819670d0c137669eaf
3 files changed
+58
-29
apps/mobile/src/components/ui/FilePreviewModal.android.tsx
+6
-3
@@ -183,11 +183,14 @@ function AndroidFilePreview(props: FilePreviewViewerProps) {
183
const { source } = props;
184
if (source.kind === "pdf") return <PdfDocumentPreview {...props} source={source} />;
185
if (source.kind !== "image") return <DocumentPreview {...props} source={source} />;
186
- if (source.images[source.selectedIndex]?.actionsSource)
187
- return <ImagePreview source={source} onRequestClose={props.onRequestClose} />;
186
+ const selected = source.images[source.selectedIndex]!;
187
+ const images = source.images.filter((image) => !image.failed);
188
+ const gallery = { ...source, images, selectedIndex: images.indexOf(selected) };
189
+ if (selected.actionsSource)
190
+ return <ImagePreview source={gallery} onRequestClose={props.onRequestClose} />;
191
return (
192
<ImageViewing
190
- {...imageViewingProps(source)}
193
+ {...imageViewingProps(gallery)}
194
visible
195
onRequestClose={props.onRequestClose}
196
swipeToCloseEnabled={false}
apps/mobile/src/components/ui/FilePreviewSession.test.tsx
+50
-24
@@ -26,7 +26,30 @@ vi.mock("../../lib/attachmentDownload", () => ({
26
}));
27
vi.mock("../../lib/previewPresentation", () => ({ usePreviewPresentation: () => {} }));
28
vi.mock("./Dialog", () => ({ alert: harness.alert }));
29
+vi.mock("./Button", () => ({ Button: () => null }));
30
+vi.mock("./SheetHeader", () => ({ SheetHeader: () => null }));
31
+vi.mock("./AppText", () => ({ AppText: () => null }));
32
+vi.mock("../PdfPreview", () => ({ PdfPreview: () => null }));
33
+vi.mock("../MediaPreviewHeader", () => ({ MediaPreviewHeader: () => null }));
34
+vi.mock("../../state/mediaActions", () => ({ useMediaActions: () => ({ actions: [] }) }));
35
+vi.mock("react-native", () => ({ Modal: () => null, View: () => null }));
36
+vi.mock("react-native-safe-area-context", () => ({ useSafeAreaInsets: () => ({ top: 0 }) }));
37
+vi.mock("react-native-image-viewing", () => ({
38
+ default: function ImageViewing(props: {
39
+ images: readonly { uri?: string }[];
40
+ imageIndex: number;
41
+ }) {
42
+ useState(() => harness.mounts++);
43
+ harness.previews.push({
44
+ kind: "image",
45
+ images: props.images,
46
+ selectedIndex: props.imageIndex,
47
+ });
48
+ return null;
49
+ },
50
+}));
51
52
+import { FilePreviewModal as AndroidFilePreviewModal } from "./FilePreviewModal.android";
53
import type { FilePreviewItem, FilePreviewViewerProps } from "./FilePreviewModal.types";
54
import { FilePreviewSession } from "./FilePreviewSession";
55
@@ -57,14 +80,19 @@ async function openGallery(
80
harness.alert.mockClear();
81
const root = createRoot(document.createElement("div"));
82
const onRequestClose = vi.fn();
83
+ const source = { ...selected, gallery };
84
await act(async () =>
85
root.render(
62
- <FilePreviewSession
63
- source={{ ...selected, gallery }}
64
- onRequestClose={onRequestClose}
65
- progressiveGallery={progressiveGallery}
66
- Viewer={Viewer}
67
- />,
86
+ progressiveGallery ? (
87
+ <FilePreviewSession
88
+ source={source}
89
+ onRequestClose={onRequestClose}
90
+ progressiveGallery
91
+ Viewer={Viewer}
92
+ />
93
+ ) : (
94
+ <AndroidFilePreviewModal source={source} onRequestClose={onRequestClose} />
95
+ ),
96
),
97
);
98
return { onRequestClose, [Symbol.asyncDispose]: () => act(async () => root.unmount()) };
@@ -105,9 +133,17 @@ it.each([true, false])(
133
},
134
);
135
108
-it.each([true, false])(
109
- "handles a failed sibling without leaving a pending page (progressive: %s)",
110
- async (progressiveGallery) => {
136
+it.each([
137
+ // The progressive viewer already gave the missing image a page; a viewer that waits opens without it.
138
+ [
139
+ true,
140
+ 1,
141
+ [{ failed: true }, { uri: "https://signed.test/a.png" }, { uri: "https://signed.test/c.png" }],
142
+ ],
143
+ [false, 0, [{ uri: "https://signed.test/a.png" }, { uri: "https://signed.test/c.png" }]],
144
+])(
145
+ "opens the gallery when a sibling cannot be resolved (progressive: %s)",
146
+ async (progressiveGallery, selectedIndex, images) => {
147
harness.refreshAssetUrl.mockImplementation(async (_environmentId, resource) => {
148
if (resource.url.endsWith("missing.png")) throw new Error("not found");
149
return `https://signed.test/${resource.url.split("/").pop()}`;
@@ -115,26 +151,16 @@ it.each([true, false])(
151
const selected = image("https://github.com/a.png");
152
await using preview = await openGallery(
153
selected,
118
- [selected, image("https://github.com/missing.png"), image("https://github.com/c.png")],
154
+ [image("https://github.com/missing.png"), selected, image("https://github.com/c.png")],
155
progressiveGallery,
156
);
157
122
- if (!progressiveGallery) {
123
- expect(preview.onRequestClose).toHaveBeenCalledOnce();
124
- expect(harness.alert).toHaveBeenCalledOnce();
125
- expect(harness.previews).toEqual([]);
126
- return;
127
- }
128
-
158
expect(preview.onRequestClose).not.toHaveBeenCalled();
159
expect(harness.alert).not.toHaveBeenCalled();
131
- expect(harness.previews.at(-1)).toMatchObject({
132
- selectedIndex: 0,
133
- images: [
134
- { uri: "https://signed.test/a.png" },
135
- { failed: true },
136
- { uri: "https://signed.test/c.png" },
137
- ],
160
+ expect(harness.previews.at(-1)).toEqual({
161
+ kind: "image",
162
+ selectedIndex,
163
+ images: images.map((page) => expect.objectContaining(page)),
164
});
165
},
166
);
apps/mobile/src/components/ui/FilePreviewSession.tsx
+2
-2
@@ -141,7 +141,7 @@ function ResolvedFilePreview(
141
},
142
(error: unknown) => {
143
if (controller.signal.aborted) return;
144
- if (progressiveGallery && index !== selectedIndex) return settle(index, null);
144
+ if (index !== selectedIndex) return settle(index, null);
145
controller.abort();
146
onResolutionError(
147
isPreviewResolutionError(error)
@@ -155,7 +155,7 @@ function ResolvedFilePreview(
155
controller.abort();
156
for (const dispose of leases) dispose();
157
};
158
- }, [items, selectedIndex, progressiveGallery]);
158
+ }, [items, selectedIndex]);
159
const selected = { ...items[selectedIndex]!, name: filePreviewName(items[selectedIndex]!) };
160
if (selected.kind === "image") {
161
// A viewer that resets image gestures when its sources change waits for every image.