Skip to content
TypeScript

revert(mobile): take the folded Duo search tab back out for now (#24626)

Julius Marminge95ffbc90287f
diff --git a/apps/mobile/src/features/workspace/WorkspaceNativeTabs.ios.tsx b/apps/mobile/src/features/workspace/WorkspaceNativeTabs.ios.tsx
index bcdc835366a..344e787d044 100644
--- a/apps/mobile/src/features/workspace/WorkspaceNativeTabs.ios.tsx
+++ b/apps/mobile/src/features/workspace/WorkspaceNativeTabs.ios.tsx
@@ -5,12 +5,7 @@ import {
} from "./navigation-tabs";
import { useCallback, useLayoutEffect, useMemo, useRef, useState, type ReactNode } from "react";
import { View, useWindowDimensions, type NativeSyntheticEvent } from "react-native";
-import {
- Tabs,
- type TabSelectedEvent,
- type TabSelectionPreventedEvent,
- type TabSelectionRejectedEvent,
-} from "react-native-screens";
+import { Tabs, type TabSelectedEvent, type TabSelectionRejectedEvent } from "react-native-screens";
import { WorkspaceTabsContext, useWorkspaceTabs } from "./WorkspaceTabsContext";
import {
@@ -31,7 +26,6 @@ import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
import { useSelectWorkspaceTab } from "./useSelectWorkspaceTab";
const PULL_REQUEST_ICON = require("../../../assets/icons/pull-request.png");
-const SEARCH_SLOT = "search";
/** Retain each native controller tree; removing its root can leave RNS's stack empty. */
function RetainedWorkspaceTab(props: {
@@ -99,17 +93,6 @@ export function WorkspaceNativeTabs(props: {
const { colors } = useControlTheme();
const selectedTab = workspace.state.selectedTab;
const selectedSlot = workspace.settingsOpen ? -1 : primaryTabs.indexOf(selectedTab);
- // The folded Duo opens list search from a search tab UIKit sets apart below the others.
- const searchTab = deviceType === "duo-folded";
- // Searching is list state: the list's toolbar mounts its field and focuses it.
- const openSearch = () => {
- const tab =
- !workspace.settingsOpen && workspaceUsesColumns(selectedTab) ? selectedTab : "threads";
- // Back on the tab's list first: folded, a chat open on top would hide the field.
- selectTab(tab);
- workspace.dispatch({ type: "scroll", tab, offset: workspace.getScrollOffset(tab) });
- workspace.dispatch({ type: "search", tab });
- };
const request = useMemo(
() => ({
selectedScreenKey:
@@ -133,19 +116,9 @@ export function WorkspaceNativeTabs(props: {
}: NativeSyntheticEvent<TabSelectionRejectedEvent>) =>
setProvenance(nativeEvent.provenance)
}
- onTabSelectionPrevented={({
- nativeEvent,
- }: NativeSyntheticEvent<TabSelectionPreventedEvent>) => {
- if (nativeEvent.preventedScreenKey === SEARCH_SLOT) openSearch();
- }}
onTabSelected={({ nativeEvent }: NativeSyntheticEvent<TabSelectedEvent>) => {
setProvenance(nativeEvent.provenance);
if (nativeEvent.actionOrigin === "programmatic-js") return;
- // UIKit reports reselecting a tab here even when its selection is prevented.
- if (nativeEvent.selectedScreenKey === SEARCH_SLOT) {
- openSearch();
- return;
- }
const tab = workspaceTabForNativeSlot(primaryTabs, nativeEvent.selectedScreenKey);
if (tab) selectTab(tab);
}}
@@ -183,24 +156,6 @@ export function WorkspaceNativeTabs(props: {
</Tabs.Screen>
);
})}
- {searchTab ? (
- // It never becomes the selected tab; pressing it opens the current list's search.
- <Tabs.Screen
- key={SEARCH_SLOT}
- screenKey={SEARCH_SLOT}
- title=""
- tabBarItemAccessibilityLabel="Search"
- preventNativeSelection
- ios={{
- role: "search",
- systemItem: "search",
- // iOS 27 only sets the search tab apart while it activates search.
- automaticallyActivatesSearch: true,
- }}
- >
- <View />
- </Tabs.Screen>
- ) : null}
</Tabs.Host>
{(deviceType === "pad" ||
compactTabs ||
diff --git a/apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx b/apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx
index 877c4b7e8db..17fff053258 100644
--- a/apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx
+++ b/apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx
@@ -121,19 +121,32 @@ export function WorkspaceToolbar(props: {
separateBackground
/>
) : null;
+ const searchButton = foldedSearch ? (
+ <Toolbar.Button
+ identifier="workspace-search"
+ accessibilityLabel={
+ searchVisible
+ ? "Close search"
+ : selectedTab === "pullRequests"
+ ? "Search pull requests"
+ : "Search threads"
+ }
+ icon={searchVisible ? "xmark" : "magnifyingglass"}
+ onPress={searchVisible ? () => searchRef.current?.cancelSearch() : focusSearch}
+ separateBackground
+ />
+ ) : null;
return (
<>
<NativeStackScreenOptions
- optionsVersion={[selectedTab, tab.searchMode, tab.searchFocusRequest]}
+ optionsVersion={[selectedTab, tab.searchMode]}
listeners={{ transitionEnd: restoreSearch }}
options={{
- // Each search request focuses the field once it exists, after it mounts if need be.
- unstable_headerSearchFocusRequest:
- tab.searchMode === "active" ? tab.searchFocusRequest : undefined,
headerSearchBarOptions:
(NATIVE_LIQUID_GLASS_SUPPORTED || tab.searchMode !== "resting") && searchVisible
? {
ref: searchRef,
+ autoFocus: tab.searchMode === "active",
autoCapitalize: "none",
hideNavigationBar: false,
hideWhenScrolling: false,
@@ -149,6 +162,7 @@ export function WorkspaceToolbar(props: {
sidebarTabs !== "picker",
placeholder:
selectedTab === "pullRequests" ? "Search pull requests" : "Search threads",
+ cancelButtonHidden: foldedSearch,
onFocus: searchFocused,
onBlur: () => workspace.dispatch({ type: "expand", tab: selectedTab }),
onSearchButtonPress: () => searchRef.current?.blur(),
@@ -165,6 +179,8 @@ export function WorkspaceToolbar(props: {
/>
{/* UIKit lays trailing items out from the edge inward. */}
<Toolbar placement="right">
+ {searchButton}
+ {nativeToolbarCompose && foldedSearch ? <Toolbar.Spacer width={8} /> : null}
{composeButton}
{selectedTab !== "threads" ||
isDuoDevice(deviceType) ||
diff --git a/apps/mobile/src/features/workspace/workspace-tabs-state.ts b/apps/mobile/src/features/workspace/workspace-tabs-state.ts
index 3afbcea4f6e..6355796c84e 100644
--- a/apps/mobile/src/features/workspace/workspace-tabs-state.ts
+++ b/apps/mobile/src/features/workspace/workspace-tabs-state.ts
@@ -24,8 +24,6 @@ export interface WorkspaceTabState {
readonly searchMode: WorkspaceSearchMode;
readonly scrollOffset: number;
readonly searchEntryOffset: number;
- /** Counts requests to focus the search field; the header focuses once per request. */
- readonly searchFocusRequest: number;
}
export interface WorkspaceTabsState {
@@ -35,13 +33,7 @@ export interface WorkspaceTabsState {
}
function emptyTab(): WorkspaceTabState {
- return {
- query: "",
- searchMode: "resting",
- scrollOffset: 0,
- searchEntryOffset: 0,
- searchFocusRequest: 0,
- };
+ return { query: "", searchMode: "resting", scrollOffset: 0, searchEntryOffset: 0 };
}
export function initialWorkspaceTabsState(): WorkspaceTabsState {
@@ -87,7 +79,6 @@ export function workspaceTabsReducer(
searchMode: "active",
searchEntryOffset:
current.searchMode === "resting" ? current.scrollOffset : current.searchEntryOffset,
- searchFocusRequest: current.searchFocusRequest + 1,
};
break;
case "query":
diff --git a/apps/mobile/src/native/StackHeader.tsx b/apps/mobile/src/native/StackHeader.tsx
index 55652b64503..a206864d4d4 100644
--- a/apps/mobile/src/native/StackHeader.tsx
+++ b/apps/mobile/src/native/StackHeader.tsx
@@ -34,8 +34,6 @@ export type AppNativeStackNavigationOptions = Omit<
readonly unstable_headerToolbarItems?: unknown;
readonly unstable_navigationItemStyle?: unknown;
readonly unstable_headerMinimizationBehavior?: unknown;
- /** Focuses the header search field once for each new value, as soon as the field exists. */
- readonly unstable_headerSearchFocusRequest?: number;
};
function useNativeStackNavigation(): NativeStackNavigationProp<ParamListBase> | null {
diff --git a/apps/mobile/src/native/V5StackHeader.ios.tsx b/apps/mobile/src/native/V5StackHeader.ios.tsx
index 01629857100..afcb5795fce 100644
--- a/apps/mobile/src/native/V5StackHeader.ios.tsx
+++ b/apps/mobile/src/native/V5StackHeader.ios.tsx
@@ -3,7 +3,7 @@ import type {
NativeStackHeaderItemMenu,
NativeStackNavigationOptions,
} from "@react-navigation/native-stack";
-import { isValidElement, useEffect, useRef, type RefObject } from "react";
+import { isValidElement, useEffect, useRef } from "react";
import { StyleSheet } from "react-native";
import { isDuoDevice } from "../lib/device-type";
import { useMobileNavigationTheme } from "../lib/useMobileNavigationTheme";
@@ -29,7 +29,6 @@ type ToolbarItem =
type Options = NativeStackNavigationOptions & {
readonly unstable_navigationItemStyle?: "editor" | "navigator";
readonly unstable_headerMinimizationBehavior?: StackHeaderMinimizationBehaviorIOS;
- readonly unstable_headerSearchFocusRequest?: number;
readonly headerSubtitle?: string;
readonly unstable_headerSubtitle?: string;
readonly headerSubtitleStyle?: { color?: string; fontSize?: number; fontFamily?: string };
@@ -244,18 +243,12 @@ export function V5StackHeader(props: {
? options.headerTitle({ children: title ?? "", tintColor: options.headerTintColor })
: undefined;
const searchOptions = options.headerSearchBarOptions;
- const searchBarRef = searchOptions?.ref ?? searchRef;
- const focusRequest = options.unstable_headerSearchFocusRequest;
- const focusedRequest = useRef<number | undefined>(undefined);
- // The field can attach a render after the request, since it mounts through these options, and
- // Screens re-attaches its commands on every render; so focus once per request, on attach.
- const attachSearchBar = (instance: SearchBarCommands | null) => {
- searchBarRef.current = instance;
- if (instance && focusRequest !== undefined && focusedRequest.current !== focusRequest) {
- focusedRequest.current = focusRequest;
- instance.focus();
- }
- };
+ const autofocusRef = searchOptions?.ref ?? searchRef;
+ useEffect(() => {
+ if (!searchOptions?.autoFocus) return;
+ const frame = requestAnimationFrame(() => autofocusRef.current?.focus());
+ return () => cancelAnimationFrame(frame);
+ }, [searchOptions?.autoFocus, autofocusRef]);
const titleStyle = StyleSheet.flatten(options.headerTitleStyle);
const headerStyle = StyleSheet.flatten(options.headerStyle);
const appearance = {
@@ -295,8 +288,7 @@ export function V5StackHeader(props: {
mailSearch || searchOptions ? (
<SearchBar
{...searchOptions}
- // React accepts callback refs here; Screens only types the object form.
- ref={attachSearchBar as unknown as RefObject<SearchBarCommands | null>}
+ ref={searchOptions?.ref ?? searchRef}
hideNavigationBar={false}
hideWhenScrolling={false}
allowToolbarIntegration={searchOptions?.allowToolbarIntegration ?? true}