fix(app): use desktop presentation defaults on GPUI

Add a presentation capabilities owner with a GPUI override so GPUI matches desktop inline rename, popover spacing, and non-sheet modal/browser presentation while keeping iOS, Android, web, and Electron unchanged.
This commit is contained in:
Mohamed Boudra
2026-11-28 19:10:26 +01:00
parent 8aaa01ad07
commit b2b862b1ea
11 changed files with 118 additions and 26 deletions
@@ -162,6 +162,14 @@ const CASES = [
native: path.join(APP_DIR, "src/constants/resource-budget.ts"),
web: path.join(APP_DIR, "src/constants/resource-budget.ts"),
},
{
label: "presentation",
origin: path.join(APP_DIR, "src/command-center/command-center.tsx"),
specifier: "@/constants/presentation",
gpui: path.join(APP_DIR, "src/constants/presentation.gpui.ts"),
native: path.join(APP_DIR, "src/constants/presentation.ts"),
web: path.join(APP_DIR, "src/constants/presentation.ts"),
},
];
afterEach(() => {
@@ -52,6 +52,7 @@ import {
} from "@/components/ui/isolated-bottom-sheet-modal";
import { useIsCompactFormFactor } from "@/constants/layout";
import { isNative, isWeb } from "@/constants/platform";
import { usesCompactBottomSheet } from "@/constants/presentation";
import { useAggregatedAgents, type AggregatedAgent } from "@/hooks/use-aggregated-agents";
import { useProjects } from "@/hooks/use-projects";
import { useTimeAgo } from "@/hooks/use-time-ago";
@@ -914,7 +915,7 @@ export function CommandCenter() {
isCompact ? COMMAND_CENTER_LIST_METRICS.compact : COMMAND_CENTER_LIST_METRICS.desktop,
interaction,
);
const showBottomSheet = isCompact && isNative;
const showBottomSheet = isCompact && usesCompactBottomSheet;
const modalLayer = useGlobalOverlayLayer("modal", state.open);
const { sheetRef, handleSheetChange, handleSheetDismiss } = useIsolatedBottomSheetVisibility({
visible: state.open,
@@ -10,7 +10,7 @@ import { Combobox, type ComboboxOption, type ComboboxProps } from "@/components/
import { ModelBrowser, ModelProviderGlyph, useModelBrowser } from "@/components/model-browser";
import { resolveModelBrowserScrolling } from "@/components/model-browser-view";
import { useIsCompactFormFactor } from "@/constants/layout";
import { isNative } from "@/constants/platform";
import { usesCompactBottomSheet } from "@/constants/presentation";
import { usesMobileResourceBudget } from "@/constants/resource-budget";
import type { ProviderSelectorProvider } from "@/provider-selection/provider-selection";
import { ICON_SIZE, type Theme } from "@/styles/theme";
@@ -102,7 +102,10 @@ export function CombinedModelSelector({
}: CombinedModelSelectorProps) {
const { t } = useTranslation();
const isCompact = useIsCompactFormFactor();
const modelBrowserScrolling = resolveModelBrowserScrolling({ isNative, isCompact });
const modelBrowserScrolling = resolveModelBrowserScrolling({
usesCompactBottomSheet,
isCompact,
});
const anchorRef = useRef<View>(null);
const [isOpen, setIsOpen] = useState(false);
const [isContentReady, setIsContentReady] = useState(!usesMobileResourceBudget);
@@ -309,7 +312,7 @@ export function CombinedModelSelector({
desktopChildrenScrollEnabled={false}
header={browser.header}
keyboard={browser.keyboard}
mobileChildrenScrollEnabled={!browser.isProviderView || !isNative}
mobileChildrenScrollEnabled={!browser.isProviderView || !usesCompactBottomSheet}
mobileChildrenContentContainerStyle={styles.mobileBrowserContent}
>
{selectorBody}
@@ -49,16 +49,18 @@ function modelRow(
}
describe("model browser scrolling", () => {
it("participates in native compact bottom-sheet scrolling", () => {
expect(resolveModelBrowserScrolling({ isNative: true, isCompact: true })).toBe("sheet");
it("participates in compact bottom-sheet scrolling on mobile targets", () => {
expect(resolveModelBrowserScrolling({ usesCompactBottomSheet: true, isCompact: true })).toBe(
"sheet",
);
});
it.each([
{ platform: "native wide", isNative: true, isCompact: false },
{ platform: "compact web", isNative: false, isCompact: true },
{ platform: "wide web", isNative: false, isCompact: false },
])("owns scrolling on $platform surfaces", ({ isNative, isCompact }) => {
expect(resolveModelBrowserScrolling({ isNative, isCompact })).toBe("independent");
{ platform: "mobile wide", usesCompactBottomSheet: true, isCompact: false },
{ platform: "compact web/desktop", usesCompactBottomSheet: false, isCompact: true },
{ platform: "wide web/desktop", usesCompactBottomSheet: false, isCompact: false },
])("owns scrolling on $platform surfaces", ({ usesCompactBottomSheet, isCompact }) => {
expect(resolveModelBrowserScrolling({ usesCompactBottomSheet, isCompact })).toBe("independent");
});
});
@@ -13,13 +13,13 @@ export type ModelBrowserView =
| { kind: "provider"; providerId: string; providerLabel: string };
export function resolveModelBrowserScrolling({
isNative,
usesCompactBottomSheet,
isCompact,
}: {
isNative: boolean;
usesCompactBottomSheet: boolean;
isCompact: boolean;
}): "sheet" | "independent" {
return isNative && isCompact ? "sheet" : "independent";
return usesCompactBottomSheet && isCompact ? "sheet" : "independent";
}
/** A profile's model reference; used to match profiles back to model rows. */
@@ -62,7 +62,8 @@ import type { EditingTextInputHandle } from "@/components/ui/text-input";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { useProviderIcon } from "@/components/provider-icons";
import { useIsCompactFormFactor } from "@/constants/layout";
import { isNative, isWeb } from "@/constants/platform";
import { isNative } from "@/constants/platform";
import { usesCompactBottomSheet, usesDesktopPopoverSpacing } from "@/constants/presentation";
import {
hasSoftwareKeyboard,
useHardwareKeyboardPresent,
@@ -1568,7 +1569,7 @@ function ModelRowList({
);
}
if (isCompact && isNative) {
if (isCompact && usesCompactBottomSheet) {
return (
<SheetFlatList
data={rows}
@@ -2074,14 +2075,14 @@ const styles = StyleSheet.create((theme) => ({
flexDirection: "row",
alignItems: "center",
gap: theme.spacing[2],
paddingHorizontal: isWeb ? theme.spacing[3] : theme.spacing[6],
paddingHorizontal: usesDesktopPopoverSpacing ? theme.spacing[3] : theme.spacing[6],
paddingTop: theme.spacing[2],
paddingBottom: theme.spacing[1],
},
sectionHeadingAction: {
position: "absolute",
top: theme.spacing[1],
right: isWeb ? theme.spacing[3] : theme.spacing[6],
right: usesDesktopPopoverSpacing ? theme.spacing[3] : theme.spacing[6],
},
sectionHeadingText: {
flex: 1,
@@ -2101,10 +2102,10 @@ const styles = StyleSheet.create((theme) => ({
position: "absolute",
top: 0,
bottom: 0,
right: isWeb ? theme.spacing[3] : theme.spacing[6],
right: usesDesktopPopoverSpacing ? theme.spacing[3] : theme.spacing[6],
justifyContent: "center",
},
browserModelRow: isWeb ? {} : { marginBottom: theme.spacing[1] },
browserModelRow: usesDesktopPopoverSpacing ? {} : { marginBottom: theme.spacing[1] },
browserRowHovered: {
backgroundColor: theme.colors.surface1,
},
@@ -2122,7 +2123,7 @@ const styles = StyleSheet.create((theme) => ({
flexDirection: "row",
alignItems: "center",
gap: theme.spacing[2],
paddingHorizontal: isWeb ? theme.spacing[3] : theme.spacing[6],
paddingHorizontal: usesDesktopPopoverSpacing ? theme.spacing[3] : theme.spacing[6],
},
browserRowLeading: {
width: 16,
@@ -24,7 +24,7 @@ import { resolveModelTriggerLabels } from "@/composer/agent-controls/layout";
import { resolveModelSheetOpening } from "@/composer/agent-controls/model-sheet-flow";
import type { ProviderSelectorProvider } from "@/provider-selection/provider-selection";
import { useIsCompactFormFactor } from "@/constants/layout";
import { isNative } from "@/constants/platform";
import { usesCompactBottomSheet } from "@/constants/presentation";
import { hasSoftwareKeyboard } from "@/keyboard";
import { readMeasuredWidth } from "@/hooks/use-container-width";
import {
@@ -167,7 +167,7 @@ export function CompactModelSheet({
const { t } = useTranslation();
const usesBottomSheet = useIsCompactFormFactor();
const modelBrowserScrolling = resolveModelBrowserScrolling({
isNative,
usesCompactBottomSheet,
isCompact: usesBottomSheet,
});
const [isOpen, setIsOpen] = useState(false);
@@ -0,0 +1,16 @@
import type { PresentationCapabilities } from "./presentation";
export function resolvePresentationCapabilities(_input: {
isNative: boolean;
isWeb: boolean;
}): PresentationCapabilities {
return {
allowsInlineWorkspaceRename: true,
usesCompactBottomSheet: false,
usesDesktopPopoverSpacing: true,
};
}
export const allowsInlineWorkspaceRename = true;
export const usesCompactBottomSheet = false;
export const usesDesktopPopoverSpacing = true;
@@ -0,0 +1,34 @@
import { describe, expect, it } from "vitest";
import * as gpuiPresentation from "./presentation.gpui";
describe("presentation capabilities per target", () => {
it("gives desktop presentation capabilities on GPUI, web, and Electron, and touch sheet/modal defaults on iOS/Android", async () => {
const basePresentation = (await import(
new URL("./presentation.ts", import.meta.url).href
)) as typeof gpuiPresentation;
expect(
basePresentation.resolvePresentationCapabilities({ isNative: true, isWeb: false }),
).toEqual({
allowsInlineWorkspaceRename: false,
usesCompactBottomSheet: true,
usesDesktopPopoverSpacing: false,
});
expect(
basePresentation.resolvePresentationCapabilities({ isNative: false, isWeb: true }),
).toEqual({
allowsInlineWorkspaceRename: true,
usesCompactBottomSheet: false,
usesDesktopPopoverSpacing: true,
});
expect({
allowsInlineWorkspaceRename: gpuiPresentation.allowsInlineWorkspaceRename,
usesCompactBottomSheet: gpuiPresentation.usesCompactBottomSheet,
usesDesktopPopoverSpacing: gpuiPresentation.usesDesktopPopoverSpacing,
}).toEqual({
allowsInlineWorkspaceRename: true,
usesCompactBottomSheet: false,
usesDesktopPopoverSpacing: true,
});
});
});
@@ -0,0 +1,27 @@
import { isNative, isWeb } from "./platform";
export interface PresentationCapabilities {
/** Wide sidebar rows rename in place instead of opening a rename modal. */
allowsInlineWorkspaceRename: boolean;
/** Compact screens present bottom sheets (`SheetFlatList` / Gorhom modal) instead of dialogs. */
usesCompactBottomSheet: boolean;
/** Popover lists use tight desktop row padding instead of touch-sheet spacing. */
usesDesktopPopoverSpacing: boolean;
}
export function resolvePresentationCapabilities(input: {
isNative: boolean;
isWeb: boolean;
}): PresentationCapabilities {
return {
allowsInlineWorkspaceRename: input.isWeb,
usesCompactBottomSheet: input.isNative,
usesDesktopPopoverSpacing: input.isWeb,
};
}
const CAPABILITIES = resolvePresentationCapabilities({ isNative, isWeb });
export const allowsInlineWorkspaceRename = CAPABILITIES.allowsInlineWorkspaceRename;
export const usesCompactBottomSheet = CAPABILITIES.usesCompactBottomSheet;
export const usesDesktopPopoverSpacing = CAPABILITIES.usesDesktopPopoverSpacing;
@@ -1,5 +1,5 @@
import { UnistylesRuntime } from "react-native-unistyles";
import { isWeb } from "@/constants/platform";
import { allowsInlineWorkspaceRename } from "@/constants/presentation";
export type WorkspaceRenameSurface = "inline" | "modal";
@@ -7,11 +7,11 @@ export type WorkspaceRenameSurface = "inline" | "modal";
* Read when a rename starts rather than subscribed to: the surface is chosen once per rename, and
* a subscription would re-render every sidebar row on each breakpoint change.
*
* Native wide layouts keep the modal. Their sidebar rows are touch targets with a permanent
* Mobile native wide layouts keep the modal. Their sidebar rows are touch targets with a permanent
* kebab, and the iPad overlay-dismissal flows drive the modal.
*/
export function resolveWorkspaceRenameSurface(): WorkspaceRenameSurface {
if (!isWeb) return "modal";
if (!allowsInlineWorkspaceRename) return "modal";
const breakpoint = UnistylesRuntime.breakpoint;
return breakpoint === "lg" || breakpoint === "xl" ? "inline" : "modal";
}