@plexui/react-native 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,57 @@
1
+ import { type ReactElement, type ReactNode } from "react";
2
+ import { type AccessibilityActionEvent, type StyleProp, type ViewStyle } from "react-native";
3
+ import { type MenuContentProps } from "../Menu/Menu";
4
+ /** A touch and hold opens the menu after half a second, as the web's ContextMenu (CONTEXT_MENU_LONG_PRESS). */
5
+ export declare const CONTEXT_MENU_LONG_PRESS = 500;
6
+ export type ContextMenuProps = {
7
+ children: ReactNode;
8
+ /** Holds the menu open or closed. */
9
+ open?: boolean;
10
+ onOpenChange?: (open: boolean) => void;
11
+ };
12
+ /**
13
+ * A menu of actions for an element, opened by a touch and hold (and a right click on the web): on iOS 27 the screen
14
+ * dims and blurs, the element stays clear over it as a lifted preview, and the glass menu stands 16 from it by the
15
+ * third of the screen it is in, over it when it stands in the lower half; on Android Material's popup under the
16
+ * element, the screen dimmed around it. Parts as @plexui/ui: `ContextMenu.Trigger`, `ContextMenu.Content`, and the
17
+ * items of Menu (`ContextMenu.Item`, `ContextMenu.Separator`, `ContextMenu.Label`).
18
+ */
19
+ declare function ContextMenuRoot({ children, open: openProp, onOpenChange }: ContextMenuProps): import("react").JSX.Element;
20
+ declare namespace ContextMenuRoot {
21
+ var displayName: string;
22
+ }
23
+ type Holdable = {
24
+ onLongPress?: (...args: unknown[]) => void;
25
+ onPress?: unknown;
26
+ accessibilityActions?: ReadonlyArray<{
27
+ name: string;
28
+ label?: string;
29
+ }>;
30
+ onAccessibilityAction?: (event: AccessibilityActionEvent) => void;
31
+ };
32
+ /**
33
+ * The element the menu is for: a ListItem, a Pressable, a Button, anything with `onLongPress`. Its own press still
34
+ * runs; a touch and hold opens the menu, and so does a right click on the web. The lifted preview on iOS is the
35
+ * element drawn again from its props, so state the element keeps inside itself is not in it.
36
+ */
37
+ declare function ContextMenuTrigger({ children, style }: {
38
+ children: ReactElement<Holdable>;
39
+ style?: StyleProp<ViewStyle>;
40
+ }): import("react").JSX.Element;
41
+ declare namespace ContextMenuTrigger {
42
+ var displayName: string;
43
+ }
44
+ export type ContextMenuContentProps = Omit<MenuContentProps, "align">;
45
+ /** The menu: Menu's items, 250 wide on iOS. */
46
+ declare function ContextMenuContent(props: ContextMenuContentProps): import("react").JSX.Element;
47
+ declare namespace ContextMenuContent {
48
+ var displayName: string;
49
+ }
50
+ export declare const ContextMenu: typeof ContextMenuRoot & {
51
+ Trigger: typeof ContextMenuTrigger;
52
+ Content: typeof ContextMenuContent;
53
+ Item: typeof import("../Menu/Menu").MenuItem;
54
+ Separator: typeof import("../Menu/Menu").MenuSeparator;
55
+ Label: typeof import("../Menu/Menu").MenuLabel;
56
+ };
57
+ export {};
@@ -101,6 +101,8 @@ export type ListItemProps = {
101
101
  /** The chevron of a row that opens a page. @default true when the row has `onPress`, no `trailing` and is not `destructive` */
102
102
  disclosure?: boolean;
103
103
  onPress?: () => void;
104
+ /** A touch and hold on the row (half a second): a ContextMenu around the row sets it. */
105
+ onLongPress?: () => void;
104
106
  disabled?: boolean;
105
107
  /** A row in red, as a destructive action row. */
106
108
  destructive?: boolean;
@@ -119,7 +121,7 @@ export type ListItemProps = {
119
121
  * in (a multi-select list); a 1px divider from the text's start to the card's end, none under a row with a tile (a
120
122
  * tiled row draws none).
121
123
  */
122
- export declare function ListItem({ label, description, leading, leadingColor, value, valuePlacement, trailing, error, checked: checkedProp, defaultChecked, onCheckedChange, disclosure, onPress, disabled, destructive, accessibilityLabel, testID, }: ListItemProps): import("react").JSX.Element;
124
+ export declare function ListItem({ label, description, leading, leadingColor, value, valuePlacement, trailing, error, checked: checkedProp, defaultChecked, onCheckedChange, disclosure, onPress, onLongPress, disabled, destructive, accessibilityLabel, testID, }: ListItemProps): import("react").JSX.Element;
123
125
  export type StackedRowProps = {
124
126
  /** The label over the value; none for a row whose placeholder names the field (`hideLabel`). */
125
127
  label?: ReactNode;
@@ -70,6 +70,7 @@ declare function MenuContent(props: MenuContentProps): import("react").JSX.Eleme
70
70
  declare namespace MenuContent {
71
71
  var displayName: string;
72
72
  }
73
+ export declare function hasCheckedItems(children: ReactNode): boolean;
73
74
  type SurfaceProps = MenuContentProps & {
74
75
  open: boolean;
75
76
  anchor: MenuAnchor | null;
@@ -83,6 +84,14 @@ type SurfaceProps = MenuContentProps & {
83
84
  row?: MenuRow | null;
84
85
  /** Opened from a bar's button: on Android the header menu, in the bar's glass. */
85
86
  header?: boolean;
87
+ /**
88
+ * A context menu's touch and hold (ContextMenu): on iOS the screen dims and blurs but the element, drawn again
89
+ * over the dimming as its lifted `preview`, and the menu stands 16 from it, by the third of the screen it is in.
90
+ */
91
+ context?: {
92
+ preview: ReactNode;
93
+ radius: number;
94
+ };
86
95
  };
87
96
  /** The floating panel of a menu, placed under its anchor (over it when the screen ends first). */
88
97
  export declare function MenuSurface(props: SurfaceProps): import("react").JSX.Element;
@@ -104,8 +113,8 @@ export type MenuItemProps = {
104
113
  onSelect?: () => void;
105
114
  testID?: string;
106
115
  };
107
- declare function MenuItem(props: MenuItemProps): import("react").JSX.Element;
108
- declare namespace MenuItem {
116
+ export declare function MenuItem(props: MenuItemProps): import("react").JSX.Element;
117
+ export declare namespace MenuItem {
109
118
  var displayName: string;
110
119
  }
111
120
  export type MenuSubContentProps = {
@@ -134,15 +143,15 @@ declare function MenuSubTrigger({ children, icon, disabled, testID }: MenuSubTri
134
143
  declare namespace MenuSubTrigger {
135
144
  var displayName: string;
136
145
  }
137
- declare function MenuSeparator(): import("react").JSX.Element;
138
- declare namespace MenuSeparator {
146
+ export declare function MenuSeparator(): import("react").JSX.Element;
147
+ export declare namespace MenuSeparator {
139
148
  var displayName: string;
140
149
  }
141
150
  /** A heading over a group of items. */
142
- declare function MenuLabel({ children }: {
151
+ export declare function MenuLabel({ children }: {
143
152
  children: ReactNode;
144
153
  }): import("react").JSX.Element;
145
- declare namespace MenuLabel {
154
+ export declare namespace MenuLabel {
146
155
  var displayName: string;
147
156
  }
148
157
  export declare const Menu: typeof MenuRoot & {
@@ -59,6 +59,19 @@ declare function ToolbarGroup({ children, style, ...rest }: ViewProps): import("
59
59
  declare namespace ToolbarGroup {
60
60
  var displayName: string;
61
61
  }
62
+ export type ToolbarLabelProps = ViewProps & {
63
+ /** The text: a step of a flow ("3 of 10"), a count, a status. Its digits keep one width as it changes. */
64
+ children: ReactNode;
65
+ };
66
+ /**
67
+ * A text in the bar that is not a button: a step of a flow, a count, a status. On iOS it stands in a capsule of the
68
+ * bar's glass as a button would, as SwiftUI draws a Text in a toolbar (iOS 27.2 ref-app tb-status: 48pt in a bottom bar,
69
+ * 15pt Semibold, 8pt from its ends); on Android it is the bar's plain text, 14sp Medium. Read as text, not a control.
70
+ */
71
+ declare function ToolbarLabel({ children, style, ...rest }: ToolbarLabelProps): import("react").JSX.Element;
72
+ declare namespace ToolbarLabel {
73
+ var displayName: string;
74
+ }
62
75
  export type ToolbarTitleProps = {
63
76
  /** The title's text. With `image` it may be left out. */
64
77
  children?: ReactNode;
@@ -100,5 +113,6 @@ export declare const Toolbar: typeof ToolbarRoot & {
100
113
  Group: typeof ToolbarGroup;
101
114
  Trailing: typeof ToolbarTrailing;
102
115
  Row: typeof ToolbarRow;
116
+ Label: typeof ToolbarLabel;
103
117
  };
104
118
  export {};
@@ -24,6 +24,7 @@ export { TagInput, type Tag, type TagInputProps } from "./components/TagInput/Ta
24
24
  export { OTPInput, type OTPInputProps } from "./components/OTPInput/OTPInput";
25
25
  export { Select, type SelectOption, type SelectProps } from "./components/Select/Select";
26
26
  export { Menu, type MenuContentProps, type MenuItemProps, type MenuProps } from "./components/Menu/Menu";
27
+ export { ContextMenu, type ContextMenuContentProps, type ContextMenuProps } from "./components/ContextMenu/ContextMenu";
27
28
  export { ActionSheet, type ActionSheetAction, type ActionSheetProps } from "./components/ActionSheet/ActionSheet";
28
29
  export { BottomSheet, type BottomSheetFooterProps, type BottomSheetProps } from "./components/BottomSheet/BottomSheet";
29
30
  export { Dialog, type DialogAction, type DialogProps } from "./components/Dialog/Dialog";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plexui/react-native",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Plex UI components for React Native and Expo: iOS 26 and Material 3, on the shared @plexui/styles tokens",
5
5
  "license": "MIT",
6
6
  "homepage": "https://plexui.com",
@@ -1,14 +1,26 @@
1
1
  import { Children, cloneElement, isValidElement, type ReactElement, type ReactNode } from "react"
2
2
  import { StyleSheet, View, type StyleProp, type ViewStyle } from "react-native"
3
3
  import { useSafeAreaInsets } from "react-native-safe-area-context"
4
+ import { ANDROID_FADE_ALPHA, ANDROID_FADE_STOPS, SoftBottomEdge } from "../../internal/BarBackdrop"
5
+ import { withAlpha } from "../../theme/material"
4
6
  import { useTheme } from "../../theme/ThemeProvider"
5
7
  import { Button, type ButtonProps } from "../Button/Button"
6
8
 
7
9
  export type BottomActionsProps = {
8
- /** The screen's main action, a Button, and an optional second Button under it (a ghost "Not now"). */
10
+ /**
11
+ * The screen's main action, a Button, and an optional second Button under it ("Not now", "Skip"). A second Button
12
+ * with no `variant` of its own takes the platform's: on iOS 26 a glass capsule of the same size, as Apple's
13
+ * step-by-step sheets set "Skip"; on Android a ghost button.
14
+ */
9
15
  children: ReactNode
10
- /** Puts the actions over the content (a scroll view under them); off, they take their room at the end of the screen. @default false */
16
+ /**
17
+ * Puts the actions over the content (a scroll view under them), over a soft edge as a bottom Toolbar draws: on iOS
18
+ * the screen's color fading in over 27pt above the actions, over a light blur; on Android the screen's color fading
19
+ * in. Off, they take their room at the end of the screen. @default false
20
+ */
11
21
  floating?: boolean
22
+ /** The color the floating edge fades into: the screen's (a grouped screen's gray). @default the theme's background */
23
+ canvasColor?: string
12
24
  testID?: string
13
25
  style?: StyleProp<ViewStyle>
14
26
  }
@@ -20,7 +32,7 @@ export type BottomActionsProps = {
20
32
  * action stands under it, 8 apart. Android: the Plex Android look's 48dp full-width button, 16dp from the sides and
21
33
  * 16 above the gesture bar. Each Button inside is a block of the size `3xl` unless it sets its own.
22
34
  */
23
- export function BottomActions({ children, floating = false, testID, style }: BottomActionsProps) {
35
+ export function BottomActions({ children, floating = false, canvasColor, testID, style }: BottomActionsProps) {
24
36
  const theme = useTheme()
25
37
  const insets = useSafeAreaInsets()
26
38
  const android = theme.isAndroid
@@ -28,27 +40,44 @@ export function BottomActions({ children, floating = false, testID, style }: Bot
28
40
  // iOS: 2pt over the safe area (34 on a Face ID iPhone); a phone with a home button has none, so 16 there
29
41
  const bottom = android ? Math.max(insets.bottom, 0) + 16 : insets.bottom > 0 ? insets.bottom + 2 : 16
30
42
  const height = android ? 48 : 52
31
- const actions = Children.toArray(children).map((child) =>
32
- isValidElement(child) && child.type === Button
33
- ? cloneElement(child as ReactElement<ButtonProps>, {
34
- block: (child.props as ButtonProps).block ?? true,
35
- size: (child.props as ButtonProps).size ?? "3xl",
36
- style: [{ minHeight: height, borderRadius: height / 2 }, (child.props as ButtonProps).style],
37
- })
38
- : child,
39
- )
43
+ const canvas = canvasColor ?? theme.colors.background
44
+ const paddingTop = 8
45
+ const actions = Children.toArray(children).map((child, index) => {
46
+ if (!isValidElement(child) || child.type !== Button) return child
47
+ const props = child.props as ButtonProps
48
+ // The second action: iOS 26's glass capsule of the main one's size, Android's ghost button
49
+ const second =
50
+ index > 0 && props.variant === undefined
51
+ ? android
52
+ ? { variant: "ghost" as const, color: props.color ?? ("secondary" as const) }
53
+ : { variant: "soft" as const, color: props.color ?? ("secondary" as const), mobileMaterial: props.mobileMaterial ?? ("glass" as const) }
54
+ : null
55
+ return cloneElement(child as ReactElement<ButtonProps>, {
56
+ ...second,
57
+ block: props.block ?? true,
58
+ size: props.size ?? "3xl",
59
+ style: [{ minHeight: height, borderRadius: height / 2 }, props.style],
60
+ })
61
+ })
40
62
  return (
41
63
  <View
42
64
  testID={testID}
43
65
  pointerEvents="box-none"
44
- style={[styles.bar, { paddingHorizontal: side, paddingBottom: bottom, gap: 8 }, floating ? styles.floating : null, style]}
66
+ style={[styles.bar, { paddingHorizontal: side, paddingTop, paddingBottom: bottom, gap: 8 }, floating ? styles.floating : null, style]}
45
67
  >
68
+ {floating ? (
69
+ android ? (
70
+ <SoftBottomEdge fill={withAlpha(canvas, ANDROID_FADE_ALPHA)} top={paddingTop - 13 + 60} tail={60} blur={0} stops={ANDROID_FADE_STOPS} />
71
+ ) : (
72
+ <SoftBottomEdge fill={canvas} top={paddingTop} tail={27} blur={theme.length("--toolbar-edge-blur-small", 3)} />
73
+ )
74
+ ) : null}
46
75
  {actions}
47
76
  </View>
48
77
  )
49
78
  }
50
79
 
51
80
  const styles = StyleSheet.create({
52
- bar: { alignSelf: "stretch", paddingTop: 8 },
81
+ bar: { alignSelf: "stretch" },
53
82
  floating: { position: "absolute", left: 0, right: 0, bottom: 0 },
54
83
  })
@@ -0,0 +1,164 @@
1
+ import { cloneElement, createContext, isValidElement, useCallback, useContext, useEffect, useRef, useState, type ReactElement, type ReactNode } from "react"
2
+ import { Dimensions, Platform, View, type AccessibilityActionEvent, type StyleProp, type ViewStyle } from "react-native"
3
+ import { useTheme } from "../../theme/ThemeProvider"
4
+ import { Menu, MenuSurface, hasCheckedItems, measure, type MenuAnchor, type MenuContentProps, type Measurable } from "../Menu/Menu"
5
+
6
+ /** A touch and hold opens the menu after half a second, as the web's ContextMenu (CONTEXT_MENU_LONG_PRESS). */
7
+ export const CONTEXT_MENU_LONG_PRESS = 500
8
+
9
+ type ContextMenuState = {
10
+ open: boolean
11
+ setOpen: (next: boolean) => void
12
+ anchor: MenuAnchor | null
13
+ preview: ReactNode
14
+ setTarget: (node: Measurable | null, preview: ReactNode) => void
15
+ }
16
+
17
+ const ContextMenuContext = createContext<ContextMenuState | null>(null)
18
+
19
+ function useContextMenu(part: string) {
20
+ const context = useContext(ContextMenuContext)
21
+ if (!context) throw new Error(`${part} must be inside a ContextMenu`)
22
+ return context
23
+ }
24
+
25
+ export type ContextMenuProps = {
26
+ children: ReactNode
27
+ /** Holds the menu open or closed. */
28
+ open?: boolean
29
+ onOpenChange?: (open: boolean) => void
30
+ }
31
+
32
+ /**
33
+ * A menu of actions for an element, opened by a touch and hold (and a right click on the web): on iOS 27 the screen
34
+ * dims and blurs, the element stays clear over it as a lifted preview, and the glass menu stands 16 from it by the
35
+ * third of the screen it is in, over it when it stands in the lower half; on Android Material's popup under the
36
+ * element, the screen dimmed around it. Parts as @plexui/ui: `ContextMenu.Trigger`, `ContextMenu.Content`, and the
37
+ * items of Menu (`ContextMenu.Item`, `ContextMenu.Separator`, `ContextMenu.Label`).
38
+ */
39
+ function ContextMenuRoot({ children, open: openProp, onOpenChange }: ContextMenuProps) {
40
+ const [own, setOwn] = useState(false)
41
+ const open = openProp ?? own
42
+ const [anchor, setAnchor] = useState<MenuAnchor | null>(null)
43
+ const target = useRef<{ node: Measurable | null; preview: ReactNode }>({ node: null, preview: null })
44
+ const [preview, setPreview] = useState<ReactNode>(null)
45
+ const apply = useCallback(
46
+ (next: boolean) => {
47
+ if (openProp === undefined) setOwn(next)
48
+ onOpenChange?.(next)
49
+ },
50
+ [openProp, onOpenChange],
51
+ )
52
+ const setOpen = apply
53
+ const applyRef = useRef(apply)
54
+ applyRef.current = apply
55
+ // The element is measured as the menu opens, by a touch and hold or by `open`: the menu and its preview stand where
56
+ // it is. Until then nothing is drawn
57
+ useEffect(() => {
58
+ if (!open) {
59
+ setAnchor(null)
60
+ return
61
+ }
62
+ let live = true
63
+ measure(target.current.node, (box) => {
64
+ if (!live) return
65
+ setAnchor(box)
66
+ setPreview(target.current.preview)
67
+ })
68
+ // A turn of the screen moves the element: the menu closes, as iOS dismisses a context menu on rotation
69
+ const sub = Dimensions.addEventListener("change", () => applyRef.current(false))
70
+ return () => {
71
+ live = false
72
+ sub.remove()
73
+ }
74
+ }, [open])
75
+ const setTarget = useCallback((node: Measurable | null, next: ReactNode) => {
76
+ target.current = { node, preview: next }
77
+ }, [])
78
+ return <ContextMenuContext.Provider value={{ open, setOpen, anchor, preview, setTarget }}>{children}</ContextMenuContext.Provider>
79
+ }
80
+ ContextMenuRoot.displayName = "ContextMenu"
81
+
82
+ type Holdable = {
83
+ onLongPress?: (...args: unknown[]) => void
84
+ onPress?: unknown
85
+ accessibilityActions?: ReadonlyArray<{ name: string; label?: string }>
86
+ onAccessibilityAction?: (event: AccessibilityActionEvent) => void
87
+ }
88
+
89
+ /**
90
+ * The element the menu is for: a ListItem, a Pressable, a Button, anything with `onLongPress`. Its own press still
91
+ * runs; a touch and hold opens the menu, and so does a right click on the web. The lifted preview on iOS is the
92
+ * element drawn again from its props, so state the element keeps inside itself is not in it.
93
+ */
94
+ function ContextMenuTrigger({ children, style }: { children: ReactElement<Holdable>; style?: StyleProp<ViewStyle> }) {
95
+ const theme = useTheme()
96
+ const { setOpen, setTarget, open, anchor } = useContextMenu("ContextMenu.Trigger")
97
+ const child = isValidElement<Holdable>(children) ? children : null
98
+ const own = child?.props
99
+ // The element's own long press gets its event, then the menu opens
100
+ const hold = (...args: unknown[]) => {
101
+ own?.onLongPress?.(...args)
102
+ setOpen(true)
103
+ }
104
+ // VoiceOver and TalkBack open it through the element's long-press action (ListItem names it itself)
105
+ const actions = own?.accessibilityActions ?? []
106
+ const a11y = actions.some((action) => action.name === "longpress")
107
+ ? null
108
+ : {
109
+ accessibilityActions: [...actions, { name: "longpress" }],
110
+ onAccessibilityAction: (event: AccessibilityActionEvent) => {
111
+ if (event.nativeEvent.actionName === "longpress") hold()
112
+ else own?.onAccessibilityAction?.(event)
113
+ },
114
+ }
115
+ // The preview is the element drawn again over the dimming, taking no presses
116
+ const preview = child ? cloneElement(child, { onLongPress: undefined, onPress: undefined }) : null
117
+ const web = Platform.OS === "web"
118
+ return (
119
+ <View
120
+ ref={(next: unknown) => setTarget(next as Measurable | null, preview)}
121
+ collapsable={false}
122
+ // On iOS the element hides under its lifted preview while the menu is open, so it is not drawn twice; Android
123
+ // keeps it lit in its place
124
+ style={[{ opacity: open && anchor && !theme.isAndroid ? 0 : 1 }, style]}
125
+ {...(web
126
+ ? {
127
+ onContextMenu: (event: { preventDefault: () => void }) => {
128
+ event.preventDefault()
129
+ setOpen(true)
130
+ },
131
+ }
132
+ : null)}
133
+ >
134
+ {child ? cloneElement(child, { onLongPress: hold, ...a11y }) : children}
135
+ </View>
136
+ )
137
+ }
138
+ ContextMenuTrigger.displayName = "ContextMenu.Trigger"
139
+
140
+ export type ContextMenuContentProps = Omit<MenuContentProps, "align">
141
+
142
+ /** The menu: Menu's items, 250 wide on iOS. */
143
+ function ContextMenuContent(props: ContextMenuContentProps) {
144
+ const theme = useTheme()
145
+ const { open, setOpen, anchor, preview } = useContextMenu("ContextMenu.Content")
146
+ // The preview keeps a row's corners to half its height, else the kit's 30 (--context-menu-preview-radius)
147
+ // Items that say `checked` make a set of options, with the checkmark's column, as in Menu
148
+ const check = hasCheckedItems(props.children)
149
+ const radius = Math.min(theme.length("--context-menu-preview-radius", 30), (anchor?.height ?? 60) / 2)
150
+ if (theme.isAndroid) {
151
+ // Android: Material's popup under the element at its end, the screen dimmed around it
152
+ return <MenuSurface {...props} check={check} open={open && anchor != null} anchor={anchor} row={anchor ? { box: anchor, radius: { top: 0, bottom: 0 } } : null} cover={false} onClose={() => setOpen(false)} />
153
+ }
154
+ return <MenuSurface {...props} check={check} open={open && anchor != null} anchor={anchor} context={{ preview, radius }} onClose={() => setOpen(false)} />
155
+ }
156
+ ContextMenuContent.displayName = "ContextMenu.Content"
157
+
158
+ export const ContextMenu = Object.assign(ContextMenuRoot, {
159
+ Trigger: ContextMenuTrigger,
160
+ Content: ContextMenuContent,
161
+ Item: Menu.Item,
162
+ Separator: Menu.Separator,
163
+ Label: Menu.Label,
164
+ })
@@ -251,21 +251,51 @@ type AndroidPanelProps = Omit<PanelProps, "title"> & {
251
251
  list?: ReactNode
252
252
  }
253
253
 
254
+ /** An iOS alert action's label inset from its capsule's ends. */
255
+ const IOS_ACTION_INSET = 16
256
+
254
257
  function IOSAlert({ theme, title, description, actions, run, ids, layout, children }: PanelProps & { layout?: "inline" | "stacked" }) {
255
258
  const { width: screen } = useWindowDimensions()
256
259
  const width = Math.min(theme.length("--dialog-alert-width", 320), screen - 32)
257
260
  const radius = theme.length("--dialog-alert-radius", 34)
258
- const inline = layout === "inline" || (layout !== "stacked" && actions.length <= 2)
261
+ const padding = theme.length("--dialog-alert-padding", 16)
262
+ const gap = theme.length("--dialog-alert-action-gap", 8)
263
+ // Two actions stand side by side while each label fits its half on one line; iOS never wraps an alert button's
264
+ // label, so a longer one stacks them at the full width (UIAlertController). Each label is measured on one line
265
+ const [labels, setLabels] = useState<number[]>([])
266
+ const half = (width - padding * 2 - gap) / 2 - IOS_ACTION_INSET * 2
267
+ const fits = actions.every((_, index) => labels[index] == null || labels[index] <= half + 0.5)
268
+ const inline = layout === "inline" || (layout !== "stacked" && actions.length <= 2 && fits)
259
269
  // The cancel action stands first of two side by side, as UIAlertController; a stack keeps the order written, as the
260
270
  // web's alert footer does. Each keeps its place in `actions` as its key, since two actions may share a label
261
271
  const indexed = actions.map((action, index) => ({ action, index }))
262
272
  const cancel = indexed.filter(({ action }) => action.variant === "cancel")
263
273
  const others = indexed.filter(({ action }) => action.variant !== "cancel")
264
- const ordered = inline ? [...cancel, ...others] : indexed
265
- const gap = theme.length("--dialog-alert-action-gap", 8)
274
+ // Two stacked because their labels do not fit: Cancel last, at the bottom, as UIAlertController stacks them
275
+ const autoStacked = !inline && layout == null && actions.length === 2
276
+ const ordered = inline ? [...cancel, ...others] : autoStacked ? [...others, ...cancel] : indexed
266
277
  const type = { fontSize: theme.length("--dialog-mobile-type-size", 17), lineHeight: theme.length("--dialog-mobile-type-leading", 22) }
267
278
  return (
268
- <Glass radius={radius} elevation="raised" fillToken="--dialog-alert-background" style={{ width, flexShrink: 1, padding: theme.length("--dialog-alert-padding", 16), gap: 10 }}>
279
+ <Glass radius={radius} elevation="raised" fillToken="--dialog-alert-background" style={{ width, flexShrink: 1, padding, gap: 10 }}>
280
+ {layout == null && actions.length === 2 ? (
281
+ // The labels on one line, unseen, to tell whether two fit side by side
282
+ <View pointerEvents="none" aria-hidden style={styles.measure}>
283
+ {actions.map((action, index) => (
284
+ <Text
285
+ key={index}
286
+ weight={action.preferred ? "semibold" : "medium"}
287
+ numberOfLines={1}
288
+ style={type}
289
+ onLayout={(event) => {
290
+ const next = event.nativeEvent.layout.width
291
+ setLabels((current) => (current[index] === next ? current : Object.assign([...current], { [index]: next })))
292
+ }}
293
+ >
294
+ {action.label}
295
+ </Text>
296
+ ))}
297
+ </View>
298
+ ) : null}
269
299
  <ScrollView style={styles.scroll} contentContainerStyle={{ gap: 10 }} bounces={false}>
270
300
  {/* The text 31 from the sides: 16 of padding and 15 of the header's own */}
271
301
  <View style={{ paddingTop: 5, paddingHorizontal: 15, paddingBottom: 5.5, gap: 5.67 }}>
@@ -298,12 +328,11 @@ function IOSAlert({ theme, title, description, actions, run, ids, layout, childr
298
328
  }
299
329
 
300
330
  function IOSAction({ theme, action, run, type, grow }: { theme: Theme; action: DialogAction; run: (action: DialogAction) => void; type: { fontSize: number; lineHeight: number }; grow: boolean }) {
301
- // The preferred action is the accent with a white label, its sheen and edge, as a bar's prominent button
302
- // (Dialog.module.css: an alert's solid footer action takes the --toolbar-prominent tokens); disabled, the phone's
303
- // disabled fill (Button.module.css). A destructive one keeps the alert's fill and its red label
331
+ // The preferred action is the accent with a white label, one flat color with no sheen and no edge, as native draws
332
+ // a preferredAction (iOS 27.2: 0082f7 on every row); disabled, the phone's disabled fill (Button.module.css). A
333
+ // destructive one keeps the alert's fill and its red label
304
334
  const accent = action.preferred && action.variant !== "destructive"
305
335
  const height = theme.length("--dialog-alert-action-height", 48)
306
- const [measured, setMeasured] = useState(height)
307
336
  const fill = accent
308
337
  ? action.disabled
309
338
  ? theme.color("--button-mobile-disabled-background", theme.color("--color-background-disabled"))
@@ -317,15 +346,12 @@ function IOSAction({ theme, action, run, type, grow }: { theme: Theme; action: D
317
346
  ? theme.color("--toolbar-prominent-color")
318
347
  : theme.colors.text
319
348
  const lit = accent && !action.disabled
320
- const shadow = lit ? theme.token("--toolbar-prominent-shadow") : undefined
321
- const sheen = lit ? sheenOf(theme, measured) : undefined
322
349
  return (
323
350
  <Pressable
324
351
  accessibilityRole="button"
325
352
  accessibilityState={{ disabled: !!action.disabled }}
326
353
  disabled={action.disabled}
327
354
  onPress={() => run(action)}
328
- onLayout={lit ? (event) => setMeasured(event.nativeEvent.layout.height) : undefined}
329
355
  testID={action.testID}
330
356
  style={({ pressed }) => [
331
357
  styles.iosAction,
@@ -334,12 +360,10 @@ function IOSAction({ theme, action, run, type, grow }: { theme: Theme; action: D
334
360
  borderRadius: height / 2,
335
361
  backgroundColor: lit && pressed ? theme.color("--toolbar-prominent-background-active") : fill,
336
362
  opacity: pressed && !lit ? 0.7 : 1,
337
- boxShadow: typeof shadow === "string" ? shadow : undefined,
338
363
  },
339
364
  grow ? styles.grow : null,
340
365
  ]}
341
366
  >
342
- {sheen ? <View pointerEvents="none" style={[StyleSheet.absoluteFill, { borderRadius: height / 2, backgroundImage: sheen }]} /> : null}
343
367
  <Text color={text} weight={action.preferred ? "semibold" : "medium"} style={[type, styles.centered]}>
344
368
  {action.label}
345
369
  </Text>
@@ -347,16 +371,6 @@ function IOSAction({ theme, action, run, type, grow }: { theme: Theme; action: D
347
371
  )
348
372
  }
349
373
 
350
- /**
351
- * `--toolbar-prominent-sheen`, lighter along the top and the bottom edge, for a face of a known height: its
352
- * `calc(100% - 8px)` stop in pixels, since React Native's gradients take no calc().
353
- */
354
- function sheenOf(theme: Theme, height: number) {
355
- const value = theme.token("--toolbar-prominent-sheen")
356
- if (typeof value !== "string" || !value.includes("gradient")) return undefined
357
- return value.replace(/calc\(\s*100%\s*-\s*([\d.]+)px\s*\)/g, (_, px: string) => `${Math.max(0, height - Number(px))}px`)
358
- }
359
-
360
374
  function AndroidDialog({ theme, title, description, actions, run, ids, children, list }: AndroidPanelProps) {
361
375
  const m = theme.material
362
376
  const { width: screen } = useWindowDimensions()
@@ -469,7 +483,8 @@ const styles = StyleSheet.create({
469
483
  row: { flexDirection: "row" },
470
484
  grow: { flex: 1, flexBasis: 0 },
471
485
  centered: { textAlign: "center" },
472
- iosAction: { alignItems: "center", justifyContent: "center", paddingVertical: 13, paddingHorizontal: 16, borderCurve: "continuous" },
486
+ iosAction: { alignItems: "center", justifyContent: "center", paddingVertical: 13, paddingHorizontal: IOS_ACTION_INSET, borderCurve: "continuous" },
487
+ measure: { position: "absolute", top: 0, left: 0, width: 2000, alignItems: "flex-start", opacity: 0 },
473
488
  // Android's alert: 21dp corners (the catalog's); the text 24 in. Measured on the reference's alerts: the title's
474
489
  // baseline 40 under the top, the message's first 33 under it in lines 18.75 apart (16sp Roboto's), its last 59
475
490
  // over the buttons' (Roboto's font padding sets these 2 to 3 lower than the layout's 19, 10 and 20 would)
@@ -578,6 +578,9 @@ export function InputField({
578
578
  const required = ownRequired ?? floatLabel?.required
579
579
  const shift = ownShift ?? floatLabel?.shift
580
580
  const [focused, setFocused] = useState(false)
581
+ // A Tab to the iOS clear button blurs the field on the web: the button stays while it has focus (a press keeps the
582
+ // field's focus, below)
583
+ const [clearing, setClearing] = useState(false)
581
584
  const [own, setOwn] = useState(defaultValue ?? "")
582
585
  const text = value ?? own
583
586
  const filled = text.length > 0
@@ -662,7 +665,14 @@ export function InputField({
662
665
  // Android's label is in the hint color at rest and in the accent while the field has focus, springing between them
663
666
  const labelColor = invalid ? dangerText(theme) : focused ? focusAccent(theme) : look.placeholder
664
667
  const labelTint = useSpringColor(labelColor, FIELD_SPRING.stiffness, !floating || theme.reducedMotion)
665
- const showClear = !!onClear && filled && !disabled && !readOnly
668
+ // iOS shows a form field's clear button while it is edited (UITextField's whileEditing), a search field's while it
669
+ // has text; Android while the field has text
670
+ const searchField = rest.inputMode === "search" || barField != null
671
+ // A value at a row's end has no clear button on iOS, as Settings' and Contacts' rows: only a value that starts its
672
+ // column or stands on its own line under the label takes one
673
+ const valueRight = !startAligned && (inRow || (fillsRow && valueAtEnd))
674
+ const showClear =
675
+ !!onClear && filled && !disabled && !readOnly && (theme.isAndroid || ((focused || clearing || searchField) && !valueRight))
666
676
  // Android's search fields keep their clear button in place and show it with the text
667
677
  const androidClear = (search || barSearch) && !!onClear && !disabled && !readOnly
668
678
  // A 24dp icon stands 12 in, the text 12 past it (48 in); otherwise the text is 14 in (the outlined field), 21 in a
@@ -704,7 +714,11 @@ export function InputField({
704
714
  // round end (Input.module.css), or keeps its box beside an end adornment
705
715
  const clearMargin: ViewStyle = theme.isAndroid
706
716
  ? { marginHorizontal: -(look.clearTarget - look.clearSize) / 2 }
707
- : { marginEnd: endAdornment ? theme.length("--input-clear-target-offset", 0) : look.height / 2 - look.clearTarget / 2 - look.gutter }
717
+ : bare
718
+ ? // In a List row the target reaches over and under the row's line, so the row keeps its height, and its circle
719
+ // ends at the row's end inset, as a form row's clear button
720
+ { marginVertical: -(look.clearTarget - look.text.lineHeight) / 2, marginEnd: -(look.clearTarget - look.clearSize) / 2 }
721
+ : { marginEnd: endAdornment ? theme.length("--input-clear-target-offset", 0) : look.height / 2 - look.clearTarget / 2 - look.gutter }
708
722
  // An adornment stands in a View of its own, centered on the field: a Button in it keeps its own `alignSelf`
709
723
  // ("flex-start", for a column) to that View, not to the field's row, where it would rise to the top of a field taller
710
724
  // than itself (an IconButton's 40dp in a 50dp field)
@@ -824,7 +838,7 @@ export function InputField({
824
838
  theme.font("regular"),
825
839
  // A label floated inside the field (8 to 24) sets the text under it
826
840
  { paddingTop: padding.top, paddingBottom: padding.bottom },
827
- (inRow && !startAligned) || (fillsRow && valueAtEnd && !startAligned) ? { textAlign: Platform.OS === "web" && rtl ? "left" : "right" } : null,
841
+ valueRight ? { textAlign: Platform.OS === "web" && rtl ? "left" : "right" } : null,
828
842
  // A value in a row that the person cannot edit is the secondary label, as the web's phone rows (iOS's
829
843
  // values of a row that only informs)
830
844
  fillsRow && readOnly && !disabled ? { color: theme.colors.labelSecondary } : null,
@@ -852,7 +866,13 @@ export function InputField({
852
866
  <Pressable
853
867
  accessibilityRole="button"
854
868
  accessibilityLabel="Clear"
869
+ onFocus={() => setClearing(true)}
870
+ onBlur={() => setClearing(false)}
871
+ // On the web a press would blur the field before it lands and take the button away: the field keeps focus
872
+ {...(Platform.OS === "web" ? ({ onMouseDown: (event: { preventDefault: () => void }) => event.preventDefault() } as object) : null)}
855
873
  onPress={() => {
874
+ // As UIKit's clear button, the field keeps editing; first, so a caller's onClear may still move the focus
875
+ if (!theme.isAndroid && !searchField) input.current?.focus()
856
876
  if (value === undefined) setOwn("")
857
877
  onChangeText?.("")
858
878
  onClear()