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
feat(mobile): the folded Duo opens search from a search tab below the tab bar (#24360)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 24, 2026 at 17:29 UTC
5cf4995ce151f9b9f31811934e5ec76c2667e7a3
5 files changed
+78
-30
apps/mobile/src/features/workspace/WorkspaceNativeTabs.ios.tsx
+46
-1
@@ -5,7 +5,12 @@ import {
5
} from "./navigation-tabs";
6
import { useCallback, useLayoutEffect, useMemo, useRef, useState, type ReactNode } from "react";
7
import { View, useWindowDimensions, type NativeSyntheticEvent } from "react-native";
8
-import { Tabs, type TabSelectedEvent, type TabSelectionRejectedEvent } from "react-native-screens";
8
+import {
9
+ Tabs,
10
+ type TabSelectedEvent,
11
+ type TabSelectionPreventedEvent,
12
+ type TabSelectionRejectedEvent,
13
+} from "react-native-screens";
14
15
import { WorkspaceTabsContext, useWorkspaceTabs } from "./WorkspaceTabsContext";
16
import {
@@ -26,6 +31,7 @@ import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
31
import { useSelectWorkspaceTab } from "./useSelectWorkspaceTab";
32
33
const PULL_REQUEST_ICON = require("../../../assets/icons/pull-request.png");
34
+const SEARCH_SLOT = "search";
35
36
/** Retain each native controller tree; removing its root can leave RNS's stack empty. */
37
function RetainedWorkspaceTab(props: {
@@ -93,6 +99,17 @@ export function WorkspaceNativeTabs(props: {
99
const { colors } = useControlTheme();
100
const selectedTab = workspace.state.selectedTab;
101
const selectedSlot = workspace.settingsOpen ? -1 : primaryTabs.indexOf(selectedTab);
102
+ // The folded Duo opens list search from a search tab UIKit sets apart below the others.
103
+ const searchTab = deviceType === "duo-folded";
104
+ // Searching is list state: the list's toolbar mounts its field and focuses it.
105
+ const openSearch = () => {
106
+ const tab =
107
+ !workspace.settingsOpen && workspaceUsesColumns(selectedTab) ? selectedTab : "threads";
108
+ // Back on the tab's list first: folded, a chat open on top would hide the field.
109
+ selectTab(tab);
110
+ workspace.dispatch({ type: "scroll", tab, offset: workspace.getScrollOffset(tab) });
111
+ workspace.dispatch({ type: "search", tab });
112
+ };
113
const request = useMemo(
114
() => ({
115
selectedScreenKey:
@@ -116,9 +133,19 @@ export function WorkspaceNativeTabs(props: {
133
}: NativeSyntheticEvent<TabSelectionRejectedEvent>) =>
134
setProvenance(nativeEvent.provenance)
135
}
136
+ onTabSelectionPrevented={({
137
+ nativeEvent,
138
+ }: NativeSyntheticEvent<TabSelectionPreventedEvent>) => {
139
+ if (nativeEvent.preventedScreenKey === SEARCH_SLOT) openSearch();
140
+ }}
141
onTabSelected={({ nativeEvent }: NativeSyntheticEvent<TabSelectedEvent>) => {
142
setProvenance(nativeEvent.provenance);
143
if (nativeEvent.actionOrigin === "programmatic-js") return;
144
+ // UIKit reports reselecting a tab here even when its selection is prevented.
145
+ if (nativeEvent.selectedScreenKey === SEARCH_SLOT) {
146
+ openSearch();
147
+ return;
148
+ }
149
const tab = workspaceTabForNativeSlot(primaryTabs, nativeEvent.selectedScreenKey);
150
if (tab) selectTab(tab);
151
}}
@@ -156,6 +183,24 @@ export function WorkspaceNativeTabs(props: {
183
</Tabs.Screen>
184
);
185
})}
186
+ {searchTab ? (
187
+ // It never becomes the selected tab; pressing it opens the current list's search.
188
+ <Tabs.Screen
189
+ key={SEARCH_SLOT}
190
+ screenKey={SEARCH_SLOT}
191
+ title=""
192
+ tabBarItemAccessibilityLabel="Search"
193
+ preventNativeSelection
194
+ ios={{
195
+ role: "search",
196
+ systemItem: "search",
197
+ // iOS 27 only sets the search tab apart while it activates search.
198
+ automaticallyActivatesSearch: true,
199
+ }}
200
+ >
201
+ <View />
202
+ </Tabs.Screen>
203
+ ) : null}
204
</Tabs.Host>
205
{(deviceType === "pad" ||
206
compactTabs ||
apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx
+4
-20
@@ -121,32 +121,19 @@ export function WorkspaceToolbar(props: {
121
separateBackground
122
/>
123
) : null;
124
- const searchButton = foldedSearch ? (
125
- <Toolbar.Button
126
- identifier="workspace-search"
127
- accessibilityLabel={
128
- searchVisible
129
- ? "Close search"
130
- : selectedTab === "pullRequests"
131
- ? "Search pull requests"
132
- : "Search threads"
133
- }
134
- icon={searchVisible ? "xmark" : "magnifyingglass"}
135
- onPress={searchVisible ? () => searchRef.current?.cancelSearch() : focusSearch}
136
- separateBackground
137
- />
138
- ) : null;
124
return (
125
<>
126
<NativeStackScreenOptions
142
- optionsVersion={[selectedTab, tab.searchMode]}
127
+ optionsVersion={[selectedTab, tab.searchMode, tab.searchFocusRequest]}
128
listeners={{ transitionEnd: restoreSearch }}
129
options={{
130
+ // Each search request focuses the field once it exists, after it mounts if need be.
131
+ unstable_headerSearchFocusRequest:
132
+ tab.searchMode === "active" ? tab.searchFocusRequest : undefined,
133
headerSearchBarOptions:
134
(NATIVE_LIQUID_GLASS_SUPPORTED || tab.searchMode !== "resting") && searchVisible
135
? {
136
ref: searchRef,
149
- autoFocus: tab.searchMode === "active",
137
autoCapitalize: "none",
138
hideNavigationBar: false,
139
hideWhenScrolling: false,
@@ -162,7 +149,6 @@ export function WorkspaceToolbar(props: {
149
sidebarTabs !== "picker",
150
placeholder:
151
selectedTab === "pullRequests" ? "Search pull requests" : "Search threads",
165
- cancelButtonHidden: foldedSearch,
152
onFocus: searchFocused,
153
onBlur: () => workspace.dispatch({ type: "expand", tab: selectedTab }),
154
onSearchButtonPress: () => searchRef.current?.blur(),
@@ -179,8 +165,6 @@ export function WorkspaceToolbar(props: {
165
/>
166
{/* UIKit lays trailing items out from the edge inward. */}
167
<Toolbar placement="right">
182
- {searchButton}
183
- {nativeToolbarCompose && foldedSearch ? <Toolbar.Spacer width={8} /> : null}
168
{composeButton}
169
{selectedTab !== "threads" ||
170
isDuoDevice(deviceType) ||
apps/mobile/src/features/workspace/workspace-tabs-state.ts
+10
-1
@@ -24,6 +24,8 @@ export interface WorkspaceTabState {
24
readonly searchMode: WorkspaceSearchMode;
25
readonly scrollOffset: number;
26
readonly searchEntryOffset: number;
27
+ /** Counts requests to focus the search field; the header focuses once per request. */
28
+ readonly searchFocusRequest: number;
29
}
30
31
export interface WorkspaceTabsState {
@@ -33,7 +35,13 @@ export interface WorkspaceTabsState {
35
}
36
37
function emptyTab(): WorkspaceTabState {
36
- return { query: "", searchMode: "resting", scrollOffset: 0, searchEntryOffset: 0 };
38
+ return {
39
+ query: "",
40
+ searchMode: "resting",
41
+ scrollOffset: 0,
42
+ searchEntryOffset: 0,
43
+ searchFocusRequest: 0,
44
+ };
45
}
46
47
export function initialWorkspaceTabsState(): WorkspaceTabsState {
@@ -79,6 +87,7 @@ export function workspaceTabsReducer(
87
searchMode: "active",
88
searchEntryOffset:
89
current.searchMode === "resting" ? current.scrollOffset : current.searchEntryOffset,
90
+ searchFocusRequest: current.searchFocusRequest + 1,
91
};
92
break;
93
case "query":
apps/mobile/src/native/StackHeader.tsx
+2
@@ -34,6 +34,8 @@ export type AppNativeStackNavigationOptions = Omit<
34
readonly unstable_headerToolbarItems?: unknown;
35
readonly unstable_navigationItemStyle?: unknown;
36
readonly unstable_headerMinimizationBehavior?: unknown;
37
+ /** Focuses the header search field once for each new value, as soon as the field exists. */
38
+ readonly unstable_headerSearchFocusRequest?: number;
39
};
40
41
function useNativeStackNavigation(): NativeStackNavigationProp<ParamListBase> | null {
apps/mobile/src/native/V5StackHeader.ios.tsx
+16
-8
@@ -3,7 +3,7 @@ import type {
3
NativeStackHeaderItemMenu,
4
NativeStackNavigationOptions,
5
} from "@react-navigation/native-stack";
6
-import { isValidElement, useEffect, useRef } from "react";
6
+import { isValidElement, useEffect, useRef, type RefObject } from "react";
7
import { StyleSheet } from "react-native";
8
import { isDuoDevice } from "../lib/device-type";
9
import { useMobileNavigationTheme } from "../lib/useMobileNavigationTheme";
@@ -29,6 +29,7 @@ type ToolbarItem =
29
type Options = NativeStackNavigationOptions & {
30
readonly unstable_navigationItemStyle?: "editor" | "navigator";
31
readonly unstable_headerMinimizationBehavior?: StackHeaderMinimizationBehaviorIOS;
32
+ readonly unstable_headerSearchFocusRequest?: number;
33
readonly headerSubtitle?: string;
34
readonly unstable_headerSubtitle?: string;
35
readonly headerSubtitleStyle?: { color?: string; fontSize?: number; fontFamily?: string };
@@ -243,12 +244,18 @@ export function V5StackHeader(props: {
244
? options.headerTitle({ children: title ?? "", tintColor: options.headerTintColor })
245
: undefined;
246
const searchOptions = options.headerSearchBarOptions;
246
- const autofocusRef = searchOptions?.ref ?? searchRef;
247
- useEffect(() => {
248
- if (!searchOptions?.autoFocus) return;
249
- const frame = requestAnimationFrame(() => autofocusRef.current?.focus());
250
- return () => cancelAnimationFrame(frame);
251
- }, [searchOptions?.autoFocus, autofocusRef]);
247
+ const searchBarRef = searchOptions?.ref ?? searchRef;
248
+ const focusRequest = options.unstable_headerSearchFocusRequest;
249
+ const focusedRequest = useRef<number | undefined>(undefined);
250
+ // The field can attach a render after the request, since it mounts through these options, and
251
+ // Screens re-attaches its commands on every render; so focus once per request, on attach.
252
+ const attachSearchBar = (instance: SearchBarCommands | null) => {
253
+ searchBarRef.current = instance;
254
+ if (instance && focusRequest !== undefined && focusedRequest.current !== focusRequest) {
255
+ focusedRequest.current = focusRequest;
256
+ instance.focus();
257
+ }
258
+ };
259
const titleStyle = StyleSheet.flatten(options.headerTitleStyle);
260
const headerStyle = StyleSheet.flatten(options.headerStyle);
261
const appearance = {
@@ -288,7 +295,8 @@ export function V5StackHeader(props: {
295
mailSearch || searchOptions ? (
296
<SearchBar
297
{...searchOptions}
291
- ref={searchOptions?.ref ?? searchRef}
298
+ // React accepts callback refs here; Screens only types the object form.
299
+ ref={attachSearchBar as unknown as RefObject<SearchBarCommands | null>}
300
hideNavigationBar={false}
301
hideWhenScrolling={false}
302
allowToolbarIntegration={searchOptions?.allowToolbarIntegration ?? true}