Skip to content

Commit 7bff9d5

Browse files
fix(mobile): update the iOS Git header menu when status changes
The native header only re-reads its stabilized item factories when optionsVersion changes, and the thread header keyed it on project scripts alone. A refreshed Git status (for example after reconnect) never reached the header Git popover, which kept showing the old "Clean" state. Key optionsVersion on the memoized header items instead. The options signature still compares by content, so streaming re-renders with equal items do not re-apply options. ThreadHeader moves to its own module so the test drives the production header wiring. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 3eb1c7a commit 7bff9d5

5 files changed

Lines changed: 273 additions & 110 deletions

File tree

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import { StackActions, useNavigation } from "@react-navigation/native";
2+
import { useMemo } from "react";
3+
import { ScreenHeader } from "../../components/ScreenHeader";
4+
import { ScreenHeaderButton } from "../../components/ScreenHeaderButton";
5+
import type { ScreenHeaderAction } from "../../components/ScreenHeader.types";
6+
import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
7+
import type { ThreadInspectorMode } from "./thread-inspector-content-stack";
8+
import { useThreadHeaderOptions } from "./useThreadHeaderOptions";
9+
10+
export function ThreadHeader(
11+
props: Parameters<typeof useThreadHeaderOptions>[0] & {
12+
readonly hasThreadCwd: boolean;
13+
readonly hasWorkspaceRoot: boolean;
14+
readonly fileInspectorSupported: boolean;
15+
readonly inspectorMode: ThreadInspectorMode | null;
16+
readonly onToggleInspector: () => void;
17+
readonly onOpenGitInspector: () => void;
18+
readonly onOpenFilesInspector: () => void;
19+
},
20+
) {
21+
const navigation = useNavigation();
22+
const { layout, panes, toggleAuxiliaryPane } = useAdaptiveWorkspaceLayout();
23+
const { onOpenTerminal, onMergeBack } = props.gitControls;
24+
const native = useThreadHeaderOptions(props);
25+
const androidHeaderActions = useMemo<ReadonlyArray<ScreenHeaderAction>>(() => {
26+
const actions: ScreenHeaderAction[] = [];
27+
if (props.onReturnToThread) {
28+
actions.push({
29+
accessibilityLabel: "Return to chat",
30+
icon: "chevron.left",
31+
onPress: props.onReturnToThread,
32+
});
33+
}
34+
if (props.hasThreadCwd) {
35+
const filesVisible = props.inspectorMode === "files" && panes.auxiliaryPaneVisible;
36+
actions.push({
37+
accessibilityLabel: filesVisible ? "Close files" : "Open files",
38+
selected: filesVisible,
39+
icon: "folder",
40+
onPress: filesVisible ? toggleAuxiliaryPane : props.onOpenFilesInspector,
41+
});
42+
}
43+
if (props.hasWorkspaceRoot) {
44+
actions.push({
45+
accessibilityLabel: "Open terminal",
46+
icon: "terminal",
47+
onPress: () => onOpenTerminal(null),
48+
});
49+
}
50+
actions.push({
51+
accessibilityLabel: "Open git controls",
52+
icon: "point.topleft.down.curvedto.point.bottomright.up",
53+
onPress: props.onOpenGitInspector,
54+
});
55+
if (onMergeBack) {
56+
actions.push({
57+
accessibilityLabel: "Merge back to source",
58+
icon: "arrow.triangle.merge",
59+
onPress: onMergeBack,
60+
});
61+
}
62+
return actions;
63+
}, [
64+
props.inspectorMode,
65+
panes.auxiliaryPaneVisible,
66+
props.onOpenFilesInspector,
67+
onOpenTerminal,
68+
onMergeBack,
69+
props.onOpenGitInspector,
70+
toggleAuxiliaryPane,
71+
props.onReturnToThread,
72+
props.hasThreadCwd,
73+
props.hasWorkspaceRoot,
74+
]);
75+
76+
return (
77+
<>
78+
<ScreenHeader
79+
title={props.title}
80+
subtitle={props.subtitle}
81+
sidebar={native.sidebar}
82+
options={native.options}
83+
optionsVersion={native.optionsVersion}
84+
trailing={
85+
props.fileInspectorSupported && props.hasThreadCwd ? (
86+
<ScreenHeaderButton
87+
accessibilityLabel={
88+
props.inspectorMode !== null && panes.auxiliaryPaneVisible
89+
? "Hide inspector"
90+
: "Show inspector"
91+
}
92+
icon="sidebar.right"
93+
selected={props.inspectorMode !== null && panes.auxiliaryPaneVisible}
94+
onPress={props.onToggleInspector}
95+
/>
96+
) : null
97+
}
98+
onBack={
99+
layout.usesSplitView
100+
? undefined
101+
: () => {
102+
// A deep link or cold start has no previous route; Home is the way out.
103+
// Read the history at press time: it changes without re-rendering this screen.
104+
if (navigation.canGoBack()) navigation.goBack();
105+
else navigation.dispatch(StackActions.replace("Home"));
106+
}
107+
}
108+
actions={androidHeaderActions}
109+
hideBottomBorder
110+
/>
111+
{native.fallback}
112+
</>
113+
);
114+
}

‎apps/mobile/src/features/threads/ThreadRouteScreen.tsx‎

Lines changed: 1 addition & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ import { makeTurnCommandMetadata } from "../../lib/commandMetadata";
22
import { buildProjectThreadStartTurnInput } from "../../lib/projectThreadStartTurn";
33
import { useWorktreeSetup } from "./use-worktree-setup";
44
import { worktreeSetupAgentStarted } from "@t3tools/client-runtime/worktree-setup";
5-
import { ScreenHeader } from "../../components/ScreenHeader";
6-
import { ScreenHeaderButton } from "../../components/ScreenHeaderButton";
7-
import type { ScreenHeaderAction } from "../../components/ScreenHeader.types";
8-
import { useThreadHeaderOptions } from "./useThreadHeaderOptions";
95
import {
106
StackActions,
117
useFocusEffect,
@@ -83,112 +79,7 @@ import {
8379
type ThreadInspectorMode,
8480
} from "./thread-inspector-content-stack";
8581
import { threadRouteIsHydrating } from "./thread-route-hydration";
86-
87-
function ThreadHeader(
88-
props: Parameters<typeof useThreadHeaderOptions>[0] & {
89-
readonly hasThreadCwd: boolean;
90-
readonly hasWorkspaceRoot: boolean;
91-
readonly fileInspectorSupported: boolean;
92-
readonly inspectorMode: ThreadInspectorMode | null;
93-
readonly onToggleInspector: () => void;
94-
readonly onOpenGitInspector: () => void;
95-
readonly onOpenFilesInspector: () => void;
96-
},
97-
) {
98-
const navigation = useNavigation();
99-
const { layout, panes, toggleAuxiliaryPane } = useAdaptiveWorkspaceLayout();
100-
const { onOpenTerminal, onMergeBack } = props.gitControls;
101-
const native = useThreadHeaderOptions(props);
102-
const androidHeaderActions = useMemo<ReadonlyArray<ScreenHeaderAction>>(() => {
103-
const actions: ScreenHeaderAction[] = [];
104-
if (props.onReturnToThread) {
105-
actions.push({
106-
accessibilityLabel: "Return to chat",
107-
icon: "chevron.left",
108-
onPress: props.onReturnToThread,
109-
});
110-
}
111-
if (props.hasThreadCwd) {
112-
const filesVisible = props.inspectorMode === "files" && panes.auxiliaryPaneVisible;
113-
actions.push({
114-
accessibilityLabel: filesVisible ? "Close files" : "Open files",
115-
selected: filesVisible,
116-
icon: "folder",
117-
onPress: filesVisible ? toggleAuxiliaryPane : props.onOpenFilesInspector,
118-
});
119-
}
120-
if (props.hasWorkspaceRoot) {
121-
actions.push({
122-
accessibilityLabel: "Open terminal",
123-
icon: "terminal",
124-
onPress: () => onOpenTerminal(null),
125-
});
126-
}
127-
actions.push({
128-
accessibilityLabel: "Open git controls",
129-
icon: "point.topleft.down.curvedto.point.bottomright.up",
130-
onPress: props.onOpenGitInspector,
131-
});
132-
if (onMergeBack) {
133-
actions.push({
134-
accessibilityLabel: "Merge back to source",
135-
icon: "arrow.triangle.merge",
136-
onPress: onMergeBack,
137-
});
138-
}
139-
return actions;
140-
}, [
141-
props.inspectorMode,
142-
panes.auxiliaryPaneVisible,
143-
props.onOpenFilesInspector,
144-
onOpenTerminal,
145-
onMergeBack,
146-
props.onOpenGitInspector,
147-
toggleAuxiliaryPane,
148-
props.onReturnToThread,
149-
props.hasThreadCwd,
150-
props.hasWorkspaceRoot,
151-
]);
152-
153-
return (
154-
<>
155-
<ScreenHeader
156-
title={props.title}
157-
subtitle={props.subtitle}
158-
sidebar={native.sidebar}
159-
options={native.options}
160-
optionsVersion={props.gitControls.projectScripts}
161-
trailing={
162-
props.fileInspectorSupported && props.hasThreadCwd ? (
163-
<ScreenHeaderButton
164-
accessibilityLabel={
165-
props.inspectorMode !== null && panes.auxiliaryPaneVisible
166-
? "Hide inspector"
167-
: "Show inspector"
168-
}
169-
icon="sidebar.right"
170-
selected={props.inspectorMode !== null && panes.auxiliaryPaneVisible}
171-
onPress={props.onToggleInspector}
172-
/>
173-
) : null
174-
}
175-
onBack={
176-
layout.usesSplitView
177-
? undefined
178-
: () => {
179-
// A deep link or cold start has no previous route; Home is the way out.
180-
// Read the history at press time: it changes without re-rendering this screen.
181-
if (navigation.canGoBack()) navigation.goBack();
182-
else navigation.dispatch(StackActions.replace("Home"));
183-
}
184-
}
185-
actions={androidHeaderActions}
186-
hideBottomBorder
187-
/>
188-
{native.fallback}
189-
</>
190-
);
191-
}
82+
import { ThreadHeader } from "./ThreadHeader";
19283

19384
interface ThreadInspectorSelection {
19485
readonly routeThreadIdentity: string | null;

‎apps/mobile/src/features/threads/useThreadHeaderOptions.android.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export function useThreadHeaderOptions(
55
): ReturnType<typeof useIosThreadHeaderOptions> {
66
return {
77
options: { contentStyle: { backgroundColor: props.headerColor } },
8+
// Android renders header actions as children, not native item factories.
9+
optionsVersion: [],
810
sidebar: true,
911
fallback: null,
1012
};

0 commit comments

Comments
 (0)