@plexui/react-native 0.2.22 → 0.2.24
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 +6 -1
- package/dist/es/components/BottomSheet/BottomSheet.js +5 -0
- package/dist/es/components/List/List.js +12 -3
- package/dist/es/components/PageControl/PageControl.js +85 -13
- package/dist/es/components/Toast/Toast.js +4 -3
- package/dist/types/components/PageControl/PageControl.d.ts +22 -2
- package/package.json +1 -1
- package/src/components/BottomActions/BottomActions.tsx +9 -1
- package/src/components/BottomSheet/BottomSheet.tsx +5 -0
- package/src/components/List/List.tsx +12 -3
- package/src/components/PageControl/PageControl.tsx +99 -18
- package/src/components/Toast/Toast.tsx +8 -3
|
@@ -33,12 +33,17 @@ export function BottomActions({ children, floating = false, background = "soft",
|
|
|
33
33
|
? { variant: "ghost", color: props.color ?? "secondary" }
|
|
34
34
|
: { variant: "soft", color: props.color ?? "secondary", mobileMaterial: props.mobileMaterial ?? "glass" }
|
|
35
35
|
: null;
|
|
36
|
-
|
|
36
|
+
const button = cloneElement(child, {
|
|
37
37
|
...second,
|
|
38
38
|
block: props.block ?? true,
|
|
39
39
|
size: props.size ?? "3xl",
|
|
40
40
|
style: [{ minHeight: height, borderRadius: height / 2 }, props.style],
|
|
41
41
|
});
|
|
42
|
+
// A disabled button's fill is see-through (the gray of iOS's disabled button): floating over the content it stands
|
|
43
|
+
// on the screen's color, so the rows under it do not show through
|
|
44
|
+
if (!floating || !props.disabled || android)
|
|
45
|
+
return button;
|
|
46
|
+
return (_jsx(View, { style: { borderRadius: height / 2, backgroundColor: canvas, alignSelf: (props.block ?? true) ? "stretch" : "flex-start" }, children: button }, child.key ?? index));
|
|
42
47
|
});
|
|
43
48
|
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 })) : background === "fade" ? (_jsx(TabBarFade, { fill: canvas, top: paddingTop })) : (_jsx(SoftBottomEdge, { fill: canvas, top: paddingTop, tail: 27, blur: theme.length("--toolbar-edge-blur-small", 3) }))) : null, actions] }));
|
|
44
49
|
}
|
|
@@ -175,6 +175,8 @@ export function BottomSheetBase({ open, onOpenChange, title, children, dismissib
|
|
|
175
175
|
const [drag] = useState(() => new Animated.Value(0));
|
|
176
176
|
const close = () => onOpenChange(false);
|
|
177
177
|
const android = theme.isAndroid;
|
|
178
|
+
// Android's content and actions 12 from the sheet's sides, as a page's groups; a token for a screen at another gutter
|
|
179
|
+
const androidInline = theme.length("--bottom-sheet-android-padding-inline", 12);
|
|
178
180
|
const reduced = theme.reducedMotion;
|
|
179
181
|
// One responder for the sheet's life, told the latest props after each render: a responder made again mid-drag
|
|
180
182
|
// would lose the drag
|
|
@@ -278,6 +280,8 @@ export function BottomSheetBase({ open, onOpenChange, title, children, dismissib
|
|
|
278
280
|
android
|
|
279
281
|
? [
|
|
280
282
|
styles.androidContent,
|
|
283
|
+
// A screen whose gutter is Material's compact 16 sets it with --bottom-sheet-android-padding-inline
|
|
284
|
+
{ paddingHorizontal: androidInline },
|
|
281
285
|
title != null ? styles.androidContentUnderBar : null,
|
|
282
286
|
// Over a footer: 8 above its height, which reaches over the sheet's bottom padding
|
|
283
287
|
footer ? { paddingBottom: 8 + Math.max(0, footerHeight - insets.bottom - keyboard) } : null,
|
|
@@ -288,6 +292,7 @@ export function BottomSheetBase({ open, onOpenChange, title, children, dismissib
|
|
|
288
292
|
android
|
|
289
293
|
? [
|
|
290
294
|
styles.androidFooter,
|
|
295
|
+
{ paddingHorizontal: androidInline },
|
|
291
296
|
// Over the sheet's color at 80%, faded in over its top 24dp, down over the gesture bar
|
|
292
297
|
{ paddingBottom: 12 + insets.bottom + keyboard, backgroundImage: `linear-gradient(to bottom, ${withAlpha(background, 0)}, ${withAlpha(background, 0.8)} 24px)` },
|
|
293
298
|
]
|
|
@@ -62,6 +62,8 @@ export function List({ children, header, description, footer, error, surface = "
|
|
|
62
62
|
.map((row) => (row.type === Button ? _jsx(ActionRow, { children: row }, row.key ?? undefined) : row));
|
|
63
63
|
const options = useMemo(() => ({ columns }), [columns]);
|
|
64
64
|
const increased = headerProminence === "increased";
|
|
65
|
+
// Android's footer 13 into the card's width, as the Settings app; a token for a screen that keeps text at its gutter
|
|
66
|
+
const footerInset = theme.length("--list-android-footer-inset", 13);
|
|
65
67
|
const fill = surface === "plain" ? theme.color("--field-group-background", theme.colors.surfaceSecondary) : theme.colors.groupedSurface;
|
|
66
68
|
// The card's corners: Android's 16dp card (a header or description inside it stands over the first row), iOS's group
|
|
67
69
|
const corner = surface === "plain" && theme.isAndroid ? 0 : theme.isAndroid ? ANDROID_CARD_RADIUS : theme.length("--field-group-radius", 26);
|
|
@@ -78,7 +80,7 @@ export function List({ children, header, description, footer, error, surface = "
|
|
|
78
80
|
// too), and its header is a band of the grouped canvas across them, 14sp Medium in the secondary label 16 in
|
|
79
81
|
const plain = surface === "plain";
|
|
80
82
|
const band = theme.colors.groupedBackground;
|
|
81
|
-
return (_jsxs(View, { testID: testID, style: style, children: [_jsxs(View, { style: plain ? { backgroundColor: theme.colors.groupedSurface } : [styles.androidCard, { backgroundColor: fill }], children: [header == null && action == null ? null : plain ? (_jsxs(View, { style: [styles.androidBand, action != null ? styles.androidBandRow : null, { backgroundColor: band }], children: [header != null ? (_jsx(Text, { accessibilityRole: "header", color: theme.colors.labelSecondary, weight: "medium", numberOfLines: 1, style: [styles.androidBandText, action != null ? styles.grow : null], children: header })) : (_jsx(View, { style: styles.grow })), action != null ? _jsx(ListActionContext.Provider, { value: "header", children: headerAction(action, styles.androidBandText, theme.colors.labelSecondary) }) : null] })) : action != null ? (_jsxs(View, { style: styles.androidHeaderRow, children: [header != null ? (_jsx(Text, { accessibilityRole: "header", color: increased ? theme.colors.text : accentText(theme), weight: "medium", style: [styles.androidHeaderTitle, increased ? styles.androidHeaderIncreased : null], children: header })) : (_jsx(View, { style: styles.grow })), _jsx(ListActionContext.Provider, { value: "header", children: headerAction(action, styles.androidHeaderTitleType, theme.colors.labelSecondary) })] })) : (_jsx(Text, { accessibilityRole: "header", color: increased ? theme.colors.text : accentText(theme), weight: "medium", style: [styles.androidHeader, increased ? styles.androidHeaderIncreased : null], children: header })), description != null ? (_jsx(Text, { color: theme.colors.labelSecondary, style: [styles.androidDescriptionLine, plain ? styles.androidDescriptionPlain : header == null ? styles.androidDescriptionAlone : null], children: description })) : null, _jsx(View, { accessibilityRole: "list", "aria-label": label, children: _jsx(ListOptionsContext.Provider, { value: options, children: body }) })] }), error != null ? (_jsx(Text, { color: dangerText(theme), accessibilityLiveRegion: "polite", style: [styles.androidFooter, plain ? [styles.androidFooterPlain, { backgroundColor: band }] : null], children: error })) : footer != null ? (_jsx(Text, { color: theme.colors.labelSecondary, style: [styles.androidFooter, plain ? [styles.androidFooterPlain, { backgroundColor: band }] : null], children: footer })) : null] }));
|
|
83
|
+
return (_jsxs(View, { testID: testID, style: style, children: [_jsxs(View, { style: plain ? { backgroundColor: theme.colors.groupedSurface } : [styles.androidCard, { backgroundColor: fill }], children: [header == null && action == null ? null : plain ? (_jsxs(View, { style: [styles.androidBand, action != null ? styles.androidBandRow : null, { backgroundColor: band }], children: [header != null ? (_jsx(Text, { accessibilityRole: "header", color: theme.colors.labelSecondary, weight: "medium", numberOfLines: 1, style: [styles.androidBandText, action != null ? styles.grow : null], children: header })) : (_jsx(View, { style: styles.grow })), action != null ? _jsx(ListActionContext.Provider, { value: "header", children: headerAction(action, styles.androidBandText, theme.colors.labelSecondary) }) : null] })) : action != null ? (_jsxs(View, { style: styles.androidHeaderRow, children: [header != null ? (_jsx(Text, { accessibilityRole: "header", color: increased ? theme.colors.text : accentText(theme), weight: "medium", style: [styles.androidHeaderTitle, increased ? styles.androidHeaderIncreased : null], children: header })) : (_jsx(View, { style: styles.grow })), _jsx(ListActionContext.Provider, { value: "header", children: headerAction(action, styles.androidHeaderTitleType, theme.colors.labelSecondary) })] })) : (_jsx(Text, { accessibilityRole: "header", color: increased ? theme.colors.text : accentText(theme), weight: "medium", style: [styles.androidHeader, increased ? styles.androidHeaderIncreased : null], children: header })), description != null ? (_jsx(Text, { color: theme.colors.labelSecondary, style: [styles.androidDescriptionLine, plain ? styles.androidDescriptionPlain : header == null ? styles.androidDescriptionAlone : null], children: description })) : null, _jsx(View, { accessibilityRole: "list", "aria-label": label, children: _jsx(ListOptionsContext.Provider, { value: options, children: body }) })] }), error != null ? (_jsx(Text, { color: dangerText(theme), accessibilityLiveRegion: "polite", style: [styles.androidFooter, { paddingHorizontal: footerInset }, plain ? [styles.androidFooterPlain, { backgroundColor: band }] : null], children: error })) : footer != null ? (_jsx(Text, { color: theme.colors.labelSecondary, style: [styles.androidFooter, { paddingHorizontal: footerInset }, plain ? [styles.androidFooterPlain, { backgroundColor: band }] : null], children: footer })) : null] }));
|
|
82
84
|
}
|
|
83
85
|
const inset = theme.length("--list-row-inset", 20);
|
|
84
86
|
const footerBox = cssBox(theme, "--field-group-footer-padding", [8, inset, 6, inset]);
|
|
@@ -371,6 +373,9 @@ function IOSContent({ handPress, valueColor, theme, label, description, descript
|
|
|
371
373
|
: Math.max(description != null ? descriptionPadding : theme.length("--field-row-text-padding-block", 12), (iosMinHeight(theme, description != null) - labelType.lineHeight - (description != null ? descriptionLine : 0)) / 2);
|
|
372
374
|
// A field at the end fills the room after the label (`RowEnd.fill`)
|
|
373
375
|
const [fill, setFill] = useState(false);
|
|
376
|
+
// A picture wider than the tile (a photo, an avatar) keeps its own size: it starts at the row's inset, where the
|
|
377
|
+
// header and the footer stand, and the text follows 14 past it, as UIKit's image to text padding
|
|
378
|
+
const [wide, setWide] = useState(false);
|
|
374
379
|
// In a List with `columns` a field's value starts at one column, 40% into the row (`--field-row-column-width`)
|
|
375
380
|
// A switch, a checkbox and a radio stay at the row's edge
|
|
376
381
|
const columns = useContext(ListOptionsContext)?.columns === true && trailing != null;
|
|
@@ -388,9 +393,13 @@ function IOSContent({ handPress, valueColor, theme, label, description, descript
|
|
|
388
393
|
});
|
|
389
394
|
return (_jsxs(_Fragment, { children: [leading != null ? (_jsx(View, { style: [
|
|
390
395
|
styles.tile,
|
|
391
|
-
{
|
|
396
|
+
{ minWidth: tile, minHeight: tile, marginStart: wide ? 0 : theme.length("--field-row-icon-offset", -2), marginEnd: theme.length("--field-row-icon-gap", 14) },
|
|
392
397
|
leadingColor ? { backgroundColor: leadingColor, borderRadius: theme.length("--field-row-icon-radius", 7) } : null,
|
|
393
|
-
],
|
|
398
|
+
], onLayout: (event) => {
|
|
399
|
+
const next = event.nativeEvent.layout.width > tile + 0.5;
|
|
400
|
+
if (next !== wide)
|
|
401
|
+
setWide(next);
|
|
402
|
+
}, children: _jsx(IconDefaultsProvider, { size: leadingColor ? 20 : theme.length("--field-row-icon-symbol-size", 24), color: leadingColor ? "#ffffff" : disabled ? theme.colors.labelTertiary : theme.colors.accent, children: leading }) })) : null, _jsxs(View, { ref: ref, onLayout: onRowLayout, style: [
|
|
394
403
|
error != null ? styles.iosColumn : styles.iosMain,
|
|
395
404
|
{ minHeight: iosMinHeight(theme, description != null || error != null), paddingEnd: inset },
|
|
396
405
|
error != null
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useRef, useState } from "react";
|
|
3
|
-
import { Animated, Platform, StyleSheet, View } from "react-native";
|
|
3
|
+
import { Animated, Easing, Platform, StyleSheet, View } from "react-native";
|
|
4
4
|
import { isRTL } from "../../internal/direction";
|
|
5
5
|
import { curves } from "../../internal/motion";
|
|
6
6
|
import { useTheme } from "../../theme/ThemeProvider";
|
|
@@ -46,17 +46,73 @@ const SCRUB_THRESHOLD = 8;
|
|
|
46
46
|
* page and back as it moves), in a 48dp target, with no capsule at all. For a screen reader it is adjustable: swipe
|
|
47
47
|
* up or down for the next or previous page.
|
|
48
48
|
*/
|
|
49
|
-
export function PageControl({ count, value: valueProp, defaultValue = 0, onChange, background = "automatic", indicator = "dots", tone = "default", direction = "horizontal", size = "md", valueText = defaultValueText, "aria-label": ariaLabel = "Pages", testID, style, }) {
|
|
49
|
+
export function PageControl({ count, value: valueProp, defaultValue = 0, position: positionProp, onChange, background = "automatic", indicator = "dots", tone = "default", direction = "horizontal", size = "md", valueText = defaultValueText, "aria-label": ariaLabel = "Pages", testID, style, }) {
|
|
50
50
|
const theme = useTheme();
|
|
51
51
|
const [own, setOwn] = useState(defaultValue);
|
|
52
52
|
const current = clampIndex(valueProp ?? own, count);
|
|
53
53
|
const [press, setPress] = useState(null);
|
|
54
54
|
// Where the dots stand inside the target, which can be wider than them (x is physical, from the left)
|
|
55
55
|
const [capsule, setCapsule] = useState({ x: 0, width: 0 });
|
|
56
|
+
// The fractional page the marks follow: the app's own `position`, or one that moves to `value` by itself
|
|
57
|
+
const [ownPosition] = useState(() => new Animated.Value(typeof positionProp === "number" ? positionProp : current));
|
|
58
|
+
const driven = positionProp != null && typeof positionProp === "object";
|
|
59
|
+
const scrubbed = useRef(false);
|
|
60
|
+
const shown = useRef(null);
|
|
61
|
+
// The page nearest the position: the dots' window from seven pages follows it, so the marks it passes stay drawn
|
|
62
|
+
const [near, setNear] = useState(current);
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (typeof positionProp === "number") {
|
|
65
|
+
ownPosition.setValue(positionProp);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const source = driven ? positionProp : ownPosition;
|
|
69
|
+
const follow = (value) => {
|
|
70
|
+
// The own position keeps up with an app's, so it moves on from there when the app's goes
|
|
71
|
+
if (driven)
|
|
72
|
+
ownPosition.setValue(value);
|
|
73
|
+
const page = clampIndex(Math.round(value), count);
|
|
74
|
+
setNear((last) => (last === page ? last : page));
|
|
75
|
+
};
|
|
76
|
+
const id = source.addListener(({ value }) => follow(value));
|
|
77
|
+
// A listener hears only what comes next: a new source's value now sets the window at once
|
|
78
|
+
const read = () => source.__getValue?.();
|
|
79
|
+
let live = true;
|
|
80
|
+
void Promise.resolve().then(() => {
|
|
81
|
+
// Read as it runs, so a change in between is not undone
|
|
82
|
+
const now = read();
|
|
83
|
+
if (live && typeof now === "number")
|
|
84
|
+
follow(now);
|
|
85
|
+
});
|
|
86
|
+
return () => {
|
|
87
|
+
live = false;
|
|
88
|
+
source.removeListener(id);
|
|
89
|
+
};
|
|
90
|
+
}, [positionProp, driven, ownPosition, count]);
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
if (positionProp != null)
|
|
93
|
+
return;
|
|
94
|
+
const still = shown.current == null || theme.reducedMotion || scrubbed.current;
|
|
95
|
+
shown.current = current;
|
|
96
|
+
scrubbed.current = false;
|
|
97
|
+
if (still) {
|
|
98
|
+
ownPosition.setValue(current);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const animation = Animated.timing(ownPosition, { toValue: current, ...(theme.isAndroid ? ANDROID_SLIDE : IOS_SLIDE), useNativeDriver: false });
|
|
102
|
+
animation.start();
|
|
103
|
+
return () => animation.stop();
|
|
104
|
+
}, [current, positionProp, ownPosition, theme.reducedMotion, theme.isAndroid]);
|
|
105
|
+
// An overscroll past the first or the last page stands on it, so its mark keeps the whole pill
|
|
106
|
+
const position = (driven ? positionProp : ownPosition).interpolate({
|
|
107
|
+
inputRange: [0, Math.max(1, count - 1)],
|
|
108
|
+
outputRange: [0, Math.max(0, count - 1)],
|
|
109
|
+
extrapolate: "clamp",
|
|
110
|
+
});
|
|
56
111
|
const go = (index, scrubbing = false) => {
|
|
57
112
|
const next = clampIndex(index, count);
|
|
58
113
|
if (next === current)
|
|
59
114
|
return;
|
|
115
|
+
scrubbed.current = scrubbing;
|
|
60
116
|
if (valueProp === undefined)
|
|
61
117
|
setOwn(next);
|
|
62
118
|
onChange?.(next, { scrubbing });
|
|
@@ -69,7 +125,7 @@ export function PageControl({ count, value: valueProp, defaultValue = 0, onChang
|
|
|
69
125
|
const padding = small ? 6 : theme.length("--page-control-padding-inline", 12);
|
|
70
126
|
const pitch = dot + gap;
|
|
71
127
|
// Android draws every page's dot at full size; the iOS kit shrinks the ends from seven pages
|
|
72
|
-
const sizes = android ? Array.from({ length: Math.max(0, count) }, () => "full") : pageControlDots(count,
|
|
128
|
+
const sizes = android ? Array.from({ length: Math.max(0, count) }, () => "full") : pageControlDots(count, clampIndex(typeof positionProp === "number" ? Math.round(positionProp) : near, count));
|
|
73
129
|
// The small and smaller ends keep their share of a full dot (6 and 4 of 8 on iOS)
|
|
74
130
|
const dotSize = (kind) => kind === "full"
|
|
75
131
|
? dot
|
|
@@ -77,8 +133,9 @@ export function PageControl({ count, value: valueProp, defaultValue = 0, onChang
|
|
|
77
133
|
? Math.max(2, dot - (kind === "small" ? 1 : 2))
|
|
78
134
|
: (dot / 8) * (kind === "small" ? theme.length("--page-control-dot-size-small", 6) : theme.length("--page-control-dot-size-smaller", 4));
|
|
79
135
|
const pill = indicator === "pill";
|
|
80
|
-
// A pill: the current page two and a half dots long (
|
|
81
|
-
const
|
|
136
|
+
// A pill: the current page two and a half dots long (14 at `sm`), along the direction
|
|
137
|
+
const pillLength = small ? 14 : dot * 2.5;
|
|
138
|
+
const dotWidth = (kind, index) => (pill && index === current ? pillLength : dotSize(kind));
|
|
82
139
|
// The center of the current dot, for a tap on either side of it
|
|
83
140
|
let x = padding;
|
|
84
141
|
let currentCenter = padding;
|
|
@@ -93,8 +150,9 @@ export function PageControl({ count, value: valueProp, defaultValue = 0, onChang
|
|
|
93
150
|
const on = onColor ? "#FFFFFF" : android ? theme.material.primary : theme.color("--page-control-dot-color-current", theme.colors.text);
|
|
94
151
|
// Android's page dots: #BBBBBB, #555555 in a dark theme
|
|
95
152
|
const off = onColor ? "rgba(255, 255, 255, 0.4)" : android ? (theme.scheme === "dark" ? "#555555" : "#BBBBBB") : theme.color("--page-control-dot-color", theme.colors.labelTertiary);
|
|
96
|
-
// Android's current dot is drawn over the gray ones (it stretches between pages)
|
|
97
|
-
|
|
153
|
+
// Android's current dot is drawn over the gray ones (it stretches between pages) unless the pages' scroll drives the
|
|
154
|
+
// dots, when their color crosses over as on iOS; a pill is a dot of its own
|
|
155
|
+
const worm = android && !pill && positionProp == null;
|
|
98
156
|
// Android draws no capsule, not even for `prominent`
|
|
99
157
|
const capsuleHeight = small ? 16 : theme.length("--page-control-height", 24);
|
|
100
158
|
const target = android ? 48 : theme.length("--page-control-target-size", 44);
|
|
@@ -152,13 +210,27 @@ export function PageControl({ count, value: valueProp, defaultValue = 0, onChang
|
|
|
152
210
|
? { flexDirection: "column", width: capsuleHeight, paddingVertical: padding, gap, borderRadius: capsuleHeight / 2 }
|
|
153
211
|
: { height: capsuleHeight, paddingHorizontal: padding, gap, borderRadius: capsuleHeight / 2 },
|
|
154
212
|
showBackground ? { backgroundColor: onColor ? "rgba(255, 255, 255, 0.2)" : theme.color("--page-control-background") } : null,
|
|
155
|
-
], children: [sizes.map((size, index) =>
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
213
|
+
], children: [sizes.map((size, index) => {
|
|
214
|
+
if (size === "hidden")
|
|
215
|
+
return null;
|
|
216
|
+
const across = dotSize(size);
|
|
217
|
+
if (worm)
|
|
218
|
+
return _jsx(View, { style: { width: vertical ? across : dotWidth(size, index), height: vertical ? dotWidth(size, index) : across, borderRadius: dot / 2, backgroundColor: off } }, index);
|
|
219
|
+
// How much of the current page this mark is: 1 on its page, 0 a page away, a line between
|
|
220
|
+
const weight = position.interpolate(pageControlWeight(index));
|
|
221
|
+
const along = pill ? weight.interpolate({ inputRange: [0, 1], outputRange: [across, pillLength] }) : across;
|
|
222
|
+
return (_jsx(Animated.View, { testID: testID ? `${testID}-mark-${index}` : undefined, style: { width: vertical ? across : along, height: vertical ? along : across, borderRadius: dot / 2, backgroundColor: off }, children: _jsx(Animated.View, { style: [StyleSheet.absoluteFill, { borderRadius: dot / 2, backgroundColor: on, opacity: weight }] }) }, index));
|
|
223
|
+
}), worm ? _jsx(AndroidCurrent, { start: currentCenter - dot / 2, color: on, reduced: theme.reducedMotion, dot: dot, vertical: vertical }) : null] }) }));
|
|
161
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* The interpolation of a mark's share of the current page from the pages' position: 1 on its own page, 0 from a page
|
|
227
|
+
* away, a line between. Two neighbours share one page between them, so a pill's length moves from one to the other and
|
|
228
|
+
* the row keeps its length.
|
|
229
|
+
*/
|
|
230
|
+
export const pageControlWeight = (index) => ({ inputRange: [index - 1, index, index + 1], outputRange: [0, 1, 0], extrapolate: "clamp" });
|
|
231
|
+
/** A new `value` with no `position`: iOS's default UIView curve, Material's standard easing and its medium duration. */
|
|
232
|
+
const IOS_SLIDE = { duration: 250, easing: curves.easeInOut };
|
|
233
|
+
const ANDROID_SLIDE = { duration: 300, easing: Easing.bezier(0.2, 0, 0, 1) };
|
|
162
234
|
/** Android's page dots: 5dp, 11dp from one to the next. */
|
|
163
235
|
const ANDROID_DOT = 5;
|
|
164
236
|
const ANDROID_GAP = 6;
|
|
@@ -361,9 +361,9 @@ function ToastView({ item, theme, hidden, replaced = false }) {
|
|
|
361
361
|
const titleWeight = Platform.OS === "web" ? fontWeight(theme.token(described ? "--font-weight-semibold" : "--font-weight-medium")) : undefined;
|
|
362
362
|
return (_jsx(Animated.View, { ...responder.panHandlers, accessibilityRole: "alert", pointerEvents: touches,
|
|
363
363
|
// An offset, not a transform: a transform would stop the glass's blur on the web
|
|
364
|
-
style: [styles.iosWrap, { top: Animated.add(progress.interpolate({ inputRange: [0, 1], outputRange: [-24, 0] }), drag), display, opacity: glassOpacity(progress, !leaving) }], children: _jsxs(Glass, { radius: described ? 24 : 21.5, elevation: "raised", fillToken: "--toast-mobile-background", style: styles.iosToast, children: [icon != null && icon !== false ? _jsx(View, { style: styles.iosIcon, children: icon }) : null, _jsxs(View, { style: [styles.iosText, item.action ? { minWidth: 8 * 15 } : null], children: [_jsx(Text, { weight: described ? "semibold" : "medium", style: { fontSize: 15, lineHeight: 17, fontWeight: titleWeight }, children: item.title }), described ? (
|
|
365
|
-
|
|
366
|
-
|
|
364
|
+
style: [styles.iosWrap, { top: Animated.add(progress.interpolate({ inputRange: [0, 1], outputRange: [-24, 0] }), drag), display, opacity: glassOpacity(progress, !leaving) }], children: _jsxs(Glass, { radius: described ? 24 : 21.5, elevation: "raised", fillToken: "--toast-mobile-background", style: styles.iosToast, children: [_jsxs(View, { style: styles.iosMessage, children: [icon != null && icon !== false ? _jsx(View, { style: styles.iosIcon, children: icon }) : null, _jsxs(View, { style: [styles.iosText, item.action ? { minWidth: 8 * 15 } : null], children: [_jsx(Text, { weight: described ? "semibold" : "medium", style: { fontSize: 15, lineHeight: 17, fontWeight: titleWeight }, children: item.title }), described ? (
|
|
365
|
+
// The web toast's description is the opaque secondary gray, not the phone's 50% label
|
|
366
|
+
_jsx(Text, { color: theme.colors.textSecondary, style: { fontSize: 15, lineHeight: 18 }, children: item.description })) : null] })] }), item.action ? (_jsx(Pressable, { accessibilityRole: "button", disabled: leaving, onPress: act,
|
|
367
367
|
// A 34pt capsule in a 44pt target
|
|
368
368
|
hitSlop: 5, style: ({ pressed }) => [styles.iosAction, { backgroundColor: theme.color("--color-background-primary-solid"), opacity: pressed ? 0.7 : 1 }], children: _jsx(Text, { weight: "regular", color: theme.color("--color-text-primary-solid"), style: { fontSize: 15, lineHeight: 20 }, children: item.action.label }) })) : null] }) }));
|
|
369
369
|
}
|
|
@@ -378,6 +378,7 @@ const styles = StyleSheet.create({
|
|
|
378
378
|
// 12/14 of padding inside sonner's 1px border, transparent on a phone
|
|
379
379
|
iosToast: { flexDirection: "row", flexWrap: "wrap", alignItems: "center", gap: 10, paddingVertical: 13, paddingHorizontal: 15 },
|
|
380
380
|
iosIcon: { width: 16, height: 16, marginStart: -3, marginEnd: 4, justifyContent: "center", alignItems: "flex-start" },
|
|
381
|
+
iosMessage: { flexDirection: "row", alignItems: "center", gap: 10, flexShrink: 1, minWidth: 0 },
|
|
381
382
|
iosText: { flexShrink: 1, minWidth: 0 },
|
|
382
383
|
iosAction: { minHeight: 34, paddingVertical: 7, paddingHorizontal: 14, borderRadius: 9999, alignItems: "center", justifyContent: "center" },
|
|
383
384
|
// Android's toast card: a 16dp-cornered card at least 48 tall, the text 16 in (56 past a 24dp icon at 16)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type StyleProp, type ViewStyle } from "react-native";
|
|
1
|
+
import { Animated, type StyleProp, type ViewStyle } from "react-native";
|
|
2
2
|
export type PageControlDotSize = "full" | "small" | "smaller" | "hidden";
|
|
3
3
|
export type PageControlChangeDetails = {
|
|
4
4
|
/** The change came from scrubbing: show the page without the scrolling animation, as the HIG asks. */
|
|
@@ -11,6 +11,16 @@ export type PageControlProps = {
|
|
|
11
11
|
value?: number;
|
|
12
12
|
/** @default 0 */
|
|
13
13
|
defaultValue?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Where the pages stand as they scroll: the page index with its fraction (the scroll offset over the page's length),
|
|
16
|
+
* a number or an `Animated` value, so a pager's scroll drives the control on every frame without a render. The
|
|
17
|
+
* pill flows from one page's mark to the next and the dots' color crosses over with it, under the finger and then
|
|
18
|
+
* with the pager's own settle. Without it the control moves to a new `value` over a short standard transition (at
|
|
19
|
+
* once while scrubbing and with reduced motion). The current page for a screen reader, a tap and the keys stays
|
|
20
|
+
* `value`. An `Animated` value drives the marks' length, so it moves on the JavaScript driver
|
|
21
|
+
* (`Animated.event(…, { useNativeDriver: false })`), as the package's own animations do.
|
|
22
|
+
*/
|
|
23
|
+
position?: number | Animated.Value | Animated.AnimatedInterpolation<number>;
|
|
14
24
|
/** Called with the index of the next page. */
|
|
15
25
|
onChange?: (index: number, details: PageControlChangeDetails) => void;
|
|
16
26
|
/**
|
|
@@ -62,4 +72,14 @@ export declare const pageControlDots: (count: number, current: number) => PageCo
|
|
|
62
72
|
* page and back as it moves), in a 48dp target, with no capsule at all. For a screen reader it is adjustable: swipe
|
|
63
73
|
* up or down for the next or previous page.
|
|
64
74
|
*/
|
|
65
|
-
export declare function PageControl({ count, value: valueProp, defaultValue, onChange, background, indicator, tone, direction, size, valueText, "aria-label": ariaLabel, testID, style, }: PageControlProps): import("react").JSX.Element;
|
|
75
|
+
export declare function PageControl({ count, value: valueProp, defaultValue, position: positionProp, onChange, background, indicator, tone, direction, size, valueText, "aria-label": ariaLabel, testID, style, }: PageControlProps): import("react").JSX.Element;
|
|
76
|
+
/**
|
|
77
|
+
* The interpolation of a mark's share of the current page from the pages' position: 1 on its own page, 0 from a page
|
|
78
|
+
* away, a line between. Two neighbours share one page between them, so a pill's length moves from one to the other and
|
|
79
|
+
* the row keeps its length.
|
|
80
|
+
*/
|
|
81
|
+
export declare const pageControlWeight: (index: number) => {
|
|
82
|
+
inputRange: number[];
|
|
83
|
+
outputRange: number[];
|
|
84
|
+
extrapolate: "clamp";
|
|
85
|
+
};
|
package/package.json
CHANGED
|
@@ -62,12 +62,20 @@ export function BottomActions({ children, floating = false, background = "soft",
|
|
|
62
62
|
? { variant: "ghost" as const, color: props.color ?? ("secondary" as const) }
|
|
63
63
|
: { variant: "soft" as const, color: props.color ?? ("secondary" as const), mobileMaterial: props.mobileMaterial ?? ("glass" as const) }
|
|
64
64
|
: null
|
|
65
|
-
|
|
65
|
+
const button = cloneElement(child as ReactElement<ButtonProps>, {
|
|
66
66
|
...second,
|
|
67
67
|
block: props.block ?? true,
|
|
68
68
|
size: props.size ?? "3xl",
|
|
69
69
|
style: [{ minHeight: height, borderRadius: height / 2 }, props.style],
|
|
70
70
|
})
|
|
71
|
+
// A disabled button's fill is see-through (the gray of iOS's disabled button): floating over the content it stands
|
|
72
|
+
// on the screen's color, so the rows under it do not show through
|
|
73
|
+
if (!floating || !props.disabled || android) return button
|
|
74
|
+
return (
|
|
75
|
+
<View key={child.key ?? index} style={{ borderRadius: height / 2, backgroundColor: canvas, alignSelf: (props.block ?? true) ? "stretch" : "flex-start" }}>
|
|
76
|
+
{button}
|
|
77
|
+
</View>
|
|
78
|
+
)
|
|
71
79
|
})
|
|
72
80
|
return (
|
|
73
81
|
<View
|
|
@@ -230,6 +230,8 @@ export function BottomSheetBase({
|
|
|
230
230
|
const [drag] = useState(() => new Animated.Value(0))
|
|
231
231
|
const close = () => onOpenChange(false)
|
|
232
232
|
const android = theme.isAndroid
|
|
233
|
+
// Android's content and actions 12 from the sheet's sides, as a page's groups; a token for a screen at another gutter
|
|
234
|
+
const androidInline = theme.length("--bottom-sheet-android-padding-inline", 12)
|
|
233
235
|
const reduced = theme.reducedMotion
|
|
234
236
|
// One responder for the sheet's life, told the latest props after each render: a responder made again mid-drag
|
|
235
237
|
// would lose the drag
|
|
@@ -395,6 +397,8 @@ export function BottomSheetBase({
|
|
|
395
397
|
android
|
|
396
398
|
? [
|
|
397
399
|
styles.androidContent,
|
|
400
|
+
// A screen whose gutter is Material's compact 16 sets it with --bottom-sheet-android-padding-inline
|
|
401
|
+
{ paddingHorizontal: androidInline },
|
|
398
402
|
title != null ? styles.androidContentUnderBar : null,
|
|
399
403
|
// Over a footer: 8 above its height, which reaches over the sheet's bottom padding
|
|
400
404
|
footer ? { paddingBottom: 8 + Math.max(0, footerHeight - insets.bottom - keyboard) } : null,
|
|
@@ -417,6 +421,7 @@ export function BottomSheetBase({
|
|
|
417
421
|
android
|
|
418
422
|
? [
|
|
419
423
|
styles.androidFooter,
|
|
424
|
+
{ paddingHorizontal: androidInline },
|
|
420
425
|
// Over the sheet's color at 80%, faded in over its top 24dp, down over the gesture bar
|
|
421
426
|
{ paddingBottom: 12 + insets.bottom + keyboard, backgroundImage: `linear-gradient(to bottom, ${withAlpha(background, 0)}, ${withAlpha(background, 0.8)} 24px)` } as ViewStyle,
|
|
422
427
|
]
|
|
@@ -130,6 +130,8 @@ export function List({
|
|
|
130
130
|
.map((row) => (row.type === Button ? <ActionRow key={row.key ?? undefined}>{row}</ActionRow> : row))
|
|
131
131
|
const options = useMemo(() => ({ columns }), [columns])
|
|
132
132
|
const increased = headerProminence === "increased"
|
|
133
|
+
// Android's footer 13 into the card's width, as the Settings app; a token for a screen that keeps text at its gutter
|
|
134
|
+
const footerInset = theme.length("--list-android-footer-inset", 13)
|
|
133
135
|
const fill = surface === "plain" ? theme.color("--field-group-background", theme.colors.surfaceSecondary) : theme.colors.groupedSurface
|
|
134
136
|
// The card's corners: Android's 16dp card (a header or description inside it stands over the first row), iOS's group
|
|
135
137
|
const corner = surface === "plain" && theme.isAndroid ? 0 : theme.isAndroid ? ANDROID_CARD_RADIUS : theme.length("--field-group-radius", 26)
|
|
@@ -196,11 +198,11 @@ export function List({
|
|
|
196
198
|
</View>
|
|
197
199
|
</View>
|
|
198
200
|
{error != null ? (
|
|
199
|
-
<Text color={dangerText(theme)} accessibilityLiveRegion="polite" style={[styles.androidFooter, plain ? [styles.androidFooterPlain, { backgroundColor: band }] : null]}>
|
|
201
|
+
<Text color={dangerText(theme)} accessibilityLiveRegion="polite" style={[styles.androidFooter, { paddingHorizontal: footerInset }, plain ? [styles.androidFooterPlain, { backgroundColor: band }] : null]}>
|
|
200
202
|
{error}
|
|
201
203
|
</Text>
|
|
202
204
|
) : footer != null ? (
|
|
203
|
-
<Text color={theme.colors.labelSecondary} style={[styles.androidFooter, plain ? [styles.androidFooterPlain, { backgroundColor: band }] : null]}>
|
|
205
|
+
<Text color={theme.colors.labelSecondary} style={[styles.androidFooter, { paddingHorizontal: footerInset }, plain ? [styles.androidFooterPlain, { backgroundColor: band }] : null]}>
|
|
204
206
|
{footer}
|
|
205
207
|
</Text>
|
|
206
208
|
) : null}
|
|
@@ -801,6 +803,9 @@ function IOSContent({ handPress, valueColor, theme, label, description, descript
|
|
|
801
803
|
)
|
|
802
804
|
// A field at the end fills the room after the label (`RowEnd.fill`)
|
|
803
805
|
const [fill, setFill] = useState(false)
|
|
806
|
+
// A picture wider than the tile (a photo, an avatar) keeps its own size: it starts at the row's inset, where the
|
|
807
|
+
// header and the footer stand, and the text follows 14 past it, as UIKit's image to text padding
|
|
808
|
+
const [wide, setWide] = useState(false)
|
|
804
809
|
// In a List with `columns` a field's value starts at one column, 40% into the row (`--field-row-column-width`)
|
|
805
810
|
// A switch, a checkbox and a radio stay at the row's edge
|
|
806
811
|
const columns = useContext(ListOptionsContext)?.columns === true && trailing != null
|
|
@@ -822,9 +827,13 @@ function IOSContent({ handPress, valueColor, theme, label, description, descript
|
|
|
822
827
|
<View
|
|
823
828
|
style={[
|
|
824
829
|
styles.tile,
|
|
825
|
-
{
|
|
830
|
+
{ minWidth: tile, minHeight: tile, marginStart: wide ? 0 : theme.length("--field-row-icon-offset", -2), marginEnd: theme.length("--field-row-icon-gap", 14) },
|
|
826
831
|
leadingColor ? { backgroundColor: leadingColor, borderRadius: theme.length("--field-row-icon-radius", 7) } : null,
|
|
827
832
|
]}
|
|
833
|
+
onLayout={(event) => {
|
|
834
|
+
const next = event.nativeEvent.layout.width > tile + 0.5
|
|
835
|
+
if (next !== wide) setWide(next)
|
|
836
|
+
}}
|
|
828
837
|
>
|
|
829
838
|
<IconDefaultsProvider size={leadingColor ? 20 : theme.length("--field-row-icon-symbol-size", 24)} color={leadingColor ? "#ffffff" : disabled ? theme.colors.labelTertiary : theme.colors.accent}>
|
|
830
839
|
{leading}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from "react"
|
|
2
|
-
import { Animated, Platform, StyleSheet, View, type AccessibilityActionEvent, type GestureResponderEvent, type StyleProp, type ViewStyle } from "react-native"
|
|
2
|
+
import { Animated, Easing, Platform, StyleSheet, View, type AccessibilityActionEvent, type GestureResponderEvent, type StyleProp, type ViewStyle } from "react-native"
|
|
3
3
|
import { isRTL } from "../../internal/direction"
|
|
4
4
|
import { curves } from "../../internal/motion"
|
|
5
5
|
import { useTheme } from "../../theme/ThemeProvider"
|
|
@@ -18,6 +18,16 @@ export type PageControlProps = {
|
|
|
18
18
|
value?: number
|
|
19
19
|
/** @default 0 */
|
|
20
20
|
defaultValue?: number
|
|
21
|
+
/**
|
|
22
|
+
* Where the pages stand as they scroll: the page index with its fraction (the scroll offset over the page's length),
|
|
23
|
+
* a number or an `Animated` value, so a pager's scroll drives the control on every frame without a render. The
|
|
24
|
+
* pill flows from one page's mark to the next and the dots' color crosses over with it, under the finger and then
|
|
25
|
+
* with the pager's own settle. Without it the control moves to a new `value` over a short standard transition (at
|
|
26
|
+
* once while scrubbing and with reduced motion). The current page for a screen reader, a tap and the keys stays
|
|
27
|
+
* `value`. An `Animated` value drives the marks' length, so it moves on the JavaScript driver
|
|
28
|
+
* (`Animated.event(…, { useNativeDriver: false })`), as the package's own animations do.
|
|
29
|
+
*/
|
|
30
|
+
position?: number | Animated.Value | Animated.AnimatedInterpolation<number>
|
|
21
31
|
/** Called with the index of the next page. */
|
|
22
32
|
onChange?: (index: number, details: PageControlChangeDetails) => void
|
|
23
33
|
/**
|
|
@@ -105,6 +115,7 @@ export function PageControl({
|
|
|
105
115
|
count,
|
|
106
116
|
value: valueProp,
|
|
107
117
|
defaultValue = 0,
|
|
118
|
+
position: positionProp,
|
|
108
119
|
onChange,
|
|
109
120
|
background = "automatic",
|
|
110
121
|
indicator = "dots",
|
|
@@ -122,9 +133,62 @@ export function PageControl({
|
|
|
122
133
|
const [press, setPress] = useState<Press | null>(null)
|
|
123
134
|
// Where the dots stand inside the target, which can be wider than them (x is physical, from the left)
|
|
124
135
|
const [capsule, setCapsule] = useState({ x: 0, width: 0 })
|
|
136
|
+
// The fractional page the marks follow: the app's own `position`, or one that moves to `value` by itself
|
|
137
|
+
const [ownPosition] = useState(() => new Animated.Value(typeof positionProp === "number" ? positionProp : current))
|
|
138
|
+
const driven = positionProp != null && typeof positionProp === "object"
|
|
139
|
+
const scrubbed = useRef(false)
|
|
140
|
+
const shown = useRef<number | null>(null)
|
|
141
|
+
// The page nearest the position: the dots' window from seven pages follows it, so the marks it passes stay drawn
|
|
142
|
+
const [near, setNear] = useState(current)
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
if (typeof positionProp === "number") {
|
|
145
|
+
ownPosition.setValue(positionProp)
|
|
146
|
+
return
|
|
147
|
+
}
|
|
148
|
+
const source = driven ? (positionProp as Animated.Value) : ownPosition
|
|
149
|
+
const follow = (value: number) => {
|
|
150
|
+
// The own position keeps up with an app's, so it moves on from there when the app's goes
|
|
151
|
+
if (driven) ownPosition.setValue(value)
|
|
152
|
+
const page = clampIndex(Math.round(value), count)
|
|
153
|
+
setNear((last) => (last === page ? last : page))
|
|
154
|
+
}
|
|
155
|
+
const id = source.addListener(({ value }) => follow(value))
|
|
156
|
+
// A listener hears only what comes next: a new source's value now sets the window at once
|
|
157
|
+
const read = () => (source as unknown as { __getValue?: () => number }).__getValue?.()
|
|
158
|
+
let live = true
|
|
159
|
+
void Promise.resolve().then(() => {
|
|
160
|
+
// Read as it runs, so a change in between is not undone
|
|
161
|
+
const now = read()
|
|
162
|
+
if (live && typeof now === "number") follow(now)
|
|
163
|
+
})
|
|
164
|
+
return () => {
|
|
165
|
+
live = false
|
|
166
|
+
source.removeListener(id)
|
|
167
|
+
}
|
|
168
|
+
}, [positionProp, driven, ownPosition, count])
|
|
169
|
+
useEffect(() => {
|
|
170
|
+
if (positionProp != null) return
|
|
171
|
+
const still = shown.current == null || theme.reducedMotion || scrubbed.current
|
|
172
|
+
shown.current = current
|
|
173
|
+
scrubbed.current = false
|
|
174
|
+
if (still) {
|
|
175
|
+
ownPosition.setValue(current)
|
|
176
|
+
return
|
|
177
|
+
}
|
|
178
|
+
const animation = Animated.timing(ownPosition, { toValue: current, ...(theme.isAndroid ? ANDROID_SLIDE : IOS_SLIDE), useNativeDriver: false })
|
|
179
|
+
animation.start()
|
|
180
|
+
return () => animation.stop()
|
|
181
|
+
}, [current, positionProp, ownPosition, theme.reducedMotion, theme.isAndroid])
|
|
182
|
+
// An overscroll past the first or the last page stands on it, so its mark keeps the whole pill
|
|
183
|
+
const position = (driven ? (positionProp as Animated.Value) : ownPosition).interpolate({
|
|
184
|
+
inputRange: [0, Math.max(1, count - 1)],
|
|
185
|
+
outputRange: [0, Math.max(0, count - 1)],
|
|
186
|
+
extrapolate: "clamp",
|
|
187
|
+
})
|
|
125
188
|
const go = (index: number, scrubbing = false) => {
|
|
126
189
|
const next = clampIndex(index, count)
|
|
127
190
|
if (next === current) return
|
|
191
|
+
scrubbed.current = scrubbing
|
|
128
192
|
if (valueProp === undefined) setOwn(next)
|
|
129
193
|
onChange?.(next, { scrubbing })
|
|
130
194
|
}
|
|
@@ -136,7 +200,7 @@ export function PageControl({
|
|
|
136
200
|
const padding = small ? 6 : theme.length("--page-control-padding-inline", 12)
|
|
137
201
|
const pitch = dot + gap
|
|
138
202
|
// Android draws every page's dot at full size; the iOS kit shrinks the ends from seven pages
|
|
139
|
-
const sizes = android ? Array.from({ length: Math.max(0, count) }, (): PageControlDotSize => "full") : pageControlDots(count,
|
|
203
|
+
const sizes = android ? Array.from({ length: Math.max(0, count) }, (): PageControlDotSize => "full") : pageControlDots(count, clampIndex(typeof positionProp === "number" ? Math.round(positionProp) : near, count))
|
|
140
204
|
// The small and smaller ends keep their share of a full dot (6 and 4 of 8 on iOS)
|
|
141
205
|
const dotSize = (kind: PageControlDotSize) =>
|
|
142
206
|
kind === "full"
|
|
@@ -145,8 +209,9 @@ export function PageControl({
|
|
|
145
209
|
? Math.max(2, dot - (kind === "small" ? 1 : 2))
|
|
146
210
|
: (dot / 8) * (kind === "small" ? theme.length("--page-control-dot-size-small", 6) : theme.length("--page-control-dot-size-smaller", 4))
|
|
147
211
|
const pill = indicator === "pill"
|
|
148
|
-
// A pill: the current page two and a half dots long (
|
|
149
|
-
const
|
|
212
|
+
// A pill: the current page two and a half dots long (14 at `sm`), along the direction
|
|
213
|
+
const pillLength = small ? 14 : dot * 2.5
|
|
214
|
+
const dotWidth = (kind: PageControlDotSize, index: number) => (pill && index === current ? pillLength : dotSize(kind))
|
|
150
215
|
// The center of the current dot, for a tap on either side of it
|
|
151
216
|
let x = padding
|
|
152
217
|
let currentCenter = padding
|
|
@@ -159,8 +224,9 @@ export function PageControl({
|
|
|
159
224
|
const on = onColor ? "#FFFFFF" : android ? theme.material.primary : theme.color("--page-control-dot-color-current", theme.colors.text)
|
|
160
225
|
// Android's page dots: #BBBBBB, #555555 in a dark theme
|
|
161
226
|
const off = onColor ? "rgba(255, 255, 255, 0.4)" : android ? (theme.scheme === "dark" ? "#555555" : "#BBBBBB") : theme.color("--page-control-dot-color", theme.colors.labelTertiary)
|
|
162
|
-
// Android's current dot is drawn over the gray ones (it stretches between pages)
|
|
163
|
-
|
|
227
|
+
// Android's current dot is drawn over the gray ones (it stretches between pages) unless the pages' scroll drives the
|
|
228
|
+
// dots, when their color crosses over as on iOS; a pill is a dot of its own
|
|
229
|
+
const worm = android && !pill && positionProp == null
|
|
164
230
|
// Android draws no capsule, not even for `prominent`
|
|
165
231
|
const capsuleHeight = small ? 16 : theme.length("--page-control-height", 24)
|
|
166
232
|
const target = android ? 48 : theme.length("--page-control-target-size", 44)
|
|
@@ -242,25 +308,40 @@ export function PageControl({
|
|
|
242
308
|
showBackground ? { backgroundColor: onColor ? "rgba(255, 255, 255, 0.2)" : theme.color("--page-control-background") } : null,
|
|
243
309
|
]}
|
|
244
310
|
>
|
|
245
|
-
{sizes.map((size, index) =>
|
|
246
|
-
size === "hidden"
|
|
247
|
-
|
|
311
|
+
{sizes.map((size, index) => {
|
|
312
|
+
if (size === "hidden") return null
|
|
313
|
+
const across = dotSize(size)
|
|
314
|
+
if (worm) return <View key={index} style={{ width: vertical ? across : dotWidth(size, index), height: vertical ? dotWidth(size, index) : across, borderRadius: dot / 2, backgroundColor: off }} />
|
|
315
|
+
// How much of the current page this mark is: 1 on its page, 0 a page away, a line between
|
|
316
|
+
const weight = position.interpolate(pageControlWeight(index))
|
|
317
|
+
const along = pill ? weight.interpolate({ inputRange: [0, 1], outputRange: [across, pillLength] }) : across
|
|
318
|
+
return (
|
|
319
|
+
<Animated.View
|
|
248
320
|
key={index}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
),
|
|
257
|
-
)}
|
|
321
|
+
testID={testID ? `${testID}-mark-${index}` : undefined}
|
|
322
|
+
style={{ width: vertical ? across : along, height: vertical ? along : across, borderRadius: dot / 2, backgroundColor: off }}
|
|
323
|
+
>
|
|
324
|
+
<Animated.View style={[StyleSheet.absoluteFill, { borderRadius: dot / 2, backgroundColor: on, opacity: weight }]} />
|
|
325
|
+
</Animated.View>
|
|
326
|
+
)
|
|
327
|
+
})}
|
|
258
328
|
{worm ? <AndroidCurrent start={currentCenter - dot / 2} color={on} reduced={theme.reducedMotion} dot={dot} vertical={vertical} /> : null}
|
|
259
329
|
</View>
|
|
260
330
|
</View>
|
|
261
331
|
)
|
|
262
332
|
}
|
|
263
333
|
|
|
334
|
+
/**
|
|
335
|
+
* The interpolation of a mark's share of the current page from the pages' position: 1 on its own page, 0 from a page
|
|
336
|
+
* away, a line between. Two neighbours share one page between them, so a pill's length moves from one to the other and
|
|
337
|
+
* the row keeps its length.
|
|
338
|
+
*/
|
|
339
|
+
export const pageControlWeight = (index: number) => ({ inputRange: [index - 1, index, index + 1], outputRange: [0, 1, 0], extrapolate: "clamp" as const })
|
|
340
|
+
|
|
341
|
+
/** A new `value` with no `position`: iOS's default UIView curve, Material's standard easing and its medium duration. */
|
|
342
|
+
const IOS_SLIDE = { duration: 250, easing: curves.easeInOut }
|
|
343
|
+
const ANDROID_SLIDE = { duration: 300, easing: Easing.bezier(0.2, 0, 0, 1) }
|
|
344
|
+
|
|
264
345
|
/** Android's page dots: 5dp, 11dp from one to the next. */
|
|
265
346
|
const ANDROID_DOT = 5
|
|
266
347
|
const ANDROID_GAP = 6
|
|
@@ -460,9 +460,12 @@ function ToastView({ item, theme, hidden, replaced = false }: { item: ToastT; th
|
|
|
460
460
|
<Glass radius={described ? 24 : 21.5} elevation="raised" fillToken="--toast-mobile-background" style={styles.iosToast}>
|
|
461
461
|
{/* sonner's 16pt icon box, 3 into the padding and 4 before the gap, holds the 20pt symbol over its edges: the
|
|
462
462
|
message starts 42 from the toast's edge, and a line of text alone keeps the toast 43 high */}
|
|
463
|
-
{
|
|
464
|
-
|
|
465
|
-
<View style={
|
|
463
|
+
{/* The symbol and the message are one piece of the row, so a long message wraps its own lines beside the
|
|
464
|
+
symbol, as the web's; only a button wraps, under them */}
|
|
465
|
+
<View style={styles.iosMessage}>
|
|
466
|
+
{icon != null && icon !== false ? <View style={styles.iosIcon}>{icon}</View> : null}
|
|
467
|
+
{/* Beside a button the message keeps 8em, and a button that would leave it less wraps under it */}
|
|
468
|
+
<View style={[styles.iosText, item.action ? { minWidth: 8 * 15 } : null]}>
|
|
466
469
|
<Text weight={described ? "semibold" : "medium"} style={{ fontSize: 15, lineHeight: 17, fontWeight: titleWeight }}>
|
|
467
470
|
{item.title}
|
|
468
471
|
</Text>
|
|
@@ -472,6 +475,7 @@ function ToastView({ item, theme, hidden, replaced = false }: { item: ToastT; th
|
|
|
472
475
|
{item.description}
|
|
473
476
|
</Text>
|
|
474
477
|
) : null}
|
|
478
|
+
</View>
|
|
475
479
|
</View>
|
|
476
480
|
{item.action ? (
|
|
477
481
|
<Pressable
|
|
@@ -504,6 +508,7 @@ const styles = StyleSheet.create({
|
|
|
504
508
|
// 12/14 of padding inside sonner's 1px border, transparent on a phone
|
|
505
509
|
iosToast: { flexDirection: "row", flexWrap: "wrap", alignItems: "center", gap: 10, paddingVertical: 13, paddingHorizontal: 15 },
|
|
506
510
|
iosIcon: { width: 16, height: 16, marginStart: -3, marginEnd: 4, justifyContent: "center", alignItems: "flex-start" },
|
|
511
|
+
iosMessage: { flexDirection: "row", alignItems: "center", gap: 10, flexShrink: 1, minWidth: 0 },
|
|
507
512
|
iosText: { flexShrink: 1, minWidth: 0 },
|
|
508
513
|
iosAction: { minHeight: 34, paddingVertical: 7, paddingHorizontal: 14, borderRadius: 9999, alignItems: "center", justifyContent: "center" },
|
|
509
514
|
// Android's toast card: a 16dp-cornered card at least 48 tall, the text 16 in (56 past a 24dp icon at 16)
|