mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-19 23:05:21 +00:00
fix(app): keep the overlay left sidebar below the status bar on wide browser layouts
The wide layout surface now pads the status bar itself and hands its content a top inset of 0. The overlay sidebar is absolutely positioned against the surface, over that padding, so it starts at the window's top edge and needs the window's top inset. The docked sidebar keeps reading the inset the surface leaves its content. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e883fdeaf1
commit
39f545b77c
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 (
|
||||
<View style={style}>
|
||||
<View testID="sidebar-first-row" style={rowStyle} />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
function firstRowTop(): number {
|
||||
const row = document.querySelector<HTMLElement>('[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(
|
||||
<GestureHandlerRootView style={fill}>
|
||||
<SafeAreaInsetsContext.Provider value={statusBarInsets}>
|
||||
<WindowLayoutProvider>
|
||||
<WindowLayoutSurface compact={false} style={fill}>
|
||||
<MobilePanelsProvider>
|
||||
<MobilePanelOverlay
|
||||
panel="agent-list"
|
||||
presentation={overlay ? "overlay" : "dock"}
|
||||
dockVisible={!overlay}
|
||||
closeGesture={closeGesture}
|
||||
>
|
||||
<SidebarFirstRow overlay={overlay} />
|
||||
</MobilePanelOverlay>
|
||||
</MobilePanelsProvider>
|
||||
</WindowLayoutSurface>
|
||||
</WindowLayoutProvider>
|
||||
</SafeAreaInsetsContext.Provider>
|
||||
</GestureHandlerRootView>,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
@@ -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({
|
||||
<DesktopSidebar
|
||||
{...sharedProps}
|
||||
{...handlers}
|
||||
insetsTop={insets.top}
|
||||
insetsTop={resolveDesktopSidebarInsetTop({
|
||||
overlay: desktopOverlay,
|
||||
safeAreaTop: insets.top,
|
||||
windowSafeAreaTop: windowInsets.top,
|
||||
})}
|
||||
active={active}
|
||||
overlay={desktopOverlay}
|
||||
/>
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 <SafeAreaInsetsContext.Provider value={insets}>{children}</SafeAreaInsetsContext.Provider>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user