Compare commits

...
Author SHA1 Message Date
paseo-bot[bot]andClaude Opus 5.5 d7663506b4 docs: state that the wide web layout surface owns the top inset
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 10:30:47 +00:00
paseo-bot[bot]andClaude Opus 5.5 c7763e24af fix(app): keep the autocomplete popover below the status bar from a wide layout surface
The popover clamped its height with the composer's top inset, which a wide
browser layout surface now sets to 0. The root portal host the popover can
render into sits outside that surface, against the window's top edge, so
the popover's top went under the status bar. The frame now reads the inset
where it renders, inside the portal host: the root host gets the window's
inset, and the workspace host, inside the surface, keeps 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 10:18:24 +00:00
paseo-bot[bot]andClaude Opus 5.5 39f545b77c 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>
2026-11-17 10:13:55 +00:00
e883fdeaf1 fix(app): keep the Mermaid fullscreen controls below the status bar
The fullscreen Mermaid viewer is a Modal that covers the whole window,
but it padded its content with the insets of the chat message that
opened it. On wide web layouts the layout surface now spends the top
inset itself and hands its children top 0, so the viewer's zoom and
close buttons moved under the iOS status bar.

Wrap the viewer in WindowSafeArea, as the attachment lightbox does, so
it reads the window's insets.

Co-authored-by: Matt Abar <mattaabar@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 09:19:03 +00:00
Matt AbarandClaude Opus 5.5 d86e5c40bd fix(app): clear the iOS status bar on wide browser layouts
In an iOS Home Screen web app at a wide (non-compact) layout there is no
compact header to absorb the top safe-area inset, so the top rows sat
under the status bar and could not be tapped (#9524). The window surface
now consumes the top inset on the web when the layout is not compact;
native window chrome keeps its own top band.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 12:37:45 -07:00
18 changed files with 365 additions and 62 deletions
+1 -1
View File
@@ -177,7 +177,7 @@ Electron window controls are top-corner obstructions, not a compact-layout condi
Windows and Linux controls are fixed window chrome, outside scrolling header content. A tab rail that reaches them ends at their obstruction and shows the shared overflow fade. On macOS, the Explorer toggle occupies a fixed top-right window slot so opening and closing Explorer does not move the pointer target.
Each window edge has one safe-area owner. `WindowLayoutProvider` publishes the bottom inset that every surface reads through `useSafeAreaInsets()`: on iOS 27.1 and later it is UIKit's bottom-bar clearance, which refines the rectangular home-indicator inset to the screen's corners, and elsewhere the system inset. Surfaces apply that value once and never stack their own spacing under it; `WindowLayoutSurface` owns the horizontal insets the same way.
Each window edge has one safe-area owner. `WindowLayoutProvider` publishes the bottom inset that every surface reads through `useSafeAreaInsets()`: on iOS 27.1 and later it is UIKit's bottom-bar clearance, which refines the rectangular home-indicator inset to the screen's corners, and elsewhere the system inset. Surfaces apply that value once and never stack their own spacing under it; `WindowLayoutSurface` owns the horizontal insets the same way, and on wide web layouts it also owns the top inset: it pads the status bar of an iOS Home Screen web app once and gives its content a top inset of 0. Content inside the surface that draws against the window instead of the padded content reads the window's insets; see Gotcha 8 in `docs/floating-panels.md`.
A new list+detail feature copies the settings shell. A new workspace-shaped feature copies the workspace shell. Inventing a third shape happens in design review, not in a PR.
+16 -5
View File
@@ -435,10 +435,15 @@ Wrapping providers _around_ the modal does nothing. They land on the wrong side.
## Gotcha 8 — Read safe-area insets where the overlay draws
A compact sheet tab's body (`SheetBottomInset` in `adaptive-modal-sheet.tsx`) pads the bottom
inset and gives its content a bottom inset of 0, so the composer dock sits the same in a sheet as
in a tab. An overlay opened from that content and calling `useSafeAreaInsets()` at its call site
gets that 0 and draws over the navigation bar.
Two containers spend an inset and give their content 0 for that edge:
- A compact sheet tab's body (`SheetBottomInset` in `adaptive-modal-sheet.tsx`) pads the bottom
inset, so the composer dock sits the same in a sheet as in a tab.
- `WindowLayoutSurface` on a wide web layout pads the top inset, the status bar of an iOS Home
Screen web app (`docs/design.md`, section 9).
An overlay opened from that content and calling `useSafeAreaInsets()` at its call site gets that 0
and draws over the navigation bar or under the status bar. Read the inset where the overlay draws:
- A Gorhom sheet reads the inset inside its children, which render in the app's sheet host. See
`CompactSheetBody`, `MenuSheetScrollView` and `ComboboxSheetFrame`.
@@ -446,7 +451,13 @@ gets that 0 and draws over the navigation bar.
`WindowSafeArea` from `@/window-layout` and read the inset below that. It provides the insets of
the whole window, published by `WindowLayoutProvider`. Do not put a `SafeAreaProvider` inside the
modal: on Android it measures the dialog window, whose bottom inset reads 24, then 0, then 24
again over the first frames, and everything padded by it jumps. See `attachment-lightbox.tsx`.
again over the first frames, and everything padded by it jumps. See `attachment-lightbox.tsx`
and the Mermaid fullscreen viewer.
- A panel in a `FloatingPanelPortalHost` reads `useSafeAreaInsets()` inside the portal, where it
resolves at the host's position (Gotcha 2): the root host sits outside the layout surface and
gets the window's inset, a workspace host inside it gets 0. See the autocomplete `PopoverFrame`.
- An absolutely positioned view that covers the surface's padding, such as the overlay left
sidebar, reads the window's insets with `useWindowSafeAreaInsets()`.
## Recipe for a new anchored panel
@@ -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);
});
+13 -2
View File
@@ -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}
/>
@@ -0,0 +1,39 @@
import React, { act } from "react";
import { createRoot } from "react-dom/client";
import { SafeAreaInsetsContext } from "react-native-safe-area-context";
import { afterEach, expect, it, vi } from "vitest";
import { WindowLayoutProvider, WindowLayoutSurface } from "@/window-layout";
import { MermaidFullscreenViewer } from "./fullscreen-viewer.web";
vi.stubGlobal("React", React);
const statusBarInsets = { top: 32, right: 0, bottom: 20, left: 0 };
const surfaceStyle = { flex: 1 };
function noClose() {}
const container = document.createElement("div");
document.body.appendChild(container);
const root = createRoot(container);
afterEach(() => {
act(() => root.render(null));
});
it("keeps the close button below the status bar when opened from a wide layout", async () => {
await act(async () => {
root.render(
<SafeAreaInsetsContext.Provider value={statusBarInsets}>
<WindowLayoutProvider>
<WindowLayoutSurface compact={false} style={surfaceStyle}>
<MermaidFullscreenViewer
source={"graph TD\n A --> B"}
colorScheme="light"
onClose={noClose}
/>
</WindowLayoutSurface>
</WindowLayoutProvider>
</SafeAreaInsetsContext.Provider>,
);
});
const close = document.querySelector<HTMLElement>('[data-testid="mermaid-fullscreen-close"]');
expect(close).not.toBeNull();
expect(close!.getBoundingClientRect().top).toBeGreaterThanOrEqual(statusBarInsets.top);
});
@@ -8,6 +8,7 @@ import { useSafeAreaInsets } from "react-native-safe-area-context";
import { ZoomableViewport } from "@/components/zoomable-viewport";
import { SPACING } from "@/styles/theme";
import { WindowChromeRootRegion } from "@/utils/desktop-window";
import { WindowSafeArea } from "@/window-layout";
import { MermaidIframeRuntime, type MermaidRenderedMessage } from "./iframe-runtime.web";
import type { DiagramColorScheme } from "./render-model";
import { useMermaidRenderModel } from "./use-render-model";
@@ -23,11 +24,25 @@ interface MermaidFullscreenViewerProps {
const FALLBACK_SIZE = { width: 240, height: 240 };
const VIEWER_FIT = { padding: SPACING[6] };
export function MermaidFullscreenViewer({
source,
colorScheme,
onClose,
}: MermaidFullscreenViewerProps) {
export function MermaidFullscreenViewer(props: MermaidFullscreenViewerProps) {
return (
<Modal
transparent
animationType="fade"
statusBarTranslucent
visible
onRequestClose={props.onClose}
>
{/* The modal draws over the whole window: its insets are the window's, not the ones left
where the diagram was opened (wide layouts spend the top one above the content). */}
<WindowSafeArea>
<MermaidFullscreenContent {...props} />
</WindowSafeArea>
</Modal>
);
}
function MermaidFullscreenContent({ source, colorScheme, onClose }: MermaidFullscreenViewerProps) {
const { t } = useTranslation();
const insets = useSafeAreaInsets();
const { state, request, rendered, renderFailed } = useMermaidRenderModel({
@@ -93,35 +108,33 @@ export function MermaidFullscreenViewer({
);
return (
<Modal transparent animationType="fade" statusBarTranslucent visible onRequestClose={onClose}>
<WindowChromeRootRegion corners="both">
<View style={styles.root}>
<View style={styles.backdrop} />
<View style={contentLayerStyle}>
{/* biome-ignore lint/a11y/noNoninteractiveTabindex: focus holder for the Escape shortcut */}
<div ref={contentLayerRef} style={focusLayerDomStyle} tabIndex={-1}>
<ZoomableViewport
accessibilityLabel={t("message.diagram.diagram")}
actions={actions}
contentSize={contentSize}
fit={VIEWER_FIT}
minScale={1}
onPressOutsideContent={onClose}
style={styles.viewport}
testID="mermaid-fullscreen-viewport"
wheelActivation="always"
>
<MermaidIframeRuntime
request={request}
onRendered={handleRendered}
onRenderFailed={renderFailed}
/>
</ZoomableViewport>
</div>
</View>
<WindowChromeRootRegion corners="both">
<View style={styles.root}>
<View style={styles.backdrop} />
<View style={contentLayerStyle}>
{/* biome-ignore lint/a11y/noNoninteractiveTabindex: focus holder for the Escape shortcut */}
<div ref={contentLayerRef} style={focusLayerDomStyle} tabIndex={-1}>
<ZoomableViewport
accessibilityLabel={t("message.diagram.diagram")}
actions={actions}
contentSize={contentSize}
fit={VIEWER_FIT}
minScale={1}
onPressOutsideContent={onClose}
style={styles.viewport}
testID="mermaid-fullscreen-viewport"
wheelActivation="always"
>
<MermaidIframeRuntime
request={request}
onRendered={handleRendered}
onRenderFailed={renderFailed}
/>
</ZoomableViewport>
</div>
</View>
</WindowChromeRootRegion>
</Modal>
</View>
</WindowChromeRootRegion>
);
}
@@ -135,7 +148,11 @@ const focusLayerDomStyle: React.CSSProperties = {
const styles = StyleSheet.create((theme) => ({
root: { flex: 1, minHeight: 0, minWidth: 0 },
backdrop: { position: "absolute", inset: 0, backgroundColor: theme.colors.surface0 },
backdrop: {
position: "absolute",
inset: 0,
backgroundColor: theme.colors.surface0,
},
contentLayer: { position: "absolute", inset: 0 },
viewport: { flex: 1 },
}));
@@ -4,10 +4,11 @@ import { createRoot, type Root } from "react-dom/client";
import { PortalProvider } from "@gorhom/portal";
import { View } from "react-native";
import { KeyboardProvider } from "react-native-keyboard-controller";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { SafeAreaInsetsContext, SafeAreaProvider } from "react-native-safe-area-context";
import { afterEach, beforeEach, expect, it, vi } from "vitest";
import { RetainedPanel } from "@/components/retained-panel";
import { KeyboardShiftProvider } from "@/keyboard/shift";
import { WindowLayoutProvider, WindowLayoutSurface } from "@/window-layout";
import type { AutocompleteOption } from "./autocomplete";
import { AutocompletePopover } from "./autocomplete-popover";
import { FloatingPanelPortalHost } from "./floating-panel-portal";
@@ -572,3 +573,64 @@ it("scrolls towards rows further from the composer when the wheel turns up", asy
expect(isRowInView("/skill-7")).toBe(true);
expect(popover.getBoundingClientRect().bottom).toBe(rectOf("composer-input")!.top - 12);
});
const STATUS_BAR_INSETS = { top: 32, left: 0, right: 0, bottom: 0 };
const SURFACE_STYLE = { flex: 1 };
const COMPOSER_NEAR_TOP_STYLE = { position: "absolute" as const, top: 60, left: 16, width: 358 };
/**
* A wide browser layout surface pads the status bar and gives its content a top inset of 0. The
* root portal host sits outside that surface, against the window's top edge, so a composer inside
* the surface that portals there still has to keep the popover below the status bar.
*/
function ComposerNearTop(): ReactNode {
return (
<View style={COMPOSER_NEAR_TOP_STYLE}>
<AutocompletePopover
visible
options={OPTIONS}
selectedIndex={OPTIONS.length - 1}
onSelect={ignoreSelection}
>
<View testID="composer-input" style={inputStyle(40)} />
</AutocompletePopover>
</View>
);
}
/** A composer near the top of a wide surface, portalling into the root host outside it. */
function WideSurfaceScreen(): ReactNode {
return (
<View style={SCREEN_STYLE}>
<WindowLayoutSurface compact={false} style={SURFACE_STYLE}>
<ComposerNearTop />
</WindowLayoutSurface>
<FloatingPanelPortalHost />
</View>
);
}
function WideSurfaceWindow(): ReactNode {
return (
<Providers>
<SafeAreaInsetsContext.Provider value={STATUS_BAR_INSETS}>
<WindowLayoutProvider>
<RetainedPanel active>
<WideSurfaceScreen />
</RetainedPanel>
</WindowLayoutProvider>
</SafeAreaInsetsContext.Provider>
</Providers>
);
}
it("keeps its top below the status bar when it portals out of a wide layout surface", async () => {
render(<WideSurfaceWindow />);
const popover = await waitForPopover();
await new Promise((resolve) => setTimeout(resolve, 200));
const screenTop = container!.getBoundingClientRect().top;
expect(popover.getBoundingClientRect().top - screenTop).toBeGreaterThanOrEqual(
STATUS_BAR_INSETS.top,
);
});
@@ -9,7 +9,6 @@ import {
import { Portal } from "@gorhom/portal";
import { useAnimatedReaction, useAnimatedRef } from "react-native-reanimated";
import { scheduleOnRN } from "react-native-worklets";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import {
Autocomplete,
type AutocompleteOption,
@@ -56,7 +55,6 @@ export function AutocompletePopover({
);
const [anchorAtRest, setAnchorAtRest] = useState<AnchorAtRest | null>(null);
const windowDimensions = useWindowDimensions();
const safeAreaInsets = useSafeAreaInsets();
const portalHostName = useFloatingPanelPortalHostName();
const { isMoving } = useKeyboardShift();
const anchor = useKeyboardAnchor();
@@ -132,7 +130,6 @@ export function AutocompletePopover({
anchorRef={anchorRef}
anchorAtRest={anchorAtRest}
reservedLift={anchor.reservedLift}
topInset={safeAreaInsets.top}
>
<Autocomplete
options={options}
@@ -5,6 +5,7 @@ import Animated, {
useFrameCallback,
useSharedValue,
} from "react-native-reanimated";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { placeAboveAnchor, type PopoverFrameProps } from "./placement";
/**
@@ -20,11 +21,13 @@ export function PopoverFrame({
anchorRef,
anchorAtRest,
reservedLift,
topInset,
children,
}: PopoverFrameProps): ReactElement {
"use no memo";
// React Compiler memoizes effect captures by reading SharedValue.value during render.
// The frame renders in the portal host, so these are the host's insets, not the composer's: a
// host against the window's top edge keeps the popover below the status bar.
const topInset = useSafeAreaInsets().top;
const anchorHeight = useSharedValue(anchorAtRest.height);
const anchorLost = useSharedValue(false);
const readAnchorHeight = useCallback(() => {
@@ -2,6 +2,7 @@ import { useLayoutEffect, useRef, useState, type ReactElement } from "react";
import { flushSync } from "react-dom";
import { View } from "react-native";
import { inlineUnistylesStyle } from "@/styles/unistyles-inline-style";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { placeAboveAnchor, type AnchorAtRest, type PopoverFrameProps } from "./placement";
type AnchorRect = Omit<AnchorAtRest, "height">;
@@ -26,11 +27,13 @@ export function PopoverFrame({
anchorRef,
anchorAtRest,
reservedLift,
topInset,
children,
}: PopoverFrameProps): ReactElement {
"use no memo";
// React Compiler memoizes effect captures by reading SharedValue.value during render.
// The frame renders in the portal host, so these are the host's insets, not the composer's: a
// host against the window's top edge keeps the popover below the status bar.
const topInset = useSafeAreaInsets().top;
const frameRef = useRef<View>(null);
const [anchor, setAnchor] = useState<AnchorRect>(anchorAtRest);
@@ -19,7 +19,6 @@ export interface PopoverFrameProps {
/** Taken asynchronously; the frame follows the anchor's live size between measurements. */
anchorAtRest: AnchorAtRest;
reservedLift: DerivedValue<number>;
topInset: number;
children: ReactNode;
}
@@ -1,8 +1,9 @@
import React, { act } from "react";
import React, { act, useMemo } from "react";
import { createRoot } from "react-dom/client";
import { PortalProvider } from "@gorhom/portal";
import { afterEach, expect, it, vi } from "vitest";
import { Text } from "react-native";
import { SafeAreaInsetsContext, useSafeAreaInsets } from "react-native-safe-area-context";
import { page } from "vitest/browser";
import {
DropdownMenu,
@@ -14,7 +15,7 @@ import { HeaderToggleButton } from "@/components/headers/header-toggle-button";
import type { WindowLayout } from "./model";
import { WindowLayoutContext } from "./context";
import { WindowLayoutActions, WindowLayoutActionsHost } from "./actions";
import { WindowLayoutDivisionGap } from "./surface";
import { WindowLayoutDivisionGap, WindowLayoutSurface } from "./surface";
import { lightTheme } from "@/styles/theme";
vi.stubGlobal("React", React);
@@ -32,6 +33,40 @@ afterEach(() => {
act(() => root.render(null));
});
const statusBarInsets = { top: 24, left: 0, right: 0, bottom: 20 };
const statusBarSurfaceStyle = { height: 200 };
it("clears the status bar in wide layouts without applying the top inset twice", () => {
function Header() {
const insets = useSafeAreaInsets();
const style = useMemo(() => ({ paddingTop: insets.top }), [insets.top]);
return (
<button type="button" style={style}>
Tabs
</button>
);
}
for (const compact of [false, true]) {
act(() =>
root.render(
<SafeAreaInsetsContext.Provider value={statusBarInsets}>
<WindowLayoutSurface compact={compact} style={statusBarSurfaceStyle}>
<Header />
</WindowLayoutSurface>
</SafeAreaInsetsContext.Provider>,
),
);
const surface = container.firstElementChild as HTMLElement;
const button = container.querySelector("button")!;
expect(getComputedStyle(surface).paddingTop).toBe(compact ? "0px" : "24px");
expect(getComputedStyle(button).paddingTop).toBe(compact ? "24px" : "0px");
if (!compact) {
expect(button.getBoundingClientRect().top - surface.getBoundingClientRect().top).toBe(24);
const rect = button.getBoundingClientRect();
expect(document.elementFromPoint(rect.left + rect.width / 2, rect.top + 1)).toBe(button);
}
}
});
it("paints the reserved division with the sidebar surface", () => {
act(() =>
root.render(<WindowLayoutDivisionGap layout={layout} sidebarVisible compact={false} />),
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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,
+13 -4
View File
@@ -2,10 +2,11 @@ import { useMemo, type ReactNode } from "react";
import { View, type StyleProp, type ViewStyle } from "react-native";
import { StyleSheet } from "react-native-unistyles";
import { SafeAreaInsetsContext, useSafeAreaInsets } from "react-native-safe-area-context";
import { isWeb } from "@/constants/platform";
import { useWindowLayout } from "./context";
import { resolveWorkspaceActionPlacement, type DesktopDivisionLayout } from "./model";
/** Consume horizontal safe areas once, including compact content beside a vertical bar. */
/** Consume safe areas once; compact headers own their top inset. */
export function WindowLayoutSurface({
children,
compact,
@@ -17,16 +18,24 @@ export function WindowLayoutSurface({
}) {
const insets = useSafeAreaInsets();
const usesBar = resolveWorkspaceActionPlacement(useWindowLayout()) === "vertical-bar";
// Wide browser layouts have no compact header to clear the standalone iOS status bar.
// Native window chrome owns its own top band.
const consumesTop = isWeb && !compact;
const surfaceStyle = useMemo(
() => [
style,
consumesTop && { paddingTop: insets.top },
(!compact || usesBar) && { paddingLeft: insets.left, paddingRight: insets.right },
],
[style, compact, usesBar, insets.left, insets.right],
[style, compact, usesBar, consumesTop, insets.top, insets.left, insets.right],
);
const contentInsets = useMemo(
() => (compact && usesBar ? { ...insets, left: 0, right: 0 } : insets),
[compact, usesBar, insets],
() => ({
...insets,
...(consumesTop ? { top: 0 } : {}),
...(compact && usesBar ? { left: 0, right: 0 } : {}),
}),
[compact, usesBar, consumesTop, insets],
);
return (
<View style={surfaceStyle}>
@@ -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>;
}