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, 18:15 UTC
fix(mobile): threads open with less waiting, and the Threads tab remembers drafts (#24750)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 25, 2026 at 00:41 UTC
8d3261ebc222f26a402afa2332b599925ddc43b7
9 files changed
+179
-46
apps/mobile/src/features/home/thread-swipe-actions.tsx
+77
-40
@@ -121,6 +121,9 @@ function resolveSecondaryAction(input: {
121
122
/** Keep the scroll gate in context so scroll start cannot re-render every row and its subscriptions. */
123
const SwipeableScrollGateContext = createContext(true);
124
+// Swipeable rebuilds its native pan gesture whenever its config changes identity, so the props
125
+// that feed it stay stable across row re-renders such as selection.
126
+const FAIL_OFFSET_Y: [number, number] = [-10, 10];
127
128
export function SwipeableScrollGateProvider(props: {
129
readonly enabled: boolean;
@@ -402,11 +405,77 @@ export function ThreadSwipeable(props: ThreadSwipeableProps) {
405
},
406
[content],
407
);
405
- const handleWillOpen = () => {
406
- if (!props.dormant && !dismissalRef.current && swipeableRef.current) {
407
- props.onSwipeableWillOpen?.(swipeableRef.current);
408
+ const { dormant, onSwipeableWillOpen, backgroundColor, containerStyle } = props;
409
+ const handleWillOpen = useCallback(() => {
410
+ if (!dormant && !dismissalRef.current && swipeableRef.current) {
411
+ onSwipeableWillOpen?.(swipeableRef.current);
412
}
413
+ }, [dormant, onSwipeableWillOpen]);
414
+ const handleSwipeableClose = useCallback(() => {
415
+ if (swipeableRef.current) onSwipeableClose?.(swipeableRef.current);
416
+ }, [onSwipeableClose]);
417
+ const compactActions = props.compactActions === true;
418
+ const { secondaryAction, threadTitle } = props;
419
+ // Swipeable calls this on every render; returning the previous element while nothing it shows
420
+ // changed keeps a selection change from re-rendering the hidden actions.
421
+ const rightActions = useRef<{ deps: readonly unknown[]; element: ReactNode } | null>(null);
422
+ const renderRightActions = (
423
+ _progress: SharedValue<number>,
424
+ translation: SharedValue<number>,
425
+ methods: SwipeableMethods,
426
+ ) => {
427
+ const deps = [
428
+ dormant,
429
+ translation,
430
+ methods,
431
+ actionStyle,
432
+ backgroundColor,
433
+ compactActions,
434
+ fullSwipeAction,
435
+ fullSwipeThreshold,
436
+ handleFullSwipeArmedChange,
437
+ primaryAction,
438
+ commitPrimaryAction,
439
+ onDelete,
440
+ secondaryAction,
441
+ threadTitle,
442
+ ];
443
+ const cached = rightActions.current;
444
+ if (cached && deps.every((dep, index) => Object.is(dep, cached.deps[index]))) {
445
+ return cached.element;
446
+ }
447
+ const element = dormant ? null : (
448
+ <Animated.View
449
+ ref={() => {
450
+ activeTranslationRef.current = translation;
451
+ }}
452
+ style={actionStyle}
453
+ >
454
+ <ThreadSwipeActions
455
+ backgroundColor={backgroundColor}
456
+ compact={compactActions}
457
+ fullSwipeAction={fullSwipeAction}
458
+ fullSwipeThreshold={fullSwipeThreshold}
459
+ onFullSwipeArmedChange={handleFullSwipeArmedChange}
460
+ primaryAction={{ ...primaryAction, onPress: commitPrimaryAction }}
461
+ secondaryAction={resolveSecondaryAction({
462
+ close: () => methods.close(),
463
+ onDelete,
464
+ secondaryAction,
465
+ threadTitle,
466
+ })}
467
+ translation={translation}
468
+ />
469
+ </Animated.View>
470
+ );
471
+ rightActions.current = { deps, element };
472
+ return element;
473
};
474
+ const childrenContainerStyle = useMemo(() => ({ backgroundColor }), [backgroundColor]);
475
+ const swipeableContainerStyle = useMemo(
476
+ () => [{ backgroundColor }, containerStyle],
477
+ [backgroundColor, containerStyle],
478
+ );
479
480
return (
481
<Animated.View style={dismissStyle}>
@@ -419,53 +488,21 @@ export function ThreadSwipeable(props: ThreadSwipeableProps) {
488
<ReanimatedSwipeable
489
ref={swipeableRef}
490
animationOptions={THREAD_SWIPE_SPRING}
422
- childrenContainerStyle={{ backgroundColor: props.backgroundColor }}
423
- containerStyle={[{ backgroundColor: props.backgroundColor }, props.containerStyle]}
491
+ childrenContainerStyle={childrenContainerStyle}
492
+ containerStyle={swipeableContainerStyle}
493
dragOffsetFromRight={-8}
494
enabled={!props.dormant && !isDismissing && props.enabled !== false && gateEnabled}
495
enableTrackpadTwoFingerGesture={props.enableTrackpadSwipe ?? true}
496
// Reject vertical pans via patched RNGH failOffsetY; simultaneous trackpad scrolls otherwise open rows on horizontal drift.
428
- failOffsetY={[-10, 10]}
497
+ failOffsetY={FAIL_OFFSET_Y}
498
friction={1}
430
- onSwipeableClose={() => {
431
- if (swipeableRef.current) {
432
- props.onSwipeableClose?.(swipeableRef.current);
433
- }
434
- }}
499
+ onSwipeableClose={handleSwipeableClose}
500
onSwipeableRelease={handleRelease}
501
onSwipeableOpenStartDrag={handleWillOpen}
502
onSwipeableWillOpen={handleWillOpen}
503
overshootFriction={1}
504
overshootRight
440
- renderRightActions={(_progress, translation, methods) =>
441
- props.dormant ? null : (
442
- <Animated.View
443
- ref={() => {
444
- activeTranslationRef.current = translation;
445
- }}
446
- style={actionStyle}
447
- >
448
- <ThreadSwipeActions
449
- backgroundColor={props.backgroundColor}
450
- compact={props.compactActions === true}
451
- fullSwipeAction={fullSwipeAction}
452
- fullSwipeThreshold={fullSwipeThreshold}
453
- onFullSwipeArmedChange={handleFullSwipeArmedChange}
454
- primaryAction={{
455
- ...primaryAction,
456
- onPress: commitPrimaryAction,
457
- }}
458
- secondaryAction={resolveSecondaryAction({
459
- close: () => methods.close(),
460
- onDelete: props.onDelete,
461
- secondaryAction: props.secondaryAction,
462
- threadTitle: props.threadTitle,
463
- })}
464
- translation={translation}
465
- />
466
- </Animated.View>
467
- )
468
- }
505
+ renderRightActions={renderRightActions}
506
rightThreshold={actionsWidth * 0.42}
507
simultaneousWith={props.simultaneousWith}
508
>
apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
+2
@@ -66,6 +66,7 @@ import {
66
type WorkspaceDetail,
67
type WorkspaceDetailSheet,
68
} from "../workspace/workspace-detail-selection";
69
+import { startOpeningDetail } from "../workspace/useSelectWorkspaceDetail";
70
import { useWorkspaceTabs } from "../workspace/WorkspaceTabsContext";
71
import { HomeListOptionsProvider } from "../home/home-list-options";
72
import { newTaskDestination } from "../threads/new-task-project-selection";
@@ -498,6 +499,7 @@ function AdaptiveWorkspaceLayoutContent(
499
type: "select",
500
tab: detail.name === "Thread" ? "threads" : "pullRequests",
501
});
502
+ startOpeningDetail(detail);
503
navigation.dispatch(selectWorkspaceDetail(detail, sheet));
504
});
505
}
apps/mobile/src/features/threads/ThreadDetailScreen.tsx
+22
-1
@@ -499,6 +499,9 @@ function ThreadVisitWatermark(props: {
499
return null;
500
}
501
502
+// Past the composer's 180 ms height animation.
503
+const COMPOSER_HEIGHT_SETTLE_MS = 220;
504
+
505
export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetailScreenProps) {
506
const usesNativeWorkspaceColumns = useNativeWorkspaceColumnsSupported();
507
const deviceType = useDeviceType();
@@ -601,6 +604,24 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
604
const selectedThreadKeyRef = useRef(selectedThreadKey);
605
const lastScrolledSubmittedMessageIdRef = useRef<MessageId | null>(null);
606
const [composerHeight, setComposerHeight] = useState<number | null>(null);
607
+ // The composer animates its height and reports a layout every frame. The feed follows those
608
+ // frames on the UI thread through onComposerLayout; this is only an estimate, so committing
609
+ // each frame would re-render the whole screen for the length of the animation.
610
+ const composerHeightSettle = useRef<ReturnType<typeof setTimeout> | null>(null);
611
+ const handleComposerHeightChange = useCallback((height: number) => {
612
+ setComposerHeight((current) => current ?? height);
613
+ if (composerHeightSettle.current !== null) clearTimeout(composerHeightSettle.current);
614
+ composerHeightSettle.current = setTimeout(() => {
615
+ composerHeightSettle.current = null;
616
+ setComposerHeight(height);
617
+ }, COMPOSER_HEIGHT_SETTLE_MS);
618
+ }, []);
619
+ useEffect(
620
+ () => () => {
621
+ if (composerHeightSettle.current !== null) clearTimeout(composerHeightSettle.current);
622
+ },
623
+ [],
624
+ );
625
const [anchorMessageId, setAnchorMessageId] = useState<MessageId | null>(null);
626
const [submittedMessageId, setSubmittedMessageId] = useState<MessageId | null>(null);
627
const [endFollowEnabled, setEndFollowEnabled] = useState(true);
@@ -1804,7 +1825,7 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
1825
onUpdateModelSelection={props.onUpdateThreadModelSelection}
1826
onUpdateRuntimeMode={props.onUpdateThreadRuntimeMode}
1827
onUpdateInteractionMode={props.onUpdateThreadInteractionMode}
1807
- onHeightChange={setComposerHeight}
1828
+ onHeightChange={handleComposerHeightChange}
1829
onEditorFocusChange={handleOwnedInputFocusChange}
1830
/>
1831
</>
apps/mobile/src/features/workspace/useSelectWorkspaceDetail.ts
+19
-2
@@ -1,11 +1,26 @@
1
+import { EnvironmentId, ThreadId } from "@t3tools/contracts";
2
import { useNavigation } from "@react-navigation/native";
3
import { useAdaptiveWorkspaceLayout } from "../layout/adaptive-workspace-context";
4
+import { startOpeningEnvironmentThread } from "../../state/threads";
5
import {
6
selectWorkspaceDetail,
7
type WorkspaceDetail,
8
type WorkspaceDetailSheet,
9
} from "./workspace-detail-selection";
10
11
+const first = (value: string | readonly string[] | undefined) =>
12
+ typeof value === "string" ? value : value?.[0];
13
+
14
+/** Starts loading a selected thread before navigation commits; see `startOpeningEnvironmentThread`. */
15
+export function startOpeningDetail(detail: WorkspaceDetail) {
16
+ if (detail.name !== "Thread") return;
17
+ const environmentId = first(detail.params?.environmentId);
18
+ const threadId = first(detail.params?.threadId);
19
+ if (environmentId && threadId) {
20
+ startOpeningEnvironmentThread(EnvironmentId.make(environmentId), ThreadId.make(threadId));
21
+ }
22
+}
23
+
24
/**
25
* Shows a page in the detail column the way selecting its list row does. Inside the workspace
26
* layout this also settles its panes; outside it, the root stack's router still does the rest.
@@ -15,7 +30,9 @@ export function useSelectWorkspaceDetail() {
30
const { selectDetail } = useAdaptiveWorkspaceLayout();
31
return (
32
selectDetail ??
18
- ((detail: WorkspaceDetail, sheet?: WorkspaceDetailSheet) =>
19
- navigation.dispatch(selectWorkspaceDetail(detail, sheet)))
33
+ ((detail: WorkspaceDetail, sheet?: WorkspaceDetailSheet) => {
34
+ startOpeningDetail(detail);
35
+ navigation.dispatch(selectWorkspaceDetail(detail, sheet));
36
+ })
37
);
38
}
apps/mobile/src/features/workspace/workspace-selection-store.ts
+1
-1
@@ -51,7 +51,7 @@ function save() {
51
function withoutRouteKeys(saved: WorkspaceSelections | undefined): WorkspaceSelections {
52
const omitKey = <Selection extends { readonly key?: string }>({ key: _, ...rest }: Selection) =>
53
rest;
54
- const { threads, pullRequests, settingsKey: _, ...rest } = saved ?? {};
54
+ const { threads, pullRequests, settingsKey: _, threadsDraft: _draft, ...rest } = saved ?? {};
55
return {
56
...rest,
57
...(threads ? { threads: omitKey(threads) } : {}),
apps/mobile/src/features/workspace/workspace-tab-navigation.test.ts
+24
@@ -96,6 +96,30 @@ describe("opening a workspace tab", () => {
96
expect(back.routes.at(-1)).toMatchObject({ key: "thread", params: thread.params });
97
});
98
99
+ it("reopens a draft the tab showed after its last chat, until another chat opens", () => {
100
+ const columns = { columns: true, check: available };
101
+ const draft = { key: "draft", name: "Thread", params: { draft: { requestId: "r" } } };
102
+ const withDraft = workspaceSelectionsIn(
103
+ [home, draft],
104
+ workspaceSelectionsIn([home, thread], {}),
105
+ );
106
+ const back = workspaceTabNavigationState(
107
+ { routes: [home, settings] },
108
+ "threads",
109
+ withDraft,
110
+ columns,
111
+ );
112
+ expect(back.routes.at(-1)).toEqual(draft);
113
+ const afterChat = workspaceSelectionsIn([home, thread], withDraft);
114
+ const again = workspaceTabNavigationState(
115
+ { routes: [home, settings] },
116
+ "threads",
117
+ afterChat,
118
+ columns,
119
+ );
120
+ expect(again.routes.at(-1)).toMatchObject({ key: "thread", params: thread.params });
121
+ });
122
+
123
it("falls back to the list for a chat that no longer exists, or an unknown Settings page", () => {
124
const missing = { thread: () => false, pullRequest: () => true };
125
expect(
apps/mobile/src/features/workspace/workspace-tab-navigation.ts
+20
-2
@@ -91,9 +91,17 @@ export function workspaceSelectionsIn(
91
threadId &&
92
(next.threads?.environmentId !== environmentId ||
93
next.threads.threadId !== threadId ||
94
- next.threads.key !== thread?.key)
94
+ next.threads.key !== thread?.key ||
95
+ next.threadsDraft)
96
) {
96
- next = { ...next, threads: { environmentId, threadId, key: thread?.key } };
97
+ const { threadsDraft: _, ...rest } = next;
98
+ next = { ...rest, threads: { environmentId, threadId, key: thread?.key } };
99
+ } else if (
100
+ thread?.key !== undefined &&
101
+ !threadId &&
102
+ (next.threadsDraft?.key !== thread.key || next.threadsDraft.params !== thread.params)
103
+ ) {
104
+ next = { ...next, threadsDraft: { key: thread.key, params: thread.params } };
105
}
106
const pullRequestRoute = routes.findLast((route) => route.name === "PullRequest");
107
const pullRequest = pullRequestSelection(pullRequestRoute?.params);
@@ -136,6 +144,16 @@ function detailRoute(
144
check: WorkspaceSelectionCheck,
145
): RouteLike | undefined {
146
if (tab === "threads") {
147
+ const draft = selections.threadsDraft;
148
+ if (draft) {
149
+ return (
150
+ state.routes.find((route) => route.key === draft.key) ?? {
151
+ key: draft.key,
152
+ name: "Thread",
153
+ params: draft.params as object | undefined,
154
+ }
155
+ );
156
+ }
157
const thread = selections.threads;
158
if (!thread || !check.thread(thread)) return undefined;
159
return (
apps/mobile/src/persistence/mobile-preferences.ts
+2
@@ -71,6 +71,8 @@ const WorkspaceSelections = Schema.Struct({
71
),
72
settings: Schema.optional(Schema.String),
73
settingsKey: Schema.optional(Schema.String),
74
+ /** A draft the threads tab showed after its last chat; only meaningful in its session. */
75
+ threadsDraft: Schema.optional(Schema.Struct({ key: Schema.String, params: Schema.Unknown })),
76
});
77
export type WorkspaceSelections = typeof WorkspaceSelections.Type;
78
apps/mobile/src/state/threads.ts
+12
@@ -46,6 +46,18 @@ export function useThreadFamily(
46
}, [environmentId, rootThreadId]);
47
}
48
49
+// Long enough for the opened screen to subscribe; its subscription keeps the thread after this.
50
+const OPENING_THREAD_HOLD_MS = 3_000;
51
+
52
+/**
53
+ * Starts loading a thread being opened before its screen renders and subscribes, which
54
+ * otherwise waits for navigation to commit.
55
+ */
56
+export function startOpeningEnvironmentThread(environmentId: EnvironmentId, threadId: ThreadId) {
57
+ const release = appAtomRegistry.mount(environmentThreads.stateAtom(environmentId, threadId));
58
+ setTimeout(release, OPENING_THREAD_HOLD_MS);
59
+}
60
+
61
const EMPTY_THREAD_STATE_ATOM = Atom.make(AsyncResult.success(EMPTY_ENVIRONMENT_THREAD_STATE)).pipe(
62
Atom.withLabel("mobile-environment-thread:empty"),
63
);