diff --git a/CLAUDE.md b/CLAUDE.md index e188836ab1..e08e1afb61 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -36,6 +36,7 @@ At the start of non-trivial work, list `docs/` and skim anything relevant to the | [docs/floating-panels.md](docs/floating-panels.md) | Anchored popovers — Portal/Modal escape for Android, lifecycle gates, keyboard-shared-value, status-bar offset, the flash | | [docs/keyboard-shortcuts.md](docs/keyboard-shortcuts.md) | The binding table, per-platform key sources, badges vs routing, iOS `UIKeyCommand` limits | | [docs/menus.md](docs/menus.md) | The menu engine — popover vs sheet, submenu pages, hover intent, when a decision earns a submenu | +| [docs/drag-reorder.md](docs/drag-reorder.md) | Drag to reorder — `DraggableList` and its handle, the scroll view that must host the drag, grip placement, testing on a phone | | [docs/expo-router.md](docs/expo-router.md) | Expo Router route ownership, startup restore, and native blank-screen gotchas | | [docs/notifications.md](docs/notifications.md) | Notification tap ownership, native replay and acknowledgement, startup handoff, and payload QA | | [docs/file-icons.md](docs/file-icons.md) | Material icon theme integration for the file explorer | diff --git a/docs/drag-reorder.md b/docs/drag-reorder.md new file mode 100644 index 0000000000..23c5fd0916 --- /dev/null +++ b/docs/drag-reorder.md @@ -0,0 +1,34 @@ +# Drag to reorder + +A list the user can reorder renders through `DraggableList` from `@/components/draggable-list`. Each row puts a `DraggableListHandle` where its grip is drawn. The Usage cards (`packages/app/src/usage/list.tsx`, `packages/app/src/usage/card.tsx`) and the agent profile roster (`packages/app/src/agent-profiles/settings/`) are the reference. + +| Platform | How a drag starts | +| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | +| Web | dnd-kit pointer drag. With `useDragHandle`, only the handle starts it, and the handle reorders by keyboard. Without it, the whole row starts it. | +| Native | Hold the handle for 180 ms without moving more than 4 px. The list then owns the touch until the finger lifts. | + +## The scroll view must host the drag + +On native, the hold calls `drag()`, which calls `useContentDrag().setActive(true)` from `@/components/ui/content-drag` on the nearest scroll view. That scroll view stops scrolling until the drag ends. If no scroll view up the tree hosts content drags, `setActive` does nothing. The page scroll then takes the touch as soon as the finger moves past the touch slop, before the list's own pan activates. The row never moves, and the page scrolls instead. + +These scroll views host content drags: + +- `ScrollView` from `@/components/ui/scroll-view`, inside and outside a sheet. +- `PageLayout`, for a settings page or any other full page. + +If you put a reorderable list in another scroll view, such as a third-party keyboard-aware one, wrap it with `withContentDrag` from `@/components/ui/content-drag`. `packages/app/src/components/page-layout/index.tsx` shows the pattern. A plain `ScrollView` from `react-native` breaks the drag. + +Inside a sheet, the `ScrollView` also registers the drag gesture with the sheet, so the sheet's pan-to-close waits for it. + +## Where the grip goes + +The grip hangs in the row's leading padding, absolutely positioned over the full row height. The row's content keeps the same left rail as rows that cannot be reordered, and the grip does not take a column. On a pointer device the grip shows on hover, focus, or while dragging. On touch and compact layouts it always shows, because there is no hover. + +## Test with a page that scrolls + +A list that fits on the screen does not show the bug, because the page has nothing to scroll. Test on a phone with enough rows that the page scrolls. Then check both directions: + +1. Hold the grip and drag a row past two others. The new order is saved. +2. Swipe quickly on a row body. The page scrolls and the order stays the same. + +On an Android emulator, `adb shell input swipe` does not hold still long enough to arm the drag. Send `input motionevent DOWN`, wait 500 ms, then send `MOVE` events and `UP`. diff --git a/packages/app/src/agent-profiles/settings/agent-profile-row.tsx b/packages/app/src/agent-profiles/settings/agent-profile-row.tsx index 869013d9e5..a396f78b29 100644 --- a/packages/app/src/agent-profiles/settings/agent-profile-row.tsx +++ b/packages/app/src/agent-profiles/settings/agent-profile-row.tsx @@ -17,7 +17,12 @@ import type { ProviderSnapshotEntry } from "@getpaseo/protocol/agent-types"; import type { AgentProfile } from "@getpaseo/protocol/messages"; import { DraggableListHandle } from "@/components/draggable-list"; import { useOpenKebabMenuVisibility } from "@/components/sidebar/use-open-kebab-menu-visibility"; -import { bySizing, TOUCH_TARGET } from "@/components/ui/control-geometry"; +import { + bySizing, + ICON_BUTTON_SIZES, + mapLayout, + TOUCH_TARGET, +} from "@/components/ui/control-geometry"; import { DropdownMenu, DropdownMenuContent, @@ -41,11 +46,16 @@ import { buildAgentProfileRosterSummary } from "../internal/profile-summary"; /** Shared column & rail geometry consumed by both RosterTableHeader and AgentProfileRow. */ export const ROSTER_COL_PROFILE_WIDTH = 184; export const ROSTER_COL_RUNTIME_WIDTH = 248; -export const ROSTER_GRIP_WIDTH = bySizing({ touch: 28, pointer: 20 }); export const ROSTER_TRAILING_WIDTH = bySizing({ touch: TOUCH_TARGET + 14, pointer: 42 }); const ROW_MIN_HEIGHT = bySizing({ touch: TOUCH_TARGET + 16, pointer: 56 }); -const GRIP_HANDLE_HEIGHT = bySizing({ touch: TOUCH_TARGET, pointer: 28 }); +const KEBAB_GLYPH_SIZE = ICON_SIZE.sm; +// The kebab's hitbox is larger than its glyph; it overhangs the row so the glyph sits on the +// card's trailing rail and the hitbox does not make the row taller. +const KEBAB_HITBOX_OVERHANG = bySizing({ + touch: (ICON_BUTTON_SIZES.small.touch - KEBAB_GLYPH_SIZE) / 2, + pointer: (ICON_BUTTON_SIZES.small.pointer - KEBAB_GLYPH_SIZE) / 2, +}); const ThemedGripVertical = withUnistyles(GripVertical); const ThemedMoreVertical = withUnistyles(MoreVertical); @@ -130,7 +140,7 @@ function AgentProfileRowMenu({ label={t("settings.host.agentProfiles.profileActions", { name: profileName })} testID={`agent-profile-menu-${profileId}`} > - + {profile.name} - - - - {fullSummary} - - + + {fullSummary} + {profile.notes ? ( [styles.gripSlot, !showRowAffordances && styles.affordanceHidden], + const gripStyle = useMemo( + () => (showRowAffordances ? styles.grip : [styles.grip, styles.affordanceHidden]), [showRowAffordances], ); const kebabVisibilityStyle = useMemo( @@ -399,22 +402,6 @@ export function AgentProfileRow({ {selected ? : null} - {reorderable ? ( - - - - - - ) : ( - - )} - - + {/* A stacked row opens on tap like the wide one; the kebab alone ends it, on the trailing rail. */} + - - - + {isStacked ? null : ( + + + + )} + + {reorderable ? ( + + + + ) : null} ); } @@ -460,8 +462,7 @@ const styles = StyleSheet.create((theme) => ({ alignItems: "center", minHeight: ROW_MIN_HEIGHT, paddingVertical: theme.spacing[3], - paddingLeft: theme.spacing[2], - paddingRight: theme.spacing[4], + paddingHorizontal: theme.spacing[4], gap: theme.spacing[2], }, rowHovered: { @@ -491,19 +492,15 @@ const styles = StyleSheet.create((theme) => ({ passThrough: { pointerEvents: "none", }, - gripSlot: { - width: ROSTER_GRIP_WIDTH, - alignItems: "center", - justifyContent: "center", - flexShrink: 0, - }, - gripSpacerCompact: { - width: theme.spacing[2], - flexShrink: 0, - }, - gripHandle: { - width: ROSTER_GRIP_WIDTH, - height: GRIP_HANDLE_HEIGHT, + // The grip hangs in the row's leading padding, as on a Usage card, so the icon tile sits on the + // card's rail with or without it and revealing it on hover moves nothing. It takes the padding's + // full height so a finger finds it. + grip: { + position: "absolute", + left: 0, + top: 0, + bottom: 0, + width: theme.spacing[4], alignItems: "center", justifyContent: "center", }, @@ -585,12 +582,6 @@ const styles = StyleSheet.create((theme) => ({ minWidth: 0, gap: theme.spacing[0.5], }, - stackedSpecLine: { - flexDirection: "row", - alignItems: "center", - gap: theme.spacing[1.5], - minWidth: 0, - }, stackedSpecText: { flexShrink: 1, color: theme.colors.foregroundMuted, @@ -609,6 +600,11 @@ const styles = StyleSheet.create((theme) => ({ gap: theme.spacing[1], flexShrink: 0, }, + trailingStacked: { + flexShrink: 0, + marginRight: mapLayout(KEBAB_HITBOX_OVERHANG, (overhang) => -overhang), + marginVertical: mapLayout(KEBAB_HITBOX_OVERHANG, (overhang) => -overhang), + }, kebabSlot: { alignItems: "center", justifyContent: "center", diff --git a/packages/app/src/agent-profiles/settings/agent-profiles-section.tsx b/packages/app/src/agent-profiles/settings/agent-profiles-section.tsx index 06a62f1420..ca8917d43e 100644 --- a/packages/app/src/agent-profiles/settings/agent-profiles-section.tsx +++ b/packages/app/src/agent-profiles/settings/agent-profiles-section.tsx @@ -44,7 +44,6 @@ import { AgentProfileRow, ROSTER_COL_PROFILE_WIDTH, ROSTER_COL_RUNTIME_WIDTH, - ROSTER_GRIP_WIDTH, ROSTER_TRAILING_WIDTH, } from "./agent-profile-row"; @@ -90,7 +89,6 @@ function RosterTableHeader(): ReactElement { const { t } = useTranslation(); return ( - {t("settings.host.agentProfiles.columns.profile")} @@ -1030,16 +1028,11 @@ const styles = StyleSheet.create((theme) => ({ flexDirection: "row", alignItems: "center", paddingVertical: theme.spacing[2], - paddingLeft: theme.spacing[2], - paddingRight: theme.spacing[4], + paddingHorizontal: theme.spacing[4], gap: theme.spacing[2], borderBottomWidth: theme.borderWidth[1], borderBottomColor: theme.colors.border, }, - tableHeaderGripSpacer: { - width: ROSTER_GRIP_WIDTH, - flexShrink: 0, - }, tableHeaderColumns: { flex: 1, minWidth: 0, diff --git a/packages/app/src/components/draggable-list.native.tsx b/packages/app/src/components/draggable-list.native.tsx index c92b04ed32..110280b020 100644 --- a/packages/app/src/components/draggable-list.native.tsx +++ b/packages/app/src/components/draggable-list.native.tsx @@ -15,7 +15,7 @@ import DraggableFlatList, { } from "react-native-draggable-flatlist"; import type { GestureType } from "react-native-gesture-handler"; import { useUnistyles } from "react-native-unistyles"; -import { useContentDrag } from "@/components/ui/scroll-view"; +import { useContentDrag } from "@/components/ui/content-drag"; import { createDragHold } from "./drag-reorder/drag-hold"; import { movedItemKey } from "./drag-reorder/native-drop"; import type { diff --git a/packages/app/src/components/page-layout/index.tsx b/packages/app/src/components/page-layout/index.tsx index 3498e3e50c..34b8cea15a 100644 --- a/packages/app/src/components/page-layout/index.tsx +++ b/packages/app/src/components/page-layout/index.tsx @@ -8,10 +8,15 @@ import { StyleSheet, withUnistyles } from "react-native-unistyles"; import { BackHeader } from "@/components/headers/back-header"; import { MenuHeader } from "@/components/headers/menu-header"; import { PressHighlight } from "@/components/ui/press-highlight"; +import { withContentDrag } from "@/components/ui/content-drag"; import { useIsCompactFormFactor } from "@/constants/layout"; import { ICON_SIZE, SPACING, type Theme } from "@/styles/theme"; -const PageScrollView = Platform.OS === "android" ? KeyboardAwareScrollView : ScrollView; +// Rows on a page drag to reorder, so the page stops scrolling while a drag holds the touch. +const PageScrollView = + Platform.OS === "android" + ? withContentDrag(KeyboardAwareScrollView) + : withContentDrag(ScrollView); interface PageLayoutProps { title?: string; diff --git a/packages/app/src/components/settings/row-density.browser.test.tsx b/packages/app/src/components/settings/row-density.browser.test.tsx index cbe24e0a60..92d6113b93 100644 --- a/packages/app/src/components/settings/row-density.browser.test.tsx +++ b/packages/app/src/components/settings/row-density.browser.test.tsx @@ -66,12 +66,16 @@ function heightOf(testID: string): number { return element(testID).getBoundingClientRect().height; } -function titleFontSize(rowTestID: string, label: string): number { - const title = [...element(rowTestID).querySelectorAll("div")].find( - (node) => node.textContent === label && node.children.length === 0, +function textNode(rowTestID: string, text: string): HTMLElement { + const found = [...element(rowTestID).querySelectorAll("div")].find( + (node) => node.textContent === text && node.children.length === 0, ); - if (!title) throw new Error(`No title ${label}`); - return Number.parseFloat(getComputedStyle(title).fontSize); + if (!found) throw new Error(`No text ${text}`); + return found; +} + +function titleFontSize(rowTestID: string, label: string): number { + return Number.parseFloat(getComputedStyle(textNode(rowTestID, label)).fontSize); } describe("settings row density", () => { @@ -100,4 +104,52 @@ describe("settings row density", () => { titleFontSize("card-row", "Card row"), ); }); + + it("keeps a row with a long summary one line tall on a phone-width card", () => { + container = document.createElement("div"); + // A 393pt phone less the sheet's side padding. + container.style.width = "360px"; + document.body.appendChild(container); + root = createRoot(container); + act(() => + root?.render( + + + + + + , + ), + ); + + expect(heightOf("long-summary-toggle")).toBe(heightOf("text-row")); + }); + + it("keeps a short summary beside the chevron on a wide card", () => { + container = document.createElement("div"); + container.style.width = "680px"; + document.body.appendChild(container); + root = createRoot(container); + act(() => + root?.render( + + + , + ), + ); + + const row = element("short-summary").getBoundingClientRect(); + const summary = textNode("short-summary", "Local").getBoundingClientRect(); + // The summary's margin, the chevron and the row's padding: about 40px. + expect(row.right - summary.right).toBeLessThan(48); + }); }); diff --git a/packages/app/src/components/settings/row-header.tsx b/packages/app/src/components/settings/row-header.tsx index 617a309804..2927dad8ba 100644 --- a/packages/app/src/components/settings/row-header.tsx +++ b/packages/app/src/components/settings/row-header.tsx @@ -88,9 +88,13 @@ export function SettingsRowHeader({ const hovered = pointerOver && !disabled; const rowStyle = useMemo(() => [layout.row, hovered && styles.hovered], [hovered, layout]); const chevronStyle = useMemo( - () => [styles.chevron, expanded && styles.chevronExpanded], + () => [styles.chevron, expanded && styles.chevronExpanded, styles.passThrough], [expanded], ); + // A hint can be a sentence, so a hinted row gives the room to the label column and caps the + // summary. A label alone keeps its one-line width and the summary truncates in what is left. + const hinted = Boolean(hint || hintStatus); + const contentStyle = hinted ? settingsStyles.rowContent : styles.labelContent; return ( ) : null} - + {label} {labelAccessory} @@ -128,28 +132,15 @@ export function SettingsRowHeader({ {control} ) : null} - - {external ? ( - // Drawn the same as a section header's docs link, so the two read as one thing. - {summary} - ) : ( - <> - {summary ? ( - - {summary} - - ) : null} - {disabled ? null : ( - - - - )} - - )} - + + {external || disabled ? null : ( + + + + )} ); } @@ -160,6 +151,32 @@ const HIDDEN_FROM_ASSISTIVE_TECH = { "aria-hidden": true, } as const; +/** The summary before the chevron, or the external link label in its place. */ +function RowTrailing({ + hinted, + external, + hovered, + summary, +}: { + hinted: boolean; + external: boolean; + hovered: boolean; + summary: string | undefined; +}) { + const style = hinted ? styles.hintedTrailing : styles.labelTrailing; + return ( + + {/* Drawn the same as a section header's docs link, so the two read as one thing. */} + {external ? {summary} : null} + {!external && summary ? ( + + {summary} + + ) : null} + + ); +} + /** * The hint with its status mark. The line keeps the hint's own height in every status, so a row * does not move when its value arrives or its work starts. A long error is cut to the line; the @@ -222,10 +239,30 @@ const styles = StyleSheet.create((theme) => ({ passThrough: { pointerEvents: "none", }, - trailing: { + // The label keeps its one-line width and takes the free space; the summary truncates in what is + // left. Any shrink, even a fraction of a pixel, would wrap the label, so it does not shrink. The + // cap lets a long label wrap before it pushes the chevron off the row. Past the cap, the auto + // margin takes the rest of the row, so the control, summary and chevron stay together at the end. + labelContent: { + flexGrow: 1, + flexShrink: 0, + maxWidth: "75%", + paddingRight: theme.spacing[3], + marginRight: "auto", + }, + labelTrailing: { flexDirection: "row", alignItems: "center", flexShrink: 1, + minWidth: 0, + }, + // A hinted row's column grows from zero width, so an unbounded summary would squeeze it to + // nothing and wrap the label one glyph per line. The summary keeps at most half the row. + hintedTrailing: { + flexDirection: "row", + alignItems: "center", + flexShrink: 1, + maxWidth: "50%", }, hintLine: { flexDirection: "row", diff --git a/packages/app/src/components/ui/content-drag.browser.test.tsx b/packages/app/src/components/ui/content-drag.browser.test.tsx new file mode 100644 index 0000000000..18fccf1a70 --- /dev/null +++ b/packages/app/src/components/ui/content-drag.browser.test.tsx @@ -0,0 +1,106 @@ +import React, { act, Children, useCallback, type ReactNode } from "react"; +import { createRoot, type Root } from "react-dom/client"; +import { afterEach, describe, expect, it } from "vitest"; +import { useContentDrag, withContentDrag } from "./content-drag"; + +let root: Root | null = null; +let container: HTMLDivElement | null = null; + +afterEach(() => { + act(() => root?.unmount()); + container?.remove(); + root = null; + container = null; +}); + +interface FakeScrollProps { + scrollEnabled?: boolean; + children?: ReactNode; +} + +/** Stands in for a scroll view: it reports the props a native scroll view would act on. */ +function FakeScroll({ scrollEnabled, children }: FakeScrollProps) { + return ( +
+ {children} +
+ ); +} + +const DragHostScroll = withContentDrag(FakeScroll); + +/** A row that holds a drag the way a draggable list does: active from press until release. */ +function DragRow() { + const { setActive } = useContentDrag(); + const arm = useCallback(() => setActive(true), [setActive]); + const release = useCallback(() => setActive(false), [setActive]); + return ( + <> +