@devries-cameron20 / t3code Mirror · read-only / commits / 89ce030d05
Fork 0

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 23, 08:00 UTC

refactor(mobile): add a device type flag for iPad and iPhone Duo UI (#20399)

Co-authored-by: Cursor <cursoragent@cursor.com>

Max Weinbach committed Oct 16, 2026 at 19:02 UTC 89ce030d0520a8fb3f749d8635b8319c43e0bde8
14 files changed +155 -51
apps/mobile/src/components/ui/AppBar.tsx
+4 -4
@@ -2,11 +2,12 @@ import { Toolbar } from "./Toolbar";
2 import { AppActivityIndicator } from "./AppActivityIndicator";
3 import type { HeaderBarButtonMailSearchToolbarItem } from "react-native-screens";
4 import { useId } from "react";
5 -import { Platform, View } from "react-native";
5 +import { View } from "react-native";
6 import { createNativeHeaderMenu } from "./nativeHeaderMenu.ios";
7 import { ScreenHeaderButton } from "./ScreenHeaderButton";
8 import { NativeStackScreenOptions } from "../../native/StackHeader";
9 import { useNativeWorkspaceColumnsSupported } from "../../native/NativeWorkspaceColumns";
10 +import { useDeviceType } from "../../native/native-layout-metrics";
11 import { useAdaptiveWorkspaceLayout } from "../../features/layout/AdaptiveWorkspaceLayout";
12 import {
13 createNativeMailSearchToolbarItem,
@@ -38,6 +39,7 @@ function mailMenuItems(items: ReadonlyArray<AppBarMenuItem>): MailMenu["items"]
39
40 export function AppBar(props: AppBarProps) {
41 const usesNativeWorkspaceColumns = useNativeWorkspaceColumnsSupported();
42 + const deviceType = useDeviceType();
43 const headerId = useId();
44 const { layout, panes, togglePrimarySidebar } = useAdaptiveWorkspaceLayout();
45 const { themeVariables } = useAppearancePreferences();
@@ -123,9 +125,7 @@ export function AppBar(props: AppBarProps) {
125 />
126 ) : null}
127 {props.sidebar !== false &&
126 - (!usesNativeWorkspaceColumns ||
127 - (Platform.OS === "ios" && Platform.isPad) ||
128 - !panes.primarySidebarVisible) ? (
128 + (!usesNativeWorkspaceColumns || deviceType === "pad" || !panes.primarySidebarVisible) ? (
129 <ScreenHeaderButton
130 axisBehavior={usesNativeWorkspaceColumns ? "horizontalOnly" : undefined}
131 accessibilityLabel={
apps/mobile/src/features/home/HomeHeader.tsx
+4 -2
@@ -11,6 +11,7 @@ import { useHardwareKeyboardCommand } from "../keyboard/hardwareKeyboardCommands
11 import { withNativeGlassHeaderItem } from "../layout/native-glass-header-items";
12 import { createNativeMailSearchToolbarItem } from "../layout/native-mail-search-toolbar";
13 import { useNativeMailSearchToolbar } from "../../native/use-native-mail-search-toolbar";
14 +import { useDeviceType } from "../../native/native-layout-metrics";
15 import { buildHomeListFilterMenu } from "./home-list-filter-menu";
16 import { createSidebarHeaderItems } from "../threads/sidebar-native-header-items";
17 import type { HomeHeaderProps } from "./HomeHeader.types";
@@ -22,12 +23,13 @@ export function HomeHeader(props: HomeHeaderProps) {
23 const navigation = useNavigation<NativeStackNavigationProp<ParamListBase>>();
24 const { layout, panes, togglePrimarySidebar } = useAdaptiveWorkspaceLayout();
25 const usesNativeMailSearchToolbar = useNativeMailSearchToolbar();
26 + const deviceType = useDeviceType();
27 const primaryColumn = use(NativePrimaryColumnContext);
28 const sidebarHeader =
29 Platform.OS === "ios" &&
30 primaryColumn !== null &&
29 - (Platform.isPad || !usesNativeMailSearchToolbar);
30 - const showsCompactCompose = Platform.OS === "ios" && Platform.isPad && !layout.usesSplitView;
31 + (deviceType === "pad" || !usesNativeMailSearchToolbar);
32 + const showsCompactCompose = deviceType === "pad" && !layout.usesSplitView;
33 const searchBarRef = useRef<SearchBarCommands>(null);
34 const focusAfterReveal = useRef(false);
35 useEffect(
apps/mobile/src/features/home/HomeRouteScreen.tsx
+3 -3
@@ -17,7 +17,7 @@ import { usePendingNewTasks } from "../../state/use-pending-new-tasks";
17 import { useWorkspaceState } from "../../state/workspace";
18 import { useSavedRemoteConnections } from "../../state/use-remote-environment-registry";
19 import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
20 -import { useNativeColumnLayoutMetrics } from "../../native/native-layout-metrics";
20 +import { useDeviceType, useNativeColumnLayoutMetrics } from "../../native/native-layout-metrics";
21 import { WorkspaceEmptyDetail } from "../layout/WorkspaceEmptyDetail";
22 import { AndroidScreenHeader } from "../../components/ui/AndroidScreenHeader";
23 import { checkForAppUpdateOnLaunch, startAppUpdateForegroundRecheck } from "../updates/app-updates";
@@ -37,6 +37,7 @@ export function HomeRouteScreen() {
37 const { width: windowWidth } = useWindowDimensions();
38 const nativePrimaryColumn = use(NativePrimaryColumnContext);
39 const columnMetrics = useNativeColumnLayoutMetrics();
40 + const deviceType = useDeviceType();
41 const headerWidth = nativePrimaryColumn ? (columnMetrics?.width ?? windowWidth) : windowWidth;
42 const { layout, panes, primarySidebarSearchQuery, setPrimarySidebarSearchQuery } =
43 useAdaptiveWorkspaceLayout();
@@ -214,8 +215,7 @@ export function HomeRouteScreen() {
215 options={{
216 ...getConnectionAwareBrandHeaderOptions({
217 headerWidth,
217 - trailingItemCount:
218 - nativePrimaryColumn && Platform.OS === "ios" && Platform.isPad ? 2 : 1,
218 + trailingItemCount: nativePrimaryColumn && deviceType === "pad" ? 2 : 1,
219 onOpenEnvironments: () =>
220 navigation.navigate("SettingsSheet", {
221 screen: "SettingsContent",
apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
+5 -6
@@ -20,13 +20,14 @@ import {
20 type NativeStackTypeBag,
21 } from "@react-navigation/native-stack";
22 import { use, useCallback, useEffect, useMemo, useRef, useState, type ComponentProps } from "react";
23 -import { Platform, View } from "react-native";
23 +import { View } from "react-native";
24 import { Split, type SplitHostCommands } from "react-native-screens";
25 import { EnvironmentId, ThreadId } from "@t3tools/contracts";
26 +import { isDuoDevice } from "../../lib/device-type";
27 import { scopedThreadKey } from "../../lib/scopedEntities";
28 import { WorkspaceTabsProvider } from "../workspace/WorkspaceTabsContext";
29 import { WorkspaceNativeTabs } from "../workspace/WorkspaceNativeTabs.ios";
29 -import { useNativeLayoutMetrics } from "../../native/native-layout-metrics";
30 +import { useDeviceType, useNativeLayoutMetrics } from "../../native/native-layout-metrics";
31
32 import { useAdaptiveWorkspaceLayout } from "./AdaptiveWorkspaceLayout";
33 import { WorkspaceEmptyDetail } from "./WorkspaceEmptyDetail";
@@ -124,6 +125,7 @@ function WorkspaceColumns(
125 props: ViewProps & { readonly primary: Route; readonly detail: Route[] },
126 ) {
127 const { layout, panes, togglePrimarySidebar, toggleAuxiliaryPane } = useAdaptiveWorkspaceLayout();
128 + const deviceType = useDeviceType();
129 const inspector = use(NativeWorkspaceInspectorContext);
130 const hostRef = useRef<SplitHostCommands>(null);
131 const activeDetailKey = props.detail.at(-1)?.key;
@@ -221,10 +223,7 @@ function WorkspaceColumns(
223 headerShown: true,
224 title: "",
225 unstable_headerRightItems: () =>
224 - Platform.OS === "ios" &&
225 - !Platform.isPad &&
226 - layout.usesSplitView &&
227 - !panes.primarySidebarVisible
226 + isDuoDevice(deviceType) && layout.usesSplitView && !panes.primarySidebarVisible
227 ? [
228 {
229 type: "button",
apps/mobile/src/features/threads/ThreadFeed.tsx
+10 -18
@@ -66,6 +66,8 @@ import { SymbolView, type AppSymbolName } from "../../components/ui/AppSymbol";
66 import { HeaderHeightContext } from "@react-navigation/elements";
67 import { useFocusEffect, useNavigation } from "@react-navigation/native";
68 import { useNativeWorkspaceColumnsSupported } from "../../native/NativeWorkspaceColumns";
69 +import { useDeviceType } from "../../native/native-layout-metrics";
70 +import { isDuoDevice } from "../../lib/device-type";
71 import {
72 createContext,
73 memo,
@@ -998,7 +1000,7 @@ function renderFeedEntry(
1000 readonly reviewCommentColors: ReviewCommentColors;
1001 readonly reviewCommentBubbleWidth: number;
1002 readonly themeAppearance: "light" | "dark";
1001 - readonly usesNativeWorkspaceColumns: boolean;
1003 + readonly duoColumns: boolean;
1004 readonly userBubbleMaxWidth: number;
1005 readonly markdownContentWidth: number;
1006 readonly contentWidth: number;
@@ -1189,19 +1191,11 @@ function renderFeedEntry(
1191 className="min-w-0 gap-2 rounded-[20px] px-3.5 py-2.5"
1192 style={{
1193 backgroundColor: userBubbleColor,
1192 - maxWidth:
1193 - props.usesNativeWorkspaceColumns && Platform.OS === "ios" && !Platform.isPad
1194 - ? "85%"
1195 - : props.userBubbleMaxWidth,
1194 + maxWidth: props.duoColumns ? "85%" : props.userBubbleMaxWidth,
1195 ...(hasReviewCommentContext
1196 ? { width: props.reviewCommentBubbleWidth }
1197 : hasWideBlock
1199 - ? {
1200 - width:
1201 - props.usesNativeWorkspaceColumns && Platform.OS === "ios" && !Platform.isPad
1202 - ? "85%"
1203 - : props.userBubbleMaxWidth,
1204 - }
1198 + ? { width: props.duoColumns ? "85%" : props.userBubbleMaxWidth }
1199 : null),
1200 }}
1201 >
@@ -1667,7 +1661,8 @@ function ThreadFeedPlaceholder(props: {
1661 }
1662
1663 export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
1670 - const usesNativeWorkspaceColumns = useNativeWorkspaceColumnsSupported();
1664 + const deviceType = useDeviceType();
1665 + const duoColumns = useNativeWorkspaceColumnsSupported() && isDuoDevice(deviceType);
1666 const openPullRequest = useOpenPullRequest();
1667 const navigation = useNavigation();
1668 const { themeAppearance } = useAppearancePreferences();
@@ -2474,7 +2469,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
2469 reviewCommentColors,
2470 reviewCommentBubbleWidth,
2471 themeAppearance,
2477 - usesNativeWorkspaceColumns,
2472 + duoColumns,
2473 userBubbleMaxWidth,
2474 markdownContentWidth,
2475 contentWidth,
@@ -2513,7 +2508,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
2508 reviewCommentColors,
2509 reviewCommentBubbleWidth,
2510 themeAppearance,
2516 - usesNativeWorkspaceColumns,
2511 + duoColumns,
2512 userBubbleMaxWidth,
2513 markdownContentWidth,
2514 contentWidth,
@@ -2568,10 +2563,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
2563 // Horizontal Duo reservations are already included in the row padding.
2564 contentInsetAdjustmentBehavior={
2565 usesNativeAutomaticInsets
2571 - ? usesNativeWorkspaceColumns &&
2572 - Platform.OS === "ios" &&
2573 - !Platform.isPad &&
2574 - props.layoutVariant === "split"
2566 + ? duoColumns && props.layoutVariant === "split"
2567 ? "scrollableAxes"
2568 : "automatic"
2569 : "never"
apps/mobile/src/features/threads/useThreadHeaderOptions.tsx
+5 -6
@@ -1,7 +1,8 @@
1 import { StackActions, useNavigation } from "@react-navigation/native";
2 import { useMemo } from "react";
3 -import { Platform } from "react-native";
3 +import { isDuoDevice } from "../../lib/device-type";
4 import type { AppNativeStackNavigationOptions } from "../../native/StackHeader";
5 +import { useDeviceType } from "../../native/native-layout-metrics";
6 import { useNativeWorkspaceColumnsSupported } from "../../native/NativeWorkspaceColumns";
7 import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
8 import { withNativeGlassHeaderItem } from "../layout/native-glass-header-items";
@@ -23,7 +24,8 @@ export function useThreadHeaderOptions(props: {
24 readonly onReturnToThread?: () => void;
25 }) {
26 const usesNativeWorkspaceColumns = useNativeWorkspaceColumnsSupported();
26 - const usesDuoHeader = usesNativeWorkspaceColumns && Platform.OS === "ios" && !Platform.isPad;
27 + const deviceType = useDeviceType();
28 + const usesDuoHeader = usesNativeWorkspaceColumns && isDuoDevice(deviceType);
29 const navigation = useNavigation();
30 const { layout, panes, togglePrimarySidebar } = useAdaptiveWorkspaceLayout();
31 const threadCenterHeaderItems = useThreadGitCenterHeaderItems(props.gitControls);
@@ -103,10 +105,7 @@ export function useThreadHeaderOptions(props: {
105 () => [
106 ...threadCenterHeaderItems,
107 { type: "spacing", spacing: 8 },
106 - ...(layout.usesSplitView &&
107 - Platform.OS === "ios" &&
108 - !Platform.isPad &&
109 - !panes.primarySidebarVisible
108 + ...(layout.usesSplitView && !panes.primarySidebarVisible
109 ? [
110 withNativeGlassHeaderItem({
111 type: "button" as const,
apps/mobile/src/features/workspace/WorkspaceNativeTabs.ios.tsx
+5 -2
@@ -1,4 +1,4 @@
1 -import { useNativeLayoutMetrics } from "../../native/native-layout-metrics";
1 +import { useDeviceType, useNativeLayoutMetrics } from "../../native/native-layout-metrics";
2 import { useCallback, useMemo, useState, type ReactNode } from "react";
3 import { Keyboard, Platform, View, type NativeSyntheticEvent } from "react-native";
4 import {
@@ -52,8 +52,11 @@ export function WorkspaceNativeTabs(props: {
52 }) {
53 const workspace = useWorkspaceTabs()!;
54 const metrics = useNativeLayoutMetrics();
55 + const deviceType = useDeviceType();
56 const phoneBar =
56 - Platform.OS === "ios" && !Platform.isPad && (metrics?.verticalBarEdge ?? "none") === "none";
57 + Platform.OS === "ios" &&
58 + deviceType !== "pad" &&
59 + (metrics?.verticalBarEdge ?? "none") === "none";
60 const [provenance, setProvenance] = useState(0);
61 const systemTabBar = useSystemWorkspaceTabBar();
62 const selectedTab = workspace.state.selectedTab;
apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx
+3 -1
@@ -9,6 +9,7 @@ import { AndroidScreenHeader } from "../../components/ui/AndroidScreenHeader";
9 import { NativeStackScreenOptions } from "../../native/StackHeader";
10 import { NativePrimaryColumnContext } from "../../native/v5-workspace-context";
11 import {
12 + useDeviceType,
13 useNativeColumnLayoutMetrics,
14 useNativeLayoutMetrics,
15 } from "../../native/native-layout-metrics";
@@ -57,13 +58,14 @@ function WorkspaceRootContent() {
58 const primaryColumn = use(NativePrimaryColumnContext);
59 const columnMetrics = useNativeColumnLayoutMetrics();
60 const nativeMetrics = useNativeLayoutMetrics();
61 + const deviceType = useDeviceType();
62 const systemTabBar = useSystemWorkspaceTabBar();
63 const sidebarTabs = useSidebarWorkspaceTabs();
64 const sidebarPicker = sidebarTabs === "picker";
65 const sidebarNavigation =
66 primaryColumn !== null &&
67 (layout.usesSplitView ||
66 - (Platform.OS === "ios" && Platform.isPad) ||
68 + deviceType === "pad" ||
69 (nativeMetrics !== null && nativeMetrics.verticalBarEdge !== "none"));
70 const width = columnMetrics?.width ?? windowWidth;
71 const insets = useSafeAreaInsets();
apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx
+5 -2
@@ -2,7 +2,7 @@ import { Toolbar } from "../../components/ui/Toolbar";
2 import { useFocusEffect, useNavigation } from "@react-navigation/native";
3 import { use, useCallback, useEffect, useRef } from "react";
4 import { Platform } from "react-native";
5 -import { useNativeLayoutMetrics } from "../../native/native-layout-metrics";
5 +import { useDeviceType, useNativeLayoutMetrics } from "../../native/native-layout-metrics";
6 import type { SearchBarCommands } from "react-native-screens";
7
8 import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass";
@@ -25,12 +25,15 @@ export function WorkspaceToolbar(props: {
25 const workspace = useWorkspaceTabs()!;
26 const navigation = useNavigation();
27 const metrics = useNativeLayoutMetrics();
28 + const deviceType = useDeviceType();
29 const sidebarTabs = useSidebarWorkspaceTabs();
30 const selectTab = useSelectWorkspaceTab();
31 const selectedTint = useMobileNavigationTheme().colors.primary;
32 const nativeToolbarCompose =
33 Platform.OS === "ios" &&
33 - (Platform.isPad || sidebarTabs !== null || (metrics?.verticalBarEdge ?? "none") !== "none");
34 + (deviceType === "pad" ||
35 + sidebarTabs !== null ||
36 + (metrics?.verticalBarEdge ?? "none") !== "none");
37 const { isTabActive } = workspace;
38 const tabActive = use(NativeWorkspaceTabActivityContext)?.active ?? true;
39 const { panes, togglePrimarySidebar } = useAdaptiveWorkspaceLayout();
apps/mobile/src/features/workspace/useSystemWorkspaceTabBar.ts
+3 -2
@@ -1,13 +1,14 @@
1 import { Platform } from "react-native";
2 import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
3 -import { useNativeLayoutMetrics } from "../../native/native-layout-metrics";
3 +import { useDeviceType, useNativeLayoutMetrics } from "../../native/native-layout-metrics";
4
5 /** Where an iOS split window shows the workspace tabs instead of UIKit's tab bar. */
6 export function useSidebarWorkspaceTabs(): "picker" | "toolbar" | null {
7 const { layout } = useAdaptiveWorkspaceLayout();
8 + const deviceType = useDeviceType();
9 const metrics = useNativeLayoutMetrics();
10 if (Platform.OS !== "ios" || !layout.usesSplitView) return null;
10 - if (Platform.isPad) return "picker";
11 + if (deviceType === "pad") return "picker";
12 // The Duo's side rail carries UIKit's tabs. Unfolded in portrait it has no
13 // rail, so the tabs sit in the thread list's own toolbar.
14 return (metrics?.verticalBarEdge ?? "none") === "none" ? "toolbar" : null;
apps/mobile/src/lib/device-type.test.ts new
+62
@@ -0,0 +1,62 @@
1 +import { describe, expect, it } from "vite-plus/test";
2 +import { deriveDeviceType, isDuoDevice } from "./device-type";
3 +import type { NativeLayoutMetrics } from "./reserved-regions";
4 +
5 +// Poses reported by the iOS 27.1 iPhone Duo simulator.
6 +const duoOuter: NativeLayoutMetrics = {
7 + width: 466,
8 + height: 678,
9 + hasHinge: true,
10 + horizontalSizeClass: "compact",
11 + verticalBarEdge: "right",
12 + safeArea: { top: 0, bottom: 34, left: 0, right: 84 },
13 + reservedRegions: [],
14 +};
15 +const duoInnerPortrait: NativeLayoutMetrics = {
16 + width: 669,
17 + height: 951,
18 + hasHinge: true,
19 + horizontalSizeClass: "regular",
20 + verticalBarEdge: "none",
21 + safeArea: { top: 82, bottom: 34, left: 0, right: 0 },
22 + reservedRegions: [{ kind: "occlusion", x: 535, y: 0, width: 134, height: 82 }],
23 +};
24 +const phone: NativeLayoutMetrics = {
25 + width: 393,
26 + height: 852,
27 + horizontalSizeClass: "compact",
28 + verticalBarEdge: "none",
29 + safeArea: { top: 59, bottom: 34, left: 0, right: 0 },
30 + reservedRegions: [],
31 +};
32 +
33 +describe("deriveDeviceType", () => {
34 + it("follows the Duo between its displays", () => {
35 + expect(deriveDeviceType({ isPad: false, metrics: duoOuter })).toBe("duo-folded");
36 + expect(deriveDeviceType({ isPad: false, metrics: duoInnerPortrait })).toBe("duo-unfolded");
37 + expect(
38 + deriveDeviceType({
39 + isPad: false,
40 + metrics: { ...duoInnerPortrait, width: 951, height: 669, verticalBarEdge: "right" },
41 + }),
42 + ).toBe("duo-unfolded");
43 + });
44 +
45 + it("treats a narrow inner-display window like the folded screen", () => {
46 + expect(
47 + deriveDeviceType({
48 + isPad: false,
49 + metrics: { ...duoInnerPortrait, width: 320, horizontalSizeClass: "compact" },
50 + }),
51 + ).toBe("duo-folded");
52 + });
53 +
54 + it("keeps ordinary phones and iPads out of the Duo branches", () => {
55 + expect(deriveDeviceType({ isPad: false, metrics: phone })).toBe("phone");
56 + expect(deriveDeviceType({ isPad: false, metrics: null })).toBe("phone");
57 + expect(deriveDeviceType({ isPad: true, metrics: null })).toBe("pad");
58 + const slideOver = { ...phone, width: 320, height: 1024 };
59 + expect(deriveDeviceType({ isPad: true, metrics: slideOver })).toBe("pad");
60 + expect(isDuoDevice(deriveDeviceType({ isPad: true, metrics: slideOver }))).toBe(false);
61 + });
62 +});
apps/mobile/src/lib/device-type.ts new
+25
@@ -0,0 +1,25 @@
1 +import type { NativeLayoutMetrics } from "./reserved-regions";
2 +
3 +/**
4 + * Hardware family for device-specific chrome. Column count still comes from
5 + * `deriveLayout`: an iPad in Slide Over or a narrow window on the Duo's inner
6 + * display keeps its device type but has no room for a sidebar.
7 + *
8 + * iOS only. Android has no layout metrics observer and always reads "phone".
9 + */
10 +export type DeviceType = "phone" | "duo-folded" | "duo-unfolded" | "pad";
11 +
12 +export function deriveDeviceType(input: {
13 + readonly isPad: boolean;
14 + readonly metrics: NativeLayoutMetrics | null;
15 +}): DeviceType {
16 + if (input.isPad) return "pad";
17 + // The hinge arrives with the first native layout pass, so a Duo reads as a
18 + // phone until then. Compact width also covers a narrow inner-display window.
19 + if (input.metrics?.hasHinge !== true) return "phone";
20 + return input.metrics.horizontalSizeClass === "regular" ? "duo-unfolded" : "duo-folded";
21 +}
22 +
23 +export function isDuoDevice(deviceType: DeviceType): boolean {
24 + return deviceType === "duo-folded" || deviceType === "duo-unfolded";
25 +}
apps/mobile/src/native/V5StackHeader.ios.tsx
+4 -3
@@ -4,9 +4,9 @@ import type {
4 NativeStackNavigationOptions,
5 } from "@react-navigation/native-stack";
6 import { isValidElement, useEffect, useRef } from "react";
7 -import { Platform, StyleSheet } from "react-native";
7 +import { StyleSheet } from "react-native";
8 import { useMobileNavigationTheme } from "../lib/useMobileNavigationTheme";
9 -import { useNativeLayoutMetrics } from "../native/native-layout-metrics";
9 +import { useDeviceType, useNativeLayoutMetrics } from "../native/native-layout-metrics";
10 import {
11 SearchBar,
12 Stack,
@@ -144,6 +144,7 @@ export function V5StackHeader(props: {
144 const { options } = props;
145 const theme = useMobileNavigationTheme();
146 const nativeMetrics = useNativeLayoutMetrics();
147 + const deviceType = useDeviceType();
148 const searchRef = useRef<SearchBarCommands>(null);
149 const itemProps = { tintColor: options.headerTintColor, canGoBack: props.canGoBack };
150 const leading = convertItems(options.unstable_headerLeftItems?.(itemProps) ?? [], "leading");
@@ -158,7 +159,7 @@ export function V5StackHeader(props: {
159 const mailSearch = toolbar.find(
160 (item): item is HeaderBarButtonMailSearchToolbarItem => item.type === "mailSearchToolbar",
161 );
161 - const bottomSearch = Boolean(mailSearch) && Platform.OS === "ios" && !Platform.isPad;
162 + const bottomSearch = Boolean(mailSearch) && deviceType !== "pad";
163 const bottom = toolbar.flatMap<HeaderItem>((item, index) => {
164 if (item.type === "mailSearchToolbar") return [];
165 if (item.type === "searchBarPlacement")
apps/mobile/src/native/native-layout-metrics.tsx
+17 -2
@@ -1,17 +1,28 @@
1 import { createContext, use, useState, type ReactNode } from "react";
2 +import { Platform } from "react-native";
3 +import { deriveDeviceType, type DeviceType } from "../lib/device-type";
4 import type { NativeLayoutMetrics } from "../lib/reserved-regions";
5 import { NativeLayoutObserver } from "./NativeLayoutObserver";
6
7 +const IS_PAD = Platform.OS === "ios" && Platform.isPad;
8 +
9 const NativeLayoutContext = createContext<NativeLayoutMetrics | null>(null);
10 +// Separate from the metrics so device checks skip every resize and safe-area update.
11 +const DeviceTypeContext = createContext<DeviceType>(
12 + deriveDeviceType({ isPad: IS_PAD, metrics: null }),
13 +);
14 // Column reservations come from UIKit's layout, outside the resizing navigator.
15 export const NativeColumnLayoutMetricsContext = createContext<NativeLayoutMetrics | null>(null);
16
17 export function NativeLayoutMetricsProvider(props: { readonly children: ReactNode }) {
18 const [metrics, setMetrics] = useState<NativeLayoutMetrics | null>(null);
19 + const deviceType = deriveDeviceType({ isPad: IS_PAD, metrics });
20 return (
21 <NativeLayoutContext value={metrics}>
13 - <NativeLayoutObserver onChange={setMetrics} />
14 - {props.children}
22 + <DeviceTypeContext value={deviceType}>
23 + <NativeLayoutObserver onChange={setMetrics} />
24 + {props.children}
25 + </DeviceTypeContext>
26 </NativeLayoutContext>
27 );
28 }
@@ -23,3 +34,7 @@ export function useNativeLayoutMetrics() {
34 export function useNativeColumnLayoutMetrics() {
35 return use(NativeColumnLayoutMetricsContext);
36 }
37 +
38 +export function useDeviceType() {
39 + return use(DeviceTypeContext);
40 +}