@plexui/react-native 0.1.1 → 0.2.1
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/README.md +34 -0
- package/dist/es/components/ActionSheet/ActionSheet.js +67 -19
- package/dist/es/components/Alert/Alert.js +163 -0
- package/dist/es/components/Avatar/Avatar.js +20 -8
- package/dist/es/components/BottomActions/BottomActions.js +34 -0
- package/dist/es/components/BottomSheet/BottomSheet.js +85 -17
- package/dist/es/components/Button/Button.js +108 -28
- package/dist/es/components/Card/Card.js +16 -8
- package/dist/es/components/Checkbox/Checkbox.js +67 -99
- package/dist/es/components/Chip/Chip.js +39 -19
- package/dist/es/components/Dialog/Dialog.js +38 -24
- package/dist/es/components/Field/Field.js +91 -0
- package/dist/es/components/FloatingLabelInput/FloatingLabelInput.js +59 -0
- package/dist/es/components/Icon/createIcon.js +13 -2
- package/dist/es/components/Indicator/CircularProgress.js +80 -0
- package/dist/es/components/Indicator/LoadingDots.js +46 -0
- package/dist/es/components/Indicator/LoadingIndicator.js +101 -0
- package/dist/es/components/Indicator/index.js +3 -0
- package/dist/es/components/Input/Input.js +69 -60
- package/dist/es/components/InputGroup/InputGroup.js +130 -0
- package/dist/es/components/List/List.js +175 -59
- package/dist/es/components/Menu/Menu.js +69 -40
- package/dist/es/components/NavigationButton/NavigationButton.js +20 -4
- package/dist/es/components/OTPInput/OTPInput.js +9 -3
- package/dist/es/components/PageControl/PageControl.js +13 -7
- package/dist/es/components/Popover/Popover.js +128 -0
- package/dist/es/components/Progress/Progress.js +142 -0
- package/dist/es/components/ProgressSteps/ProgressSteps.js +207 -0
- package/dist/es/components/RollingNumber/RollingNumber.js +125 -0
- package/dist/es/components/Select/Select.js +97 -34
- package/dist/es/components/Separator/Separator.js +31 -0
- package/dist/es/components/ShimmerText/ShimmerText.js +98 -0
- package/dist/es/components/Stepper/Stepper.js +219 -0
- package/dist/es/components/Switch/Switch.js +26 -12
- package/dist/es/components/TagInput/TagInput.js +121 -0
- package/dist/es/components/Text/Text.js +7 -4
- package/dist/es/components/TextLink/TextLink.js +42 -0
- package/dist/es/components/Textarea/Textarea.js +12 -0
- package/dist/es/components/Tip/Tip.js +193 -0
- package/dist/es/components/Toolbar/Toolbar.js +6 -2
- package/dist/es/components/Tooltip/Tooltip.js +272 -0
- package/dist/es/index.js +20 -2
- package/dist/es/internal/FloatingPanel.js +111 -0
- package/dist/es/internal/fieldStack.js +73 -0
- package/dist/es/internal/floating.js +97 -0
- package/dist/es/internal/ripple.js +119 -0
- package/dist/es/internal/row.js +2 -1
- package/dist/es/internal/transition.js +113 -0
- package/dist/es/theme/ThemeProvider.js +41 -9
- package/dist/es/theme/material.js +37 -7
- package/dist/types/components/ActionSheet/ActionSheet.d.ts +15 -7
- package/dist/types/components/Alert/Alert.d.ts +51 -0
- package/dist/types/components/Avatar/Avatar.d.ts +4 -2
- package/dist/types/components/BottomActions/BottomActions.d.ts +18 -0
- package/dist/types/components/BottomSheet/BottomSheet.d.ts +4 -2
- package/dist/types/components/Button/Button.d.ts +20 -5
- package/dist/types/components/Card/Card.d.ts +14 -1
- package/dist/types/components/Checkbox/Checkbox.d.ts +4 -3
- package/dist/types/components/Chip/Chip.d.ts +23 -4
- package/dist/types/components/Dialog/Dialog.d.ts +9 -5
- package/dist/types/components/Field/Field.d.ts +64 -0
- package/dist/types/components/FloatingLabelInput/FloatingLabelInput.d.ts +42 -0
- package/dist/types/components/Indicator/CircularProgress.d.ts +34 -0
- package/dist/types/components/Indicator/LoadingDots.d.ts +17 -0
- package/dist/types/components/Indicator/LoadingIndicator.d.ts +46 -0
- package/dist/types/components/Indicator/index.d.ts +3 -0
- package/dist/types/components/Input/Input.d.ts +13 -3
- package/dist/types/components/InputGroup/InputGroup.d.ts +71 -0
- package/dist/types/components/List/List.d.ts +57 -14
- package/dist/types/components/Menu/Menu.d.ts +4 -0
- package/dist/types/components/NavigationButton/NavigationButton.d.ts +11 -3
- package/dist/types/components/OTPInput/OTPInput.d.ts +10 -1
- package/dist/types/components/PageControl/PageControl.d.ts +11 -1
- package/dist/types/components/Popover/Popover.d.ts +86 -0
- package/dist/types/components/Progress/Progress.d.ts +56 -0
- package/dist/types/components/ProgressSteps/ProgressSteps.d.ts +61 -0
- package/dist/types/components/RollingNumber/RollingNumber.d.ts +36 -0
- package/dist/types/components/Select/Select.d.ts +36 -8
- package/dist/types/components/Separator/Separator.d.ts +19 -0
- package/dist/types/components/ShimmerText/ShimmerText.d.ts +28 -0
- package/dist/types/components/Stepper/Stepper.d.ts +61 -0
- package/dist/types/components/Switch/Switch.d.ts +5 -5
- package/dist/types/components/TagInput/TagInput.d.ts +44 -0
- package/dist/types/components/TextLink/TextLink.d.ts +30 -0
- package/dist/types/components/Textarea/Textarea.d.ts +19 -0
- package/dist/types/components/Tip/Tip.d.ts +71 -0
- package/dist/types/components/Toolbar/Toolbar.d.ts +9 -1
- package/dist/types/components/Tooltip/Tooltip.d.ts +84 -0
- package/dist/types/index.d.ts +20 -2
- package/dist/types/internal/FloatingPanel.d.ts +70 -0
- package/dist/types/internal/fieldStack.d.ts +48 -0
- package/dist/types/internal/floating.d.ts +71 -0
- package/dist/types/internal/ripple.d.ts +17 -0
- package/dist/types/internal/row.d.ts +15 -3
- package/dist/types/internal/transition.d.ts +37 -0
- package/dist/types/theme/ThemeProvider.d.ts +28 -4
- package/dist/types/theme/material.d.ts +20 -6
- package/dist/types/theme/types.d.ts +8 -0
- package/package.json +2 -2
- package/src/components/ActionSheet/ActionSheet.tsx +123 -38
- package/src/components/Alert/Alert.tsx +279 -0
- package/src/components/Avatar/Avatar.tsx +21 -9
- package/src/components/BottomActions/BottomActions.tsx +54 -0
- package/src/components/BottomSheet/BottomSheet.tsx +111 -25
- package/src/components/Button/Button.tsx +170 -35
- package/src/components/Card/Card.tsx +33 -9
- package/src/components/Checkbox/Checkbox.tsx +89 -124
- package/src/components/Chip/Chip.tsx +83 -20
- package/src/components/Dialog/Dialog.tsx +68 -37
- package/src/components/Field/Field.tsx +227 -0
- package/src/components/FloatingLabelInput/FloatingLabelInput.tsx +144 -0
- package/src/components/Icon/createIcon.tsx +16 -6
- package/src/components/Indicator/CircularProgress.tsx +141 -0
- package/src/components/Indicator/LoadingDots.tsx +79 -0
- package/src/components/Indicator/LoadingIndicator.tsx +166 -0
- package/src/components/Indicator/index.ts +3 -0
- package/src/components/Input/Input.tsx +126 -97
- package/src/components/InputGroup/InputGroup.tsx +261 -0
- package/src/components/List/List.tsx +345 -88
- package/src/components/Menu/Menu.tsx +83 -41
- package/src/components/NavigationButton/NavigationButton.tsx +35 -5
- package/src/components/OTPInput/OTPInput.tsx +21 -2
- package/src/components/PageControl/PageControl.tsx +36 -8
- package/src/components/Popover/Popover.tsx +261 -0
- package/src/components/Progress/Progress.tsx +255 -0
- package/src/components/ProgressSteps/ProgressSteps.tsx +415 -0
- package/src/components/RollingNumber/RollingNumber.tsx +189 -0
- package/src/components/Select/Select.tsx +175 -71
- package/src/components/Separator/Separator.tsx +51 -0
- package/src/components/ShimmerText/ShimmerText.tsx +144 -0
- package/src/components/Stepper/Stepper.tsx +386 -0
- package/src/components/Switch/Switch.tsx +26 -12
- package/src/components/TagInput/TagInput.tsx +227 -0
- package/src/components/Text/Text.tsx +8 -4
- package/src/components/TextLink/TextLink.tsx +77 -0
- package/src/components/Textarea/Textarea.tsx +23 -0
- package/src/components/Tip/Tip.tsx +410 -0
- package/src/components/Toolbar/Toolbar.tsx +27 -2
- package/src/components/Tooltip/Tooltip.tsx +478 -0
- package/src/index.ts +36 -2
- package/src/internal/FloatingPanel.tsx +199 -0
- package/src/internal/fieldStack.tsx +179 -0
- package/src/internal/floating.ts +131 -0
- package/src/internal/ripple.tsx +132 -0
- package/src/internal/row.ts +16 -3
- package/src/internal/transition.ts +124 -0
- package/src/theme/ThemeProvider.tsx +65 -15
- package/src/theme/material.ts +39 -7
- package/src/theme/types.ts +8 -0
|
@@ -5,8 +5,9 @@ import Svg, { Circle } from "react-native-svg";
|
|
|
5
5
|
import { flattenChildren } from "../../internal/children";
|
|
6
6
|
import { Glass } from "../../internal/Glass";
|
|
7
7
|
import { useAndroidGlass } from "../../internal/BarBackdrop";
|
|
8
|
+
import { useRipple } from "../../internal/ripple";
|
|
8
9
|
import { curves } from "../../internal/motion";
|
|
9
|
-
import { barShadow, stateLayer, withAlpha } from "../../theme/material";
|
|
10
|
+
import { accentText, barShadow, controlHighlight, dangerText, stateLayer, withAlpha } from "../../theme/material";
|
|
10
11
|
import { useTheme } from "../../theme/ThemeProvider";
|
|
11
12
|
import { IconDefaultsProvider } from "../Icon/createIcon";
|
|
12
13
|
import { Text, TextColorProvider } from "../Text/Text";
|
|
@@ -17,6 +18,7 @@ export const BarItemContext = createContext(null);
|
|
|
17
18
|
* search field. Null outside a bar.
|
|
18
19
|
*/
|
|
19
20
|
export const BarFieldContext = createContext(null);
|
|
21
|
+
export const ListActionContext = createContext(null);
|
|
20
22
|
/** The control icon size a button size falls back to (Button.module.css). */
|
|
21
23
|
const CONTROL_ICON = { "3xs": "xs", "2xs": "sm", xs: "sm", sm: "md", md: "md", lg: "md", xl: "md", "2xl": "lg", "3xl": "lg" };
|
|
22
24
|
/**
|
|
@@ -26,16 +28,16 @@ const CONTROL_ICON = { "3xs": "xs", "2xs": "sm", xs: "sm", sm: "md", md: "md", l
|
|
|
26
28
|
const ANDROID_SIZE = (size) => (["3xs", "2xs", "xs", "sm"].includes(size) ? "XS" : size === "md" || size === "lg" ? "S" : "M");
|
|
27
29
|
export function buttonMetrics(theme, size, shape = "round", uniform = false) {
|
|
28
30
|
if (theme.isAndroid) {
|
|
29
|
-
// Android's buttons: the big one 48dp with a
|
|
30
|
-
// corners (square); the steps under it keep the
|
|
31
|
-
//
|
|
31
|
+
// Android's buttons: the big one 48dp with a 15 Medium label, a pill in the redesigned screens (round) or 8dp
|
|
32
|
+
// corners (square); the steps under it keep the shape and a 14 label. No shape morphs on a press or a selection,
|
|
33
|
+
// as the Android look has none
|
|
32
34
|
const step = ANDROID_SIZE(size);
|
|
33
35
|
const height = step === "XS" ? 32 : step === "S" ? 40 : 48;
|
|
34
36
|
const corner = shape === "round" ? height / 2 : step === "XS" ? 6 : 8;
|
|
35
37
|
return {
|
|
36
38
|
height,
|
|
37
39
|
gutter: step === "XS" ? 12 : step === "S" ? 16 : 20,
|
|
38
|
-
fontSize: 14,
|
|
40
|
+
fontSize: step === "M" ? 15 : 14,
|
|
39
41
|
lineHeight: 20,
|
|
40
42
|
iconSize: uniform ? (step === "XS" ? 18 : step === "S" ? 20 : 24) : step === "XS" ? 16 : 20,
|
|
41
43
|
gap: step === "XS" ? 4 : 6,
|
|
@@ -88,11 +90,11 @@ export function buttonColors(theme, color, variant, disabled, selected, uniform
|
|
|
88
90
|
}
|
|
89
91
|
// The phone CSS: the tertiary label in every style (iOS 27's disabled content-area button), the fill of a gray
|
|
90
92
|
// button behind a solid or soft one
|
|
93
|
+
// An outline button is iOS's Gray (below): disabled, the gray fill as the others
|
|
91
94
|
return {
|
|
92
|
-
background: variant === "
|
|
95
|
+
background: variant === "ghost" ? "transparent" : theme.color("--button-mobile-disabled-background"),
|
|
93
96
|
pressed: "transparent",
|
|
94
97
|
text: theme.colors.labelTertiary,
|
|
95
|
-
border: variant === "outline" ? theme.colors.border : undefined,
|
|
96
98
|
};
|
|
97
99
|
}
|
|
98
100
|
const colors = (() => {
|
|
@@ -104,6 +106,15 @@ export function buttonColors(theme, color, variant, disabled, selected, uniform
|
|
|
104
106
|
? { background: c(`background-${color}-solid`), pressed: c(`background-${color}-solid-active`), text: c(`text-${color}-solid`) }
|
|
105
107
|
: { background: c(`background-${color}-soft`), pressed: c(`background-${color}-soft-active`), text: c(`text-${color}-soft`) };
|
|
106
108
|
case "outline":
|
|
109
|
+
// iOS has no outlined button: its styles are Filled, Tinted, Gray and Plain. An outline button is the Gray
|
|
110
|
+
// one there, the neutral soft fill with the label in the button's color
|
|
111
|
+
if (theme.isIOS) {
|
|
112
|
+
return {
|
|
113
|
+
background: selected ? c(`background-${color}-outline-active`) : c("background-secondary-soft"),
|
|
114
|
+
pressed: c("background-secondary-soft-active"),
|
|
115
|
+
text: c(`text-${color}-outline`),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
107
118
|
return {
|
|
108
119
|
background: selected ? c(`background-${color}-outline-active`) : "transparent",
|
|
109
120
|
pressed: c(`background-${color}-outline-active`),
|
|
@@ -241,9 +252,74 @@ function renderChildren(children, metrics) {
|
|
|
241
252
|
/**
|
|
242
253
|
* A button after the platform: an iOS 26 capsule (the native sizes of the Plex UI phone layer, its colors and glass)
|
|
243
254
|
* or the Android button (a pill, 14 Medium, the Plex colors; a disabled one keeps its fill and dims its label to
|
|
244
|
-
* half). Props follow @plexui/ui.
|
|
255
|
+
* half). Props follow @plexui/ui. A ghost Button in a List's header or among its rows is drawn as the list's text action
|
|
256
|
+
* (`ListActionContext`).
|
|
245
257
|
*/
|
|
246
|
-
export function Button(
|
|
258
|
+
export function Button(props) {
|
|
259
|
+
const list = useContext(ListActionContext);
|
|
260
|
+
const bar = useContext(BarItemContext);
|
|
261
|
+
if (list != null && bar == null && props.variant === "ghost")
|
|
262
|
+
return _jsx(ListActionButton, { ...props, place: list });
|
|
263
|
+
return _jsx(ButtonBody, { ...props });
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* A ghost Button as a List draws an action. In a row (iOS 27.2's button cell): the row's 17/22 Regular words where a
|
|
267
|
+
* row's label starts, tinted (the accent for `primary`, `secondary` and `info`, red for `danger`), an icon after them at
|
|
268
|
+
* the row's trailing edge, the row's press fill, no chevron; on Android a 50dp row with the 16sp words 20 in, in the
|
|
269
|
+
* accent or the error color, pressed in the list selector. In a header: iOS's list header action, tinted 17/22 text on
|
|
270
|
+
* the title's line with a 44pt target; Android's 14sp Medium in the accent on the header's line. `style` reaches the
|
|
271
|
+
* row (`justifyContent: "center"` centres the words, as the web's `data-align="center"`).
|
|
272
|
+
*/
|
|
273
|
+
function ListActionButton({ place, color = "primary", disabled = false, loading = false, inert: inertProp = loading, children, style, onPressIn, onPressOut, accessibilityState, ...rest }) {
|
|
274
|
+
const theme = useTheme();
|
|
275
|
+
const android = theme.isAndroid;
|
|
276
|
+
const [pressed, setPressed] = useState(false);
|
|
277
|
+
const inert = disabled || inertProp;
|
|
278
|
+
const row = place === "row";
|
|
279
|
+
const tinted = color === "primary" || color === "secondary" || color === "info";
|
|
280
|
+
const base = color === "danger"
|
|
281
|
+
? android
|
|
282
|
+
? dangerText(theme)
|
|
283
|
+
: theme.color("--color-text-danger")
|
|
284
|
+
: tinted
|
|
285
|
+
? android
|
|
286
|
+
? accentText(theme)
|
|
287
|
+
: // The web's phone rows tint an action with the info text (#0169cc, blue-200 in the dark)
|
|
288
|
+
theme.color("--color-text-info", theme.colors.accent)
|
|
289
|
+
: buttonColors(theme, color, "ghost", false, false).text;
|
|
290
|
+
const ink = disabled ? (android ? withAlpha(base, 0.5) : theme.colors.labelTertiary) : !row && pressed && !android ? lighten(theme, base) : base;
|
|
291
|
+
// Android: a row's words 16/20, a header's 15/20 Medium (the web's FieldGroup header action)
|
|
292
|
+
const type = android
|
|
293
|
+
? row
|
|
294
|
+
? { fontSize: 16, lineHeight: 20 }
|
|
295
|
+
: { fontSize: 15, lineHeight: 20 }
|
|
296
|
+
: row
|
|
297
|
+
? { fontSize: theme.length("--field-row-label-font-size", 17), lineHeight: theme.length("--field-row-label-line-height", 22) }
|
|
298
|
+
: { fontSize: theme.length("--field-group-title-font-size", 17), lineHeight: theme.length("--field-group-title-line-height", 22) };
|
|
299
|
+
const parts = flattenChildren(children);
|
|
300
|
+
// Words and then an icon: the words take the room, so the icon ends the row
|
|
301
|
+
const trailingIcon = row && parts.length > 1 && isValidElement(parts[parts.length - 1]);
|
|
302
|
+
const content = parts.map((part, index) => typeof part === "string" || typeof part === "number" ? (_jsx(Text, { weight: android && !row ? "medium" : "regular", numberOfLines: row ? undefined : 1, style: [type, trailingIcon && index < parts.length - 1 ? styles.grow : null], children: part }, `label-${index}`)) : (_jsx(Fragment, { children: part }, `part-${index}`)));
|
|
303
|
+
const fill = row && pressed && !inert ? (android ? controlHighlight(theme.scheme) : theme.color("--field-row-press-background")) : undefined;
|
|
304
|
+
// The header's words stand on the title's line: their target reaches over and under it to 44 (48 on Android)
|
|
305
|
+
const reach = row ? 0 : Math.max(0, ((android ? 48 : 44) - type.lineHeight) / 2);
|
|
306
|
+
return (_jsx(Pressable, { accessibilityRole: "button", accessibilityState: { disabled: inert, busy: loading, ...accessibilityState }, "aria-busy": loading, disabled: inert, hitSlop: row ? undefined : { top: reach, bottom: reach, left: 8, right: 8 }, onPressIn: (event) => {
|
|
307
|
+
setPressed(true);
|
|
308
|
+
onPressIn?.(event);
|
|
309
|
+
}, onPressOut: (event) => {
|
|
310
|
+
setPressed(false);
|
|
311
|
+
onPressOut?.(event);
|
|
312
|
+
}, ...rest, style: [
|
|
313
|
+
styles.row,
|
|
314
|
+
row
|
|
315
|
+
? { alignSelf: "stretch", justifyContent: "flex-start", minHeight: android ? 50 : theme.length("--field-row-min-height", 52), paddingHorizontal: android ? 21 : theme.length("--list-row-inset", 20), gap: 8 }
|
|
316
|
+
: { flexShrink: 0, gap: 4 },
|
|
317
|
+
fill ? { backgroundColor: fill } : null,
|
|
318
|
+
!row && android && pressed && !inert ? { opacity: 0.6 } : null,
|
|
319
|
+
style,
|
|
320
|
+
], children: _jsx(TextColorProvider, { value: ink, children: _jsx(IconDefaultsProvider, { size: android ? 24 : row ? theme.length("--field-row-icon-symbol-size", 24) : theme.length("--control-icon-size-md", 20), color: ink, children: loading ? _jsx(ActivityIndicator, { color: ink, size: "small" }) : content }) }) }));
|
|
321
|
+
}
|
|
322
|
+
function ButtonBody({ color = "primary", variant = "solid", size = "md", shape = "round", mobileMaterial, uniform = false, block = false, selected = false, loading = false, disabled = false, inert: inertProp = loading, iconSize, gutterSize, opticallyAlign, children, style, onPressIn, onPressOut, accessibilityState, ...rest }) {
|
|
247
323
|
const theme = useTheme();
|
|
248
324
|
const bar = useContext(BarItemContext);
|
|
249
325
|
const sized = buttonMetrics(theme, size, shape, uniform);
|
|
@@ -305,8 +381,9 @@ export function Button({ color = "primary", variant = "solid", size = "md", shap
|
|
|
305
381
|
const corners = android && selected ? metrics.selectedRadius : metrics.radius;
|
|
306
382
|
// An icon in a group's capsule takes the group's 38dp slot, a circle of its own the bar's height
|
|
307
383
|
const width = uniform ? (android && bar?.inGroup ? 38 : metrics.height) : undefined;
|
|
308
|
-
// Android's press on a bar's icon: its borderless ripple, a 40dp circle (20dp radius) centered on the icon,
|
|
309
|
-
// wider than a group's slot
|
|
384
|
+
// Android's press on a bar's icon: its borderless ripple, a 40dp circle (20dp radius) centered on the icon, inside
|
|
385
|
+
// a 46dp glass circle and a little wider than a group's slot (the reference's selector of mask 1, radius 20); a label
|
|
386
|
+
// in a bar ripples in its own pill
|
|
310
387
|
const dot = android && bar && uniform && width ? 40 : 0;
|
|
311
388
|
// Android's press of a button standing on its own (a bar's have none): it shrinks to 0.98 in 80ms on the default
|
|
312
389
|
// curve and comes back on release in 350ms on an overshoot of 1.2, just past its size and back
|
|
@@ -322,22 +399,32 @@ export function Button({ color = "primary", variant = "solid", size = "md", shap
|
|
|
322
399
|
? { toValue: 0.98, duration: 80, easing: curves.accelerateDecelerate, useNativeDriver: false }
|
|
323
400
|
: { toValue: 1, duration: 350, easing: curves.overshoot(1.2), useNativeDriver: false }).start();
|
|
324
401
|
};
|
|
325
|
-
//
|
|
326
|
-
|
|
402
|
+
// Android's press in a bar: the list selector on its glass circles and pills, the content color at 20% on an accent
|
|
403
|
+
// one, the ink at 7% (#121A1D21) in a plain bar; a filled button's is the list selector; any other's Material's
|
|
404
|
+
// pressed state layer of its label
|
|
405
|
+
const pressLayer = android && bar
|
|
406
|
+
? bar.plain
|
|
407
|
+
? withAlpha(colors.text, 0.07)
|
|
408
|
+
: accentAction
|
|
409
|
+
? withAlpha(colors.text, 0.2)
|
|
410
|
+
: listSelector(theme.scheme)
|
|
411
|
+
: android && variant === "solid"
|
|
412
|
+
? listSelector(theme.scheme)
|
|
413
|
+
: withAlpha(colors.text, stateLayer.pressed);
|
|
414
|
+
// Android's press: the ripple from the touch point, the platform's on a device and drawn here on the web, in the
|
|
415
|
+
// button's shape (its corners clip it) or a bar's bare icon's 40dp circle
|
|
416
|
+
const ripple = useRipple(pressLayer, android && !nativeRipple, still, dot && width ? { width: dot, height: dot, borderRadius: dot / 2, top: (metrics.height - dot) / 2, start: (width - dot) / 2 } : undefined);
|
|
327
417
|
const handleIn = (event) => {
|
|
328
418
|
setPressed(true);
|
|
329
419
|
scaleTo(true);
|
|
330
|
-
if (
|
|
331
|
-
|
|
332
|
-
glow.setValue(still ? 1 : 0);
|
|
333
|
-
if (!still)
|
|
334
|
-
Animated.timing(glow, { toValue: 1, duration: 80, easing: Easing.linear, useNativeDriver: false }).start();
|
|
335
|
-
}
|
|
420
|
+
if (android && !nativeRipple && !(disabled || inertProp))
|
|
421
|
+
ripple.start(event);
|
|
336
422
|
onPressIn?.(event);
|
|
337
423
|
};
|
|
338
424
|
const handleOut = (event) => {
|
|
339
425
|
setPressed(false);
|
|
340
426
|
scaleTo(false);
|
|
427
|
+
ripple.end();
|
|
341
428
|
onPressOut?.(event);
|
|
342
429
|
};
|
|
343
430
|
const inert = disabled || inertProp;
|
|
@@ -424,15 +511,7 @@ export function Button({ color = "primary", variant = "solid", size = "md", shap
|
|
|
424
511
|
: { opacity: loading ? 0 : 1 };
|
|
425
512
|
const spinner = android ? (loading || leaving ? (_jsx(Animated.View, { pointerEvents: "none", style: [StyleSheet.absoluteFill, styles.row, { opacity: swap, transform: [{ translateY: swap.interpolate({ inputRange: [0, 1], outputRange: [24, 0] }) }] }], children: _jsx(Spinner, { color: ink }) })) : null) : loading ? (_jsx(ActivityIndicator, { style: StyleSheet.absoluteFill, color: text, size: metrics.indicator > 20 ? "large" : "small" })) : null;
|
|
426
513
|
const content = (_jsx(TextColorProvider, { value: ink, children: _jsxs(IconDefaultsProvider, { size: metrics.iconSize, color: ink, children: [_jsx(Animated.View, { style: [styles.row, android ? styles.fromTop : null, { gap: metrics.gap }, labelMotion], children: renderChildren(children, metrics) }), spinner] }) }));
|
|
427
|
-
|
|
428
|
-
// Material's pressed state layer of its label
|
|
429
|
-
const pressLayer = android && bar ? withAlpha(colors.text, 0.07) : android && variant === "solid" ? listSelector(theme.scheme) : withAlpha(colors.text, stateLayer.pressed);
|
|
430
|
-
const layer = theme.isAndroid && !nativeRipple && pressed && !inert ? (_jsx(Animated.View, { pointerEvents: "none", style: [
|
|
431
|
-
dot && width
|
|
432
|
-
? { position: "absolute", width: dot, height: dot, borderRadius: dot / 2, top: (metrics.height - dot) / 2, start: (width - dot) / 2, opacity: glow }
|
|
433
|
-
: StyleSheet.absoluteFill,
|
|
434
|
-
{ backgroundColor: pressLayer },
|
|
435
|
-
] })) : null;
|
|
514
|
+
const layer = ripple.layer;
|
|
436
515
|
const pressable = {
|
|
437
516
|
accessibilityRole: "button",
|
|
438
517
|
accessibilityState: { disabled: inert, selected, busy: loading, ...accessibilityState },
|
|
@@ -455,4 +534,5 @@ const AnimatedPressable = Animated.createAnimatedComponent(Pressable);
|
|
|
455
534
|
const styles = StyleSheet.create({
|
|
456
535
|
row: { flexDirection: "row", alignItems: "center", justifyContent: "center" },
|
|
457
536
|
fromTop: { alignSelf: "stretch", transformOrigin: "top" },
|
|
537
|
+
grow: { flexGrow: 1, flexShrink: 1 },
|
|
458
538
|
});
|
|
@@ -3,10 +3,11 @@ import { cloneElement, createContext, isValidElement, useContext } from "react";
|
|
|
3
3
|
import { Image, Platform, Pressable, StyleSheet, View } from "react-native";
|
|
4
4
|
import { flattenChildren } from "../../internal/children";
|
|
5
5
|
import { space } from "../../internal/spacing";
|
|
6
|
-
import { controlHighlight } from "../../theme/material";
|
|
6
|
+
import { controlHighlight, withAlpha } from "../../theme/material";
|
|
7
7
|
import { useTheme } from "../../theme/ThemeProvider";
|
|
8
8
|
import { materialType } from "../../theme/typography";
|
|
9
|
-
import {
|
|
9
|
+
import { IconDefaultsProvider } from "../Icon/createIcon";
|
|
10
|
+
import { Text, TextColorProvider } from "../Text/Text";
|
|
10
11
|
const Context = createContext(null);
|
|
11
12
|
function useCard(part) {
|
|
12
13
|
const context = useContext(Context);
|
|
@@ -47,8 +48,15 @@ export function cardSurface(theme, variant) {
|
|
|
47
48
|
* section card of a settings screen (16dp corners, no border, the white card on the gray page; `solid` a gray fill),
|
|
48
49
|
* 16dp padding, Title M and Body M, pressed in the list selector as a List row.
|
|
49
50
|
*/
|
|
50
|
-
|
|
51
|
+
/** A colored card's fill and the color of what stands on it. */
|
|
52
|
+
export function cardColors(theme, color) {
|
|
53
|
+
if (color === "accent")
|
|
54
|
+
return { fill: theme.colors.accent, ink: theme.color("--color-text-accent-solid", "#FFFFFF") };
|
|
55
|
+
return { fill: theme.color(`--color-background-${color}-solid`), ink: theme.color(`--color-text-${color}-solid`, "#FFFFFF") };
|
|
56
|
+
}
|
|
57
|
+
function CardRoot({ children, variant = "outline", size = "md", color, onPress, interactive = false, accessibilityLabel, testID, style }) {
|
|
51
58
|
const theme = useTheme();
|
|
59
|
+
const tint = color ? cardColors(theme, color) : null;
|
|
52
60
|
const inset = theme.isAndroid ? (size === "lg" ? 24 : size === "sm" ? 12 : 16) : theme.length(`--card-padding-${size}`, PADDING[size]);
|
|
53
61
|
// A ghost card has no padding, as the web's: its parts stand at its edges, unclipped (it has no fill to clip to)
|
|
54
62
|
const ghost = variant === "ghost";
|
|
@@ -61,11 +69,11 @@ function CardRoot({ children, variant = "outline", size = "md", onPress, interac
|
|
|
61
69
|
const body = parts.map((child, index) => isValidElement(child) && child.type === CardMedia
|
|
62
70
|
? cloneElement(child, { first: index === 0, last: index === parts.length - 1 })
|
|
63
71
|
: child);
|
|
64
|
-
const box = [styles.card, { padding, gap, borderRadius: radius }, ghost ? styles.ghost : null, cardSurface(theme, variant), style];
|
|
65
|
-
const content = _jsx(Context.Provider, { value: { padding, inset, radius, theme }, children: body });
|
|
72
|
+
const box = [styles.card, { padding, gap, borderRadius: radius }, ghost && !tint ? styles.ghost : null, tint ? { backgroundColor: tint.fill } : cardSurface(theme, variant), style];
|
|
73
|
+
const content = tint ? (_jsx(Context.Provider, { value: { padding, inset, radius, theme, ink: tint.ink }, children: _jsx(TextColorProvider, { value: tint.ink, children: _jsx(IconDefaultsProvider, { color: tint.ink, children: body }) }) })) : (_jsx(Context.Provider, { value: { padding, inset, radius, theme }, children: body }));
|
|
66
74
|
if (onPress || interactive) {
|
|
67
75
|
// Android: the press of a row in a section (the settings list selector), as a List row's
|
|
68
|
-
const layer = theme.isAndroid ? controlHighlight(theme.scheme) : theme.color("--alpha-08");
|
|
76
|
+
const layer = tint ? withAlpha(tint.ink, 0.12) : theme.isAndroid ? controlHighlight(theme.scheme) : theme.color("--alpha-08");
|
|
69
77
|
// The ripple on a device, clipped to the card's corners; a layer elsewhere
|
|
70
78
|
const nativeRipple = theme.isAndroid && Platform.OS === "android";
|
|
71
79
|
return (_jsx(Pressable
|
|
@@ -94,9 +102,9 @@ function CardTitle({ children }) {
|
|
|
94
102
|
}
|
|
95
103
|
CardTitle.displayName = "Card.Title";
|
|
96
104
|
function CardDescription({ children }) {
|
|
97
|
-
const { theme } = useCard("Card.Description");
|
|
105
|
+
const { theme, ink } = useCard("Card.Description");
|
|
98
106
|
const type = theme.isAndroid ? materialType.bodyMedium : { fontSize: theme.length("--card-description-font-size", 15), lineHeight: theme.length("--card-description-line-height", 20) };
|
|
99
|
-
return (_jsx(Text, { color: theme.isAndroid ? "secondary" : theme.color("--card-description-color", theme.colors.textSecondary), style: [{ fontSize: type.fontSize, lineHeight: type.lineHeight }, theme.isIOS ? { marginTop: -space(theme, 1.5) } : null], children: children }));
|
|
107
|
+
return (_jsx(Text, { color: ink ? withAlpha(ink, 0.8) : theme.isAndroid ? "secondary" : theme.color("--card-description-color", theme.colors.textSecondary), style: [{ fontSize: type.fontSize, lineHeight: type.lineHeight }, theme.isIOS ? { marginTop: -space(theme, 1.5) } : null], children: children }));
|
|
100
108
|
}
|
|
101
109
|
CardDescription.displayName = "Card.Description";
|
|
102
110
|
function CardContent({ children, style, testID }) {
|
|
@@ -1,50 +1,66 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useContext, useEffect, useState } from "react";
|
|
3
|
-
import { Animated, Pressable, StyleSheet, View } from "react-native";
|
|
3
|
+
import { Animated, Easing, Pressable, StyleSheet, View } from "react-native";
|
|
4
4
|
import Svg, { Path } from "react-native-svg";
|
|
5
5
|
import CheckMd from "../../icons/plex/CheckMd";
|
|
6
6
|
import Minus from "../../icons/plex/Minus";
|
|
7
7
|
import { spaceToggles, useDescription } from "../../internal/a11y";
|
|
8
8
|
import { ControlLabel, controlLabelLine } from "../../internal/ControlLabel";
|
|
9
|
-
import { RowEndContext, RowHoldContext, rowHold } from "../../internal/row";
|
|
10
|
-
import {
|
|
9
|
+
import { RowEndContext, RowHoldContext, RowStartContext, rowHold } from "../../internal/row";
|
|
10
|
+
import { androidGray, withAlpha } from "../../theme/material";
|
|
11
11
|
import { useTheme } from "../../theme/ThemeProvider";
|
|
12
|
-
import { ANDROID_ROW_END,
|
|
13
|
-
/** Android's
|
|
14
|
-
const ANDROID_BOX =
|
|
12
|
+
import { ANDROID_ROW_END, iosCheckmarkColor, selectionColor } from "../Switch/Switch";
|
|
13
|
+
/** Android's round check: a 20dp circle (the reference's 19.8), in a 48dp target that reaches 14dp past it. */
|
|
14
|
+
const ANDROID_BOX = 20;
|
|
15
15
|
const ANDROID_REACH = (48 - ANDROID_BOX) / 2;
|
|
16
|
-
/** A checkbox
|
|
16
|
+
/** A checkbox with a label: the text starts 11dp after the circle (the web's -3 margin and 14 of the target). */
|
|
17
17
|
const ANDROID_LABEL_GAP = 11;
|
|
18
|
-
/** A checkbox row's
|
|
18
|
+
/** A checkbox at a List row's end stands 21dp in from the row's edge. */
|
|
19
19
|
const ANDROID_ROW_INSET = 21;
|
|
20
|
+
/** The ring of an empty circle, 1.5dp. */
|
|
21
|
+
const ANDROID_RING = 1.5;
|
|
22
|
+
/** Android's check eases both ways on cubic-bezier(0.37, 0, 0.63, 1) (the web's `--android-checkbox-ease`). */
|
|
23
|
+
const androidCheckEase = Easing.bezier(0.37, 0, 0.63, 1);
|
|
20
24
|
/**
|
|
21
25
|
* A checkbox: on iOS the 22pt circle of the phone layer (`--checkbox-*`: a 1.5pt ring, filled in the primary with a
|
|
22
|
-
* check), on Android
|
|
23
|
-
* color with a round-capped check) in a 48dp target.
|
|
26
|
+
* check), on Android the reference's round check (a 20dp circle, a 1.5dp ring in a light gray, filled in the
|
|
27
|
+
* selection color with a white round-capped check) in a 48dp target. As the first control of a List row (`RowStart`)
|
|
28
|
+
* it leads the row, 22 in.
|
|
24
29
|
*/
|
|
25
30
|
export function Checkbox({ checked: checkedProp, defaultChecked = false, onCheckedChange, label, description, orientation = "left", variant = "solid", invalid = false, disabled = false, accessibilityLabel, testID, style, }) {
|
|
26
31
|
const theme = useTheme();
|
|
27
|
-
// At a List row's end with no text of its own: the row is its label
|
|
28
|
-
|
|
32
|
+
// At a List row's end with no text of its own: the row is its label. Leading the row (Android's multi-select row),
|
|
33
|
+
// the row sets its place
|
|
34
|
+
const atRowStart = useContext(RowStartContext) && label == null && description == null;
|
|
35
|
+
const inRow = useContext(RowEndContext) != null && label == null && description == null && !atRowStart;
|
|
29
36
|
const hold = useContext(RowHoldContext);
|
|
30
37
|
const [own, setOwn] = useState(defaultChecked);
|
|
31
38
|
const state = checkedProp ?? own;
|
|
32
39
|
const on = state !== false;
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
|
|
40
|
+
// Android's round check, as the web's: the ring and the fill turn in 150ms, then the mark is drawn from its start
|
|
41
|
+
// in 150ms; unchecking fades the mark out in 150ms as the fill goes. Android only: iOS shows a list row's
|
|
42
|
+
// checkmark, which does not animate
|
|
43
|
+
const [fillIn] = useState(() => new Animated.Value(on ? 1 : 0));
|
|
44
|
+
const [draw] = useState(() => new Animated.Value(on ? 1 : 0));
|
|
45
|
+
const [markIn] = useState(() => new Animated.Value(on ? 1 : 0));
|
|
36
46
|
const animate = theme.isAndroid && !disabled;
|
|
37
47
|
useEffect(() => {
|
|
48
|
+
const values = [fillIn, draw, markIn];
|
|
38
49
|
// A disabled box snaps: no motion between enabled and disabled
|
|
39
50
|
if (theme.reducedMotion || !animate) {
|
|
40
|
-
|
|
41
|
-
|
|
51
|
+
values.forEach((value) => {
|
|
52
|
+
value.stopAnimation();
|
|
53
|
+
value.setValue(on ? 1 : 0);
|
|
54
|
+
});
|
|
42
55
|
return;
|
|
43
56
|
}
|
|
44
|
-
const
|
|
57
|
+
const timing = (value, toValue, delay = 0) => Animated.timing(value, { toValue, duration: 150, delay, easing: androidCheckEase, useNativeDriver: false });
|
|
58
|
+
const animation = on
|
|
59
|
+
? Animated.parallel([timing(fillIn, 1), Animated.sequence([Animated.timing(markIn, { toValue: 1, duration: 0, useNativeDriver: false }), timing(draw, 1, 150)])])
|
|
60
|
+
: Animated.parallel([timing(fillIn, 0), Animated.sequence([timing(markIn, 0), Animated.timing(draw, { toValue: 0, duration: 0, useNativeDriver: false })])]);
|
|
45
61
|
animation.start();
|
|
46
62
|
return () => animation.stop();
|
|
47
|
-
}, [on, animate, theme.reducedMotion,
|
|
63
|
+
}, [on, animate, theme.reducedMotion, fillIn, draw, markIn]);
|
|
48
64
|
const toggle = () => {
|
|
49
65
|
if (disabled)
|
|
50
66
|
return;
|
|
@@ -58,22 +74,26 @@ export function Checkbox({ checked: checkedProp, defaultChecked = false, onCheck
|
|
|
58
74
|
let box;
|
|
59
75
|
const hasText = label != null || description != null;
|
|
60
76
|
if (theme.isAndroid) {
|
|
61
|
-
// The
|
|
62
|
-
//
|
|
63
|
-
// the near-white primary at night
|
|
77
|
+
// The ring a light gray (#B0B9C2, --gray-500 at night), the fill the selection color, the error when invalid
|
|
78
|
+
// (in a List row the error is the row's line: the circle keeps its colors). The mark is the fill's own text
|
|
79
|
+
// color: white on the accent and on the ink of a light theme, dark on the near-white primary at night
|
|
64
80
|
const m = theme.material;
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
//
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
81
|
+
const red = invalid && !inRow && !atRowStart;
|
|
82
|
+
const ring = red ? m.error : androidGray(theme, "checkboxRing");
|
|
83
|
+
const fill = red ? m.error : selectionColor(theme);
|
|
84
|
+
const markColor = red ? m.onError : theme.color(`--color-text-${theme.selectionColor}-solid`, "#FFFFFF");
|
|
85
|
+
// The 48dp target reaches past the circle without taking room: on the outer side the circle keeps the row's edge,
|
|
86
|
+
// on the label's side the text starts 11dp after it. At a List row's end the circle stands 21dp in; leading a
|
|
87
|
+
// row the row places it
|
|
88
|
+
const reach = atRowStart
|
|
89
|
+
? { margin: -ANDROID_REACH }
|
|
90
|
+
: inRow
|
|
91
|
+
? { marginStart: -ANDROID_REACH, marginEnd: -(ANDROID_REACH - (ANDROID_ROW_INSET - ANDROID_ROW_END)) }
|
|
92
|
+
: orientation === "right"
|
|
93
|
+
? { marginEnd: -ANDROID_REACH, marginStart: hasText ? -(ANDROID_REACH - ANDROID_LABEL_GAP) : 0 }
|
|
94
|
+
: { marginStart: -ANDROID_REACH, marginEnd: hasText ? -(ANDROID_REACH - ANDROID_LABEL_GAP) : 0 };
|
|
95
|
+
// No press of its own: a row shows the press. Disabled, the circle keeps its colors at half (as a checkbox row's)
|
|
96
|
+
box = (_jsx(View, { style: [styles.androidTarget, reach], children: _jsx(View, { style: disabled ? styles.half : null, children: _jsx(AndroidCheck, { fillIn: fillIn, draw: draw, markIn: markIn, ring: ring, fill: fill, markColor: markColor, indeterminate: state === "indeterminate" }) }) }));
|
|
77
97
|
}
|
|
78
98
|
else {
|
|
79
99
|
const size = theme.length("--checkbox-indicator-size", 22);
|
|
@@ -112,70 +132,17 @@ export function Checkbox({ checked: checkedProp, defaultChecked = false, onCheck
|
|
|
112
132
|
style,
|
|
113
133
|
], children: [box, hasText ? _jsx(View, { style: [styles.grow, { paddingTop: (targetSize - controlLabelLine(theme)) / 2 }, orientation === "right" ? styles.fill : null], children: text }) : null] }));
|
|
114
134
|
}
|
|
115
|
-
/** The
|
|
116
|
-
const
|
|
117
|
-
const
|
|
118
|
-
const LONG_ARM = { length: 7 * Math.SQRT2, angle: -45 };
|
|
135
|
+
/** The reference's check in its 20dp circle, and the dash of a mixed one: 2dp strokes with round ends. */
|
|
136
|
+
const CHECK_PATH = "M5.2 11l3 3 6.6-6.6";
|
|
137
|
+
const DASH_PATH = "M6 10h8";
|
|
119
138
|
/**
|
|
120
|
-
*
|
|
121
|
-
*
|
|
139
|
+
* Android's round check: a 20dp circle whose 1.5dp ring turns from the gray to the fill as the fill comes in
|
|
140
|
+
* (`fillIn`), and the mark, shown by `markIn` and drawn from its start as a clip opens over it (`draw`).
|
|
122
141
|
*/
|
|
123
|
-
function
|
|
124
|
-
const
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
return (_jsx(Animated.View, { style: [
|
|
128
|
-
styles.arm,
|
|
129
|
-
{
|
|
130
|
-
backgroundColor: color,
|
|
131
|
-
width: Animated.add(along(1), 2),
|
|
132
|
-
// The bar's middle is half its length along the arm from the corner; its box is then half its width back
|
|
133
|
-
left: Animated.add(along((cos - 1) / 2), CORNER.x - 1),
|
|
134
|
-
top: Animated.add(along(sin / 2), CORNER.y - 1),
|
|
135
|
-
transform: [{ rotate: `${angle}deg` }],
|
|
136
|
-
},
|
|
137
|
-
] }));
|
|
138
|
-
}
|
|
139
|
-
/** A rounded rectangle from `from` to `to` on both axes, as a path of fixed shape (its numbers alone change). */
|
|
140
|
-
const roundedSquare = (from, to, corner) => {
|
|
141
|
-
const n = (value) => value.toFixed(4);
|
|
142
|
-
const [a, b, r] = [from, to, corner];
|
|
143
|
-
return (`M ${n(a + r)} ${n(a)} H ${n(b - r)} A ${n(r)} ${n(r)} 0 0 1 ${n(b)} ${n(a + r)} V ${n(b - r)} A ${n(r)} ${n(r)} 0 0 1 ${n(b - r)} ${n(b)} ` +
|
|
144
|
-
`H ${n(a + r)} A ${n(r)} ${n(r)} 0 0 1 ${n(a)} ${n(b - r)} V ${n(a + r)} A ${n(r)} ${n(r)} 0 0 1 ${n(a + r)} ${n(a)} Z`);
|
|
145
|
-
};
|
|
146
|
-
/** The outline's width, at rest and around the hole. */
|
|
147
|
-
const ANDROID_RING = 1.33;
|
|
148
|
-
/**
|
|
149
|
-
* The box at `progress`, a 4dp-cornered square with the hole it cuts. Over the first half the box shrinks 1dp on each
|
|
150
|
-
* side while the hole, fixed in the 18dp frame, closes 16dp per unit of progress (to 7dp in from the outline) with
|
|
151
|
-
* corners of 3dp, or of half its width once it is under 6dp; past the middle the box is solid and grows back.
|
|
152
|
-
*/
|
|
153
|
-
function androidBoxPath(progress) {
|
|
154
|
-
const half = Math.min(1, progress * 2);
|
|
155
|
-
const box = progress <= 0.5 ? half : 2 - progress * 2;
|
|
156
|
-
const holed = progress <= 0.5;
|
|
157
|
-
const closed = ANDROID_RING + Math.min(7, 8 * half);
|
|
158
|
-
const hole = holed ? ANDROID_BOX - 2 * closed : 0;
|
|
159
|
-
const from = holed ? closed : ANDROID_BOX / 2;
|
|
160
|
-
return `${roundedSquare(box, ANDROID_BOX - box, 4)} ${roundedSquare(from, from + hole, Math.min(3, hole / 2))}`;
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Android's square checkbox, drawn from its numbers. Over the first half of `progress` the box shrinks 1dp on each
|
|
164
|
-
* side while its 1.33dp outline closes inward and turns from the outline's color to the fill's; over the second half
|
|
165
|
-
* the box grows back and the mark grows from its corner. One path draws the box and its hole, redrawn from the
|
|
166
|
-
* progress on each frame (an animated path's props do not reach an SVG element on the web).
|
|
167
|
-
*/
|
|
168
|
-
function AndroidBox({ progress, initial, ring, fill, markColor, indeterminate }) {
|
|
169
|
-
const [at, setAt] = useState(initial);
|
|
170
|
-
useEffect(() => {
|
|
171
|
-
const id = progress.addListener(({ value }) => setAt(value));
|
|
172
|
-
return () => progress.removeListener(id);
|
|
173
|
-
}, [progress]);
|
|
174
|
-
const grow = progress.interpolate({ inputRange: [0.5, 1], outputRange: [0, 1], extrapolate: "clamp" });
|
|
175
|
-
const shown = progress.interpolate({ inputRange: [0.5, 0.5001], outputRange: [0, 1], extrapolate: "clamp" });
|
|
176
|
-
return (_jsxs(View, { style: styles.androidFrame, children: [_jsx(Svg, { width: ANDROID_BOX, height: ANDROID_BOX, style: StyleSheet.absoluteFill, children: _jsx(Path, { d: androidBoxPath(at), fill: mix(fill, ring, Math.min(1, at * 2)), fillRule: "evenodd" }) }), _jsx(Animated.View, { pointerEvents: "none", style: [StyleSheet.absoluteFill, { opacity: shown }], children: indeterminate ? (
|
|
177
|
-
// The box has no indeterminate look: a 2dp dash with round ends across the middle, growing from its center
|
|
178
|
-
_jsx(Animated.View, { style: [styles.arm, { backgroundColor: markColor, top: ANDROID_BOX / 2 - 1, width: grow.interpolate({ inputRange: [0, 1], outputRange: [2, 10] }), left: grow.interpolate({ inputRange: [0, 1], outputRange: [8, 4] }) }] })) : (_jsxs(_Fragment, { children: [_jsx(CheckArm, { grow: grow, color: markColor, ...SHORT_ARM }), _jsx(CheckArm, { grow: grow, color: markColor, ...LONG_ARM })] })) })] }));
|
|
142
|
+
function AndroidCheck({ fillIn, draw, markIn, ring, fill, markColor, indeterminate, }) {
|
|
143
|
+
const borderColor = fillIn.interpolate({ inputRange: [0, 1], outputRange: [ring, fill] });
|
|
144
|
+
const backgroundColor = fillIn.interpolate({ inputRange: [0, 1], outputRange: [withAlpha(fill, 0), fill] });
|
|
145
|
+
return (_jsx(Animated.View, { style: [styles.androidCircle, { borderColor, backgroundColor }], children: _jsx(Animated.View, { pointerEvents: "none", style: [styles.androidClip, { opacity: markIn, width: draw.interpolate({ inputRange: [0, 1], outputRange: [0, ANDROID_BOX] }) }], children: _jsx(Svg, { width: ANDROID_BOX, height: ANDROID_BOX, viewBox: "0 0 20 20", children: _jsx(Path, { d: indeterminate ? DASH_PATH : CHECK_PATH, fill: "none", stroke: markColor, strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round" }) }) }) }));
|
|
179
146
|
}
|
|
180
147
|
const styles = StyleSheet.create({
|
|
181
148
|
row: { flexDirection: "row", alignItems: "center", alignSelf: "stretch" },
|
|
@@ -186,6 +153,7 @@ const styles = StyleSheet.create({
|
|
|
186
153
|
fill: { flexGrow: 1 },
|
|
187
154
|
androidTarget: { width: 48, height: 48, alignItems: "center", justifyContent: "center" },
|
|
188
155
|
half: { opacity: 0.5 },
|
|
189
|
-
|
|
190
|
-
|
|
156
|
+
androidCircle: { width: ANDROID_BOX, height: ANDROID_BOX, borderRadius: ANDROID_BOX / 2, borderWidth: ANDROID_RING },
|
|
157
|
+
// The mark spans the circle's box, over its ring
|
|
158
|
+
androidClip: { position: "absolute", top: -ANDROID_RING, left: -ANDROID_RING, height: ANDROID_BOX, overflow: "hidden" },
|
|
191
159
|
});
|