@plexui/react-native 0.2.2 → 0.2.3
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.
- package/dist/es/components/BottomActions/BottomActions.js +25 -11
- package/dist/es/components/Dialog/Dialog.js +26 -24
- package/dist/es/components/Input/Input.js +20 -4
- package/dist/es/components/Toolbar/Toolbar.js +22 -0
- package/dist/types/components/BottomActions/BottomActions.d.ts +13 -3
- package/dist/types/components/Toolbar/Toolbar.d.ts +14 -0
- package/package.json +1 -1
- package/src/components/BottomActions/BottomActions.tsx +43 -14
- package/src/components/Dialog/Dialog.tsx +39 -24
- package/src/components/Input/Input.tsx +23 -3
- package/src/components/Toolbar/Toolbar.tsx +50 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Children, cloneElement, isValidElement } from "react";
|
|
3
3
|
import { StyleSheet, View } from "react-native";
|
|
4
4
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
5
|
+
import { ANDROID_FADE_ALPHA, ANDROID_FADE_STOPS, SoftBottomEdge } from "../../internal/BarBackdrop";
|
|
6
|
+
import { withAlpha } from "../../theme/material";
|
|
5
7
|
import { useTheme } from "../../theme/ThemeProvider";
|
|
6
8
|
import { Button } from "../Button/Button";
|
|
7
9
|
/**
|
|
@@ -11,7 +13,7 @@ import { Button } from "../Button/Button";
|
|
|
11
13
|
* action stands under it, 8 apart. Android: the Plex Android look's 48dp full-width button, 16dp from the sides and
|
|
12
14
|
* 16 above the gesture bar. Each Button inside is a block of the size `3xl` unless it sets its own.
|
|
13
15
|
*/
|
|
14
|
-
export function BottomActions({ children, floating = false, testID, style }) {
|
|
16
|
+
export function BottomActions({ children, floating = false, canvasColor, testID, style }) {
|
|
15
17
|
const theme = useTheme();
|
|
16
18
|
const insets = useSafeAreaInsets();
|
|
17
19
|
const android = theme.isAndroid;
|
|
@@ -19,16 +21,28 @@ export function BottomActions({ children, floating = false, testID, style }) {
|
|
|
19
21
|
// iOS: 2pt over the safe area (34 on a Face ID iPhone); a phone with a home button has none, so 16 there
|
|
20
22
|
const bottom = android ? Math.max(insets.bottom, 0) + 16 : insets.bottom > 0 ? insets.bottom + 2 : 16;
|
|
21
23
|
const height = android ? 48 : 52;
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
:
|
|
29
|
-
|
|
24
|
+
const canvas = canvasColor ?? theme.colors.background;
|
|
25
|
+
const paddingTop = 8;
|
|
26
|
+
const actions = Children.toArray(children).map((child, index) => {
|
|
27
|
+
if (!isValidElement(child) || child.type !== Button)
|
|
28
|
+
return child;
|
|
29
|
+
const props = child.props;
|
|
30
|
+
// The second action: iOS 26's glass capsule of the main one's size, Android's ghost button
|
|
31
|
+
const second = index > 0 && props.variant === undefined
|
|
32
|
+
? android
|
|
33
|
+
? { variant: "ghost", color: props.color ?? "secondary" }
|
|
34
|
+
: { variant: "soft", color: props.color ?? "secondary", mobileMaterial: props.mobileMaterial ?? "glass" }
|
|
35
|
+
: null;
|
|
36
|
+
return cloneElement(child, {
|
|
37
|
+
...second,
|
|
38
|
+
block: props.block ?? true,
|
|
39
|
+
size: props.size ?? "3xl",
|
|
40
|
+
style: [{ minHeight: height, borderRadius: height / 2 }, props.style],
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
return (_jsxs(View, { testID: testID, pointerEvents: "box-none", style: [styles.bar, { paddingHorizontal: side, paddingTop, paddingBottom: bottom, gap: 8 }, floating ? styles.floating : null, style], children: [floating ? (android ? (_jsx(SoftBottomEdge, { fill: withAlpha(canvas, ANDROID_FADE_ALPHA), top: paddingTop - 13 + 60, tail: 60, blur: 0, stops: ANDROID_FADE_STOPS })) : (_jsx(SoftBottomEdge, { fill: canvas, top: paddingTop, tail: 27, blur: theme.length("--toolbar-edge-blur-small", 3) }))) : null, actions] }));
|
|
30
44
|
}
|
|
31
45
|
const styles = StyleSheet.create({
|
|
32
|
-
bar: { alignSelf: "stretch"
|
|
46
|
+
bar: { alignSelf: "stretch" },
|
|
33
47
|
floating: { position: "absolute", left: 0, right: 0, bottom: 0 },
|
|
34
48
|
});
|
|
@@ -107,31 +107,45 @@ export function ChoiceDialog({ open, onClose, title, cancelLabel, okLabel, onOk,
|
|
|
107
107
|
]
|
|
108
108
|
: [{ label: cancelLabel, testID: testID ? `${testID}-cancel` : undefined }], run: run, ids: ids, list: _jsx(View, { ...listProps, children: children }) }) }));
|
|
109
109
|
}
|
|
110
|
+
/** An iOS alert action's label inset from its capsule's ends. */
|
|
111
|
+
const IOS_ACTION_INSET = 16;
|
|
110
112
|
function IOSAlert({ theme, title, description, actions, run, ids, layout, children }) {
|
|
111
113
|
const { width: screen } = useWindowDimensions();
|
|
112
114
|
const width = Math.min(theme.length("--dialog-alert-width", 320), screen - 32);
|
|
113
115
|
const radius = theme.length("--dialog-alert-radius", 34);
|
|
114
|
-
const
|
|
116
|
+
const padding = theme.length("--dialog-alert-padding", 16);
|
|
117
|
+
const gap = theme.length("--dialog-alert-action-gap", 8);
|
|
118
|
+
// Two actions stand side by side while each label fits its half on one line; iOS never wraps an alert button's
|
|
119
|
+
// label, so a longer one stacks them at the full width (UIAlertController). Each label is measured on one line
|
|
120
|
+
const [labels, setLabels] = useState([]);
|
|
121
|
+
const half = (width - padding * 2 - gap) / 2 - IOS_ACTION_INSET * 2;
|
|
122
|
+
const fits = actions.every((_, index) => labels[index] == null || labels[index] <= half + 0.5);
|
|
123
|
+
const inline = layout === "inline" || (layout !== "stacked" && actions.length <= 2 && fits);
|
|
115
124
|
// The cancel action stands first of two side by side, as UIAlertController; a stack keeps the order written, as the
|
|
116
125
|
// web's alert footer does. Each keeps its place in `actions` as its key, since two actions may share a label
|
|
117
126
|
const indexed = actions.map((action, index) => ({ action, index }));
|
|
118
127
|
const cancel = indexed.filter(({ action }) => action.variant === "cancel");
|
|
119
128
|
const others = indexed.filter(({ action }) => action.variant !== "cancel");
|
|
120
|
-
|
|
121
|
-
const
|
|
129
|
+
// Two stacked because their labels do not fit: Cancel last, at the bottom, as UIAlertController stacks them
|
|
130
|
+
const autoStacked = !inline && layout == null && actions.length === 2;
|
|
131
|
+
const ordered = inline ? [...cancel, ...others] : autoStacked ? [...others, ...cancel] : indexed;
|
|
122
132
|
const type = { fontSize: theme.length("--dialog-mobile-type-size", 17), lineHeight: theme.length("--dialog-mobile-type-leading", 22) };
|
|
123
|
-
return (_jsxs(Glass, { radius: radius, elevation: "raised", fillToken: "--dialog-alert-background", style: { width, flexShrink: 1, padding
|
|
133
|
+
return (_jsxs(Glass, { radius: radius, elevation: "raised", fillToken: "--dialog-alert-background", style: { width, flexShrink: 1, padding, gap: 10 }, children: [layout == null && actions.length === 2 ? (
|
|
134
|
+
// The labels on one line, unseen, to tell whether two fit side by side
|
|
135
|
+
_jsx(View, { pointerEvents: "none", "aria-hidden": true, style: styles.measure, children: actions.map((action, index) => (_jsx(Text, { weight: action.preferred ? "semibold" : "medium", numberOfLines: 1, style: type, onLayout: (event) => {
|
|
136
|
+
const next = event.nativeEvent.layout.width;
|
|
137
|
+
setLabels((current) => (current[index] === next ? current : Object.assign([...current], { [index]: next })));
|
|
138
|
+
}, children: action.label }, index))) })) : null, _jsxs(ScrollView, { style: styles.scroll, contentContainerStyle: { gap: 10 }, bounces: false, children: [_jsxs(View, { style: { paddingTop: 5, paddingHorizontal: 15, paddingBottom: 5.5, gap: 5.67 }, children: [_jsx(Text, { nativeID: ids.title, weight: "semibold", style: [type, { textAlign: description == null ? "center" : "auto" }], accessibilityRole: "header", children: title }), description != null ? (_jsx(Text, { nativeID: ids.description, color: theme.color("--dialog-alert-message-color"), style: { fontSize: 15, lineHeight: 20 }, children: description })) : null] }), children != null ? (
|
|
124
139
|
// A field fills the alert as its actions do: the largest control size is the alert's 48 there
|
|
125
140
|
// (Dialog.module.css sets --control-size-3xl to --dialog-alert-field-height in the alert's body)
|
|
126
141
|
_jsx(ThemeProvider, { brand: { tokens: { "--control-size-3xl": `${theme.length("--dialog-alert-field-height", 48)}px` } }, children: _jsx(View, { style: { paddingBottom: 10, marginHorizontal: -1 }, children: children }) })) : null] }), ordered.length ? (_jsx(View, { style: [{ gap, marginTop: children != null ? 0 : 4 }, inline ? styles.row : null], children: ordered.map(({ action, index }) => (_jsx(IOSAction, { theme: theme, action: action, run: run, type: type, grow: inline }, index))) })) : null] }));
|
|
127
142
|
}
|
|
128
143
|
function IOSAction({ theme, action, run, type, grow }) {
|
|
129
|
-
// The preferred action is the accent with a white label,
|
|
130
|
-
// (
|
|
131
|
-
//
|
|
144
|
+
// The preferred action is the accent with a white label, one flat color with no sheen and no edge, as native draws
|
|
145
|
+
// a preferredAction (iOS 27.2: 0082f7 on every row); disabled, the phone's disabled fill (Button.module.css). A
|
|
146
|
+
// destructive one keeps the alert's fill and its red label
|
|
132
147
|
const accent = action.preferred && action.variant !== "destructive";
|
|
133
148
|
const height = theme.length("--dialog-alert-action-height", 48);
|
|
134
|
-
const [measured, setMeasured] = useState(height);
|
|
135
149
|
const fill = accent
|
|
136
150
|
? action.disabled
|
|
137
151
|
? theme.color("--button-mobile-disabled-background", theme.color("--color-background-disabled"))
|
|
@@ -145,29 +159,16 @@ function IOSAction({ theme, action, run, type, grow }) {
|
|
|
145
159
|
? theme.color("--toolbar-prominent-color")
|
|
146
160
|
: theme.colors.text;
|
|
147
161
|
const lit = accent && !action.disabled;
|
|
148
|
-
|
|
149
|
-
const sheen = lit ? sheenOf(theme, measured) : undefined;
|
|
150
|
-
return (_jsxs(Pressable, { accessibilityRole: "button", accessibilityState: { disabled: !!action.disabled }, disabled: action.disabled, onPress: () => run(action), onLayout: lit ? (event) => setMeasured(event.nativeEvent.layout.height) : undefined, testID: action.testID, style: ({ pressed }) => [
|
|
162
|
+
return (_jsx(Pressable, { accessibilityRole: "button", accessibilityState: { disabled: !!action.disabled }, disabled: action.disabled, onPress: () => run(action), testID: action.testID, style: ({ pressed }) => [
|
|
151
163
|
styles.iosAction,
|
|
152
164
|
{
|
|
153
165
|
minHeight: height,
|
|
154
166
|
borderRadius: height / 2,
|
|
155
167
|
backgroundColor: lit && pressed ? theme.color("--toolbar-prominent-background-active") : fill,
|
|
156
168
|
opacity: pressed && !lit ? 0.7 : 1,
|
|
157
|
-
boxShadow: typeof shadow === "string" ? shadow : undefined,
|
|
158
169
|
},
|
|
159
170
|
grow ? styles.grow : null,
|
|
160
|
-
], children:
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* `--toolbar-prominent-sheen`, lighter along the top and the bottom edge, for a face of a known height: its
|
|
164
|
-
* `calc(100% - 8px)` stop in pixels, since React Native's gradients take no calc().
|
|
165
|
-
*/
|
|
166
|
-
function sheenOf(theme, height) {
|
|
167
|
-
const value = theme.token("--toolbar-prominent-sheen");
|
|
168
|
-
if (typeof value !== "string" || !value.includes("gradient"))
|
|
169
|
-
return undefined;
|
|
170
|
-
return value.replace(/calc\(\s*100%\s*-\s*([\d.]+)px\s*\)/g, (_, px) => `${Math.max(0, height - Number(px))}px`);
|
|
171
|
+
], children: _jsx(Text, { color: text, weight: action.preferred ? "semibold" : "medium", style: [type, styles.centered], children: action.label }) }));
|
|
171
172
|
}
|
|
172
173
|
function AndroidDialog({ theme, title, description, actions, run, ids, children, list }) {
|
|
173
174
|
const m = theme.material;
|
|
@@ -219,7 +220,8 @@ const styles = StyleSheet.create({
|
|
|
219
220
|
row: { flexDirection: "row" },
|
|
220
221
|
grow: { flex: 1, flexBasis: 0 },
|
|
221
222
|
centered: { textAlign: "center" },
|
|
222
|
-
iosAction: { alignItems: "center", justifyContent: "center", paddingVertical: 13, paddingHorizontal:
|
|
223
|
+
iosAction: { alignItems: "center", justifyContent: "center", paddingVertical: 13, paddingHorizontal: IOS_ACTION_INSET, borderCurve: "continuous" },
|
|
224
|
+
measure: { position: "absolute", top: 0, left: 0, width: 2000, alignItems: "flex-start", opacity: 0 },
|
|
223
225
|
// Android's alert: 21dp corners (the catalog's); the text 24 in. Measured on the reference's alerts: the title's
|
|
224
226
|
// baseline 40 under the top, the message's first 33 under it in lines 18.75 apart (16sp Roboto's), its last 59
|
|
225
227
|
// over the buttons' (Roboto's font padding sets these 2 to 3 lower than the layout's 19, 10 and 20 would)
|
|
@@ -361,6 +361,9 @@ export function InputField({ variant = "outline", size = "md", disabled = false,
|
|
|
361
361
|
const required = ownRequired ?? floatLabel?.required;
|
|
362
362
|
const shift = ownShift ?? floatLabel?.shift;
|
|
363
363
|
const [focused, setFocused] = useState(false);
|
|
364
|
+
// A Tab to the iOS clear button blurs the field on the web: the button stays while it has focus (a press keeps the
|
|
365
|
+
// field's focus, below)
|
|
366
|
+
const [clearing, setClearing] = useState(false);
|
|
364
367
|
const [own, setOwn] = useState(defaultValue ?? "");
|
|
365
368
|
const text = value ?? own;
|
|
366
369
|
const filled = text.length > 0;
|
|
@@ -439,7 +442,13 @@ export function InputField({ variant = "outline", size = "md", disabled = false,
|
|
|
439
442
|
// Android's label is in the hint color at rest and in the accent while the field has focus, springing between them
|
|
440
443
|
const labelColor = invalid ? dangerText(theme) : focused ? focusAccent(theme) : look.placeholder;
|
|
441
444
|
const labelTint = useSpringColor(labelColor, FIELD_SPRING.stiffness, !floating || theme.reducedMotion);
|
|
442
|
-
|
|
445
|
+
// iOS shows a form field's clear button while it is edited (UITextField's whileEditing), a search field's while it
|
|
446
|
+
// has text; Android while the field has text
|
|
447
|
+
const searchField = rest.inputMode === "search" || barField != null;
|
|
448
|
+
// A value at a row's end has no clear button on iOS, as Settings' and Contacts' rows: only a value that starts its
|
|
449
|
+
// column or stands on its own line under the label takes one
|
|
450
|
+
const valueRight = !startAligned && (inRow || (fillsRow && valueAtEnd));
|
|
451
|
+
const showClear = !!onClear && filled && !disabled && !readOnly && (theme.isAndroid || ((focused || clearing || searchField) && !valueRight));
|
|
443
452
|
// Android's search fields keep their clear button in place and show it with the text
|
|
444
453
|
const androidClear = (search || barSearch) && !!onClear && !disabled && !readOnly;
|
|
445
454
|
// 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
|
|
@@ -481,7 +490,11 @@ export function InputField({ variant = "outline", size = "md", disabled = false,
|
|
|
481
490
|
// round end (Input.module.css), or keeps its box beside an end adornment
|
|
482
491
|
const clearMargin = theme.isAndroid
|
|
483
492
|
? { marginHorizontal: -(look.clearTarget - look.clearSize) / 2 }
|
|
484
|
-
:
|
|
493
|
+
: bare
|
|
494
|
+
? // In a List row the target reaches over and under the row's line, so the row keeps its height, and its circle
|
|
495
|
+
// ends at the row's end inset, as a form row's clear button
|
|
496
|
+
{ marginVertical: -(look.clearTarget - look.text.lineHeight) / 2, marginEnd: -(look.clearTarget - look.clearSize) / 2 }
|
|
497
|
+
: { marginEnd: endAdornment ? theme.length("--input-clear-target-offset", 0) : look.height / 2 - look.clearTarget / 2 - look.gutter };
|
|
485
498
|
// An adornment stands in a View of its own, centered on the field: a Button in it keeps its own `alignSelf`
|
|
486
499
|
// ("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
|
|
487
500
|
// than itself (an IconButton's 40dp in a 50dp field)
|
|
@@ -523,7 +536,7 @@ export function InputField({ variant = "outline", size = "md", disabled = false,
|
|
|
523
536
|
theme.font("regular"),
|
|
524
537
|
// A label floated inside the field (8 to 24) sets the text under it
|
|
525
538
|
{ paddingTop: padding.top, paddingBottom: padding.bottom },
|
|
526
|
-
|
|
539
|
+
valueRight ? { textAlign: Platform.OS === "web" && rtl ? "left" : "right" } : null,
|
|
527
540
|
// A value in a row that the person cannot edit is the secondary label, as the web's phone rows (iOS's
|
|
528
541
|
// values of a row that only informs)
|
|
529
542
|
fillsRow && readOnly && !disabled ? { color: theme.colors.labelSecondary } : null,
|
|
@@ -536,7 +549,10 @@ export function InputField({ variant = "outline", size = "md", disabled = false,
|
|
|
536
549
|
}, onHiddenPress: () => {
|
|
537
550
|
if (!locked)
|
|
538
551
|
input.current?.focus();
|
|
539
|
-
} })) : showClear ? (_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: "Clear", onPress: () => {
|
|
552
|
+
} })) : showClear ? (_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: "Clear", onFocus: () => setClearing(true), onBlur: () => setClearing(false), ...(Platform.OS === "web" ? { onMouseDown: (event) => event.preventDefault() } : null), onPress: () => {
|
|
553
|
+
// As UIKit's clear button, the field keeps editing; first, so a caller's onClear may still move the focus
|
|
554
|
+
if (!theme.isAndroid && !searchField)
|
|
555
|
+
input.current?.focus();
|
|
540
556
|
if (value === undefined)
|
|
541
557
|
setOwn("");
|
|
542
558
|
onChangeText?.("");
|
|
@@ -98,6 +98,26 @@ function ToolbarGroup({ children, style, ...rest }) {
|
|
|
98
98
|
], children: children }) }));
|
|
99
99
|
}
|
|
100
100
|
ToolbarGroup.displayName = "Toolbar.Group";
|
|
101
|
+
/**
|
|
102
|
+
* 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
|
|
103
|
+
* 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,
|
|
104
|
+
* 15pt Semibold, 8pt from its ends); on Android it is the bar's plain text, 14sp Medium. Read as text, not a control.
|
|
105
|
+
*/
|
|
106
|
+
function ToolbarLabel({ children, style, ...rest }) {
|
|
107
|
+
const theme = useTheme();
|
|
108
|
+
const item = useContext(BarItemContext);
|
|
109
|
+
const text = (_jsx(Text, { weight: theme.isAndroid ? "medium" : "semibold", tabularNums: true, numberOfLines: 1, style: theme.isAndroid ? { fontSize: 14, lineHeight: 20 } : { fontSize: theme.length("--toolbar-status-font-size", 15), lineHeight: theme.length("--toolbar-status-line-height", 20) }, children: children }));
|
|
110
|
+
if (theme.isAndroid || !item || item.inGroup) {
|
|
111
|
+
return (_jsx(View, { ...rest, style: [styles.slot, styles.label, item ? { minHeight: item.height, paddingHorizontal: theme.isAndroid ? 8 : 0 } : null, style], children: text }));
|
|
112
|
+
}
|
|
113
|
+
return (_jsx(Glass, { ...rest, elevation: item.raised ? "raised" : "regular", radius: item.height / 2, style: [
|
|
114
|
+
styles.slot,
|
|
115
|
+
styles.label,
|
|
116
|
+
{ height: item.height, minWidth: item.height, paddingHorizontal: theme.length("--toolbar-status-padding", 8) },
|
|
117
|
+
style,
|
|
118
|
+
], children: text }));
|
|
119
|
+
}
|
|
120
|
+
ToolbarLabel.displayName = "Toolbar.Label";
|
|
101
121
|
/** The title of the bar, and an optional subtitle under it. Announced as a header. */
|
|
102
122
|
function ToolbarTitle(_) {
|
|
103
123
|
// Drawn by Toolbar, which knows the title style
|
|
@@ -386,11 +406,13 @@ export const Toolbar = Object.assign(ToolbarRoot, {
|
|
|
386
406
|
Group: ToolbarGroup,
|
|
387
407
|
Trailing: ToolbarTrailing,
|
|
388
408
|
Row: ToolbarRow,
|
|
409
|
+
Label: ToolbarLabel,
|
|
389
410
|
});
|
|
390
411
|
const styles = StyleSheet.create({
|
|
391
412
|
titleImage: { flexDirection: "row", alignItems: "center" },
|
|
392
413
|
slot: { flexDirection: "row", alignItems: "center" },
|
|
393
414
|
trailing: { justifyContent: "flex-end" },
|
|
415
|
+
label: { justifyContent: "center" },
|
|
394
416
|
content: { justifyContent: "center" },
|
|
395
417
|
// A filling content stretches its control across (a search field, a block button), as a column would
|
|
396
418
|
fill: { flex: 1, flexDirection: "column", alignItems: "stretch" },
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import { type StyleProp, type ViewStyle } from "react-native";
|
|
3
3
|
export type BottomActionsProps = {
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* The screen's main action, a Button, and an optional second Button under it ("Not now", "Skip"). A second Button
|
|
6
|
+
* with no `variant` of its own takes the platform's: on iOS 26 a glass capsule of the same size, as Apple's
|
|
7
|
+
* step-by-step sheets set "Skip"; on Android a ghost button.
|
|
8
|
+
*/
|
|
5
9
|
children: ReactNode;
|
|
6
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Puts the actions over the content (a scroll view under them), over a soft edge as a bottom Toolbar draws: on iOS
|
|
12
|
+
* the screen's color fading in over 27pt above the actions, over a light blur; on Android the screen's color fading
|
|
13
|
+
* in. Off, they take their room at the end of the screen. @default false
|
|
14
|
+
*/
|
|
7
15
|
floating?: boolean;
|
|
16
|
+
/** The color the floating edge fades into: the screen's (a grouped screen's gray). @default the theme's background */
|
|
17
|
+
canvasColor?: string;
|
|
8
18
|
testID?: string;
|
|
9
19
|
style?: StyleProp<ViewStyle>;
|
|
10
20
|
};
|
|
@@ -15,4 +25,4 @@ export type BottomActionsProps = {
|
|
|
15
25
|
* action stands under it, 8 apart. Android: the Plex Android look's 48dp full-width button, 16dp from the sides and
|
|
16
26
|
* 16 above the gesture bar. Each Button inside is a block of the size `3xl` unless it sets its own.
|
|
17
27
|
*/
|
|
18
|
-
export declare function BottomActions({ children, floating, testID, style }: BottomActionsProps): import("react").JSX.Element;
|
|
28
|
+
export declare function BottomActions({ children, floating, canvasColor, testID, style }: BottomActionsProps): import("react").JSX.Element;
|
|
@@ -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 {};
|
package/package.json
CHANGED
|
@@ -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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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"
|
|
81
|
+
bar: { alignSelf: "stretch" },
|
|
53
82
|
floating: { position: "absolute", left: 0, right: 0, bottom: 0 },
|
|
54
83
|
})
|
|
@@ -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
|
|
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
|
-
|
|
265
|
-
const
|
|
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
|
|
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,
|
|
302
|
-
// (
|
|
303
|
-
//
|
|
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:
|
|
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
|
-
|
|
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
|
-
:
|
|
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
|
-
|
|
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()
|
|
@@ -201,6 +201,54 @@ function ToolbarGroup({ children, style, ...rest }: ViewProps) {
|
|
|
201
201
|
}
|
|
202
202
|
ToolbarGroup.displayName = "Toolbar.Group"
|
|
203
203
|
|
|
204
|
+
export type ToolbarLabelProps = ViewProps & {
|
|
205
|
+
/** The text: a step of a flow ("3 of 10"), a count, a status. Its digits keep one width as it changes. */
|
|
206
|
+
children: ReactNode
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* 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
|
|
211
|
+
* 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,
|
|
212
|
+
* 15pt Semibold, 8pt from its ends); on Android it is the bar's plain text, 14sp Medium. Read as text, not a control.
|
|
213
|
+
*/
|
|
214
|
+
function ToolbarLabel({ children, style, ...rest }: ToolbarLabelProps) {
|
|
215
|
+
const theme = useTheme()
|
|
216
|
+
const item = useContext(BarItemContext)
|
|
217
|
+
const text = (
|
|
218
|
+
<Text
|
|
219
|
+
weight={theme.isAndroid ? "medium" : "semibold"}
|
|
220
|
+
tabularNums
|
|
221
|
+
numberOfLines={1}
|
|
222
|
+
style={theme.isAndroid ? { fontSize: 14, lineHeight: 20 } : { fontSize: theme.length("--toolbar-status-font-size", 15), lineHeight: theme.length("--toolbar-status-line-height", 20) }}
|
|
223
|
+
>
|
|
224
|
+
{children}
|
|
225
|
+
</Text>
|
|
226
|
+
)
|
|
227
|
+
if (theme.isAndroid || !item || item.inGroup) {
|
|
228
|
+
return (
|
|
229
|
+
<View {...rest} style={[styles.slot, styles.label, item ? { minHeight: item.height, paddingHorizontal: theme.isAndroid ? 8 : 0 } : null, style]}>
|
|
230
|
+
{text}
|
|
231
|
+
</View>
|
|
232
|
+
)
|
|
233
|
+
}
|
|
234
|
+
return (
|
|
235
|
+
<Glass
|
|
236
|
+
{...rest}
|
|
237
|
+
elevation={item.raised ? "raised" : "regular"}
|
|
238
|
+
radius={item.height / 2}
|
|
239
|
+
style={[
|
|
240
|
+
styles.slot,
|
|
241
|
+
styles.label,
|
|
242
|
+
{ height: item.height, minWidth: item.height, paddingHorizontal: theme.length("--toolbar-status-padding", 8) },
|
|
243
|
+
style,
|
|
244
|
+
]}
|
|
245
|
+
>
|
|
246
|
+
{text}
|
|
247
|
+
</Glass>
|
|
248
|
+
)
|
|
249
|
+
}
|
|
250
|
+
ToolbarLabel.displayName = "Toolbar.Label"
|
|
251
|
+
|
|
204
252
|
export type ToolbarTitleProps = {
|
|
205
253
|
/** The title's text. With `image` it may be left out. */
|
|
206
254
|
children?: ReactNode
|
|
@@ -682,12 +730,14 @@ export const Toolbar = Object.assign(ToolbarRoot, {
|
|
|
682
730
|
Group: ToolbarGroup,
|
|
683
731
|
Trailing: ToolbarTrailing,
|
|
684
732
|
Row: ToolbarRow,
|
|
733
|
+
Label: ToolbarLabel,
|
|
685
734
|
})
|
|
686
735
|
|
|
687
736
|
const styles = StyleSheet.create({
|
|
688
737
|
titleImage: { flexDirection: "row", alignItems: "center" },
|
|
689
738
|
slot: { flexDirection: "row", alignItems: "center" },
|
|
690
739
|
trailing: { justifyContent: "flex-end" },
|
|
740
|
+
label: { justifyContent: "center" },
|
|
691
741
|
content: { justifyContent: "center" },
|
|
692
742
|
// A filling content stretches its control across (a search field, a block button), as a column would
|
|
693
743
|
fill: { flex: 1, flexDirection: "column", alignItems: "stretch" },
|