TypeScript
fix(mobile): keep Duo toolbar actions clear of workspace tabs (#22976)
Julius Marminge9cdd05926b28
diff --git a/apps/mobile/src/features/home/HomeHeader.tsx b/apps/mobile/src/features/home/HomeHeader.tsxindex b6203916dea..2062c518afe 100644--- a/apps/mobile/src/features/home/HomeHeader.tsx+++ b/apps/mobile/src/features/home/HomeHeader.tsx@@ -1,243 +1,8 @@-import { Toolbar } from "../../components/ui/Toolbar";-import { NativeStackScreenOptions } from "../../native/StackHeader";-import { use, useCallback, useEffect, useRef } from "react";-import { useNavigation, type ParamListBase } from "@react-navigation/native";-import type { NativeStackNavigationProp } from "@react-navigation/native-stack";-import { Platform } from "react-native";-import type { SearchBarCommands } from "react-native-screens";-import { NativePrimaryColumnContext } from "../../native/v5-workspace-context";-import { useUniwindTheme } from "../../lib/useUniwindTheme";-import { useHardwareKeyboardCommand } from "../keyboard/hardwareKeyboardCommands";-import { withNativeGlassHeaderItem } from "../layout/native-glass-header-items";-import { createNativeMailSearchToolbarItem } from "../layout/native-mail-search-toolbar";-import { useNativeMailSearchToolbar } from "../../native/use-native-mail-search-toolbar";-import { useDeviceType } from "../../native/native-layout-metrics";-import { buildHomeListFilterMenu } from "./home-list-filter-menu";-import {- createSidebarFilterHeaderItem,- createSidebarHeaderItems,-} from "../threads/sidebar-native-header-items";import type { HomeHeaderProps } from "./HomeHeader.types";-import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";export type { HomeHeaderEnvironment } from "./HomeHeader.types";-export function HomeHeader(props: HomeHeaderProps) {- const navigation = useNavigation<NativeStackNavigationProp<ParamListBase>>();- const { layout, panes, togglePrimarySidebar } = useAdaptiveWorkspaceLayout();- const usesNativeMailSearchToolbar = useNativeMailSearchToolbar();- const deviceType = useDeviceType();- const primaryColumn = use(NativePrimaryColumnContext);- const sidebarHeader =- Platform.OS === "ios" &&- primaryColumn !== null &&- (deviceType === "pad" || !usesNativeMailSearchToolbar);- const showsCompactCompose = deviceType === "pad" && !layout.usesSplitView;- const searchBarRef = useRef<SearchBarCommands>(null);- const focusAfterReveal = useRef(false);- useEffect(- () =>- navigation.addListener("transitionEnd", (event) => {- if (focusAfterReveal.current && !event.data.closing) {- focusAfterReveal.current = false;- searchBarRef.current?.focus();- }- }),- [navigation],- );- const iconColor = useUniwindTheme()["--color-icon"];- const hasCustomListOptions =- props.selectedEnvironmentId !== null || props.selectedProjectKey !== null;- const focusSearch = useCallback(() => {- if (primaryColumn && !panes.primarySidebarVisible) {- focusAfterReveal.current = true;- togglePrimarySidebar();- return true;- }- searchBarRef.current?.focus();- return searchBarRef.current !== null;- }, [primaryColumn, panes.primarySidebarVisible, togglePrimarySidebar]);- useHardwareKeyboardCommand("focusSearch", focusSearch);- const filterMenu = buildHomeListFilterMenu(props);-- if (props.usesWorkspaceToolbar) {- return deviceType === "duo-unfolded" ? (- <NativeStackScreenOptions- optionsVersion={filterMenu.items}- options={{- nativeSidebarFilter: createSidebarFilterHeaderItem({- filterIcon: hasCustomListOptions- ? "line.3.horizontal.decrease.circle.fill"- : "line.3.horizontal.decrease.circle",- filterMenu,- }),- }}- />- ) : null;- }-- return (- <>- <NativeStackScreenOptions- optionsVersion={[filterMenu.items, showsCompactCompose]}- options={{- headerTintColor: iconColor,- unstable_headerRightItems: () =>- sidebarHeader- ? [- ...createSidebarHeaderItems({- filterIcon: hasCustomListOptions- ? "line.3.horizontal.decrease.circle.fill"- : "line.3.horizontal.decrease.circle",- filterMenu,- onOpenSettings: props.onOpenSettings,- }),- ...(showsCompactCompose- ? [- withNativeGlassHeaderItem({- accessibilityLabel: "New task",- axisBehavior: "horizontalOnly",- icon: { name: "square.and.pencil", type: "sfSymbol" } as const,- identifier: "home-new-task",- label: "",- onPress: props.onStartNewTask,- type: "button",- }),- ]- : []),- ]- : [- withNativeGlassHeaderItem({- accessibilityLabel: "Open settings",- icon: { name: "ellipsis", type: "sfSymbol" } as const,- identifier: "home-settings",- label: "",- onPress: props.onOpenSettings,- type: "button",- }),- ],- // The keys below are set per-branch (not `undefined`) so a later- // reapply cannot clobber options owned by Toolbar.- ...(sidebarHeader- ? {- headerSearchBarOptions: {- ref: searchBarRef,- autoCapitalize: "none" as const,- hideNavigationBar: false,- hideWhenScrolling: false,- obscureBackground: false,- placement: "stacked" as const,- allowToolbarIntegration: false,- placeholder: "Search",- onCancelButtonPress: () => props.onSearchQueryChange(""),- onChangeText: (event) => props.onSearchQueryChange(event.nativeEvent.text),- },- unstable_headerToolbarItems: () => [],- }- : usesNativeMailSearchToolbar- ? {- headerSearchBarOptions: {- ref: searchBarRef,- autoCapitalize: "none" as const,- onCancelButtonPress: () => props.onSearchQueryChange(""),- },- unstable_headerToolbarItems: () => [- createNativeMailSearchToolbarItem({- composeButtonId: "home-new-task",- composeSystemImageName: "square.and.pencil",- filterMenu,- filterButtonId: "home-filter",- filterSystemImageName: hasCustomListOptions- ? "line.3.horizontal.decrease.circle.fill"- : "line.3.horizontal.decrease",- onComposePress: props.onStartNewTask,- onSearchTextChange: props.onSearchQueryChange,- placeholder: "Search",- searchTextChangeId: "home-search-text",- showsSearchDismissButton: true,- }),- ],- }- : {- headerSearchBarOptions: {- ref: searchBarRef,- autoCapitalize: "none" as const,- hideNavigationBar: false,- placeholder: "Search",- onCancelButtonPress: () => {- props.onSearchQueryChange("");- },- onChangeText: (event) => {- props.onSearchQueryChange(event.nativeEvent.text);- },- },- }),- }}- />-- {sidebarHeader || usesNativeMailSearchToolbar ? null : (- <Toolbar placement="bottom">- <Toolbar.Menu- accessibilityLabel="Filter threads"- icon={- hasCustomListOptions- ? "line.3.horizontal.decrease.circle.fill"- : "line.3.horizontal.decrease.circle"- }- title="Thread list options"- separateBackground- >- <Toolbar.Menu title="Environment">- <Toolbar.Label>Environment</Toolbar.Label>- <Toolbar.MenuAction- isOn={props.selectedEnvironmentId === null}- onPress={() => props.onEnvironmentChange(null)}- subtitle="Show threads from every environment"- >- <Toolbar.Label>All environments</Toolbar.Label>- </Toolbar.MenuAction>- {props.environments.map((environment) => (- <Toolbar.MenuAction- key={environment.environmentId}- isOn={props.selectedEnvironmentId === environment.environmentId}- onPress={() => props.onEnvironmentChange(environment.environmentId)}- >- <Toolbar.Label>{environment.label}</Toolbar.Label>- </Toolbar.MenuAction>- ))}- </Toolbar.Menu>-- {props.projects.length > 0 ? (- <Toolbar.Menu title="Project">- <Toolbar.Label>Project</Toolbar.Label>- <Toolbar.MenuAction- isOn={props.selectedProjectKey === null}- onPress={() => props.onProjectChange(null)}- subtitle="Show threads from every project"- >- <Toolbar.Label>All projects</Toolbar.Label>- </Toolbar.MenuAction>- {props.projects.map((project) => (- <Toolbar.MenuAction- key={project.key}- isOn={props.selectedProjectKey === project.key}- onPress={() => props.onProjectChange(project.key)}- >- <Toolbar.Label>{project.label}</Toolbar.Label>- </Toolbar.MenuAction>- ))}- </Toolbar.Menu>- ) : null}- </Toolbar.Menu>- <Toolbar.Spacer flexible />- <Toolbar.Button- accessibilityLabel="New task"- icon="square.and.pencil"- onPress={props.onStartNewTask}- separateBackground- />- </Toolbar>- )}- </>- );+/** The iOS thread list lives in the workspace, whose WorkspaceToolbar owns its header and search. */+export function HomeHeader(_props: HomeHeaderProps) {+ return null;}diff --git a/apps/mobile/src/features/home/HomeHeader.types.ts b/apps/mobile/src/features/home/HomeHeader.types.tsindex 32648ef843a..3c5f580f9ee 100644--- a/apps/mobile/src/features/home/HomeHeader.types.ts+++ b/apps/mobile/src/features/home/HomeHeader.types.ts@@ -7,7 +7,6 @@ import type {export type HomeHeaderEnvironment = HomeListFilterMenuEnvironment;export interface HomeHeaderProps {- readonly usesWorkspaceToolbar?: boolean;readonly environments: ReadonlyArray<HomeHeaderEnvironment>;readonly projects: ReadonlyArray<HomeListFilterMenuProject>;readonly searchQuery: string;diff --git a/apps/mobile/src/features/home/HomeRouteScreen.tsx b/apps/mobile/src/features/home/HomeRouteScreen.tsxindex 8ab642eb44f..c0e2b8c8f59 100644--- a/apps/mobile/src/features/home/HomeRouteScreen.tsx+++ b/apps/mobile/src/features/home/HomeRouteScreen.tsx@@ -228,7 +228,6 @@ export function HomeRouteScreen() {/>)}<HomeHeader- usesWorkspaceToolbar={workspace !== null}environments={environments}projects={projectFilterOptions}searchQuery={searchQuery}diff --git a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsxindex c4c0946fffd..bb3ed7fa4a3 100644--- a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx+++ b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx@@ -14,7 +14,6 @@ import {} from "@react-navigation/native";import {NativeStackView,- type NativeStackHeaderItemMenu,type NativeStackNavigationEventMap,type NativeStackNavigationOptions,type NativeStackNavigatorProps,@@ -25,9 +24,10 @@ import { View } from "react-native";import { Split, type SplitHostCommands } from "react-native-screens";import { EnvironmentId, ThreadId } from "@t3tools/contracts";import { scopedThreadKey } from "../../lib/scopedEntities";-import { WorkspaceTabsProvider } from "../workspace/WorkspaceTabsContext";+import { WorkspaceTabsProvider, useWorkspaceTabs } from "../workspace/WorkspaceTabsContext";import { WorkspaceNativeTabs } from "../workspace/WorkspaceNativeTabs.ios";-import { useNativeLayoutMetrics } from "../../native/native-layout-metrics";+import { isDuoDevice } from "../../lib/device-type";+import { useDeviceType, useNativeLayoutMetrics } from "../../native/native-layout-metrics";import { useAdaptiveWorkspaceLayout } from "./AdaptiveWorkspaceLayout";import { WorkspaceEmptyDetail } from "./WorkspaceEmptyDetail";@@ -60,14 +60,20 @@ type ViewProps = ComponentProps<typeof NativeStackView>;type Descriptor = ViewProps["descriptors"][string];type Route = ViewProps["state"]["routes"][number];+const isPullRequestRoute = (route: Route) =>+ route.name === "PullRequest" ||+ route.name === "PullRequestFile" ||+ route.name === "PullRequestFiles";+function ColumnScreen(props: {readonly descriptor: Descriptor;readonly primary?: boolean;readonly selectedThreadKey?: string | null;readonly selectedPullRequestKey?: string | null;- readonly sidebarFilter?: NativeStackHeaderItemMenu;readonly onDismiss: (routeKey: string) => void;readonly onAppearance: (type: "willAppear" | "didAppear" | "willDisappear", key: string) => void;+ readonly onCompose?: () => void;+ readonly covered?: boolean;readonly navigation: ViewProps["navigation"];}) {const { descriptor } = props;@@ -109,8 +115,9 @@ function ColumnScreen(props: {<V5StackHeaderoptions={descriptor.options}canGoBack={!props.primary}- primary={props.primary}- sidebarFilter={props.sidebarFilter}+ column={props.primary ? "primary" : "detail"}+ onCompose={props.onCompose}+ covered={props.covered}/><ColumnContentprimary={props.primary}@@ -132,6 +139,15 @@ function WorkspaceColumns(props: ViewProps & { readonly primary: Route; readonly detail: Route[] },) {const { layout, panes, togglePrimarySidebar, toggleAuxiliaryPane } = useAdaptiveWorkspaceLayout();+ const deviceType = useDeviceType();+ const selectedTab = useWorkspaceTabs()?.state.selectedTab;+ const openNewTask = () => props.navigation.navigate("NewTaskSheet", { screen: "NewTask" });+ // The Duo keeps compose in the detail column's bar, which is its vertical bar in landscape+ // and folded, so it sits with the column's other actions whichever screen is shown. Pull+ // requests leave it out, including one opened from a thread; their bar is already full of+ // review actions.+ const detailCompose =+ isDuoDevice(deviceType) && selectedTab !== "pullRequests" ? openNewTask : undefined;const inspector = use(NativeWorkspaceInspectorContext);const hostRef = useRef<SplitHostCommands>(null);const activeDetailKey = props.detail.at(-1)?.key;@@ -139,12 +155,7 @@ function WorkspaceColumns(const collapsed = useRef(!layout.usesSplitView);const collapsedColumn = useRef<CollapsedSplitColumn>({ visible: compactColumn, leaving: null });const threadParams = props.detail.findLast((route) => route.name === "Thread")?.params;- const pullRequestParams = props.detail.findLast(- (route) =>- route.name === "PullRequest" ||- route.name === "PullRequestFile" ||- route.name === "PullRequestFiles",- )?.params;+ const pullRequestParams = props.detail.findLast(isPullRequestRoute)?.params;const selectedPullRequestKey =pullRequestParams &&"environmentId" in pullRequestParams &&@@ -199,7 +210,6 @@ function WorkspaceColumns(const primary = props.descriptors[props.primary.key];if (!primary) return null;- const sidebarFilter = (primary.options as AppNativeStackNavigationOptions).nativeSidebarFilter;return (<Split.Hostref={hostRef}@@ -240,6 +250,7 @@ function WorkspaceColumns(selectedPullRequestKey={selectedPullRequestKey}onDismiss={handleNativeDismiss}onAppearance={followCollapsedSplit}+ covered={!layout.usesSplitView && activeDetailKey !== undefined}navigation={props.navigation}/></Split.Stack>@@ -264,12 +275,14 @@ function WorkspaceColumns(],}}canGoBack={false}- sidebarFilter={sidebarFilter}+ column="detail"+ onCompose={detailCompose}/><ColumnContent><WorkspaceEmptyDetail- onStartNewTask={() =>- props.navigation.navigate("NewTaskSheet", { screen: "NewTask" })+ onStartNewTask={+ // The detail bar or a visible sidebar already carries compose.+ detailCompose || panes.primarySidebarVisible ? undefined : openNewTask}/></ColumnContent>@@ -282,8 +295,8 @@ function WorkspaceColumns(descriptor={descriptor}onDismiss={handleNativeDismiss}onAppearance={followCollapsedSplit}+ onCompose={isPullRequestRoute(route) ? undefined : detailCompose}navigation={props.navigation}- sidebarFilter={sidebarFilter}/>) : null;})}diff --git a/apps/mobile/src/features/threads/sidebar-native-header-items.ts b/apps/mobile/src/features/threads/sidebar-native-header-items.tsindex c2f309a011e..cfbaf755e89 100644--- a/apps/mobile/src/features/threads/sidebar-native-header-items.ts+++ b/apps/mobile/src/features/threads/sidebar-native-header-items.ts@@ -31,30 +31,23 @@ function toNativeHeaderMenuItems(items: HomeListFilterMenu["items"]): NativeHead);}-export function createSidebarFilterHeaderItem(input: {- readonly filterIcon: string;- readonly filterMenu: HomeListFilterMenu;-}): NativeStackHeaderItemMenu {- return withNativeGlassHeaderItem({- type: "menu",- axisBehavior: "horizontalOnly",- label: "",- accessibilityLabel: "Filter threads",- icon: sfSymbolIcon(input.filterIcon),- menu: {- title: input.filterMenu.title,- items: toNativeHeaderMenuItems(input.filterMenu.items),- },- });-}-export function createSidebarHeaderItems(input: {readonly filterIcon: string;readonly filterMenu: HomeListFilterMenu;readonly onOpenSettings: () => void;}): NativeStackHeaderItem[] {return [- createSidebarFilterHeaderItem(input),+ withNativeGlassHeaderItem({+ type: "menu",+ axisBehavior: "horizontalOnly",+ label: "",+ accessibilityLabel: "Filter threads",+ icon: sfSymbolIcon(input.filterIcon),+ menu: {+ title: input.filterMenu.title,+ items: toNativeHeaderMenuItems(input.filterMenu.items),+ },+ }),withNativeGlassHeaderItem({type: "button",axisBehavior: "horizontalOnly",diff --git a/apps/mobile/src/features/threads/useThreadHeaderOptions.tsx b/apps/mobile/src/features/threads/useThreadHeaderOptions.tsxindex 366c2640b4c..2153918ab06 100644--- a/apps/mobile/src/features/threads/useThreadHeaderOptions.tsx+++ b/apps/mobile/src/features/threads/useThreadHeaderOptions.tsx@@ -100,23 +100,6 @@ export function useThreadHeaderOptions(props: {[navigation],);- const duoRightHeaderItems = useMemo<NativeHeaderItems>(- () => [- ...threadCenterHeaderItems,- { type: "spacing", spacing: 8 },- withNativeGlassHeaderItem({- type: "button" as const,- axisBehavior: "verticalPreferred",- identifier: "thread-right-new-task",- label: "New task",- accessibilityLabel: "New task",- icon: { name: "square.and.pencil", type: "sfSymbol" as const },- onPress: () => navigation.navigate("NewTaskSheet", { screen: "NewTask" }),- }),- ],- [navigation, threadCenterHeaderItems],- );-const options: AppNativeStackNavigationOptions = {headerShown: true,headerTitle: props.title,@@ -133,12 +116,9 @@ export function useThreadHeaderOptions(props: {: canGoBack? undefined: () => compactHomeHeaderItems,+ // The workspace navigator adds compose to the Duo detail column's bar.unstable_headerRightItems: () =>- usesDuoHeader- ? duoRightHeaderItems- : layout.usesSplitView- ? threadCenterHeaderItems- : compactRightHeaderItems,+ usesDuoHeader || layout.usesSplitView ? threadCenterHeaderItems : compactRightHeaderItems,unstable_headerToolbarItems: () => [],unstable_headerSubtitle: props.usesNativeHeaderGlass ? props.subtitle : undefined,contentStyle: undefined,@@ -154,7 +134,6 @@ export function useThreadHeaderOptions(props: {splitLeftHeaderItems,threadCenterHeaderItems,compactRightHeaderItems,- duoRightHeaderItems,usesDuoHeader,environmentId,threadId,diff --git a/apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx b/apps/mobile/src/features/workspace/WorkspaceRootScreen.tsxindex 98040a69c0f..3f6dc6415e2 100644--- a/apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx+++ b/apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx@@ -112,7 +112,6 @@ function WorkspaceRootContent() {headerShown: true,unstable_headerLeftItems: () => [],headerTitle: renderHeaderTitle,- ...(state.selectedTab === "threads" ? {} : { nativeSidebarFilter: undefined }),}}/>) : (diff --git a/apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx b/apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsxindex af815639fab..fa282f2104f 100644--- a/apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx+++ b/apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx@@ -2,7 +2,8 @@ import { Toolbar } from "../../components/ui/Toolbar";import { useFocusEffect, useNavigation } from "@react-navigation/native";import { use, useCallback, useEffect, useRef } from "react";import { Platform } from "react-native";-import { useDeviceType, useNativeLayoutMetrics } from "../../native/native-layout-metrics";+import { isDuoDevice } from "../../lib/device-type";+import { useDeviceType } from "../../native/native-layout-metrics";import type { SearchBarCommands } from "react-native-screens";import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass";@@ -24,16 +25,22 @@ export function WorkspaceToolbar(props: {}) {const workspace = useWorkspaceTabs()!;const navigation = useNavigation();- const metrics = useNativeLayoutMetrics();const deviceType = useDeviceType();const sidebarTabs = useSidebarWorkspaceTabs();const selectTab = useSelectWorkspaceTab();const selectedTint = useMobileNavigationTheme().colors.primary;+ // On the Duo, compose belongs to the threads tab, in the detail column's bar when unfolded.const nativeToolbarCompose =Platform.OS === "ios" &&- (deviceType === "pad" ||- sidebarTabs !== null ||- (metrics?.verticalBarEdge ?? "none") !== "none");+ (isDuoDevice(deviceType)+ ? deviceType === "duo-folded" && workspace.state.selectedTab === "threads"+ : deviceType === "pad");+ // The expanded Duo sidebar keeps a full search field in its bottom toolbar. UIKit holds the+ // integrated field there, but moves the button form into the detail column's vertical bar.+ // Folded, the workspace tab bar owns the bottom of the vertical bar, so search keeps UIKit's+ // own placement.+ const toolbarSearch =+ NATIVE_LIQUID_GLASS_SUPPORTED && deviceType === "duo-unfolded" && props.sidebar === true;const { isTabActive } = workspace;const tabActive = use(NativeWorkspaceTabActivityContext)?.active ?? true;const { panes, togglePrimarySidebar } = useAdaptiveWorkspaceLayout();@@ -87,8 +94,15 @@ export function WorkspaceToolbar(props: {hideNavigationBar: false,hideWhenScrolling: false,obscureBackground: false,- placement: NATIVE_LIQUID_GLASS_SUPPORTED ? "integratedButton" : "stacked",- allowToolbarIntegration: NATIVE_LIQUID_GLASS_SUPPORTED,+ placement: toolbarSearch+ ? "integrated"+ : NATIVE_LIQUID_GLASS_SUPPORTED+ ? "integratedButton"+ : "stacked",+ // Folded, the tab bar owns the bottom of the vertical bar; refusing toolbar+ // integration also makes UIKit re-place a visible search in the navigation bar.+ allowToolbarIntegration:+ NATIVE_LIQUID_GLASS_SUPPORTED && deviceType !== "duo-folded",placeholder:selectedTab === "pullRequests" ? "Search pull requests" : "Search threads",cancelButtonText: "✕",@@ -154,6 +168,7 @@ export function WorkspaceToolbar(props: {/>) : null}{nativeToolbarCompose ? <Toolbar.Spacer flexible /> : null}+ {toolbarSearch ? <Toolbar.SearchBarSlot /> : null}{nativeToolbarCompose ? (<Toolbar.Buttonidentifier="workspace-compose"diff --git a/apps/mobile/src/native/StackHeader.tsx b/apps/mobile/src/native/StackHeader.tsxindex 698a345035c..3aa13736e02 100644--- a/apps/mobile/src/native/StackHeader.tsx+++ b/apps/mobile/src/native/StackHeader.tsx@@ -1,6 +1,5 @@import { useNavigation, type ParamListBase } from "@react-navigation/native";import type {- NativeStackHeaderItemMenu,NativeStackNavigationOptions,NativeStackNavigationProp,} from "@react-navigation/native-stack";@@ -20,7 +19,6 @@ export type AppNativeStackNavigationOptions = Omit<"headerTintColor" | "unstable_headerLeftItems" | "unstable_headerRightItems"> & {readonly nativeContentInsetHorizontally?: boolean;- readonly nativeSidebarFilter?: NativeStackHeaderItemMenu;readonly headerTintColor?: string | ColorValue;readonly unstable_headerCenterItems?: unknown;readonly unstable_headerLeftItems?: unknown;diff --git a/apps/mobile/src/native/V5StackHeader.ios.tsx b/apps/mobile/src/native/V5StackHeader.ios.tsxindex 85419d80353..e2a89fd28c4 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 } from "react";+import { isValidElement, useEffect, useRef, useState } from "react";import { StyleSheet } from "react-native";import { useMobileNavigationTheme } from "../lib/useMobileNavigationTheme";import { useDeviceType, useNativeLayoutMetrics } from "../native/native-layout-metrics";@@ -139,36 +139,34 @@ function convertItems(items: NativeStackHeaderItem[], prefix: string): HeaderIteexport function V5StackHeader(props: {readonly options: Options;readonly canGoBack: boolean;- readonly primary?: boolean;- readonly sidebarFilter?: NativeStackHeaderItemMenu;+ /** Workspace split columns share the vertical bar with the workspace tab bar. */+ readonly column?: "primary" | "detail";+ /** The workspace's compose action, shown as its own group in this column's bar. */+ readonly onCompose?: () => void;+ /** Whether another column covers this one in a collapsed split. */+ readonly covered?: boolean;}) {const { options } = props;const theme = useMobileNavigationTheme();const nativeMetrics = useNativeLayoutMetrics();const deviceType = useDeviceType();const searchRef = useRef<SearchBarCommands>(null);- const usesDuoToolbarRail =- deviceType === "duo-unfolded" && (nativeMetrics?.verticalBarEdge ?? "none") !== "none";const itemProps = { tintColor: options.headerTintColor, canGoBack: props.canGoBack };const leading = convertItems(options.unstable_headerLeftItems?.(itemProps) ?? [], "leading");- const trailingItems = [- ...(options.unstable_headerCenterItems?.() ?? []),- ...(options.unstable_headerRightItems?.(itemProps) ?? []),- ];- // Keep the sidebar's filter actions when UIKit moves the menu to the detail rail.- if (usesDuoToolbarRail && !props.primary && props.sidebarFilter) {- trailingItems.push({- ...props.sidebarFilter,- identifier: "home-filter",- axisBehavior: "verticalPreferred",- });- }- const trailing = convertItems(trailingItems, "trailing");+ const trailing = convertItems(+ [+ ...(options.unstable_headerCenterItems?.() ?? []),+ ...(options.unstable_headerRightItems?.(itemProps) ?? []),+ ],+ "trailing",+ );const toolbar = options.unstable_headerToolbarItems?.() ?? [];const mailSearch = toolbar.find((item): item is HeaderBarButtonMailSearchToolbarItem => item.type === "mailSearchToolbar",);const bottomSearch = Boolean(mailSearch) && deviceType !== "pad";+ // A vertical bar keeps fixed spaces at full length and separates items itself.+ const spacesSearch = bottomSearch && (nativeMetrics?.verticalBarEdge ?? "none") === "none";const bottom = toolbar.flatMap<HeaderItem>((item, index) => {if (item.type === "mailSearchToolbar") return [];if (item.type === "searchBarPlacement")@@ -180,7 +178,6 @@ export function V5StackHeader(props: {bottom.push({type: "item",id: mailSearch.filterButtonId ?? "filter",- axisBehavior: bottomSearch ? "horizontalOnly" : undefined,icon: {type: "sfSymbol",name: mailSearch.filterSystemImageName ?? "line.3.horizontal.decrease",@@ -188,37 +185,46 @@ export function V5StackHeader(props: {menu: convertMenu(mailSearch.filterMenu, "filter-menu"),});if (bottomSearch) {- if (bottom.length)+ if (spacesSearch && bottom.length)bottom.push({ type: "spacer", id: "before-search", sizing: "fixed", width: 8 });- bottom.push({- type: "item",- id: "home-search",- axisBehavior: "horizontalOnly",- searchBarPlacement: true,- });- if (mailSearch.onComposePress)+ bottom.push({ type: "item", id: "home-search", searchBarPlacement: true });+ if (spacesSearch && mailSearch.onComposePress)bottom.push({ type: "spacer", id: "after-search", sizing: "fixed", width: 8 });}if (mailSearch.onComposePress)bottom.push({type: "item",id: mailSearch.composeButtonId ?? "compose",- axisBehavior: bottomSearch ? "horizontalOnly" : undefined,identifier: "workspace-trailing-action",icon: { type: "sfSymbol", name: mailSearch.composeSystemImageName ?? "square.and.pencil" },onPress: mailSearch.onComposePress,});}- // Duo keeps compose at the bottom of a visible sidebar. On a single panel,- // the primary column owns the rail too; its separate UIToolbar is inaccessible.+ // UIKit doesn't stack a column's toolbar against the workspace tab bar, which owns the+ // bottom of the vertical bar and draws over it. Those columns keep the group in their+ // navigation items. An expanded sidebar's toolbar stays horizontal, outside the bar.if (+ props.column &&nativeMetrics &&nativeMetrics.verticalBarEdge !== "none" &&- (!props.primary || nativeMetrics.horizontalSizeClass === "compact")+ (props.column === "detail" || nativeMetrics.horizontalSizeClass === "compact")) {+ if (trailing.length && bottom.length)+ trailing.push({ type: "spacer", id: "toolbar-group", sizing: "fixed", width: 8 });trailing.push(...bottom);bottom.length = 0;}+ if (props.onCompose) {+ if (trailing.length)+ trailing.push({ type: "spacer", id: "compose-group", sizing: "fixed", width: 8 });+ trailing.push({+ type: "item",+ id: "workspace-compose",+ title: "New task",+ icon: { type: "sfSymbol", name: "square.and.pencil" },+ onPress: props.onCompose,+ });+ }const left = options.headerLeft?.(itemProps);const right = options.headerRight?.(itemProps);if (!options.unstable_headerLeftItems && isValidElement(left))@@ -231,6 +237,20 @@ export function V5StackHeader(props: {? options.headerTitle({ children: title ?? "", tintColor: options.headerTintColor }): undefined;const searchOptions = options.headerSearchBarOptions;+ const searchPlacement = bottomSearch ? "integrated" : (searchOptions?.placement ?? "automatic");+ // UIKit re-places a visible search controller when its placement changes, but not one whose+ // column is covered; that one needs a new controller to place once the column shows again.+ // A hidden tab only sees the new placement as it returns, after its detail uncovered the list.+ const covered = props.covered === true;+ const [search, setSearch] = useState({ placement: searchPlacement, covered, epoch: 0 });+ if (search.placement !== searchPlacement || search.covered !== covered)+ setSearch({+ placement: searchPlacement,+ covered,+ epoch:+ search.epoch ++ (search.placement !== searchPlacement && (search.covered || covered) ? 1 : 0),+ });const autofocusRef = searchOptions?.ref ?? searchRef;const searchHasFocus = useRef(false);useEffect(() => {@@ -277,12 +297,13 @@ export function V5StackHeader(props: {searchBar:mailSearch || searchOptions ? (<SearchBar+ key={search.epoch}{...searchOptions}ref={searchOptions?.ref ?? searchRef}hideNavigationBar={false}hideWhenScrolling={false}allowToolbarIntegration={searchOptions?.allowToolbarIntegration ?? true}- placement={bottomSearch ? "integrated" : (searchOptions?.placement ?? "automatic")}+ placement={searchPlacement}placeholder={mailSearch?.placeholder ?? searchOptions?.placeholder ?? "Search"}onFocus={(event) => {searchHasFocus.current = true;