@devries-cameron20 / t3code Mirror · read-only / commits / a9ac1e8e54
Fork 0

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 22, 07:00 UTC

fix(mobile): keep the conversation steady during layout changes (#29545)

Julius Marminge committed Nov 2, 2026 at 13:18 UTC a9ac1e8e54bd1a411e8bfff8124871adeb4129a2
7 files changed +306 -114
apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
+32 -15
@@ -825,10 +825,22 @@ function AdaptiveWorkspaceLayoutContent(
825 0,
826 viewportWidth -
827 renderedRailWidth.value -
828 - renderedSidebarWidth.value -
828 + (workspacePage ? 0 : renderedSidebarWidth.value) -
829 renderedInspectorWidth.value,
830 ),
831 );
832 + // Android can resize the native row before React removes its split panes on a fold.
833 + const androidSplit = Platform.OS === "android" && layout.usesSplitView;
834 + const androidContentSlotStyle = useAnimatedStyle(() => ({
835 + width: androidSplit ? renderedContentWidth.value : ("100%" as const),
836 + }));
837 + // While the sidebar animates, clip the settled navigator instead of reflowing its text every frame.
838 + const androidNavigatorLimit = useAnimatedStyle(() => ({
839 + maxWidth:
840 + androidSplit && contentTargetWidth !== null && renderedContentWidth.value < contentTargetWidth
841 + ? contentTargetWidth
842 + : ("100%" as const),
843 + }));
844
845 const handleSelectThread = (thread: EnvironmentThreadShell) => {
846 handleSelectThreadRoute({
@@ -899,11 +911,11 @@ function AdaptiveWorkspaceLayoutContent(
911 >
912 <AndroidHingeObserver onChange={handleHingeChange} />
913 {shouldRenderNavigationRail ? (
902 - <Animated.View className="self-stretch" style={railAnimatedStyle} />
914 + <Animated.View className="shrink self-stretch" style={railAnimatedStyle} />
915 ) : null}
916 {shouldRenderPrimarySidebar && layout.listPaneWidth !== null ? (
917 <Animated.View
906 - className="self-stretch overflow-hidden"
918 + className="self-stretch overflow-hidden android:shrink"
919 accessibilityElementsHidden={workspacePage || !panes.primarySidebarVisible}
920 collapsable={false}
921 importantForAccessibility={
@@ -966,17 +978,18 @@ function AdaptiveWorkspaceLayoutContent(
978 </Animated.View>
979 </Animated.View>
980 ) : null}
969 - <View
981 + <Animated.View
982 className={
983 Platform.OS === "android"
972 - ? "flex-1 overflow-hidden bg-header"
984 + ? "max-w-full shrink-0 overflow-hidden bg-header"
985 : "flex-1 overflow-hidden bg-screen"
986 }
987 + style={Platform.OS === "android" ? androidContentSlotStyle : undefined}
988 collapsable={false}
989 >
977 - <View
990 + <Animated.View
991 collapsable={false}
979 - style={
992 + style={[
993 contentTargetWidth !== null
994 ? {
995 flex: 1,
@@ -984,8 +997,9 @@ function AdaptiveWorkspaceLayoutContent(
997 alignSelf: contentAnchor.end ? "flex-end" : "flex-start",
998 marginRight: contentAnchor.end ? contentEndGap : 0,
999 }
987 - : { flex: 1 }
988 - }
1000 + : { flex: 1 },
1001 + Platform.OS === "android" ? androidNavigatorLimit : undefined,
1002 + ]}
1003 >
1004 {/* Android holds the content still, so its floating controls keep its width. */}
1005 <WorkspaceContentWidthContext
@@ -1028,8 +1042,8 @@ function AdaptiveWorkspaceLayoutContent(
1042 ) : null}
1043 </WorkspaceSettledContentWidthContext>
1044 </WorkspaceContentWidthContext>
1031 - </View>
1032 - </View>
1045 + </Animated.View>
1046 + </Animated.View>
1047 <WorkspaceInspectorPane
1048 pathname={props.pathname}
1049 renderedInspectorWidth={renderedInspectorWidth}
@@ -1040,11 +1054,14 @@ function AdaptiveWorkspaceLayoutContent(
1054 onClosed={handleWorkspaceInspectorClosed}
1055 />
1056 {shouldRenderNavigationRail && navigationRailWidth > 0 ? (
1043 - // The rail reserves its slot above and draws over the panes, so it can widen over
1044 - // the list in place. It takes the whole workspace only while it is open.
1057 + // Its trailing inset clips the old rail as soon as Android fits the workspace to a cover display.
1058 <View
1046 - className="absolute inset-y-0 left-0"
1047 - style={railOverlay ? { right: 0 } : { width: navigationRailWidth }}
1059 + className="absolute inset-y-0 left-0 overflow-hidden"
1060 + style={
1061 + railOverlay
1062 + ? { right: 0 }
1063 + : { right: viewportWidth - navigationRailWidth, maxWidth: navigationRailWidth }
1064 + }
1065 >
1066 <AndroidWorkspaceNavigation
1067 onNewThread={handleStartNewTask}
apps/mobile/src/features/threads/ComposerPopoverHost.tsx
+3 -2
@@ -19,6 +19,7 @@ export function useComposerPopoverHost() {
19 /** Mount inside KeyboardStickyView for Android gestures. Hide explicitly because portal content outlives its subtree. */
20 export function ComposerPopoverHost(props: {
21 readonly hidden: boolean;
22 + readonly inFlow?: boolean;
23 readonly popoverHeight: SharedValue<number>;
24 readonly children: ReactNode;
25 }) {
@@ -33,8 +34,8 @@ export function ComposerPopoverHost(props: {
34 ref={hostRef}
35 collapsable={false}
36 pointerEvents="box-none"
36 - className="absolute inset-0"
37 - onLayout={() => setLayoutVersion((version) => version + 1)}
37 + className={props.inFlow ? undefined : "absolute inset-0"}
38 + onLayout={props.hidden ? undefined : () => setLayoutVersion((version) => version + 1)}
39 >
40 {props.children}
41 {props.hidden ? null : content}
apps/mobile/src/features/threads/PendingUserInputCard.tsx
+31 -50
@@ -10,17 +10,12 @@ import {
10 import { useRef } from "react";
11 import { Platform, Pressable, ScrollView, View, type LayoutChangeEvent } from "react-native";
12 import Animated, {
13 - Easing,
14 - FadeInUp,
15 - FadeOutDown,
13 useAnimatedStyle,
14 useSharedValue,
15 type DerivedValue,
16 type SharedValue,
17 } from "react-native-reanimated";
18
22 -import { USER_INPUT_TOGGLE_DURATION_MS } from "./pendingUserInputLayout";
23 -
19 import { SymbolView } from "../../components/ui/AppSymbol";
20 import { AppText as Text } from "../../components/ui/AppText";
21 import { ControlPill } from "../../components/ui/ControlPill";
@@ -43,8 +38,8 @@ export interface PendingUserInputCardProps {
38 readonly collapsed: boolean;
39 readonly onToggleCollapsed: () => void;
40 readonly onStopThread?: () => void;
46 - readonly cardProgress?: SharedValue<number>;
47 - readonly cardCoverage?: SharedValue<number>;
41 + readonly cardProgress: SharedValue<number>;
42 + readonly cardCoverage: SharedValue<number>;
43 readonly onInputFocusChange?: (focused: boolean) => void;
44 readonly drafts: Record<string, PendingUserInputDraftAnswer>;
45 readonly answers: Record<string, string | ReadonlyArray<string>> | null;
@@ -63,9 +58,6 @@ export interface PendingUserInputCardProps {
58 readonly onDismiss: () => Promise<unknown>;
59 }
60
66 -/** Android cannot hit-test overlays beyond their parent's bounds; render its expanded card in-flow. */
67 -const EXPANDED_CARD_IS_OVERLAY = Platform.OS === "ios";
68 -
61 function proseDirectionStyle(text: string, setDirection: TextDirection | undefined) {
62 const direction = textDirection(text);
63 return {
@@ -111,14 +103,11 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
103 .join(" "),
104 );
105
114 - const cardCoverage = props.cardCoverage;
106 + const { cardCoverage, cardProgress, maxHeight } = props;
107 const barHeightRef = useRef(0);
108 const cardHeightRef = useRef(0);
109 const cardHeight = useSharedValue(0);
110 const notifyCoverage = () => {
119 - if (!cardCoverage) {
120 - return;
121 - }
111 // The card resizes with the keyboard every frame, so easing each sample would leave the
112 // feed inset and floating controls trailing it.
113 cardCoverage.set(Math.max(0, cardHeightRef.current - barHeightRef.current));
@@ -132,22 +121,25 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
121 cardHeight.set(event.nativeEvent.layout.height);
122 notifyCoverage();
123 };
135 - const cardProgress = props.cardProgress;
136 - const maxHeight = props.maxHeight;
124 const cardAnimatedStyle = useAnimatedStyle(() => {
138 - const progress = cardProgress === undefined ? 1 : cardProgress.value;
125 + const progress = cardProgress.value;
126 + const travel = Platform.OS === "android" ? cardCoverage.value : cardHeight.value;
127 return {
128 maxHeight: maxHeight.value,
141 - transform: [{ translateY: (1 - progress) * cardHeight.value }],
129 + opacity:
130 + Platform.OS === "android"
131 + ? Math.min(1, (progress * cardHeight.value) / Math.max(1, cardHeight.value - travel))
132 + : 1,
133 + transform: [{ translateY: (1 - progress) * travel }],
134 };
135 });
144 - const cardMaxHeightStyle = useAnimatedStyle(() => ({ maxHeight: maxHeight.value }));
136 + // Android hit-tests inside the parent; its height is also the space the card takes below the feed.
137 + const androidBoundsStyle = useAnimatedStyle(() => ({
138 + paddingTop: cardCoverage.value * cardProgress.value,
139 + }));
140 const overlayHeightStyle = useAnimatedStyle(() => ({ height: maxHeight.value }));
141
147 - // Keep the iOS card mounted so expansion starts on the UI thread without waiting for React layout.
148 - const renderCard = EXPANDED_CARD_IS_OVERLAY || !props.collapsed;
149 - const showBar = props.collapsed || EXPANDED_CARD_IS_OVERLAY;
150 - const bar = showBar ? (
142 + const bar = (
143 <View
144 onLayout={handleBarLayout}
145 pointerEvents={props.collapsed ? "auto" : "none"}
@@ -188,25 +180,15 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
180 />
181 ) : null}
182 </View>
191 - ) : null;
192 - const card = renderCard ? (
183 + );
184 + const card = (
185 <Animated.View
186 onLayout={handleCardLayout}
187 pointerEvents={props.collapsed ? "none" : "auto"}
188 accessibilityElementsHidden={props.collapsed}
189 importantForAccessibility={props.collapsed ? "no-hide-descendants" : "auto"}
198 - entering={
199 - EXPANDED_CARD_IS_OVERLAY
200 - ? undefined
201 - : FadeInUp.duration(USER_INPUT_TOGGLE_DURATION_MS).easing(Easing.out(Easing.cubic))
202 - }
203 - exiting={
204 - EXPANDED_CARD_IS_OVERLAY
205 - ? undefined
206 - : FadeOutDown.duration(USER_INPUT_TOGGLE_DURATION_MS).easing(Easing.out(Easing.cubic))
207 - }
190 className="overflow-hidden gap-2.5 rounded-[20px] border border-border bg-card-alt p-4"
209 - style={EXPANDED_CARD_IS_OVERLAY ? cardAnimatedStyle : cardMaxHeightStyle}
191 + style={cardAnimatedStyle}
192 >
193 <Pressable
194 accessibilityRole="button"
@@ -345,21 +327,20 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
327 </Text>
328 ) : null}
329 </Animated.View>
348 - ) : null;
330 + );
331 return (
350 - <View className="relative">
332 + <Animated.View
333 + className="relative"
334 + style={Platform.OS === "android" ? androidBoundsStyle : undefined}
335 + >
336 {bar}
352 - {EXPANDED_CARD_IS_OVERLAY ? (
353 - <Animated.View
354 - pointerEvents={props.collapsed ? "none" : "box-none"}
355 - className="absolute inset-x-0 bottom-0 justify-end overflow-hidden"
356 - style={overlayHeightStyle}
357 - >
358 - {card}
359 - </Animated.View>
360 - ) : (
361 - card
362 - )}
363 - </View>
337 + <Animated.View
338 + pointerEvents={props.collapsed ? "none" : "box-none"}
339 + className="absolute inset-x-0 bottom-0 justify-end overflow-hidden"
340 + style={overlayHeightStyle}
341 + >
342 + {card}
343 + </Animated.View>
344 + </Animated.View>
345 );
346 }
apps/mobile/src/features/threads/ThreadDetailScreen.tsx
+77 -37
@@ -292,6 +292,7 @@ export interface ThreadDetailScreenProps {
292 text: string,
293 hasAttachmentsOrContext: boolean,
294 ) => Promise<boolean | "responded">,
295 + onWillEnqueue?: () => void,
296 ) => Promise<MessageId | null>;
297 readonly onReconnectEnvironment: () => void;
298 readonly canSwitchThreadProvider: boolean;
@@ -512,6 +513,8 @@ function ThreadDetailBody(
513 }, COMPOSER_HEIGHT_SETTLE_MS);
514 };
515 const [anchorMessageId, setAnchorMessageId] = useState<MessageId | null>(null);
516 + const [sendingWithKeyboard, setSendingWithKeyboard] = useState(false);
517 + if (sendingWithKeyboard && !isKeyboardVisible) setSendingWithKeyboard(false);
518 const feedRef = useRef<ThreadFeedHandle>(null);
519 const [endFollowEnabled, setEndFollowEnabled] = useState(true);
520 // Keep the bottom padding fixed while the keyboard animates. Changing it at
@@ -908,6 +911,7 @@ function ThreadDetailBody(
911 readonly collapsed: boolean;
912 } | null>(null);
913 const activeUserInputRequestId = props.activePendingUserInput?.requestId ?? null;
914 + const questionInFlow = Platform.OS === "android" && activeUserInputRequestId !== null;
915 const composerSlotHidden =
916 activeUserInputRequestId !== null || props.creationState?.kind === "failed";
917 const pendingMessageEditBlocked =
@@ -1011,7 +1015,7 @@ function ThreadDetailBody(
1015 const usageLimitsOpen = usageLimitsReport !== null && activeUserInputRequestId === null;
1016 const [usageLimitsLayout, setUsageLimitsLayout] = useState({ overlay: 0, panel: 0 });
1017 const handleComposerOverlayLayout = (event: LayoutChangeEvent) => {
1014 - onComposerLayout(event);
1018 + if (!questionInFlow) onComposerLayout(event);
1019 if (!usageLimitsOpen) return;
1020 const overlay = event.nativeEvent.layout.height;
1021 setUsageLimitsLayout((current) =>
@@ -1072,12 +1076,9 @@ function ThreadDetailBody(
1076 }
1077 overlayRepinTimerRef.current = setTimeout(() => {
1078 overlayRepinTimerRef.current = null;
1075 - if (!endFollowEnabledRef.current) {
1076 - return;
1077 - }
1078 - void scrollMessageToEnd({ animated: false, closeKeyboard: false }).catch(() => {
1079 - freeze.set(false);
1080 - });
1079 + const list = listRef.current;
1080 + if (!endFollowEnabledRef.current || !list || list.getState().isAtEnd) return;
1081 + void list.scrollToEnd({ animated: Platform.OS === "ios" && !reduceMotion });
1082 }, delayMs);
1083 };
1084 // LegendList does not re-anchor short followed conversations when floating
@@ -1101,20 +1102,24 @@ function ThreadDetailBody(
1102 ),
1103 [floatingCoverageTarget],
1104 );
1104 - // Android measures its expanded card in-flow; only iOS needs extra overlay coverage.
1105 const userInputCoverageApplies = Platform.OS === "ios" && activeUserInputRequestId !== null;
1106 + const questionStatusSpace = useAnimatedStyle(() => ({ height: floatingControlCoverage.value }));
1107 const combinedContentInsetEndAdjustment = useSharedValue(
1108 Math.max(0, estimatedOverlayHeight - nativeInsetOvercount),
1109 );
1110 useAnimatedReaction(
1111 () =>
1111 - contentInsetEndAdjustment.value +
1112 - floatingControlCoverage.value +
1113 - (userInputCoverageApplies ? userInputInsetProgress.value * userInputCardCoverage.value : 0),
1112 + questionInFlow
1113 + ? 0
1114 + : contentInsetEndAdjustment.value +
1115 + floatingControlCoverage.value +
1116 + (userInputCoverageApplies
1117 + ? userInputInsetProgress.value * userInputCardCoverage.value
1118 + : 0),
1119 (value) => {
1120 combinedContentInsetEndAdjustment.set(value);
1121 },
1117 - [userInputCoverageApplies],
1122 + [questionInFlow, userInputCoverageApplies],
1123 );
1124 const composerPopoverLift = useDerivedValue(() =>
1125 withTiming(
@@ -1152,11 +1157,11 @@ function ThreadDetailBody(
1157 }
1158 if (userInputCollapsed) {
1159 setUserInputToggle({ requestId: activeUserInputRequestId, collapsed: false });
1155 - scheduleOverlayRepin(USER_INPUT_TOGGLE_DURATION_MS + 50);
1160 + if (!questionInFlow) scheduleOverlayRepin(USER_INPUT_TOGGLE_DURATION_MS + 50);
1161 } else {
1162 Keyboard.dismiss();
1163 setUserInputToggle({ requestId: activeUserInputRequestId, collapsed: true });
1159 - scheduleOverlayRepin(60);
1164 + if (!questionInFlow) scheduleOverlayRepin(60);
1165 }
1166 };
1167 const showContent = props.showContent ?? true;
@@ -1264,7 +1269,18 @@ function ThreadDetailBody(
1269 );
1270 }
1271 : undefined;
1267 - const messageId = await props.onSendMessage(followUp, declineBeforeDispatch);
1272 + let dismissingKeyboard = false;
1273 + const messageId = await props.onSendMessage(followUp, declineBeforeDispatch, () => {
1274 + if (
1275 + scope.aborted ||
1276 + Platform.OS !== "ios" ||
1277 + !hasUserMessage ||
1278 + !KeyboardController.isVisible()
1279 + )
1280 + return;
1281 + setSendingWithKeyboard(true);
1282 + dismissingKeyboard = true;
1283 + });
1284 if (messageId === null || scope.aborted) {
1285 return messageId;
1286 }
@@ -1281,19 +1297,18 @@ function ThreadDetailBody(
1297 });
1298 feedRef.current?.resetEndFollow();
1299 setAnchorMessageId(nextAnchorMessageId);
1284 - composerEditorRef.current?.blur();
1285 - // The send enqueued the message optimistically, so it is in the feed or
1286 - // the queue by the next frame, once the new anchor has rendered.
1287 - if (nextAnchorMessageId === messageId && contentPresentationKind === "ready") {
1300 + if (!dismissingKeyboard) composerEditorRef.current?.blur();
1301 + const followSubmission =
1302 + contentPresentationKind === "ready" &&
1303 + (dismissingKeyboard || nextAnchorMessageId === messageId);
1304 + if (dismissingKeyboard || followSubmission) {
1305 + // Commit the optimistic row before UIKit chooses the closing scroll offset.
1306 requestAnimationFrame(() => {
1307 if (scope.aborted) return;
1290 - // Wait for the keyboard to finish dismissing: scrollMessageToEnd freezes
1291 - // keyboard-driven inset updates, and a close event swallowed by that
1292 - // freeze leaves a phantom bottom inset.
1308 + // Scrolling freezes the keyboard inset, so wait until dismissal has removed it.
1309 void KeyboardController.dismiss()
1310 .then(() => {
1295 - // A scroll during the dismissal turns end-follow off; leave the reader where they are.
1296 - if (scope.aborted || !endFollowEnabledRef.current) return;
1311 + if (!followSubmission || scope.aborted || !endFollowEnabledRef.current) return;
1312 return scrollMessageToEnd({ animated: !reduceMotion, closeKeyboard: false });
1313 })
1314 .catch(() => {
@@ -1451,10 +1466,14 @@ function ThreadDetailBody(
1466 ref={feedRef}
1467 contentInsetEndAdjustment={combinedContentInsetEndAdjustment}
1468 keyboardOffset={composerKeyboardOffset}
1469 + sendingWithKeyboard={sendingWithKeyboard}
1470 + fitShortFeedToViewport={questionInFlow && !isKeyboardVisible}
1471 contentTopInset={0}
1472 contentBottomInset={
1456 - estimatedOverlayHeight +
1457 - (showFloatingStatus ? FLOATING_WORKING_CONTROL_COVERAGE : 0)
1473 + questionInFlow
1474 + ? 0
1475 + : estimatedOverlayHeight +
1476 + (showFloatingStatus ? FLOATING_WORKING_CONTROL_COVERAGE : 0)
1477 }
1478 contentMaxWidth={contentMaxWidth}
1479 historyControls={props.historyControls}
@@ -1488,24 +1507,45 @@ function ThreadDetailBody(
1507 <KeyboardStickyView
1508 enabled={keyboardStickyEnabled}
1509 pointerEvents="box-none"
1491 - style={{ position: "absolute", bottom: 0, left: 0, right: 0, top: 0 }}
1510 + style={
1511 + questionInFlow
1512 + ? {
1513 + marginLeft: controlInsets.left,
1514 + marginRight: controlInsets.right,
1515 + marginBottom: controlInsets.bottom,
1516 + }
1517 + : { position: "absolute", bottom: 0, left: 0, right: 0, top: 0 }
1518 + }
1519 offset={{ closed: 0, opened: composerKeyboardOffset }}
1520 >
1494 - <ComposerPopoverHost hidden={composerSlotHidden} popoverHeight={composerPopoverHeight}>
1521 + {questionInFlow ? (
1522 + <Animated.View pointerEvents="none" style={questionStatusSpace} />
1523 + ) : null}
1524 + <ComposerPopoverHost
1525 + hidden={composerSlotHidden}
1526 + popoverHeight={composerPopoverHeight}
1527 + inFlow={questionInFlow}
1528 + >
1529 {/* The fixed sticky host gives this bottom-anchored child a stable
1530 coordinate space. Its top and height can then animate together
1531 instead of the auto-sized host jumping to Yoga's destination. */}
1532 <Animated.View
1533 pointerEvents="box-none"
1500 - style={[
1501 - {
1502 - position: "absolute",
1503 - bottom: controlInsets.bottom,
1504 - left: controlInsets.left,
1505 - right: controlInsets.right,
1506 - },
1507 - composerWidthStyle,
1508 - ]}
1534 + style={
1535 + questionInFlow
1536 + ? isSplitLayout
1537 + ? composerWidthStyle
1538 + : undefined
1539 + : [
1540 + {
1541 + position: "absolute",
1542 + bottom: controlInsets.bottom,
1543 + left: controlInsets.left,
1544 + right: controlInsets.right,
1545 + },
1546 + composerWidthStyle,
1547 + ]
1548 + }
1549 >
1550 {/* No paddingTop here: the overlay's measured height becomes the
1551 list's bottom inset, so any padding above the pill/composer
apps/mobile/src/features/threads/ThreadFeed.tsx
+157 -10
@@ -111,8 +111,10 @@ import {
111 useMemo,
112 useRef,
113 useState,
114 + useSyncExternalStore,
115 useId,
116 type ComponentPropsWithRef,
117 + type ComponentRef,
118 type ReactNode,
119 type Ref,
120 type RefObject,
@@ -131,6 +133,7 @@ import {
133 } from "react-native";
134 import { Image as ExpoImage } from "expo-image";
135 import { useResolveClassNames } from "uniwind";
136 +import { useReduceMotionEnabled } from "../../lib/appState";
137 import { useFilePreviewGallery, FilePreviewGallery } from "../../components/FilePreviewGallery";
138 import { assetImageSource } from "../../lib/assetImageSource";
139 import { composerImageGallery } from "../../lib/composerImageGallery";
@@ -315,9 +318,6 @@ const FEED_REFLOW_SETTLE_MS = 200;
318 const FEED_REFLOW_HOLD_MS = 600;
319 const USER_BUBBLE_HORIZONTAL_PADDING = 3.5 * 3.5;
320 const ASSISTANT_ROW_HORIZONTAL_PADDING = 3.5;
318 -const THREAD_FEED_DISCLOSURE_ENTER_TRANSITION = FadeIn.delay(
319 - THREAD_DISCLOSURE_TRANSITION_MS,
320 -).duration(140);
321
322 // Virtualization remounts old rows; only newly created content should replay an entrance.
323 const FRESH_ENTRY_WINDOW_MS = 3_000;
@@ -366,6 +366,8 @@ export interface ThreadFeedProps {
366 readonly onJumpedToMessage?: () => void;
367 readonly contentInsetEndAdjustment: SharedValue<number>;
368 readonly keyboardOffset: number;
369 + readonly sendingWithKeyboard?: boolean;
370 + readonly fitShortFeedToViewport?: boolean;
371 readonly contentTopInset?: number;
372 readonly contentBottomInset?: number;
373 readonly historyControls?: ThreadFeedHistoryControls;
@@ -2594,6 +2596,64 @@ function useThreadFeedPresentation(
2596 );
2597 }
2598
2599 +type DisclosureLayout = {
2600 + positions: ReadonlyMap<string, number>;
2601 + anchorIndex: number;
2602 + list: LegendListRef;
2603 + playing: boolean;
2604 +};
2605 +const DISCLOSURE_DETAIL_DELAY_MS = 135;
2606 +const DISCLOSURE_DETAIL_FADE_MS = 70;
2607 +const unsubscribeNothing = () => {};
2608 +
2609 +function DisclosureRow(props: {
2610 + itemKey: string;
2611 + index: number;
2612 + layout: DisclosureLayout | null;
2613 + children: ReactNode;
2614 +}) {
2615 + const { itemKey, layout } = props;
2616 + const previous = layout?.positions.get(itemKey);
2617 + const subscribe = useCallback(
2618 + (notify: () => void) => {
2619 + if (!layout || layout.playing || previous === undefined || previous <= 0)
2620 + return unsubscribeNothing;
2621 + return layout.list.getState().listenToPosition(itemKey, notify);
2622 + },
2623 + [itemKey, layout, previous],
2624 + );
2625 + const getOffset = () => {
2626 + if (!layout || layout.playing || previous === undefined || previous <= 0) return 0;
2627 + const state = layout.list.getState();
2628 + const position = state.positionAtIndex(props.index);
2629 + const anchor = state.positionAtIndex(layout.anchorIndex);
2630 + return position === undefined || anchor === undefined ? 0 : previous - (position - anchor);
2631 + };
2632 + const offset = useSyncExternalStore(subscribe, getOffset, getOffset);
2633 + const entering = !!layout && previous === undefined;
2634 + return (
2635 + <Animated.View
2636 + collapsable={false}
2637 + style={
2638 + layout
2639 + ? {
2640 + opacity: entering && !layout.playing ? 0 : 1,
2641 + transform: [{ translateY: offset }],
2642 + transitionProperty: layout?.playing ? (entering ? "opacity" : "transform") : "none",
2643 + transitionDuration: entering
2644 + ? DISCLOSURE_DETAIL_FADE_MS
2645 + : THREAD_DISCLOSURE_TRANSITION_MS,
2646 + transitionDelay: entering ? DISCLOSURE_DETAIL_DELAY_MS : 0,
2647 + transitionTimingFunction: "ease-out",
2648 + }
2649 + : undefined
2650 + }
2651 + >
2652 + {props.children}
2653 + </Animated.View>
2654 + );
2655 +}
2656 +
2657 export const ThreadFeed = memo(function ThreadFeed({
2658 ref,
2659 ...props
@@ -2640,6 +2700,17 @@ export const ThreadFeed = memo(function ThreadFeed({
2700 settledPaneWidth !== null ? Math.round(settledPaneWidth) : measuredViewportWidth;
2701 const [viewportHeight, setViewportHeight] = useState(0);
2702 const [disclosureToggleSettling, setDisclosureToggleSettling] = useState(false);
2703 + const [disclosureLayout, setDisclosureLayout] = useState<DisclosureLayout | null>(null);
2704 + const disclosureMotionRef = useRef<DisclosureLayout | null>(null);
2705 + const disclosureMotionTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
2706 + const reduceMotion = useReduceMotionEnabled();
2707 + const headerEndRef = useRef<ComponentRef<typeof View>>(null);
2708 + const lastFeedId = props.feed.at(-1)?.id;
2709 + const [disclosureGap, setDisclosureGap] = useState<{
2710 + space: number;
2711 + tail: typeof lastFeedId;
2712 + } | null>(null);
2713 + const disclosureTopSpace = disclosureGap?.tail === lastFeedId ? (disclosureGap?.space ?? 0) : 0;
2714 // LegendList's geometric follow threshold can reclaim users reading history when streamed rows grow.
2715 const [endFollowEnabled, setEndFollowEnabled] = useState(true);
2716 const endFollowEnabledRef = useRef(true);
@@ -3144,6 +3215,8 @@ export const ThreadFeed = memo(function ThreadFeed({
3215 // Include turn completion so unchanged message rows reveal their footer and spacing
3216 // even when the final message update arrives before the turn settles.
3217 const listAppearanceData = {
3218 + disclosureLayout,
3219 + reduceMotion,
3220 worktreeSetup: props.worktreeSetup,
3221 setupWorkingStartedAt: props.setupWorkingStartedAt,
3222 dispatchingMessageId: props.dispatchingMessageId,
@@ -3228,6 +3301,7 @@ export const ThreadFeed = memo(function ThreadFeed({
3301 resetEndFollow: () => {
3302 clearUserScrollSettle();
3303 userScrollSessionRef.current = false;
3304 + setDisclosureGap(null);
3305 cancelReflow();
3306 transitionEndFollow({ type: "reset" });
3307 },
@@ -3349,6 +3423,12 @@ export const ThreadFeed = memo(function ThreadFeed({
3423 // A native resize re-wraps the rows before JS hears of it. This event reaches JS ahead
3424 // of the row measurements it caused, since layout events are sent parent first.
3425 if (Math.abs(measuredViewportWidth - nextWidth) > 1) beginReflow();
3426 + if (
3427 + Math.abs(measuredViewportWidth - nextWidth) > 1 ||
3428 + Math.abs(viewportHeight - nextHeight) > 1
3429 + ) {
3430 + setDisclosureGap(null);
3431 + }
3432 setViewportWidth((current) => (Math.abs(current - nextWidth) > 1 ? nextWidth : current));
3433 setViewportHeight((current) => (Math.abs(current - nextHeight) > 1 ? nextHeight : current));
3434 };
@@ -3400,6 +3480,7 @@ export const ThreadFeed = memo(function ThreadFeed({
3480 if (userScrollSettleTimerRef.current !== null) clearTimeout(userScrollSettleTimerRef.current);
3481 if (reflowSettleTimerRef.current !== null) clearTimeout(reflowSettleTimerRef.current);
3482 if (copyFeedbackTimeoutRef.current) clearTimeout(copyFeedbackTimeoutRef.current);
3483 + if (disclosureMotionTimer.current !== null) clearTimeout(disclosureMotionTimer.current);
3484 if (disclosureSettleFrameRef.current !== null) {
3485 cancelAnimationFrame(disclosureSettleFrameRef.current);
3486 }
@@ -3429,6 +3510,20 @@ export const ThreadFeed = memo(function ThreadFeed({
3510 }
3511 disclosureAnchorKeyRef.current = null;
3512 setDisclosureToggleSettling(false);
3513 + const motion = disclosureMotionRef.current;
3514 + if (motion && !motion.playing) {
3515 + const playing = { ...motion, playing: true };
3516 + disclosureMotionRef.current = playing;
3517 + setDisclosureLayout(playing);
3518 + disclosureMotionTimer.current = setTimeout(
3519 + () => {
3520 + disclosureMotionRef.current = null;
3521 + setDisclosureLayout(null);
3522 + disclosureMotionTimer.current = null;
3523 + },
3524 + DISCLOSURE_DETAIL_DELAY_MS + DISCLOSURE_DETAIL_FADE_MS + 16,
3525 + );
3526 + }
3527 disclosureSettleFrameRef.current = null;
3528 disclosureSettleSecondFrameRef.current = null;
3529 });
@@ -3440,6 +3535,45 @@ export const ThreadFeed = memo(function ThreadFeed({
3535 // wake between the data mutation and LegendList's final layout correction.
3536 const suspendEndScrollMaintenanceForDisclosure = (anchorKey: string | null) => {
3537 cancelReflow();
3538 + const list = listRef.current;
3539 + if (list && anchorKey && !reduceMotion) {
3540 + const state = list.getState();
3541 + const anchorIndex = state.indexByKey(anchorKey);
3542 + if (anchorIndex !== undefined) {
3543 + const anchor = state.positionAtIndex(anchorIndex);
3544 + const anchorTop = state.elementAtIndex(anchorIndex)?.getBoundingClientRect().top;
3545 + const positions = new Map<string, number>();
3546 + for (let i = state.startBuffered; i <= state.endBuffered; i++) {
3547 + const item = groupedFeed[i];
3548 + if (!item) continue;
3549 + const displayed =
3550 + disclosureMotionRef.current &&
3551 + state.elementAtIndex(i)?.firstElementChild?.getBoundingClientRect().top;
3552 + positions.set(
3553 + item.id,
3554 + displayed != null && anchorTop !== undefined
3555 + ? displayed - anchorTop
3556 + : state.positionAtIndex(i) - anchor,
3557 + );
3558 + }
3559 + const motion = {
3560 + positions,
3561 + anchorIndex,
3562 + list,
3563 + playing: false,
3564 + };
3565 + if (disclosureMotionTimer.current !== null) clearTimeout(disclosureMotionTimer.current);
3566 + disclosureMotionRef.current = motion;
3567 + setDisclosureLayout(motion);
3568 + }
3569 + }
3570 + // Keep a short feed's bottom-alignment gap through collapse too; replacing it mid-frame moves the tap target.
3571 + const first = list?.getState().elementAtIndex(0);
3572 + if (first && headerEndRef.current) {
3573 + const gap =
3574 + first.getBoundingClientRect().top - headerEndRef.current.getBoundingClientRect().bottom;
3575 + if (gap > 1) setDisclosureGap({ space: disclosureTopSpace + gap, tail: lastFeedId });
3576 + }
3577 disclosureAnchorKeyRef.current = anchorKey;
3578 setDisclosureToggleSettling(true);
3579 settleDisclosureAfterLayout();
@@ -3583,9 +3717,11 @@ export const ThreadFeed = memo(function ThreadFeed({
3717 }, [textSizeKey, contentWidth, hasHtmlRenders, beginReflow, listRef]);
3718
3719 const renderItem = (info: { item: GroupedThreadFeedRow; index: number }) => (
3586 - <Animated.View
3720 + <DisclosureRow
3721 key={info.item.id}
3588 - entering={disclosureToggleSettling ? THREAD_FEED_DISCLOSURE_ENTER_TRANSITION : undefined}
3722 + itemKey={info.item.id}
3723 + index={info.index}
3724 + layout={disclosureLayout}
3725 >
3726 <MessageImageGalleryScope
3727 entry={info.item}
@@ -3654,7 +3790,7 @@ export const ThreadFeed = memo(function ThreadFeed({
3790 ) : null}
3791 </ThreadMediaVisibility>
3792 </MessageImageGalleryScope>
3657 - </Animated.View>
3793 + </DisclosureRow>
3794 );
3795
3796 if (props.contentPresentation.kind === "unavailable" && props.queuedMessages.length === 0) {
@@ -3711,7 +3847,7 @@ export const ThreadFeed = memo(function ThreadFeed({
3847 freeze={props.freeze}
3848 // Follow the measured end immediately; animating estimates races row measurement on acknowledgement.
3849 maintainScrollAtEnd={
3714 - disclosureToggleSettling || !followsEnd
3850 + disclosureToggleSettling || props.sendingWithKeyboard || !followsEnd
3851 ? false
3852 : {
3853 animated: false,
@@ -3727,7 +3863,10 @@ export const ThreadFeed = memo(function ThreadFeed({
3863 maintainScrollAtEndThreshold={reflowFollowsEnd ? Number.POSITIVE_INFINITY : undefined}
3864 sizeChangeAnchor={reflowAnchorsSizeChanges ? holdReflowAnchor : undefined}
3865 maintainVisibleContentPosition={
3730 - followsEnd && !disclosureToggleSettling ? false : maintainVisibleContentPosition
3866 + (followsEnd && !disclosureToggleSettling) ||
3867 + (disclosureToggleSettling && disclosureTopSpace > 0)
3868 + ? false
3869 + : maintainVisibleContentPosition
3870 }
3871 data={groupedFeed}
3872 extraData={listAppearanceData}
@@ -3737,6 +3876,12 @@ export const ThreadFeed = memo(function ThreadFeed({
3876 getItemType={(entry) => {
3877 if (entry.type !== "message") return entry.type;
3878 if (isCompactionCommandFeedEntry(entry)) return "message:compaction";
3879 + if (
3880 + entry.message.role === "assistant" &&
3881 + !terminalAssistantMessageIds.has(entry.message.id)
3882 + ) {
3883 + return "message:assistant-progress";
3884 + }
3885 const { attribution } = resolveUserMessagePresentation(entry.message);
3886 return attribution === "automation" || attribution === "agent"
3887 ? `message:${attribution}`
@@ -3748,7 +3893,7 @@ export const ThreadFeed = memo(function ThreadFeed({
3893 drawDistance={500}
3894 keyboardShouldPersistTaps="always"
3895 keyboardDismissMode="none"
3751 - keyboardLiftBehavior="whenAtEnd"
3896 + keyboardLiftBehavior={props.sendingWithKeyboard ? "persistent" : "whenAtEnd"}
3897 // Seed viewport size to skip programmatic attach-time positioning, which races UIKit's adjustedContentInset.
3898 {...(viewportHeight > 0 && viewportWidth > 0
3899 ? { estimatedListSize: { height: viewportHeight, width: viewportWidth } }
@@ -3781,6 +3926,7 @@ export const ThreadFeed = memo(function ThreadFeed({
3926 {props.historyControls ? (
3927 <ThreadFeedLoadEarlierControl {...props.historyControls} />
3928 ) : null}
3929 + <View ref={headerEndRef} collapsable={false} />
3930 </>
3931 }
3932 ListFooterComponent={
@@ -3795,7 +3941,8 @@ export const ThreadFeed = memo(function ThreadFeed({
3941 ) : null
3942 }
3943 contentContainerStyle={{
3798 - paddingTop: FEED_PADDING_TOP,
3944 + ...(props.fitShortFeedToViewport ? { minHeight: "100%" } : {}),
3945 + paddingTop: FEED_PADDING_TOP + disclosureTopSpace,
3946 paddingLeft: contentHorizontalPadding + contentLeftInset,
3947 paddingRight: contentHorizontalPadding + contentRightInset,
3948 }}
apps/mobile/src/lib/filePreview.test.ts
+4
@@ -80,6 +80,10 @@ vi.mock("react-native", () => ({
80 useWindowDimensions: () => ({ width: 390, height: 844, fontScale: 1 }),
81 Text: ({ children }: { children?: ReactNode }) => createElement("span", null, children),
82 AppState: { currentState: "active", addEventListener: () => ({ remove() {} }) },
83 + AccessibilityInfo: {
84 + isReduceMotionEnabled: async () => true,
85 + addEventListener: () => ({ remove() {} }),
86 + },
87 View: ({ children }: { children?: ReactNode }) => createElement("div", null, children),
88 Pressable: (props: {
89 children?: ReactNode;
apps/mobile/src/state/use-thread-composer-state.ts
+2
@@ -501,6 +501,7 @@ export function useThreadComposerState() {
501 text: string,
502 hasAttachmentsOrContext: boolean,
503 ) => Promise<boolean | "responded">,
504 + onWillEnqueue?: () => void,
505 ) => {
506 if (
507 selectedThreadShell &&
@@ -661,6 +662,7 @@ export function useThreadComposerState() {
662
663 const metadata = makeQueuedMessageMetadata();
664 const messageId = MessageId.make(metadata.messageId);
665 + onWillEnqueue?.();
666 clearThreadComposerError(threadKey);
667 const enqueuePromise = enqueueThreadOutboxMessage({
668 environmentId: selectedThreadShell.environmentId,