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, 20:45 UTC
fix(mobile): folded Back clears the detail route before the next selection (#22526)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 20, 2026 at 15:07 UTC
4af32312db6eebad26b158e65a0f2771abecd543
3 files changed
+196
-12
apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
+42
-12
@@ -44,9 +44,11 @@ import {
44
import { V5StackHeader } from "../../native/V5StackHeader.ios";
45
import type { AppNativeStackNavigationOptions } from "../../native/StackHeader";
46
import {
47
+ collapsedSplitTransition,
48
nativeWorkspacePopAction,
49
projectWorkspaceStack,
50
partitionStackPresentations,
51
+ type CollapsedSplitColumn,
52
} from "../../native/workspace-stack-projection";
53
import {
54
NativePrimaryColumnContext,
@@ -65,6 +67,7 @@ function ColumnScreen(props: {
67
readonly selectedPullRequestKey?: string | null;
68
readonly sidebarFilter?: NativeStackHeaderItemMenu;
69
readonly onDismiss: (routeKey: string) => void;
70
+ readonly onAppearance: (type: "willAppear" | "didAppear" | "willDisappear", key: string) => void;
71
readonly navigation: ViewProps["navigation"];
72
}) {
73
const { descriptor } = props;
@@ -85,15 +88,18 @@ function ColumnScreen(props: {
88
onDismiss={(event) => {
89
if (event.nativeEvent.isNativeDismiss) props.onDismiss(key);
90
}}
88
- onWillAppear={() =>
89
- props.navigation.emit({ type: "transitionStart", target: key, data: { closing: false } })
90
- }
91
- onDidAppear={() =>
92
- props.navigation.emit({ type: "transitionEnd", target: key, data: { closing: false } })
93
- }
94
- onWillDisappear={() =>
95
- props.navigation.emit({ type: "transitionStart", target: key, data: { closing: true } })
96
- }
91
+ onWillAppear={() => {
92
+ props.onAppearance("willAppear", key);
93
+ props.navigation.emit({ type: "transitionStart", target: key, data: { closing: false } });
94
+ }}
95
+ onDidAppear={() => {
96
+ props.onAppearance("didAppear", key);
97
+ props.navigation.emit({ type: "transitionEnd", target: key, data: { closing: false } });
98
+ }}
99
+ onWillDisappear={() => {
100
+ props.onAppearance("willDisappear", key);
101
+ props.navigation.emit({ type: "transitionStart", target: key, data: { closing: true } });
102
+ }}
103
onDidDisappear={() =>
104
props.navigation.emit({ type: "transitionEnd", target: key, data: { closing: true } })
105
}
@@ -130,7 +136,8 @@ function WorkspaceColumns(
136
const hostRef = useRef<SplitHostCommands>(null);
137
const activeDetailKey = props.detail.at(-1)?.key;
138
const compactColumn = activeDetailKey ? "secondary" : "primary";
133
- const shownCompactColumn = useRef(compactColumn);
139
+ const collapsed = useRef(!layout.usesSplitView);
140
+ const collapsedColumn = useRef<CollapsedSplitColumn>({ visible: compactColumn, leaving: null });
141
const threadParams = props.detail.findLast((route) => route.name === "Thread")?.params;
142
const pullRequestParams = props.detail.findLast(
143
(route) =>
@@ -169,10 +176,24 @@ function WorkspaceColumns(
176
},
177
[props.navigation],
178
);
179
+ const followCollapsedSplit = (
180
+ type: "willAppear" | "didAppear" | "willDisappear",
181
+ key: string,
182
+ ) => {
183
+ if (!collapsed.current || layout.usesSplitView) return;
184
+ const transition = collapsedSplitTransition(
185
+ collapsedColumn.current,
186
+ { type, key },
187
+ props.navigation.getState(),
188
+ props.primary.key,
189
+ );
190
+ collapsedColumn.current = transition.column;
191
+ if (transition.pop) props.navigation.dispatch(transition.pop);
192
+ };
193
194
useEffect(() => {
174
- if (layout.usesSplitView || shownCompactColumn.current === compactColumn) return;
175
- shownCompactColumn.current = compactColumn;
195
+ if (layout.usesSplitView || collapsedColumn.current.visible === compactColumn) return;
196
+ collapsedColumn.current = { ...collapsedColumn.current, visible: compactColumn };
197
hostRef.current?.show(compactColumn);
198
}, [compactColumn, layout.usesSplitView]);
199
@@ -185,6 +206,13 @@ function WorkspaceColumns(
206
testID="adaptive-workspace-layout"
207
preferredSplitBehavior="tile"
208
topColumnForCollapsing={compactColumn}
209
+ onCollapse={() => {
210
+ collapsed.current = true;
211
+ collapsedColumn.current = { visible: compactColumn, leaving: null };
212
+ }}
213
+ onExpand={() => {
214
+ collapsed.current = false;
215
+ }}
216
preferredDisplayMode={
217
panes.primarySidebarVisible || (!layout.usesSplitView && !activeDetailKey)
218
? "oneBesideSecondary"
@@ -211,6 +239,7 @@ function WorkspaceColumns(
239
selectedThreadKey={selectedThreadKey}
240
selectedPullRequestKey={selectedPullRequestKey}
241
onDismiss={handleNativeDismiss}
242
+ onAppearance={followCollapsedSplit}
243
navigation={props.navigation}
244
/>
245
</Split.Stack>
@@ -252,6 +281,7 @@ function WorkspaceColumns(
281
key={route.key}
282
descriptor={descriptor}
283
onDismiss={handleNativeDismiss}
284
+ onAppearance={followCollapsedSplit}
285
navigation={props.navigation}
286
sidebarFilter={sidebarFilter}
287
/>
apps/mobile/src/native/workspace-stack-projection.test.ts
+107
@@ -3,12 +3,14 @@ import type { ParamListBase, StackNavigationState } from "@react-navigation/nati
3
import { describe, expect, it } from "vite-plus/test";
4
5
import {
6
+ collapsedSplitTransition,
7
nativeStackPopAction,
8
nativeWorkspacePopAction,
9
nativeWorkspacePopCount,
10
projectWorkspaceStack,
11
partitionStackPresentations,
12
reconcileStackScreens,
13
+ type CollapsedSplitColumn,
14
} from "./workspace-stack-projection";
15
16
const requireNavigation = NodeModule.createRequire(
@@ -185,6 +187,111 @@ describe("native card pop handoff", () => {
187
});
188
});
189
190
+describe("collapsed split Back", () => {
191
+ const routerOptions = {
192
+ routeNames: history([home]).routeNames,
193
+ routeParamList: {},
194
+ routeGetIdList: {},
195
+ };
196
+ type Appearance = "willAppear" | "didAppear" | "willDisappear";
197
+ // UIKit's appearance callbacks for one collapsed transition, against the router at each step.
198
+ function replay(
199
+ steps: ReadonlyArray<readonly [Appearance, string, StackNavigationState<ParamListBase>]>,
200
+ ) {
201
+ let column: CollapsedSplitColumn = { visible: "secondary", leaving: null };
202
+ let pop: ReturnType<typeof nativeStackPopAction> = null;
203
+ for (const [type, key, state] of steps) {
204
+ const transition = collapsedSplitTransition(column, { type, key }, state, home.key);
205
+ column = transition.column;
206
+ pop ??= transition.pop;
207
+ }
208
+ return { visible: column.visible, pop };
209
+ }
210
+
211
+ it("returns the router to the list so the next selection opens a new detail", () => {
212
+ const state = history([home, thread]);
213
+ const back = replay([
214
+ ["willDisappear", thread.key, state],
215
+ ["willAppear", home.key, state],
216
+ ["didAppear", home.key, state],
217
+ ]);
218
+ expect(back.visible).toBe("primary");
219
+ const router = StackRouter({});
220
+ const listed = router.getStateForAction(state, back.pop!, routerOptions);
221
+ expect(listed?.routes).toEqual([home]);
222
+ if (!listed || listed.stale !== false) throw new Error("Expected a rehydrated router history");
223
+ const select = {
224
+ type: "NAVIGATE",
225
+ payload: { name: "Thread", params: { threadId: "next" } },
226
+ } as const;
227
+ expect(router.getStateForAction(listed, select, routerOptions)?.routes[1]?.key).not.toBe(
228
+ thread.key,
229
+ );
230
+ // Left on the hidden detail, the selection would only rename it and never show the column.
231
+ expect(router.getStateForAction(state, select, routerOptions)?.routes[1]?.key).toBe(thread.key);
232
+ });
233
+
234
+ it("clears every detail while keeping a presentation opened during the Back animation", () => {
235
+ const leaving = history([home, thread, files]);
236
+ const presented = history([home, thread, files, settings]);
237
+ const { pop } = replay([
238
+ ["willDisappear", files.key, leaving],
239
+ ["didAppear", home.key, presented],
240
+ ]);
241
+ expect(StackRouter({}).getStateForAction(presented, pop!, routerOptions)?.routes).toEqual([
242
+ home,
243
+ settings,
244
+ ]);
245
+ });
246
+
247
+ it("keeps the detail when it appears again before the list finishes appearing", () => {
248
+ const state = history([home, thread]);
249
+ const cancelledSwipe = replay([
250
+ ["willDisappear", thread.key, state],
251
+ ["willAppear", home.key, state],
252
+ ["willAppear", thread.key, state],
253
+ ["didAppear", thread.key, state],
254
+ ]);
255
+ expect(cancelledSwipe).toEqual({ visible: "secondary", pop: null });
256
+ expect(
257
+ replay([
258
+ ["willDisappear", thread.key, state],
259
+ ["willAppear", thread.key, state],
260
+ ["didAppear", home.key, state],
261
+ ]).pop,
262
+ ).toBeNull();
263
+ });
264
+
265
+ it("does not mistake JS navigation or a cold link for native Back", () => {
266
+ const pushed = history([home, thread, files]);
267
+ expect(
268
+ replay([
269
+ ["willDisappear", thread.key, pushed],
270
+ ["didAppear", files.key, pushed],
271
+ ]),
272
+ ).toEqual({ visible: "secondary", pop: null });
273
+ const presented = history([home, thread, settings]);
274
+ expect(
275
+ replay([
276
+ ["willDisappear", thread.key, presented],
277
+ ["didAppear", home.key, presented],
278
+ ]).pop,
279
+ ).toBeNull();
280
+ const popped = history([home]);
281
+ expect(
282
+ replay([
283
+ ["willDisappear", thread.key, popped],
284
+ ["didAppear", home.key, popped],
285
+ ]).pop,
286
+ ).toBeNull();
287
+ // A linked thread whose list appears first still needs its detail column shown.
288
+ expect(replay([["didAppear", home.key, history([home, thread])]])).toEqual({
289
+ visible: "primary",
290
+ pop: null,
291
+ });
292
+ });
293
+});
294
+
295
describe("v5 stack handoff", () => {
296
it("releases a completed native pop when the router acknowledges it", () => {
297
const completed = new Set([files.key]);
apps/mobile/src/native/workspace-stack-projection.ts
+47
@@ -70,6 +70,53 @@ export function nativeStackPopAction(
70
};
71
}
72
73
+/** The column UIKit shows while a split is collapsed, and the active detail it began removing. */
74
+export interface CollapsedSplitColumn {
75
+ readonly visible: "primary" | "secondary";
76
+ readonly leaving: string | null;
77
+}
78
+
79
+/**
80
+ * A collapsed split nests the detail column's navigation controller in the list column's. Back
81
+ * from the detail root pops that controller whole, so no screen leaves its own stack or reports a
82
+ * dismissal: the list appearing after the active detail began leaving is the only sign of it.
83
+ */
84
+export function collapsedSplitTransition(
85
+ column: CollapsedSplitColumn,
86
+ event: { readonly type: "willAppear" | "didAppear" | "willDisappear"; readonly key: string },
87
+ state: Pick<NavigationState, "key" | "index" | "routes">,
88
+ primaryKey: string,
89
+): {
90
+ readonly column: CollapsedSplitColumn;
91
+ readonly pop: ReturnType<typeof nativeStackPopAction>;
92
+} {
93
+ switch (event.type) {
94
+ case "willDisappear":
95
+ // JS pushes, pops, and presentations have already moved the router past this screen.
96
+ return {
97
+ column:
98
+ state.index > 0 && state.routes[state.index]?.key === event.key
99
+ ? { ...column, leaving: event.key }
100
+ : column,
101
+ pop: null,
102
+ };
103
+ case "willAppear":
104
+ // A cancelled swipe, or an expansion that keeps the detail on screen.
105
+ return {
106
+ column: column.leaving === event.key ? { ...column, leaving: null } : column,
107
+ pop: null,
108
+ };
109
+ case "didAppear":
110
+ return {
111
+ column: { visible: event.key === primaryKey ? "primary" : "secondary", leaving: null },
112
+ pop:
113
+ event.key === primaryKey && column.leaving
114
+ ? nativeStackPopAction(state, column.leaving, primaryKey)
115
+ : null,
116
+ };
117
+ }
118
+}
119
+
120
export function partitionStackPresentations<T>(
121
routes: readonly T[],
122
isModal: (route: T) => boolean,