Skip to content

Commit d35882e

Browse files
fix(ios): show a sidebar toggle on the unfolded iPhone Duo in portrait (#20133)
Co-authored-by: Julius Marminge <[email protected]>
1 parent c0de6bd commit d35882e

7 files changed

Lines changed: 111 additions & 18 deletions

File tree

‎apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ function WorkspaceRootContent() {
5959
const nativeMetrics = useNativeLayoutMetrics();
6060
const systemTabBar = useSystemWorkspaceTabBar();
6161
const sidebarTabs = useSidebarWorkspaceTabs();
62+
const sidebarPicker = sidebarTabs === "picker";
6263
const sidebarNavigation =
6364
primaryColumn !== null &&
6465
(layout.usesSplitView ||
@@ -98,8 +99,8 @@ function WorkspaceRootContent() {
9899
return (
99100
<WorkspaceTabsContext value={context}>
100101
<View
101-
className={sidebarTabs ? "flex-1 bg-drawer" : "flex-1 bg-screen"}
102-
style={sidebarTabs ? { paddingTop: insets.top } : undefined}
102+
className={sidebarPicker ? "flex-1 bg-drawer" : "flex-1 bg-screen"}
103+
style={sidebarPicker ? { paddingTop: insets.top } : undefined}
103104
>
104105
{Platform.OS === "ios" ? (
105106
<NativeStackScreenOptions
@@ -136,8 +137,8 @@ function WorkspaceRootContent() {
136137
]}
137138
/>
138139
)}
139-
{sidebarTabs ? <WorkspaceSidebarTabs /> : null}
140-
<SafeAreaInsetsContext value={sidebarTabs ? { ...insets, top: 0 } : insets}>
140+
{sidebarPicker ? <WorkspaceSidebarTabs /> : null}
141+
<SafeAreaInsetsContext value={sidebarPicker ? { ...insets, top: 0 } : insets}>
141142
{state.selectedTab === "threads" ? <HomeRouteScreen /> : <PullRequestsScreen />}
142143
</SafeAreaInsetsContext>
143144
<WorkspaceToolbar

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { StackActions, useNavigation } from "@react-navigation/native";
2-
import { Keyboard, View } from "react-native";
1+
import { View } from "react-native";
32
import { SegmentedControl } from "../../components/ui/SegmentedControl";
43
import { useWorkspaceTabs } from "./WorkspaceTabsContext";
54
import type { WorkspaceTab } from "./workspace-tabs-state";
5+
import { useSelectWorkspaceTab } from "./useSelectWorkspaceTab";
66

77
export function WorkspaceSidebarTabs() {
88
const workspace = useWorkspaceTabs()!;
9-
const navigation = useNavigation();
9+
const selectTab = useSelectWorkspaceTab();
1010
return (
1111
<View className="px-4 pb-3 pt-2">
1212
<SegmentedControl
@@ -16,12 +16,7 @@ export function WorkspaceSidebarTabs() {
1616
{ value: "pullRequests", label: "Pull requests" },
1717
]}
1818
selected={workspace.state.selectedTab}
19-
onSelect={(tab: WorkspaceTab) => {
20-
if (tab === workspace.state.selectedTab) return;
21-
Keyboard.dismiss();
22-
if (navigation.getState()?.index) navigation.dispatch(StackActions.popToTop());
23-
workspace.dispatch({ type: "select", tab });
24-
}}
19+
onSelect={(tab: WorkspaceTab) => selectTab(tab)}
2520
/>
2621
</View>
2722
);

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import { NativeWorkspaceTabActivityContext } from "../../native/v5-workspace-con
1111
import { useHardwareKeyboardCommand } from "../keyboard/hardwareKeyboardCommands";
1212
import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
1313
import { useWorkspaceTabs } from "./WorkspaceTabsContext";
14+
import { useSidebarWorkspaceTabs } from "./useSystemWorkspaceTabBar";
15+
import { useSelectWorkspaceTab } from "./useSelectWorkspaceTab";
16+
import { useMobileNavigationTheme } from "../../lib/useMobileNavigationTheme";
17+
18+
// Tabler's git-pull-request geometry, shared with the UIKit tab bar.
19+
const PULL_REQUEST_ICON = require("../../../assets/icons/pull-request.png");
1420

1521
export function WorkspaceToolbar(props: {
1622
readonly onNewTask: () => void;
@@ -19,8 +25,12 @@ export function WorkspaceToolbar(props: {
1925
const workspace = useWorkspaceTabs()!;
2026
const navigation = useNavigation();
2127
const metrics = useNativeLayoutMetrics();
28+
const sidebarTabs = useSidebarWorkspaceTabs();
29+
const selectTab = useSelectWorkspaceTab();
30+
const selectedTint = useMobileNavigationTheme().colors.primary;
2231
const nativeToolbarCompose =
23-
Platform.OS === "ios" && (Platform.isPad || (metrics?.verticalBarEdge ?? "none") !== "none");
32+
Platform.OS === "ios" &&
33+
(Platform.isPad || sidebarTabs !== null || (metrics?.verticalBarEdge ?? "none") !== "none");
2434
const { isTabActive } = workspace;
2535
const tabActive = use(NativeWorkspaceTabActivityContext)?.active ?? true;
2636
const { panes, togglePrimarySidebar } = useAdaptiveWorkspaceLayout();
@@ -122,6 +132,24 @@ export function WorkspaceToolbar(props: {
122132
)}
123133
</Toolbar>
124134
<Toolbar placement="bottom">
135+
{sidebarTabs === "toolbar" ? (
136+
<Toolbar.Button
137+
identifier="workspace-tab-threads"
138+
accessibilityLabel="Threads"
139+
icon={selectedTab === "threads" ? "text.bubble.fill" : "text.bubble"}
140+
tintColor={selectedTab === "threads" ? selectedTint : undefined}
141+
onPress={() => selectTab("threads")}
142+
/>
143+
) : null}
144+
{sidebarTabs === "toolbar" ? (
145+
<Toolbar.Button
146+
identifier="workspace-tab-pull-requests"
147+
accessibilityLabel="Pull requests"
148+
icon={{ type: "image", source: PULL_REQUEST_ICON, tinted: true }}
149+
tintColor={selectedTab === "pullRequests" ? selectedTint : undefined}
150+
onPress={() => selectTab("pullRequests")}
151+
/>
152+
) : null}
125153
{nativeToolbarCompose ? <Toolbar.Spacer flexible /> : null}
126154
{nativeToolbarCompose ? (
127155
<Toolbar.Button
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { StackActions, useNavigation } from "@react-navigation/native";
2+
import { useCallback } from "react";
3+
import { Keyboard } from "react-native";
4+
import { useWorkspaceTabs } from "./WorkspaceTabsContext";
5+
import type { WorkspaceTab } from "./workspace-tabs-state";
6+
7+
/** Switch workspace tabs from inside the sidebar, closing any open detail first. */
8+
export function useSelectWorkspaceTab() {
9+
const workspace = useWorkspaceTabs()!;
10+
const navigation = useNavigation();
11+
const selectedTab = workspace.state.selectedTab;
12+
const { dispatch } = workspace;
13+
return useCallback(
14+
(tab: WorkspaceTab) => {
15+
if (tab === selectedTab) return;
16+
Keyboard.dismiss();
17+
if (navigation.getState()?.index) navigation.dispatch(StackActions.popToTop());
18+
dispatch({ type: "select", tab });
19+
},
20+
[dispatch, navigation, selectedTab],
21+
);
22+
}
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import { Platform } from "react-native";
22
import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
3+
import { useNativeLayoutMetrics } from "../../native/native-layout-metrics";
34

4-
export function useSidebarWorkspaceTabs() {
5+
/** Where an iOS split window shows the workspace tabs instead of UIKit's tab bar. */
6+
export function useSidebarWorkspaceTabs(): "picker" | "toolbar" | null {
57
const { layout } = useAdaptiveWorkspaceLayout();
6-
return Platform.OS === "ios" && Platform.isPad && layout.usesSplitView;
8+
const metrics = useNativeLayoutMetrics();
9+
if (Platform.OS !== "ios" || !layout.usesSplitView) return null;
10+
if (Platform.isPad) return "picker";
11+
// The Duo's side rail carries UIKit's tabs. Unfolded in portrait it has no
12+
// rail, so the tabs sit in the thread list's own toolbar.
13+
return (metrics?.verticalBarEdge ?? "none") === "none" ? "toolbar" : null;
714
}
815

916
export function useSystemWorkspaceTabBar() {
1017
const sidebarTabs = useSidebarWorkspaceTabs();
11-
return Platform.OS === "ios" && !sidebarTabs;
18+
return Platform.OS === "ios" && sidebarTabs === null;
1219
}

‎apps/mobile/src/lib/layout.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,12 @@ export function deriveLayout(input: {
9191
const usableWidth = width - (metrics?.safeArea.left ?? 0) - (metrics?.safeArea.right ?? 0);
9292
// UIKit's size class supports the shorter Duo inner display. Geometry remains
9393
// a floor so a narrow multitasking window cannot squeeze both columns.
94+
// Unfolded in portrait, the inner display reports neither a side bar nor a
95+
// fold, only its hinge.
9496
const hasDuoGeometry =
9597
metrics &&
96-
(metrics.verticalBarEdge !== "none" ||
98+
(metrics.hasHinge === true ||
99+
metrics.verticalBarEdge !== "none" ||
97100
metrics.reservedRegions.some((region) => region.kind === "division"));
98101
const wideEnoughForSplit = hasDuoGeometry
99102
? metrics.horizontalSizeClass === "regular" &&

‎apps/mobile/src/lib/reserved-regions.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,43 @@ describe("Duo workspace sizing", () => {
108108
).toBe(false);
109109
});
110110

111+
it("shows both columns on the unfolded inner display in portrait", () => {
112+
// Reported by the iOS 27.1 Duo simulator: no side bar or fold, only the hinge.
113+
const portrait: NativeLayoutMetrics = {
114+
width: 669,
115+
height: 951,
116+
hasHinge: true,
117+
horizontalSizeClass: "regular",
118+
verticalBarEdge: "none",
119+
safeArea: { top: 82, bottom: 34, left: 0, right: 0 },
120+
reservedRegions: [{ kind: "occlusion", x: 535, y: 0, width: 134, height: 82 }],
121+
};
122+
expect(deriveLayout({ ...portrait, nativeMetrics: portrait }).usesSplitView).toBe(true);
123+
// Without the hinge, the same window is an ordinary narrow iPad-style window.
124+
const withoutHinge = { ...portrait, hasHinge: false };
125+
expect(deriveLayout({ ...withoutHinge, nativeMetrics: withoutHinge }).usesSplitView).toBe(
126+
false,
127+
);
128+
});
129+
130+
it("keeps the folded front screen compact in both orientations", () => {
131+
for (const [width, height] of [
132+
[466, 678],
133+
[678, 466],
134+
]) {
135+
const folded: NativeLayoutMetrics = {
136+
width: width!,
137+
height: height!,
138+
hasHinge: true,
139+
horizontalSizeClass: "compact",
140+
verticalBarEdge: "right",
141+
safeArea: { top: 0, bottom: 34, left: 0, right: 84 },
142+
reservedRegions: [],
143+
};
144+
expect(deriveLayout({ ...folded, nativeMetrics: folded }).usesSplitView).toBe(false);
145+
}
146+
});
147+
111148
it("requires enough safe width for both panes in a multitasking window", () => {
112149
const metrics = { ...innerDisplay, width: 660 };
113150
expect(deriveLayout({ ...metrics, nativeMetrics: metrics }).usesSplitView).toBe(false);

0 commit comments

Comments
 (0)