Skip to content

Commit 95ffbc9

Browse files
revert(mobile): take the folded Duo search tab back out for now (#24626)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 5cf4995 commit 95ffbc9

5 files changed

Lines changed: 30 additions & 78 deletions

File tree

‎apps/mobile/src/features/workspace/WorkspaceNativeTabs.ios.tsx‎

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ import {
55
} from "./navigation-tabs";
66
import { useCallback, useLayoutEffect, useMemo, useRef, useState, type ReactNode } from "react";
77
import { View, useWindowDimensions, type NativeSyntheticEvent } from "react-native";
8-
import {
9-
Tabs,
10-
type TabSelectedEvent,
11-
type TabSelectionPreventedEvent,
12-
type TabSelectionRejectedEvent,
13-
} from "react-native-screens";
8+
import { Tabs, type TabSelectedEvent, type TabSelectionRejectedEvent } from "react-native-screens";
149

1510
import { WorkspaceTabsContext, useWorkspaceTabs } from "./WorkspaceTabsContext";
1611
import {
@@ -31,7 +26,6 @@ import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
3126
import { useSelectWorkspaceTab } from "./useSelectWorkspaceTab";
3227

3328
const PULL_REQUEST_ICON = require("../../../assets/icons/pull-request.png");
34-
const SEARCH_SLOT = "search";
3529

3630
/** Retain each native controller tree; removing its root can leave RNS's stack empty. */
3731
function RetainedWorkspaceTab(props: {
@@ -99,17 +93,6 @@ export function WorkspaceNativeTabs(props: {
9993
const { colors } = useControlTheme();
10094
const selectedTab = workspace.state.selectedTab;
10195
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-
};
11396
const request = useMemo(
11497
() => ({
11598
selectedScreenKey:
@@ -133,19 +116,9 @@ export function WorkspaceNativeTabs(props: {
133116
}: NativeSyntheticEvent<TabSelectionRejectedEvent>) =>
134117
setProvenance(nativeEvent.provenance)
135118
}
136-
onTabSelectionPrevented={({
137-
nativeEvent,
138-
}: NativeSyntheticEvent<TabSelectionPreventedEvent>) => {
139-
if (nativeEvent.preventedScreenKey === SEARCH_SLOT) openSearch();
140-
}}
141119
onTabSelected={({ nativeEvent }: NativeSyntheticEvent<TabSelectedEvent>) => {
142120
setProvenance(nativeEvent.provenance);
143121
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-
}
149122
const tab = workspaceTabForNativeSlot(primaryTabs, nativeEvent.selectedScreenKey);
150123
if (tab) selectTab(tab);
151124
}}
@@ -183,24 +156,6 @@ export function WorkspaceNativeTabs(props: {
183156
</Tabs.Screen>
184157
);
185158
})}
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}
204159
</Tabs.Host>
205160
{(deviceType === "pad" ||
206161
compactTabs ||

‎apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,32 @@ export function WorkspaceToolbar(props: {
121121
separateBackground
122122
/>
123123
) : 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;
124139
return (
125140
<>
126141
<NativeStackScreenOptions
127-
optionsVersion={[selectedTab, tab.searchMode, tab.searchFocusRequest]}
142+
optionsVersion={[selectedTab, tab.searchMode]}
128143
listeners={{ transitionEnd: restoreSearch }}
129144
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,
133145
headerSearchBarOptions:
134146
(NATIVE_LIQUID_GLASS_SUPPORTED || tab.searchMode !== "resting") && searchVisible
135147
? {
136148
ref: searchRef,
149+
autoFocus: tab.searchMode === "active",
137150
autoCapitalize: "none",
138151
hideNavigationBar: false,
139152
hideWhenScrolling: false,
@@ -149,6 +162,7 @@ export function WorkspaceToolbar(props: {
149162
sidebarTabs !== "picker",
150163
placeholder:
151164
selectedTab === "pullRequests" ? "Search pull requests" : "Search threads",
165+
cancelButtonHidden: foldedSearch,
152166
onFocus: searchFocused,
153167
onBlur: () => workspace.dispatch({ type: "expand", tab: selectedTab }),
154168
onSearchButtonPress: () => searchRef.current?.blur(),
@@ -165,6 +179,8 @@ export function WorkspaceToolbar(props: {
165179
/>
166180
{/* UIKit lays trailing items out from the edge inward. */}
167181
<Toolbar placement="right">
182+
{searchButton}
183+
{nativeToolbarCompose && foldedSearch ? <Toolbar.Spacer width={8} /> : null}
168184
{composeButton}
169185
{selectedTab !== "threads" ||
170186
isDuoDevice(deviceType) ||

‎apps/mobile/src/features/workspace/workspace-tabs-state.ts‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ export interface WorkspaceTabState {
2424
readonly searchMode: WorkspaceSearchMode;
2525
readonly scrollOffset: number;
2626
readonly searchEntryOffset: number;
27-
/** Counts requests to focus the search field; the header focuses once per request. */
28-
readonly searchFocusRequest: number;
2927
}
3028

3129
export interface WorkspaceTabsState {
@@ -35,13 +33,7 @@ export interface WorkspaceTabsState {
3533
}
3634

3735
function emptyTab(): WorkspaceTabState {
38-
return {
39-
query: "",
40-
searchMode: "resting",
41-
scrollOffset: 0,
42-
searchEntryOffset: 0,
43-
searchFocusRequest: 0,
44-
};
36+
return { query: "", searchMode: "resting", scrollOffset: 0, searchEntryOffset: 0 };
4537
}
4638

4739
export function initialWorkspaceTabsState(): WorkspaceTabsState {
@@ -87,7 +79,6 @@ export function workspaceTabsReducer(
8779
searchMode: "active",
8880
searchEntryOffset:
8981
current.searchMode === "resting" ? current.scrollOffset : current.searchEntryOffset,
90-
searchFocusRequest: current.searchFocusRequest + 1,
9182
};
9283
break;
9384
case "query":

‎apps/mobile/src/native/StackHeader.tsx‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ export type AppNativeStackNavigationOptions = Omit<
3434
readonly unstable_headerToolbarItems?: unknown;
3535
readonly unstable_navigationItemStyle?: unknown;
3636
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;
3937
};
4038

4139
function useNativeStackNavigation(): NativeStackNavigationProp<ParamListBase> | null {

‎apps/mobile/src/native/V5StackHeader.ios.tsx‎

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {
33
NativeStackHeaderItemMenu,
44
NativeStackNavigationOptions,
55
} from "@react-navigation/native-stack";
6-
import { isValidElement, useEffect, useRef, type RefObject } from "react";
6+
import { isValidElement, useEffect, useRef } from "react";
77
import { StyleSheet } from "react-native";
88
import { isDuoDevice } from "../lib/device-type";
99
import { useMobileNavigationTheme } from "../lib/useMobileNavigationTheme";
@@ -29,7 +29,6 @@ type ToolbarItem =
2929
type Options = NativeStackNavigationOptions & {
3030
readonly unstable_navigationItemStyle?: "editor" | "navigator";
3131
readonly unstable_headerMinimizationBehavior?: StackHeaderMinimizationBehaviorIOS;
32-
readonly unstable_headerSearchFocusRequest?: number;
3332
readonly headerSubtitle?: string;
3433
readonly unstable_headerSubtitle?: string;
3534
readonly headerSubtitleStyle?: { color?: string; fontSize?: number; fontFamily?: string };
@@ -244,18 +243,12 @@ export function V5StackHeader(props: {
244243
? options.headerTitle({ children: title ?? "", tintColor: options.headerTintColor })
245244
: undefined;
246245
const searchOptions = options.headerSearchBarOptions;
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-
};
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]);
259252
const titleStyle = StyleSheet.flatten(options.headerTitleStyle);
260253
const headerStyle = StyleSheet.flatten(options.headerStyle);
261254
const appearance = {
@@ -295,8 +288,7 @@ export function V5StackHeader(props: {
295288
mailSearch || searchOptions ? (
296289
<SearchBar
297290
{...searchOptions}
298-
// React accepts callback refs here; Screens only types the object form.
299-
ref={attachSearchBar as unknown as RefObject<SearchBarCommands | null>}
291+
ref={searchOptions?.ref ?? searchRef}
300292
hideNavigationBar={false}
301293
hideWhenScrolling={false}
302294
allowToolbarIntegration={searchOptions?.allowToolbarIntegration ?? true}

0 commit comments

Comments
 (0)