diff --git a/packages/app/src/components/desktop-sidebar-layout.test.ts b/packages/app/src/components/desktop-sidebar-layout.test.ts
index 41a663a9e3..452369e491 100644
--- a/packages/app/src/components/desktop-sidebar-layout.test.ts
+++ b/packages/app/src/components/desktop-sidebar-layout.test.ts
@@ -10,6 +10,7 @@ import {
resolveDesktopAppChromeLayout,
resolveDesktopAppContentMinimum,
resolveDesktopSidebarInsetLeft,
+ resolveDesktopSidebarInsetTop,
resolveDesktopSidebarVisibility,
resolveSidebarActivity,
resolveDesktopSidebarWidth,
@@ -248,3 +249,13 @@ it("insets an overlay sidebar's content by the left safe area and leaves the doc
expect(resolveDesktopSidebarInsetLeft({ overlay: true, safeAreaLeft: 20 })).toBe(20);
expect(resolveDesktopSidebarInsetLeft({ overlay: false, safeAreaLeft: 20 })).toBe(0);
});
+
+it("gives the overlay sidebar the window's top inset, which a wide layout surface spends", () => {
+ // A wide web surface pads the status bar itself and leaves its content a top inset of 0.
+ expect(
+ resolveDesktopSidebarInsetTop({ overlay: true, safeAreaTop: 0, windowSafeAreaTop: 32 }),
+ ).toBe(32);
+ expect(
+ resolveDesktopSidebarInsetTop({ overlay: false, safeAreaTop: 0, windowSafeAreaTop: 32 }),
+ ).toBe(0);
+});
diff --git a/packages/app/src/components/desktop-sidebar-layout.ts b/packages/app/src/components/desktop-sidebar-layout.ts
index 692934d73e..176bbe2edc 100644
--- a/packages/app/src/components/desktop-sidebar-layout.ts
+++ b/packages/app/src/components/desktop-sidebar-layout.ts
@@ -52,6 +52,18 @@ export function resolveDesktopSidebarInsetLeft(input: {
return input.overlay ? input.safeAreaLeft : 0;
}
+/**
+ * The overlay sidebar also starts at the window's top edge, over the layout surface's top padding,
+ * so it takes the window's top inset. The dock reads the inset the surface leaves its content.
+ */
+export function resolveDesktopSidebarInsetTop(input: {
+ overlay: boolean;
+ safeAreaTop: number;
+ windowSafeAreaTop: number;
+}): number {
+ return input.overlay ? input.windowSafeAreaTop : input.safeAreaTop;
+}
+
export function resolveDesktopAppChromeLayout(input: {
desktopSidebarRendered: boolean;
hasTopLeftWindowControls: boolean;
diff --git a/packages/app/src/components/desktop-sidebar-overlay.browser.test.tsx b/packages/app/src/components/desktop-sidebar-overlay.browser.test.tsx
new file mode 100644
index 0000000000..0c05ece197
--- /dev/null
+++ b/packages/app/src/components/desktop-sidebar-overlay.browser.test.tsx
@@ -0,0 +1,85 @@
+import React, { act, useMemo } from "react";
+import { createRoot } from "react-dom/client";
+import { View } from "react-native";
+import { Gesture, GestureHandlerRootView } from "react-native-gesture-handler";
+import { SafeAreaInsetsContext, useSafeAreaInsets } from "react-native-safe-area-context";
+import { afterEach, expect, it, vi } from "vitest";
+import { resolveDesktopSidebarInsetTop } from "@/components/desktop-sidebar-layout";
+import { MobilePanelOverlay } from "@/mobile-panels/presentation";
+import { MobilePanelsProvider } from "@/mobile-panels/provider";
+import { usePanelStore } from "@/stores/panel-store";
+import {
+ WindowLayoutProvider,
+ WindowLayoutSurface,
+ useWindowSafeAreaInsets,
+} from "@/window-layout";
+
+vi.stubGlobal("React", React);
+const statusBarInsets = { top: 24, right: 0, bottom: 0, left: 0 };
+const fill = { flex: 1 };
+const rowStyle = { height: 40 };
+const container = document.createElement("div");
+container.style.height = "800px";
+document.body.appendChild(container);
+const root = createRoot(container);
+afterEach(() => {
+ act(() => root.render(null));
+});
+
+/** The first row of the sidebar, padded the way `DesktopSidebar` pads it. */
+function SidebarFirstRow({ overlay }: { overlay: boolean }) {
+ const insetTop = resolveDesktopSidebarInsetTop({
+ overlay,
+ safeAreaTop: useSafeAreaInsets().top,
+ windowSafeAreaTop: useWindowSafeAreaInsets().top,
+ });
+ const style = useMemo(() => ({ paddingTop: insetTop }), [insetTop]);
+ return (
+
+
+
+ );
+}
+
+function firstRowTop(): number {
+ const row = document.querySelector('[data-testid="sidebar-first-row"]');
+ expect(row).not.toBeNull();
+ return row!.getBoundingClientRect().top - container.getBoundingClientRect().top;
+}
+
+async function renderSidebar(overlay: boolean) {
+ const closeGesture = Gesture.Pan();
+ await act(async () => {
+ root.render(
+
+
+
+
+
+
+
+
+
+
+
+
+ ,
+ );
+ });
+}
+
+it("keeps the overlay sidebar's first row below the status bar on a wide layout", async () => {
+ usePanelStore.getState().showMobileAgentList();
+ await renderSidebar(true);
+ expect(firstRowTop()).toBe(statusBarInsets.top);
+});
+
+it("keeps the docked sidebar's first row below the status bar without padding it twice", async () => {
+ await renderSidebar(false);
+ expect(firstRowTop()).toBe(statusBarInsets.top);
+});
diff --git a/packages/app/src/components/left-sidebar.tsx b/packages/app/src/components/left-sidebar.tsx
index 38b01fd334..ce47ba3e3d 100644
--- a/packages/app/src/components/left-sidebar.tsx
+++ b/packages/app/src/components/left-sidebar.tsx
@@ -28,9 +28,15 @@ import { TitlebarDragRegion } from "@/components/desktop/titlebar-drag-region";
import { SidebarCloseButton } from "@/components/headers/sidebar-close-button";
import {
resolveDesktopSidebarInsetLeft,
+ resolveDesktopSidebarInsetTop,
resolveDesktopSidebarWidth,
} from "@/components/desktop-sidebar-layout";
-import { useTopBand, useWindowLayout, resolveDesktopDivisionLayout } from "@/window-layout";
+import {
+ useTopBand,
+ useWindowLayout,
+ useWindowSafeAreaInsets,
+ resolveDesktopDivisionLayout,
+} from "@/window-layout";
import {
SIDEBAR_RESIZE_ACTIVATION_OFFSET,
SIDEBAR_RESIZE_FAIL_OFFSET,
@@ -156,6 +162,7 @@ export const LeftSidebar = memo(function LeftSidebar({
const { theme } = useUnistyles();
const { t } = useTranslation();
const insets = useSafeAreaInsets();
+ const windowInsets = useWindowSafeAreaInsets();
const isCompactLayout = useIsCompactFormFactor();
const activeWorkspace = useActiveWorkspaceSelection();
const showMobileAgent = usePanelStore((state) => state.showMobileAgent);
@@ -272,7 +279,11 @@ export const LeftSidebar = memo(function LeftSidebar({
diff --git a/packages/app/src/window-layout/index.ios.tsx b/packages/app/src/window-layout/index.ios.tsx
index e698fb72fd..2b0bee7550 100644
--- a/packages/app/src/window-layout/index.ios.tsx
+++ b/packages/app/src/window-layout/index.ios.tsx
@@ -14,7 +14,7 @@ export { useWindowLayout } from "./context";
export { WindowLayoutActions, WindowLayoutActionsHost } from "./actions";
export { WindowLayoutSurface, WindowLayoutDivisionGap } from "./surface";
export { useTopBand } from "./context";
-export { WindowSafeArea } from "./window-safe-area";
+export { WindowSafeArea, useWindowSafeAreaInsets } from "./window-safe-area";
export {
resolveDesktopDivisionLayout,
resolveWorkspaceActionPlacement,
diff --git a/packages/app/src/window-layout/index.tsx b/packages/app/src/window-layout/index.tsx
index 0b71f1f0cd..8b506f682f 100644
--- a/packages/app/src/window-layout/index.tsx
+++ b/packages/app/src/window-layout/index.tsx
@@ -6,7 +6,7 @@ export { useWindowLayout } from "./context";
export { WindowLayoutActions, WindowLayoutActionsHost } from "./actions";
export { WindowLayoutSurface, WindowLayoutDivisionGap } from "./surface";
export { useTopBand } from "./context";
-export { WindowSafeArea } from "./window-safe-area";
+export { WindowSafeArea, useWindowSafeAreaInsets } from "./window-safe-area";
export {
resolveDesktopDivisionLayout,
resolveWorkspaceActionPlacement,
diff --git a/packages/app/src/window-layout/window-safe-area.tsx b/packages/app/src/window-layout/window-safe-area.tsx
index 908e4a26f2..766221e431 100644
--- a/packages/app/src/window-layout/window-safe-area.tsx
+++ b/packages/app/src/window-layout/window-safe-area.tsx
@@ -1,15 +1,24 @@
import { useContext, type ReactNode } from "react";
-import { SafeAreaInsetsContext } from "react-native-safe-area-context";
+import { SafeAreaInsetsContext, type EdgeInsets } from "react-native-safe-area-context";
import { WindowInsetsContext } from "./context";
+/**
+ * The window's insets, for content that draws against the window instead of the surface it was
+ * rendered in: an overlay over the layout surface, or a panel in a portal host outside it.
+ */
+export function useWindowSafeAreaInsets(): EdgeInsets {
+ const insets = useContext(WindowInsetsContext);
+ if (!insets) {
+ throw new Error("useWindowSafeAreaInsets must be used inside WindowLayoutProvider");
+ }
+ return insets;
+}
+
/**
* Gives an overlay that draws over the whole window, such as an RN `Modal`, the window's insets
* instead of the ones its call site was given. Read them below it with `useSafeAreaInsets()`.
*/
export function WindowSafeArea({ children }: { children: ReactNode }) {
- const insets = useContext(WindowInsetsContext);
- if (!insets) {
- throw new Error("WindowSafeArea must render inside WindowLayoutProvider");
- }
+ const insets = useWindowSafeAreaInsets();
return {children};
}