The best way to control Claude Code, Codex and more from any computer or phone
fix(mobile): size a chat image's frame before its bytes arrive (#10199)
Co-authored-by: Claude Code <noreply@anthropic.com>
Julius Marminge committed
Sep 5, 2026 at 15:51 UTC
7451d17a69ff7585f302933beeae1037d2c708a8
2 files changed
+67
-28
apps/mobile/src/features/threads/ThreadFeed.tsx
+32
-16
@@ -177,6 +177,7 @@ import {
177
} from "../files/filePath";
178
import { fileChipMenu, resolveFileChipTarget, type FileChipAction } from "./fileChipMenu";
179
import {
180
+ MarkdownImageAvailableWidthContext,
181
ThreadMarkdownImage,
182
ThreadMarkdownImageUnavailable,
183
ThreadMarkdownImageView,
@@ -206,6 +207,10 @@ function formatMessageTime(input: string): string {
207
// text fits at the current font settings. Larger accessibility text is measured.
208
const TURN_FOLD_HEIGHT = 42; // min-h-11 (38.5) + mb-1 (3.5), with the mobile 14px rem
209
const THREAD_FEED_LAYOUT_TRANSITION = LinearTransition.duration(THREAD_DISCLOSURE_TRANSITION_MS);
210
+// Tailwind spacing on the mobile 14px rem: px-3.5 on the user bubble, px-1 on
211
+// assistant rows. Images size their frame from these before their own layout.
212
+const USER_BUBBLE_HORIZONTAL_PADDING = 3.5 * 3.5;
213
+const ASSISTANT_ROW_HORIZONTAL_PADDING = 3.5;
214
// Let neighboring rows move out of the new rows' space before showing their text.
215
const THREAD_FEED_DISCLOSURE_ENTER_TRANSITION = FadeIn.delay(
216
THREAD_DISCLOSURE_TRANSITION_MS,
@@ -1331,6 +1336,8 @@ function renderFeedEntry(
1336
readonly reviewCommentBubbleWidth: number;
1337
readonly themeAppearance: "light" | "dark";
1338
readonly userBubbleMaxWidth: number;
1339
+ /** Width assistant markdown lays out in, so images can size their frame before layout. */
1340
+ readonly markdownContentWidth: number;
1341
},
1342
) {
1343
const entry = info.item;
@@ -1452,14 +1459,18 @@ function renderFeedEntry(
1459
}}
1460
>
1461
{message.text.trim().length > 0 ? (
1455
- <UserMessageContent
1456
- text={renderedText}
1457
- markdownStyles={styles}
1458
- reviewCommentColors={props.reviewCommentColors}
1459
- skills={props.skills}
1460
- linkHandlers={props.markdownLinkHandlers}
1461
- renderImage={props.renderMarkdownImage}
1462
- />
1462
+ <MarkdownImageAvailableWidthContext
1463
+ value={props.userBubbleMaxWidth - USER_BUBBLE_HORIZONTAL_PADDING * 2}
1464
+ >
1465
+ <UserMessageContent
1466
+ text={renderedText}
1467
+ markdownStyles={styles}
1468
+ reviewCommentColors={props.reviewCommentColors}
1469
+ skills={props.skills}
1470
+ linkHandlers={props.markdownLinkHandlers}
1471
+ renderImage={props.renderMarkdownImage}
1472
+ />
1473
+ </MarkdownImageAvailableWidthContext>
1474
) : null}
1475
{attachments.map((attachment) => {
1476
return isImageAttachment(attachment) ? (
@@ -1516,14 +1527,16 @@ function renderFeedEntry(
1527
{...(enterAnimated ? { entering: FadeIn.duration(220) } : {})}
1528
>
1529
{renderedText.trim().length > 0 ? (
1519
- <AssistantMarkdownContent
1520
- markdown={renderedText}
1521
- markdownStyles={styles}
1522
- linkHandlers={props.markdownLinkHandlers}
1523
- onUseArtifactTemplate={props.onUseArtifactTemplate}
1524
- renderImage={props.renderMarkdownImage}
1525
- skills={props.skills}
1526
- />
1530
+ <MarkdownImageAvailableWidthContext value={props.markdownContentWidth}>
1531
+ <AssistantMarkdownContent
1532
+ markdown={renderedText}
1533
+ markdownStyles={styles}
1534
+ linkHandlers={props.markdownLinkHandlers}
1535
+ onUseArtifactTemplate={props.onUseArtifactTemplate}
1536
+ renderImage={props.renderMarkdownImage}
1537
+ skills={props.skills}
1538
+ />
1539
+ </MarkdownImageAvailableWidthContext>
1540
) : null}
1541
{attachments.map((attachment) => {
1542
return isImageAttachment(attachment) ? (
@@ -1942,6 +1955,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
1955
});
1956
const contentWidth = Math.max(0, viewportWidth - contentHorizontalPadding * 2);
1957
const userBubbleMaxWidth = contentWidth * 0.85;
1958
+ const markdownContentWidth = Math.max(0, contentWidth - ASSISTANT_ROW_HORIZONTAL_PADDING * 2);
1959
const reviewCommentBubbleWidth = Math.min(Math.max(280, contentWidth * 0.85), contentWidth);
1960
const insets = useSafeAreaInsets();
1961
const topContentInset = props.contentTopInset ?? insets.top + IOS_NAV_BAR_HEIGHT;
@@ -2620,6 +2634,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
2634
reviewCommentBubbleWidth,
2635
themeAppearance,
2636
userBubbleMaxWidth,
2637
+ markdownContentWidth,
2638
skills: props.skills,
2639
onUseArtifactTemplate: props.onUseArtifactTemplate,
2640
})}
@@ -2641,6 +2656,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
2656
reviewCommentBubbleWidth,
2657
themeAppearance,
2658
userBubbleMaxWidth,
2659
+ markdownContentWidth,
2660
onCopyWorkRow,
2661
markdownLinkHandlers,
2662
onPressPreview,
apps/mobile/src/features/threads/ThreadMarkdownImage.tsx
+35
-12
@@ -1,5 +1,5 @@
1
import type { AssetResource, EnvironmentId } from "@t3tools/contracts";
2
-import { useEffect, useId, useState } from "react";
2
+import { createContext, useContext, useEffect, useId, useState } from "react";
3
import {
4
ActivityIndicator,
5
Image,
@@ -15,32 +15,56 @@ import { MediaActionsMenu } from "../../components/MediaActionsMenu";
15
import { PresentationSource } from "../../components/NativePresentation";
16
import { useMediaActions, type MediaActionsSource } from "../../lib/mediaActions";
17
import { useAssetUrlState } from "../../state/assets";
18
-import { MARKDOWN_IMAGE_MAX_WIDTH, resolveMarkdownImageDisplaySize } from "./markdownImageSize";
18
+import {
19
+ MARKDOWN_IMAGE_MAX_WIDTH,
20
+ type MarkdownImageDisplaySize,
21
+ resolveMarkdownImageDisplaySize,
22
+} from "./markdownImageSize";
23
+
24
+/**
25
+ * Width the feed lays markdown out in. The feed already knows this from its
26
+ * viewport, so an image can size its frame on the first render instead of
27
+ * waiting for its own onLayout, which would change the row's height once
28
+ * more after the list has positioned the rows below it. It is an upper
29
+ * bound: a list item or blockquote indents its column, and the measured
30
+ * width takes over once it is known.
31
+ */
32
+export const MarkdownImageAvailableWidthContext = createContext(0);
33
34
export function ThreadMarkdownImageView(props: {
35
readonly uri: string | null;
36
readonly sourceKey: string;
37
readonly unavailable: boolean;
38
readonly alt: string | null;
39
+ /** Pixel size from the server, when it could read the header; the frame is final from the first render. */
40
+ readonly knownSize?: { readonly width: number; readonly height: number } | undefined;
41
readonly actionsSource?: MediaActionsSource;
42
readonly onPressPreview: (source: FilePreviewSource) => void;
43
}) {
44
const sourceIdentifier = useId();
45
const mediaActions = useMediaActions(props.actionsSource);
30
- const [availableWidth, setAvailableWidth] = useState(0);
31
- const [sourceSize, setSourceSize] = useState<{ width: number; height: number } | null>(null);
46
+ const contextWidth = useContext(MarkdownImageAvailableWidthContext);
47
+ const [measuredWidth, setMeasuredWidth] = useState(0);
48
+ const availableWidth =
49
+ measuredWidth > 0 && contextWidth > 0
50
+ ? Math.min(contextWidth, measuredWidth)
51
+ : contextWidth || measuredWidth;
52
+ const [decodedSize, setDecodedSize] = useState<{ width: number; height: number } | null>(null);
53
const [failedUri, setFailedUri] = useState<string | null>(null);
54
55
useEffect(() => {
35
- setSourceSize(null);
56
+ setDecodedSize(null);
57
}, [props.sourceKey]);
58
59
useEffect(() => {
60
setFailedUri(null);
61
}, [props.uri]);
62
42
- const displaySize =
43
- sourceSize === null
63
+ // The decoded size is what the platform actually drew, so it wins over the
64
+ // server's header hint once it exists.
65
+ const sourceSize = decodedSize ?? props.knownSize ?? null;
66
+ const displaySize: MarkdownImageDisplaySize | null =
67
+ sourceSize === null || availableWidth <= 0
68
? null
69
: resolveMarkdownImageDisplaySize({
70
sourceWidth: sourceSize.width,
@@ -54,7 +78,7 @@ export function ThreadMarkdownImageView(props: {
78
79
return (
80
<View
57
- onLayout={(event) => setAvailableWidth(event.nativeEvent.layout.width)}
81
+ onLayout={(event) => setMeasuredWidth(event.nativeEvent.layout.width)}
82
style={{ alignSelf: "stretch", gap: 6 }}
83
>
84
{props.uri === null || failed ? (
@@ -97,14 +121,12 @@ export function ThreadMarkdownImageView(props: {
121
>
122
<View
123
className="items-center justify-center overflow-hidden rounded-[10px] bg-md-code-bg"
100
- style={{
101
- ...frameStyle,
102
- }}
124
+ style={frameStyle}
125
>
126
<ThreadMarkdownImageRequest
127
key={props.uri}
128
uri={props.uri}
107
- onLoad={setSourceSize}
129
+ onLoad={setDecodedSize}
130
onError={() => setFailedUri(props.uri)}
131
/>
132
</View>
@@ -173,6 +195,7 @@ export function ThreadMarkdownImage(props: {
195
: `workspace:${props.resource.path}`
196
}
197
unavailable={assetUrl._tag === "Failure"}
198
+ knownSize={assetUrl._tag === "Success" ? assetUrl.imageDimensions : undefined}
199
alt={props.alt}
200
actionsSource={props.actionsSource}
201
onPressPreview={props.onPressPreview}