Skip to content

Commit 112a230

Browse files
committed
fix(mobile): overlay the unfolded portrait Duo sidebar
1 parent 3af154d commit 112a230

10 files changed

Lines changed: 154 additions & 39 deletions

‎apps/mobile/src/features/home/home-thread-navigation.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import type { NativeStackNavigationProp } from "@react-navigation/native-stack";
99
import { useCallback, useEffect, useRef } from "react";
1010
import { Platform } from "react-native";
11+
import { useAdaptiveWorkspaceLayout } from "../layout/adaptive-workspace-context";
1112
import { useAndroidWorkspaceSelection } from "../workspace/useAndroidWorkspaceSelection";
1213

1314
type ThreadSelection = Pick<EnvironmentThreadShell, "environmentId" | "id">;
@@ -53,6 +54,7 @@ export function useHomeThreadRouteSelection() {
5354
const navigation =
5455
useNavigation<NativeStackNavigationProp<ReactNavigation.RootParamList, "Home">>();
5556
const dismissingRouteKey = useRef<string | null>(null);
57+
const { layout, setPrimarySidebarVisible } = useAdaptiveWorkspaceLayout();
5658
const selectAndroidWorkspace = useAndroidWorkspaceSelection();
5759

5860
useEffect(() => {
@@ -85,6 +87,7 @@ export function useHomeThreadRouteSelection() {
8587
});
8688
return;
8789
}
90+
if (layout.primarySidebarOverlaysContent) setPrimarySidebarVisible(false);
8891
navigation.dispatch((state) =>
8992
createHomeThreadRouteAction({
9093
state,
@@ -93,7 +96,12 @@ export function useHomeThreadRouteSelection() {
9396
}),
9497
);
9598
},
96-
[navigation, selectAndroidWorkspace],
99+
[
100+
layout.primarySidebarOverlaysContent,
101+
navigation,
102+
selectAndroidWorkspace,
103+
setPrimarySidebarVisible,
104+
],
97105
);
98106
}
99107

‎apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx‎

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,24 @@ function AdaptiveWorkspaceLayoutContent(
233233
() => deriveLayout({ width: viewportWidth, height, nativeMetrics, nativeWorkspace }),
234234
[height, viewportWidth, nativeMetrics, nativeWorkspace],
235235
);
236+
const [overlaySidebar, setOverlaySidebar] = useState({
237+
active: baseLayout.primarySidebarOverlaysContent,
238+
pathname,
239+
visible: pathname === "/",
240+
});
241+
if (
242+
overlaySidebar.active !== baseLayout.primarySidebarOverlaysContent ||
243+
(overlaySidebar.active && overlaySidebar.pathname !== pathname)
244+
) {
245+
setOverlaySidebar({
246+
active: baseLayout.primarySidebarOverlaysContent,
247+
pathname,
248+
visible: pathname === "/",
249+
});
250+
}
251+
const preferredSidebarVisible = baseLayout.primarySidebarOverlaysContent
252+
? overlaySidebar.visible
253+
: primarySidebarPreferredVisible;
236254
const primarySidebarPinned = isPrimarySidebarPinned({
237255
pathname,
238256
nativeWorkspace,
@@ -250,7 +268,7 @@ function AdaptiveWorkspaceLayoutContent(
250268
);
251269
const showPrimarySidebar =
252270
!workspacePage &&
253-
(primarySidebarPinned || (primarySidebarPreferredVisible && !composerKeyboardActive));
271+
(primarySidebarPinned || (preferredSidebarVisible && !composerKeyboardActive));
254272
const shouldRenderNavigationRail = Platform.OS === "android" && baseLayout.usesSplitView;
255273
const navigationRailWidth =
256274
shouldRenderNavigationRail && (showPrimarySidebar || workspacePage)
@@ -282,7 +300,7 @@ function AdaptiveWorkspaceLayoutContent(
282300
viewportWidth: width,
283301
preferredWidth: fileInspectorPreferredWidth ?? undefined,
284302
reservedLeadingWidth:
285-
shouldRenderPrimarySidebar && showPrimarySidebar
303+
shouldRenderPrimarySidebar && showPrimarySidebar && !layout.primarySidebarOverlaysContent
286304
? (layout.listPaneWidth ?? 0) + (layout.listPaneGap ?? 0)
287305
: 0,
288306
}),
@@ -366,6 +384,13 @@ function AdaptiveWorkspaceLayoutContent(
366384
setFocusedAuxiliaryPaneRole(null);
367385
};
368386
};
387+
const setPrimarySidebarVisible = (visible: boolean) => {
388+
if (layout.primarySidebarOverlaysContent) {
389+
setOverlaySidebar((current) => ({ ...current, visible }));
390+
} else {
391+
setPrimarySidebarPreferredVisible(visible);
392+
}
393+
};
369394
const togglePrimarySidebar = () => {
370395
if (primarySidebarPinned) {
371396
return;
@@ -381,14 +406,14 @@ function AdaptiveWorkspaceLayoutContent(
381406
setPrimarySidebarPreferredVisible(true);
382407
return;
383408
}
384-
setPrimarySidebarPreferredVisible((current) => !current);
409+
setPrimarySidebarVisible(!preferredSidebarVisible);
385410
};
386411
const revealPrimarySidebar = () => {
387412
if (composerKeyboardActive) void KeyboardController.dismiss();
388413
if (panes.primarySidebarSuppressedByAuxiliary) {
389414
setFileInspectorPreferredVisible(false);
390415
}
391-
setPrimarySidebarPreferredVisible(true);
416+
setPrimarySidebarVisible(true);
392417
};
393418
const handleToggleSidebarCommand = () => {
394419
togglePrimarySidebar();
@@ -745,6 +770,7 @@ function AdaptiveWorkspaceLayoutContent(
745770
showAuxiliaryPane,
746771
toggleAuxiliaryPane,
747772
togglePrimarySidebar,
773+
setPrimarySidebarVisible,
748774
setAuxiliaryPaneWidth,
749775
composerKeyboardActive,
750776
setComposerEditing,

‎apps/mobile/src/features/layout/adaptive-workspace-context.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ interface AdaptiveWorkspaceContextValue {
2525
readonly showAuxiliaryPane: (role: WorkspaceAuxiliaryPaneRole) => void;
2626
readonly toggleAuxiliaryPane: () => void;
2727
readonly togglePrimarySidebar: () => void;
28+
readonly setPrimarySidebarVisible: (visible: boolean) => void;
2829
readonly setAuxiliaryPaneWidth: (width: number) => void;
2930
/**
3031
* Android split view while the thread composer has the soft keyboard: the
@@ -61,6 +62,7 @@ export const AdaptiveWorkspaceContext = createContext<AdaptiveWorkspaceContextVa
6162
showAuxiliaryPane: () => undefined,
6263
toggleAuxiliaryPane: () => undefined,
6364
togglePrimarySidebar: () => undefined,
65+
setPrimarySidebarVisible: () => undefined,
6466
setAuxiliaryPaneWidth: () => undefined,
6567
composerKeyboardActive: false,
6668
setComposerEditing: () => undefined,

‎apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,14 @@ function ColumnScreen(props: {
149149
function WorkspaceColumns(
150150
props: ViewProps & { readonly primary: Route; readonly detail: Route[] },
151151
) {
152-
const { layout, panes, togglePrimarySidebar, toggleAuxiliaryPane, startNewTask } =
153-
useAdaptiveWorkspaceLayout();
152+
const {
153+
layout,
154+
panes,
155+
togglePrimarySidebar,
156+
setPrimarySidebarVisible,
157+
toggleAuxiliaryPane,
158+
startNewTask,
159+
} = useAdaptiveWorkspaceLayout();
154160
const deviceType = useDeviceType();
155161
// Split screens must remain mounted while UIKit animates a detached route away.
156162
const [screens, setScreens] = useState({
@@ -259,7 +265,7 @@ function WorkspaceColumns(
259265
<Split.Host
260266
ref={hostRef}
261267
testID="adaptive-workspace-layout"
262-
preferredSplitBehavior="tile"
268+
preferredSplitBehavior={layout.primarySidebarOverlaysContent ? "overlay" : "tile"}
263269
primaryBackgroundStyle={deviceType === "pad" ? "none" : "default"}
264270
topColumnForCollapsing={compactColumn}
265271
onCollapse={() => {
@@ -274,9 +280,16 @@ function WorkspaceColumns(
274280
// collapsed split already carries the sidebar the expanded one will show.
275281
(layout.usesSplitView ? panes.primarySidebarVisible : panes.primarySidebarWhenExpanded) ||
276282
(!layout.usesSplitView && !activeDetailKey)
277-
? "oneBesideSecondary"
283+
? layout.primarySidebarOverlaysContent
284+
? "oneOverSecondary"
285+
: "oneBesideSecondary"
278286
: "secondaryOnly"
279287
}
288+
onDisplayModeWillChange={({ nativeEvent }) => {
289+
if (!layout.primarySidebarOverlaysContent) return;
290+
if (nativeEvent.nextDisplayMode === "oneOverSecondary") setPrimarySidebarVisible(true);
291+
else if (nativeEvent.nextDisplayMode === "secondaryOnly") setPrimarySidebarVisible(false);
292+
}}
280293
displayModeButtonVisibility="never"
281294
presentsWithGesture
282295
showInspector={inspector.visible}

‎apps/mobile/src/features/layout/useWorkspaceSidebarHeaderItem.ts‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,35 @@ import { withNativeGlassHeaderItem } from "./native-glass-header-items";
55

66
export function useWorkspaceSidebarHeaderItem() {
77
const usesNativeWorkspaceColumns = useNativeWorkspaceColumnsSupported();
8-
const { panes, togglePrimarySidebar } = useAdaptiveWorkspaceLayout();
8+
const { layout, panes, togglePrimarySidebar } = useAdaptiveWorkspaceLayout();
9+
const label = panes.primarySidebarVisible
10+
? layout.primarySidebarOverlaysContent
11+
? "Hide thread sidebar"
12+
: "Maximize content"
13+
: "Show thread sidebar";
914
return useMemo(
1015
() =>
1116
withNativeGlassHeaderItem({
1217
axisBehavior: usesNativeWorkspaceColumns ? "horizontalOnly" : undefined,
13-
accessibilityLabel: panes.primarySidebarVisible
14-
? "Maximize content"
15-
: "Show thread sidebar",
18+
accessibilityLabel: label,
1619
icon: {
17-
name: panes.primarySidebarVisible ? "arrow.up.left.and.arrow.down.right" : "sidebar.left",
20+
name:
21+
panes.primarySidebarVisible && !layout.primarySidebarOverlaysContent
22+
? "arrow.up.left.and.arrow.down.right"
23+
: "sidebar.left",
1824
type: "sfSymbol" as const,
1925
},
2026
identifier: "thread-left-sidebar",
21-
label: panes.primarySidebarVisible ? "Maximize content" : "Show thread sidebar",
27+
label,
2228
onPress: togglePrimarySidebar,
2329
type: "button" as const,
2430
}),
25-
[panes.primarySidebarVisible, togglePrimarySidebar, usesNativeWorkspaceColumns],
31+
[
32+
label,
33+
layout.primarySidebarOverlaysContent,
34+
panes.primarySidebarVisible,
35+
togglePrimarySidebar,
36+
usesNativeWorkspaceColumns,
37+
],
2638
);
2739
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { WorkspaceTabsContext, useWorkspaceTabs } from "./WorkspaceTabsContext";
1717
import {
1818
NATIVE_WORKSPACE_TAB_SLOTS,
1919
workspaceTabForNativeSlot,
20+
workspaceUsesColumns,
2021
type WorkspaceTab,
2122
} from "./workspace-tabs-state";
2223
import { NativeWorkspaceTabActivityContext } from "../../native/v5-workspace-context";
@@ -162,7 +163,11 @@ export function WorkspaceNativeTabs(props: {
162163
);
163164
})}
164165
</Tabs.Host>
165-
{(deviceType === "pad" || compactTabs) && !props.hidden ? (
166+
{(deviceType === "pad" ||
167+
compactTabs ||
168+
(layout.primarySidebarOverlaysContent &&
169+
(workspace.settingsOpen || !workspaceUsesColumns(selectedTab)))) &&
170+
!props.hidden ? (
166171
<View
167172
pointerEvents="box-none"
168173
style={{

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -110,24 +110,26 @@ function WorkspaceRootContent() {
110110
);
111111
const tab = state.tabs[state.selectedTab];
112112
const bottomClearance =
113-
Platform.OS === "ios" && isDuoDevice(deviceType)
114-
? workspaceSearchBottomClearance({
115-
bottomInset: insets.bottom,
116-
bottomBarInset,
117-
keyboardHeight,
118-
})
119-
: compactTabs || deviceType === "pad"
120-
? workspaceDockBottomClearance({ bottomInset: insets.bottom, keyboardHeight })
121-
: Platform.OS === "ios"
122-
? Math.max(insets.bottom, keyboardHeight) +
123-
(systemTabBar || sidebarTabs || tab.searchMode !== "resting"
124-
? sidebarPicker
125-
? 80
126-
: 16
127-
: WORKSPACE_DOCK.height + WORKSPACE_DOCK.bottomGap + 16)
128-
: keyboardHeight > 0 && tab.searchMode !== "resting"
129-
? keyboardHeight + 64
130-
: Math.max(insets.bottom, 12) + workspaceToolbarHeight(tab.searchMode) + 16;
113+
layout.primarySidebarOverlaysContent && state.selectedTab === "usage"
114+
? workspaceDockBottomClearance({ bottomInset: insets.bottom, keyboardHeight })
115+
: Platform.OS === "ios" && isDuoDevice(deviceType)
116+
? workspaceSearchBottomClearance({
117+
bottomInset: insets.bottom,
118+
bottomBarInset,
119+
keyboardHeight,
120+
})
121+
: compactTabs || deviceType === "pad"
122+
? workspaceDockBottomClearance({ bottomInset: insets.bottom, keyboardHeight })
123+
: Platform.OS === "ios"
124+
? Math.max(insets.bottom, keyboardHeight) +
125+
(systemTabBar || sidebarTabs || tab.searchMode !== "resting"
126+
? sidebarPicker
127+
? 80
128+
: 16
129+
: WORKSPACE_DOCK.height + WORKSPACE_DOCK.bottomGap + 16)
130+
: keyboardHeight > 0 && tab.searchMode !== "resting"
131+
? keyboardHeight + 64
132+
: Math.max(insets.bottom, 12) + workspaceToolbarHeight(tab.searchMode) + 16;
131133
const context = useMemo(() => ({ ...workspace, bottomClearance }), [workspace, bottomClearance]);
132134

133135
return (

‎apps/mobile/src/features/workspace/useSystemWorkspaceTabBar.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,14 @@ export function useCompactWorkspaceTabs() {
4141

4242
export function useSystemWorkspaceTabBar() {
4343
const deviceType = useDeviceType();
44+
const { layout } = useAdaptiveWorkspaceLayout();
4445
const sidebarTabs = useSidebarWorkspaceTabs();
4546
const compactTabs = useCompactWorkspaceTabs();
46-
return Platform.OS === "ios" && deviceType !== "pad" && sidebarTabs === null && !compactTabs;
47+
return (
48+
Platform.OS === "ios" &&
49+
deviceType !== "pad" &&
50+
!layout.primarySidebarOverlaysContent &&
51+
sidebarTabs === null &&
52+
!compactTabs
53+
);
4754
}

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,40 @@ describe("deriveThreadFeedInitialContentInset", () => {
5050
});
5151

5252
describe("native workspace sizing", () => {
53+
it.each([
54+
{ width: 669, height: 951, hasHinge: true, nativeWorkspace: true, overlay: true },
55+
{ width: 951, height: 669, hasHinge: true, nativeWorkspace: true, overlay: false },
56+
{ width: 669, height: 951, hasHinge: false, nativeWorkspace: true, overlay: false },
57+
{ width: 669, height: 951, hasHinge: true, nativeWorkspace: false, overlay: false },
58+
])(
59+
"overlays only a native unfolded portrait Duo sidebar: %j",
60+
({ overlay, nativeWorkspace, ...size }) => {
61+
const nativeMetrics = {
62+
...size,
63+
horizontalSizeClass: "regular" as const,
64+
verticalBarEdge: "none" as const,
65+
safeArea: { top: 24, bottom: 20, left: 0, right: 0 },
66+
reservedRegions: [],
67+
};
68+
const layout = deriveLayout({ ...size, nativeMetrics, nativeWorkspace });
69+
expect(layout.primarySidebarOverlaysContent).toBe(overlay);
70+
for (const primarySidebarPreferredVisible of [true, false]) {
71+
expect(
72+
deriveWorkspacePaneLayout({
73+
layout,
74+
viewportWidth: size.width,
75+
primarySidebarPreferredVisible,
76+
auxiliaryPanePreferredVisible: false,
77+
}).contentPaneWidth,
78+
).toBe(
79+
!overlay && primarySidebarPreferredVisible
80+
? size.width - (layout.listPaneWidth ?? 0)
81+
: size.width,
82+
);
83+
}
84+
},
85+
);
86+
5387
it("keeps the detail mounted in a narrow iPad window while UIKit still has two columns", () => {
5488
const nativeMetrics = {
5589
width: 715,

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export type LayoutVariant = "compact" | "split";
5151
export interface Layout {
5252
readonly variant: LayoutVariant;
5353
readonly usesSplitView: boolean;
54+
readonly primarySidebarOverlaysContent: boolean;
5455
readonly listPaneWidth: number | null;
5556
readonly listPaneGap?: number;
5657
readonly shellPadding: number;
@@ -115,6 +116,7 @@ export function deriveLayout(input: {
115116
return {
116117
variant: "compact",
117118
usesSplitView: false,
119+
primarySidebarOverlaysContent: false,
118120
listPaneWidth: null,
119121
shellPadding: 0,
120122
};
@@ -130,6 +132,8 @@ export function deriveLayout(input: {
130132
return {
131133
variant: "split",
132134
usesSplitView: true,
135+
primarySidebarOverlaysContent:
136+
input.nativeWorkspace === true && metrics?.hasHinge === true && width < height,
133137
listPaneWidth:
134138
division?.x ??
135139
clamp(Math.round(width * 0.32), SPLIT_SIDEBAR_MIN_WIDTH, SPLIT_SIDEBAR_DEFAULT_MAX_WIDTH),
@@ -191,9 +195,10 @@ export function deriveWorkspacePaneLayout(input: {
191195
const auxiliaryPaneRole = input.auxiliaryPaneRole ?? "supplementary";
192196
const preferredPrimarySidebarVisible =
193197
input.layout.usesSplitView && input.primarySidebarPreferredVisible;
194-
const preferredPrimarySidebarWidth = preferredPrimarySidebarVisible
195-
? (input.layout.listPaneWidth ?? 0) + (input.layout.listPaneGap ?? 0)
196-
: 0;
198+
const preferredPrimarySidebarWidth =
199+
preferredPrimarySidebarVisible && !input.layout.primarySidebarOverlaysContent
200+
? (input.layout.listPaneWidth ?? 0) + (input.layout.listPaneGap ?? 0)
201+
: 0;
197202

198203
if (auxiliaryPaneRole === "inspector") {
199204
const fileInspector = deriveFileInspectorPaneLayout({
@@ -205,6 +210,7 @@ export function deriveWorkspacePaneLayout(input: {
205210
const auxiliaryPaneVisible = fileInspector.supported && input.auxiliaryPanePreferredVisible;
206211
const primarySidebarSuppressedByAuxiliary =
207212
preferredPrimarySidebarVisible &&
213+
!input.layout.primarySidebarOverlaysContent &&
208214
auxiliaryPaneVisible &&
209215
fileInspector.width !== null &&
210216
input.layout.listPaneWidth !== null &&

0 commit comments

Comments
 (0)