Skip to content
TypeScript

feat(mobile): medium windows float the sidebar over the page (#27088)

Julius Marminge6df3584ca20a
diff --git a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
index 504a8309b83..bcd03f36121 100644
--- a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
+++ b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
@@ -20,7 +20,14 @@ import {
useState,
type ReactNode,
} from "react";
-import { Keyboard, Platform, useWindowDimensions, View } from "react-native";
+import {
+ BackHandler,
+ Keyboard,
+ Platform,
+ Pressable,
+ useWindowDimensions,
+ View,
+} from "react-native";
import { KeyboardController, useKeyboardState } from "react-native-keyboard-controller";
import Animated, {
runOnJS,
@@ -241,17 +248,17 @@ function AdaptiveWorkspaceLayoutContent(
// The overlay sidebar closes when a page opens from it, and stays open on a list or on the
// page a tab switch opened (`keepOpenFor`, set by that switch).
const [overlaySidebar, setOverlaySidebar] = useState({
- active: baseLayout.primarySidebarOverlaysContent,
+ active: baseLayout.variant === "medium",
pathname,
visible: isWorkspaceListPath(pathname),
keepOpenFor: null as string | null,
});
if (
- overlaySidebar.active !== baseLayout.primarySidebarOverlaysContent ||
+ overlaySidebar.active !== (baseLayout.variant === "medium") ||
(overlaySidebar.active && overlaySidebar.pathname !== pathname)
) {
setOverlaySidebar({
- active: baseLayout.primarySidebarOverlaysContent,
+ active: baseLayout.variant === "medium",
pathname,
visible:
isWorkspaceListPath(pathname) ||
@@ -260,9 +267,8 @@ function AdaptiveWorkspaceLayoutContent(
keepOpenFor: null,
});
}
- const preferredSidebarVisible = baseLayout.primarySidebarOverlaysContent
- ? overlaySidebar.visible
- : primarySidebarPreferredVisible;
+ const preferredSidebarVisible =
+ baseLayout.variant === "medium" ? overlaySidebar.visible : primarySidebarPreferredVisible;
const primarySidebarPinned = isPrimarySidebarPinned({
pathname,
nativeWorkspace,
@@ -279,6 +285,10 @@ function AdaptiveWorkspaceLayoutContent(
const showPrimarySidebar =
!workspacePage &&
(primarySidebarPinned || (preferredSidebarVisible && !composerKeyboardActive));
+ // Medium windows float the sidebar over a page; beside a list it keeps its room.
+ const sidebarFloats =
+ baseLayout.variant === "medium" &&
+ (nativeWorkspace || (!primarySidebarPinned && !workspacePage));
const shouldRenderNavigationRail =
Platform.OS === "android" && baseLayout.usesSplitView && !floatingTabsEnabled;
const enabledTabs = useEnabledNavigationTabs();
@@ -319,7 +329,8 @@ function AdaptiveWorkspaceLayoutContent(
floatingTabs.row,
floatingTabsEnabled,
]);
- const width = viewportWidth - navigationRailWidth;
+ // A floating sidebar brings the rail with it.
+ const width = viewportWidth - (sidebarFloats ? 0 : navigationRailWidth);
// The sidebar stays mounted under a workspace page, so its list is ready on the way back.
const shouldRenderPrimarySidebar = layout.usesSplitView;
const fileInspector = useMemo(
@@ -329,11 +340,18 @@ function AdaptiveWorkspaceLayoutContent(
viewportWidth: width,
preferredWidth: fileInspectorPreferredWidth ?? undefined,
reservedLeadingWidth:
- shouldRenderPrimarySidebar && showPrimarySidebar && !layout.primarySidebarOverlaysContent
+ shouldRenderPrimarySidebar && showPrimarySidebar && !sidebarFloats
? (layout.listPaneWidth ?? 0) + (layout.listPaneGap ?? 0)
: 0,
}),
- [fileInspectorPreferredWidth, layout, showPrimarySidebar, shouldRenderPrimarySidebar, width],
+ [
+ fileInspectorPreferredWidth,
+ layout,
+ showPrimarySidebar,
+ shouldRenderPrimarySidebar,
+ sidebarFloats,
+ width,
+ ],
);
const [workspaceInspector, setWorkspaceInspector] = useState<{
readonly render: () => ReactNode;
@@ -346,6 +364,7 @@ function AdaptiveWorkspaceLayoutContent(
layout,
viewportWidth: width,
nativeWorkspace,
+ primarySidebarFloats: sidebarFloats,
primarySidebarPreferredVisible: showPrimarySidebar,
// Only a column a screen fills makes room, so a stale preference can't hide the sidebar.
auxiliaryPanePreferredVisible:
@@ -359,6 +378,7 @@ function AdaptiveWorkspaceLayoutContent(
layout,
nativeWorkspace,
showPrimarySidebar,
+ sidebarFloats,
width,
workspacePage,
],
@@ -396,7 +416,7 @@ function AdaptiveWorkspaceLayoutContent(
setWorkspaceInspector((current) => (current !== null && !current.active ? null : current));
};
const setPrimarySidebarVisible = (visible: boolean) => {
- if (layout.primarySidebarOverlaysContent) {
+ if (layout.variant === "medium") {
setOverlaySidebar((current) => ({ ...current, visible }));
} else {
setPrimarySidebarPreferredVisible(visible);
@@ -410,7 +430,7 @@ function AdaptiveWorkspaceLayoutContent(
// intact. One the user had hidden still opens.
if (composerKeyboardActive) {
void KeyboardController.dismiss();
- if (primarySidebarPreferredVisible) return;
+ if (preferredSidebarVisible) return;
}
if (!panes.primarySidebarVisible && panes.primarySidebarSuppressedByAuxiliary) {
setFileInspectorPreferredVisible(false);
@@ -469,7 +489,7 @@ function AdaptiveWorkspaceLayoutContent(
overlays,
},
);
- if (layout.primarySidebarOverlaysContent) {
+ if (layout.variant === "medium") {
const opened = next.routes.at(-1 - overlays.length)?.key ?? null;
setOverlaySidebar((current) => ({ ...current, visible: true, keepOpenFor: opened }));
}
@@ -482,7 +502,7 @@ function AdaptiveWorkspaceLayoutContent(
threadSelectionDeferral.run(() => {
if (Platform.OS === "android") Keyboard.dismiss();
setFileInspectorPreferredVisible(false);
- if (layout.primarySidebarOverlaysContent) setPrimarySidebarVisible(false);
+ if (layout.variant === "medium") setPrimarySidebarVisible(false);
workspace?.dispatch({
type: "select",
tab: detail.name === "Thread" ? "threads" : "pullRequests",
@@ -604,11 +624,12 @@ function AdaptiveWorkspaceLayoutContent(
// against the edge that stays put while the other one slides, so nothing reflows after the
// panes land. A sliding sidebar uncovers the strip it is about to fill, or covers the content
// until it is gone.
- const contentLeftTarget =
- navigationRailWidth +
- (shouldRenderPrimarySidebar && !workspacePage && panes.primarySidebarVisible
- ? (layout.listPaneWidth ?? 0) + (layout.listPaneGap ?? 0)
- : 0);
+ const contentLeftTarget = sidebarFloats
+ ? 0
+ : navigationRailWidth +
+ (shouldRenderPrimarySidebar && !workspacePage && panes.primarySidebarVisible
+ ? (layout.listPaneWidth ?? 0) + (layout.listPaneGap ?? 0)
+ : 0);
const [contentAnchor, setContentAnchor] = useState({
viewportWidth,
left: contentLeftTarget,
@@ -670,6 +691,29 @@ function AdaptiveWorkspaceLayoutContent(
workspacePage,
]);
const railAnimatedStyle = useAnimatedStyle(() => ({ width: renderedRailWidth.value }));
+ const floatingSidebarAnimatedStyle = useAnimatedStyle(() => ({ left: renderedRailWidth.value }));
+ const floatingSidebarOpen = sidebarFloats && panes.primarySidebarVisible;
+ // Its own value, so a sidebar that was beside a list doesn't dim the page as it leaves.
+ const scrimOpacity = useSharedValue(0);
+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- animates the Reanimated scrim with the floating sidebar
+ useEffect(() => {
+ scrimOpacity.set(withTiming(floatingSidebarOpen ? 0.32 : 0, WORKSPACE_PANE_TIMING));
+ }, [floatingSidebarOpen, scrimOpacity]);
+ const scrimAnimatedStyle = useAnimatedStyle(() => ({ opacity: scrimOpacity.value }));
+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- Back closes a floating sidebar before it leaves the page
+ useEffect(() => {
+ if (!floatingSidebarOpen || nativeWorkspace) return;
+ const subscription = BackHandler.addEventListener("hardwareBackPress", () => {
+ // A sheet or modal over the workspace takes Back first.
+ const state = rootStackState(navigation);
+ if (state && workspaceRoutesOf(state.routes.slice(0, state.index + 1)).overlays.length > 0) {
+ return false;
+ }
+ setPrimarySidebarVisible(false);
+ return true;
+ });
+ return () => subscription.remove();
+ }, [floatingSidebarOpen, nativeWorkspace, navigation, setPrimarySidebarVisible]);
// Showing or hiding the sidebar clips a fixed-width list. A hinge resize instead tracks the
// animated edge, so the header actions slide with it rather than jumping or being covered.
const listPaneGap = layout.listPaneGap ?? 0;
@@ -694,8 +738,8 @@ function AdaptiveWorkspaceLayoutContent(
Math.max(
0,
viewportWidth -
- renderedRailWidth.value -
- (workspacePage ? 0 : renderedSidebarWidth.value) -
+ (sidebarFloats ? 0 : renderedRailWidth.value) -
+ (workspacePage || sidebarFloats ? 0 : renderedSidebarWidth.value) -
renderedInspectorWidth.value,
),
);
@@ -716,14 +760,13 @@ function AdaptiveWorkspaceLayoutContent(
const sidebarOverRotates =
nativeWorkspace && nativeMetrics?.hasHinge === true && layout.usesSplitView;
// The current orientation's panes already account for an inspector that needs the sidebar's room.
- const sidebarInLandscape = baseLayout.primarySidebarOverlaysContent
- ? primarySidebarPinned || primarySidebarPreferredVisible
- : panes.primarySidebarVisible;
+ const sidebarInLandscape =
+ baseLayout.variant === "medium"
+ ? primarySidebarPinned || primarySidebarPreferredVisible
+ : panes.primarySidebarVisible;
const sidebarInPortrait =
primarySidebarPinned ||
- (baseLayout.primarySidebarOverlaysContent
- ? overlaySidebar.visible
- : isWorkspaceListPath(pathname));
+ (baseLayout.variant === "medium" ? overlaySidebar.visible : isWorkspaceListPath(pathname));
const sidebarByOrientation = useMemo(
() =>
sidebarOverRotates ? { landscape: sidebarInLandscape, portrait: sidebarInPortrait } : null,
@@ -775,7 +818,10 @@ function AdaptiveWorkspaceLayoutContent(
>
<AndroidHingeObserver onChange={handleHingeChange} />
{shouldRenderNavigationRail ? (
- <Animated.View className="shrink self-stretch" style={railAnimatedStyle} />
+ <Animated.View
+ className={sidebarFloats ? "absolute inset-y-0 left-0" : "shrink self-stretch"}
+ style={railAnimatedStyle}
+ />
) : null}
{shouldRenderPrimarySidebar && layout.listPaneWidth !== null ? (
<Animated.View
@@ -791,6 +837,12 @@ function AdaptiveWorkspaceLayoutContent(
// content pane, laid out after it, covers it, in the same mount as the page.
style={[
workspacePage ? { position: "absolute", top: 0, bottom: 0, left: 0 } : null,
+ sidebarFloats
+ ? [
+ { position: "absolute", top: 0, bottom: 0, zIndex: 2, elevation: 8 },
+ floatingSidebarAnimatedStyle,
+ ]
+ : null,
sidebarAnimatedStyle,
]}
>
@@ -828,6 +880,8 @@ function AdaptiveWorkspaceLayoutContent(
}
style={Platform.OS === "android" ? androidContentSlotStyle : undefined}
collapsable={false}
+ importantForAccessibility={floatingSidebarOpen ? "no-hide-descendants" : "auto"}
+ accessibilityElementsHidden={floatingSidebarOpen}
>
<Animated.View
collapsable={false}
@@ -888,6 +942,19 @@ function AdaptiveWorkspaceLayoutContent(
</WorkspaceContentWidthContext>
</Animated.View>
</Animated.View>
+ {sidebarFloats ? (
+ <Animated.View
+ className="absolute inset-0 bg-black"
+ pointerEvents={floatingSidebarOpen ? "auto" : "none"}
+ style={[{ zIndex: 1 }, scrimAnimatedStyle]}
+ >
+ <Pressable
+ accessibilityLabel="Hide sidebar"
+ className="flex-1"
+ onPress={() => setPrimarySidebarVisible(false)}
+ />
+ </Animated.View>
+ ) : null}
<PaneContext value="inspector">
<WorkspaceInspectorPane
pathname={props.pathname}
@@ -903,11 +970,12 @@ function AdaptiveWorkspaceLayoutContent(
// Its trailing inset clips the old rail as soon as Android fits the workspace to a cover display.
<View
className="absolute inset-y-0 left-0 overflow-hidden"
- style={
+ style={[
railOverlay
? { right: 0 }
- : { right: viewportWidth - navigationRailWidth, maxWidth: navigationRailWidth }
- }
+ : { right: viewportWidth - navigationRailWidth, maxWidth: navigationRailWidth },
+ sidebarFloats ? { zIndex: 3, elevation: 8 } : null,
+ ]}
>
<AndroidWorkspaceNavigation
onNewThread={handleStartNewTask}
diff --git a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
index f7a9c26b715..2deb592e9ea 100644
--- a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
+++ b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
@@ -320,7 +320,7 @@ function WorkspaceColumns(
ref={hostRef}
testID="adaptive-workspace-layout"
preferredSplitBehavior={
- !sidebarByOrientation && layout.primarySidebarOverlaysContent ? "overlay" : "tile"
+ !sidebarByOrientation && layout.variant === "medium" ? "overlay" : "tile"
}
portraitPreferredSplitBehavior={sidebarByOrientation ? "overlay" : undefined}
portraitPreferredDisplayMode={
@@ -358,11 +358,11 @@ function WorkspaceColumns(
? panes.primarySidebarVisible
: panes.primarySidebarWhenExpanded) ||
(!layout.usesSplitView && !activeDetailKey),
- layout.primarySidebarOverlaysContent,
+ layout.variant === "medium",
)
}
onDisplayModeWillChange={({ nativeEvent }) => {
- if (!layout.primarySidebarOverlaysContent) return;
+ if (layout.variant !== "medium") return;
if (nativeEvent.nextDisplayMode === "oneOverSecondary") setPrimarySidebarVisible(true);
else if (nativeEvent.nextDisplayMode === "secondaryOnly") setPrimarySidebarVisible(false);
}}
diff --git a/apps/mobile/src/features/layout/useSidebarToggle.ts b/apps/mobile/src/features/layout/useSidebarToggle.ts
index 729f05676a9..5b0beed08a4 100644
--- a/apps/mobile/src/features/layout/useSidebarToggle.ts
+++ b/apps/mobile/src/features/layout/useSidebarToggle.ts
@@ -6,7 +6,7 @@ export function useSidebarToggle() {
const role = usePaneRole();
const { layout, panes, sidebarToggleable, togglePrimarySidebar } = useAdaptiveWorkspaceLayout();
if (role !== "content" || !sidebarToggleable) return null;
- const maximizes = panes.primarySidebarVisible && !layout.primarySidebarOverlaysContent;
+ const maximizes = panes.primarySidebarVisible && layout.variant !== "medium";
return {
visible: panes.primarySidebarVisible,
accessibilityLabel: panes.primarySidebarVisible
diff --git a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx
index d0b08ce405d..be338a76a0b 100644
--- a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx
+++ b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx
@@ -1175,7 +1175,7 @@ function ThreadDetailBody(
),
);
const layoutVariant = props.layoutVariant ?? "compact";
- const isSplitLayout = layoutVariant === "split";
+ const isSplitLayout = layoutVariant !== "compact";
const contentMaxWidth =
Platform.OS === "android"
? ANDROID_READING_MAX_WIDTH
diff --git a/apps/mobile/src/features/threads/ThreadFeed.tsx b/apps/mobile/src/features/threads/ThreadFeed.tsx
index 682f2cdb6b2..b5e0ab3cb42 100644
--- a/apps/mobile/src/features/threads/ThreadFeed.tsx
+++ b/apps/mobile/src/features/threads/ThreadFeed.tsx
@@ -2693,9 +2693,8 @@ export const ThreadFeed = memo(function ThreadFeed({
fontScale,
});
const settledPaneWidth = useWorkspaceSettledContentWidth();
- const [measuredViewportWidth, setViewportWidth] = useState(() =>
- props.layoutVariant === "split" ? 0 : windowWidth,
- );
+ const splitLayout = (props.layoutVariant ?? "compact") !== "compact";
+ const [measuredViewportWidth, setViewportWidth] = useState(() => (splitLayout ? 0 : windowWidth));
const viewportWidth =
settledPaneWidth !== null ? Math.round(settledPaneWidth) : measuredViewportWidth;
const [viewportHeight, setViewportHeight] = useState(0);
@@ -2797,7 +2796,7 @@ export const ThreadFeed = memo(function ThreadFeed({
props.threadId,
fileShareSourceIdentifier,
);
- const horizontalPadding = props.layoutVariant === "split" ? 20 : 16;
+ const horizontalPadding = splitLayout ? 20 : 16;
const contentLeftInset = props.contentSideInsets?.left ?? 0;
const contentRightInset = props.contentSideInsets?.right ?? 0;
const usableViewportWidth = Math.max(0, viewportWidth - contentLeftInset - contentRightInset);
@@ -3822,7 +3821,7 @@ export const ThreadFeed = memo(function ThreadFeed({
// Horizontal Duo reservations are already included in the row padding.
contentInsetAdjustmentBehavior={
usesNativeAutomaticInsets
- ? duoColumns && props.layoutVariant === "split"
+ ? duoColumns && splitLayout
? "scrollableAxes"
: "automatic"
: "never"
diff --git a/apps/mobile/src/features/workspace/WorkspaceNativeTabs.ios.tsx b/apps/mobile/src/features/workspace/WorkspaceNativeTabs.ios.tsx
index e93175677fc..c294d22cc8e 100644
--- a/apps/mobile/src/features/workspace/WorkspaceNativeTabs.ios.tsx
+++ b/apps/mobile/src/features/workspace/WorkspaceNativeTabs.ios.tsx
@@ -151,7 +151,7 @@ export function WorkspaceNativeTabs(props: {
</Tabs.Host>
{(deviceType === "pad" ||
compactTabs ||
- (layout.primarySidebarOverlaysContent &&
+ (layout.variant === "medium" &&
!workspaceUsesColumns(selectedTab, workspace.settingsOpen))) &&
!props.hidden ? (
<View
diff --git a/apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx b/apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx
index 9a7d456fad6..bd9524f15ad 100644
--- a/apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx
+++ b/apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx
@@ -107,7 +107,7 @@ function WorkspaceRootContent() {
);
const tab = state.tabs[settingsOpen ? "settings" : state.selectedTab];
const bottomClearance =
- layout.primarySidebarOverlaysContent && state.selectedTab === "usage"
+ layout.variant === "medium" && state.selectedTab === "usage"
? workspaceDockBottomClearance({ bottomInset: insets.bottom, keyboardHeight })
: Platform.OS === "ios" && isDuoDevice(deviceType)
? // The column's safe area already holds the Duo's search toolbar and keyboard.
diff --git a/apps/mobile/src/features/workspace/useSystemWorkspaceTabBar.ts b/apps/mobile/src/features/workspace/useSystemWorkspaceTabBar.ts
index 5aa714eb6dc..f5a3f0af703 100644
--- a/apps/mobile/src/features/workspace/useSystemWorkspaceTabBar.ts
+++ b/apps/mobile/src/features/workspace/useSystemWorkspaceTabBar.ts
@@ -58,7 +58,7 @@ export function useSystemWorkspaceTabBar() {
return (
Platform.OS === "ios" &&
deviceType !== "pad" &&
- !layout.primarySidebarOverlaysContent &&
+ layout.variant !== "medium" &&
sidebarTabs === null &&
!compactTabs
);
diff --git a/apps/mobile/src/lib/layout.test.ts b/apps/mobile/src/lib/layout.test.ts
index 76583340aba..62a52b3d6aa 100644
--- a/apps/mobile/src/lib/layout.test.ts
+++ b/apps/mobile/src/lib/layout.test.ts
@@ -79,7 +79,7 @@ describe("native workspace sizing", () => {
reservedRegions: [],
};
const layout = deriveLayout({ ...size, nativeMetrics, nativeWorkspace });
- expect(layout.primarySidebarOverlaysContent).toBe(overlay);
+ expect(layout.variant === "medium").toBe(overlay);
for (const primarySidebarPreferredVisible of [true, false]) {
expect(
deriveWorkspacePaneLayout({
@@ -131,6 +131,18 @@ describe("native workspace sizing", () => {
});
});
+describe("width classes", () => {
+ it.each([
+ { width: 599, height: 900, variant: "compact" },
+ { width: 600, height: 900, variant: "medium" },
+ { width: 719, height: 900, variant: "medium" },
+ { width: 720, height: 900, variant: "expanded" },
+ { width: 900, height: 599, variant: "compact" },
+ ] as const)("classes a window without native columns by size: %j", ({ variant, ...size }) => {
+ expect(deriveLayout(size).variant).toBe(variant);
+ });
+});
+
describe("isPrimarySidebarPinned", () => {
// regression: #20406 sidebar toggle works on iPad and iPhone Duo
it("keeps compact native roots pinned so search cannot hide the sidebar for a later split", () => {
diff --git a/apps/mobile/src/lib/layout.ts b/apps/mobile/src/lib/layout.ts
index e41ade6e7f5..d0f80f6ecaf 100644
--- a/apps/mobile/src/lib/layout.ts
+++ b/apps/mobile/src/lib/layout.ts
@@ -6,7 +6,8 @@ function clamp(value: number, min: number, max: number): number {
return Math.min(Math.max(value, min), max);
}
-const SPLIT_LAYOUT_MIN_WIDTH = 720;
+const MEDIUM_LAYOUT_MIN_WIDTH = 600;
+const EXPANDED_LAYOUT_MIN_WIDTH = 720;
const SPLIT_LAYOUT_MIN_HEIGHT = 600;
const SPLIT_SIDEBAR_MIN_WIDTH = 280;
@@ -58,12 +59,16 @@ const AUXILIARY_PANE_DEFAULT_MAX_WIDTH = 320;
const FILE_INSPECTOR_MIN_VIEWPORT_WIDTH = 820;
const FILE_INSPECTOR_MIN_MAIN_WIDTH = 560;
-export type LayoutVariant = "compact" | "split";
+/**
+ * The window's width class. Compact: the sidebar is the root and pages push over it. Medium: the
+ * sidebar floats over the content. Expanded: the sidebar sits beside the content.
+ */
+export type LayoutVariant = "compact" | "medium" | "expanded";
export interface Layout {
readonly variant: LayoutVariant;
+ /** Medium or expanded: pages replace the content beside the sidebar instead of pushing. */
readonly usesSplitView: boolean;
- readonly primarySidebarOverlaysContent: boolean;
readonly listPaneWidth: number | null;
readonly listPaneGap?: number;
readonly shellPadding: number;
@@ -115,18 +120,29 @@ export function deriveLayout(input: {
(metrics.hasHinge === true ||
metrics.verticalBarEdge !== "none" ||
metrics.reservedRegions.some((region) => region.kind === "division"));
- const wideEnoughForSplit =
+ const variant: LayoutVariant =
metrics && (input.nativeWorkspace || hasDuoGeometry)
? metrics.horizontalSizeClass === "regular" &&
usableWidth >= SPLIT_SIDEBAR_MIN_WIDTH + 320 &&
(input.nativeWorkspace || height >= 400)
- : width >= SPLIT_LAYOUT_MIN_WIDTH && height >= SPLIT_LAYOUT_MIN_HEIGHT;
+ ? // The native split floats its sidebar over an unfolded portrait Duo.
+ input.nativeWorkspace === true && metrics.hasHinge === true && width < height
+ ? "medium"
+ : "expanded"
+ : "compact"
+ : height < SPLIT_LAYOUT_MIN_HEIGHT || width < MEDIUM_LAYOUT_MIN_WIDTH
+ ? "compact"
+ : width >= EXPANDED_LAYOUT_MIN_WIDTH
+ ? "expanded"
+ : // Only the Android shell floats a sidebar over a page; iOS keeps its phone stack.
+ metrics
+ ? "compact"
+ : "medium";
- if (!wideEnoughForSplit) {
+ if (variant === "compact") {
return {
- variant: "compact",
+ variant,
usesSplitView: false,
- primarySidebarOverlaysContent: false,
listPaneWidth: null,
shellPadding: 0,
};
@@ -140,10 +156,8 @@ export function deriveLayout(input: {
width - region.x - region.width - metrics.safeArea.right >= 320,
);
return {
- variant: "split",
+ variant,
usesSplitView: true,
- primarySidebarOverlaysContent:
- input.nativeWorkspace === true && metrics?.hasHinge === true && width < height,
listPaneWidth:
division?.x ??
clamp(Math.round(width * 0.32), SPLIT_SIDEBAR_MIN_WIDTH, SPLIT_SIDEBAR_DEFAULT_MAX_WIDTH),
@@ -202,15 +216,18 @@ export function deriveWorkspacePaneLayout(input: {
readonly layout: Layout;
readonly viewportWidth: number;
readonly nativeWorkspace?: boolean;
+ /** Whether the sidebar floats over the content rather than taking its room; medium by default. */
+ readonly primarySidebarFloats?: boolean;
readonly primarySidebarPreferredVisible: boolean;
readonly auxiliaryPanePreferredVisible: boolean;
readonly auxiliaryPanePreferredWidth?: number;
}): WorkspacePaneLayout {
const viewportWidth = Math.max(0, input.viewportWidth);
+ const floats = input.primarySidebarFloats ?? input.layout.variant === "medium";
const preferredPrimarySidebarVisible =
input.layout.usesSplitView && input.primarySidebarPreferredVisible;
const preferredPrimarySidebarWidth =
- preferredPrimarySidebarVisible && !input.layout.primarySidebarOverlaysContent
+ preferredPrimarySidebarVisible && !floats
? (input.layout.listPaneWidth ?? 0) + (input.layout.listPaneGap ?? 0)
: 0;
const fileInspector = deriveFileInspectorPaneLayout({
@@ -223,7 +240,7 @@ export function deriveWorkspacePaneLayout(input: {
const primarySidebarSuppressedByAuxiliary =
!input.nativeWorkspace &&
preferredPrimarySidebarVisible &&
- !input.layout.primarySidebarOverlaysContent &&
+ !floats &&
auxiliaryPaneVisible &&
fileInspector.width !== null &&
input.layout.listPaneWidth !== null &&