@plexui/react-native 0.2.0 → 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.
|
@@ -63,20 +63,34 @@ export function ActionSheet({ open, onOpenChange, title, message, actions, cance
|
|
|
63
63
|
const { width: windowWidth } = useWindowDimensions();
|
|
64
64
|
const sourced = !theme.isAndroid && source != null && !unplaced;
|
|
65
65
|
useEffect(() => {
|
|
66
|
-
if (
|
|
66
|
+
if (theme.isAndroid || source == null)
|
|
67
67
|
return;
|
|
68
|
+
// Closed, the next opening tries its source again
|
|
69
|
+
if (!open) {
|
|
70
|
+
setUnplaced(false);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
68
73
|
let live = true;
|
|
69
74
|
// A new opening measures again: the panel never shows at the source's last place first
|
|
70
75
|
setAnchor(null);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
// A frame at a time: a sheet open as its screen appears waits for its source's layout, up to 120 frames (2s), then
|
|
77
|
+
// stands in the middle
|
|
78
|
+
let frame = 0;
|
|
79
|
+
const attempt = (left) => {
|
|
80
|
+
frame = requestAnimationFrame(() => measure(source.current, (box) => {
|
|
81
|
+
if (!live)
|
|
82
|
+
return;
|
|
83
|
+
const placed = box.width > 0 || box.height > 0;
|
|
84
|
+
if (!placed && left > 0)
|
|
85
|
+
return attempt(left - 1);
|
|
86
|
+
setAnchor(placed ? box : null);
|
|
87
|
+
setUnplaced(!placed);
|
|
88
|
+
}));
|
|
89
|
+
};
|
|
90
|
+
attempt(120);
|
|
78
91
|
return () => {
|
|
79
92
|
live = false;
|
|
93
|
+
cancelAnimationFrame(frame);
|
|
80
94
|
};
|
|
81
95
|
}, [open, theme.isAndroid, source, windowWidth, screen]);
|
|
82
96
|
if (theme.isAndroid) {
|
|
@@ -107,7 +121,7 @@ export function ActionSheet({ open, onOpenChange, title, message, actions, cance
|
|
|
107
121
|
backgroundColor: theme.color("--dialog-alert-fill"),
|
|
108
122
|
opacity: pressed ? 0.7 : 1,
|
|
109
123
|
},
|
|
110
|
-
], children: _jsx(Text, { weight: "
|
|
124
|
+
], children: _jsx(Text, { weight: "medium", color: item.disabled ? theme.color("--mobile-label-tertiary") : item.destructive ? theme.color("--color-background-danger-solid") : theme.colors.text, style: styles.iosLabel, children: item.label }) }, key));
|
|
111
125
|
const header = title != null || message != null ? (_jsxs(View, { style: styles.iosHeader, children: [title != null ? (_jsx(Text, { nativeID: ids.title, weight: "semibold", accessibilityRole: "header", style: styles.iosHeaderText, children: title })) : null, message != null ? (_jsx(Text, { nativeID: ids.message, style: styles.iosHeaderText, children: message })) : null] })) : null;
|
|
112
126
|
if (sourced) {
|
|
113
127
|
// At its source: the phone popover's glass and corners (the web's Popover "Confirmation"), no Cancel
|
|
@@ -4,6 +4,7 @@ import { Animated, Easing, Platform, Pressable, StyleSheet, View } from "react-n
|
|
|
4
4
|
import ChevronDownSm from "../../icons/plex/ChevronDownSm";
|
|
5
5
|
import CloseBold from "../../icons/plex/CloseBold";
|
|
6
6
|
import { spaceToggles } from "../../internal/a11y";
|
|
7
|
+
import { Glass } from "../../internal/Glass";
|
|
7
8
|
import { withAlpha } from "../../theme/material";
|
|
8
9
|
import { useTheme } from "../../theme/ThemeProvider";
|
|
9
10
|
import { IconDefaultsProvider } from "../Icon/createIcon";
|
|
@@ -11,11 +12,12 @@ import { MaterialArrowDropDown } from "../Icon/material";
|
|
|
11
12
|
import { Text, textStyle } from "../Text/Text";
|
|
12
13
|
/**
|
|
13
14
|
* A compact choice or action. Android: a chip (a 32dp capsule filled with the text color at 5%, Regular 14; a
|
|
14
|
-
* selected one in the Plex primary
|
|
15
|
-
*
|
|
15
|
+
* selected one in the Plex primary). iOS has no chip control: the filter capsules of iOS 26 apps (Maps), measured on
|
|
16
|
+
* an iPhone: a `tag` 40pt tall in the gray fill, or a `glass` capsule 44pt tall, the label 17/22 Regular; a selected
|
|
17
|
+
* one in the app's accent (its tint) with a white label. The web has
|
|
16
18
|
* no Chip; the props follow Toggle-like controls (`selected`, `onSelectedChange`) and Badge's `onRemove`.
|
|
17
19
|
*/
|
|
18
|
-
export function Chip({ children, selected: selectedProp, defaultSelected, onSelectedChange, onPress, icon, trailingIcon, menu, expanded, accessibilityLabel, onRemove, removeLabel = "Remove", disabled = false, testID, style, }) {
|
|
20
|
+
export function Chip({ children, selected: selectedProp, defaultSelected, onSelectedChange, onPress, icon, trailingIcon, menu, expanded, accessibilityLabel, appearance = "tag", onRemove, removeLabel = "Remove", disabled = false, testID, style, }) {
|
|
19
21
|
const theme = useTheme();
|
|
20
22
|
const [own, setOwn] = useState(defaultSelected ?? false);
|
|
21
23
|
const filter = selectedProp !== undefined || defaultSelected !== undefined || onSelectedChange !== undefined;
|
|
@@ -31,6 +33,7 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
31
33
|
onPress?.();
|
|
32
34
|
};
|
|
33
35
|
const android = theme.isAndroid;
|
|
36
|
+
const glass = !android && appearance === "glass";
|
|
34
37
|
const m = theme.material;
|
|
35
38
|
// Android: the label and the fill of either state, which a selection blends between
|
|
36
39
|
const androidColor = { off: m.onSurface, on: theme.color("--color-text-primary-solid") };
|
|
@@ -41,7 +44,7 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
41
44
|
? androidColor.on
|
|
42
45
|
: androidColor.off
|
|
43
46
|
: selected
|
|
44
|
-
? theme.color("--color-text-
|
|
47
|
+
? theme.color("--color-text-accent-solid", "#FFFFFF")
|
|
45
48
|
: disabled
|
|
46
49
|
? theme.colors.textDisabled
|
|
47
50
|
: theme.colors.text;
|
|
@@ -50,9 +53,12 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
50
53
|
? androidFill.on
|
|
51
54
|
: androidFill.off
|
|
52
55
|
: selected
|
|
53
|
-
? //
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
? // The app's accent, as iOS tints a chosen filter; a disabled selected chip fades to 40%, so it still stands
|
|
57
|
+
// apart from an off one
|
|
58
|
+
withAlpha(theme.colors.accent, disabled ? 0.4 : 1)
|
|
59
|
+
: glass
|
|
60
|
+
? "transparent"
|
|
61
|
+
: theme.color("--color-background-secondary-soft-alpha");
|
|
56
62
|
// Android blends the fill and the label from one state to the other in 120ms, linear; iOS changes at once
|
|
57
63
|
const [blend] = useState(() => new Animated.Value(selected ? 1 : 0));
|
|
58
64
|
const blends = android && !theme.reducedMotion;
|
|
@@ -69,13 +75,16 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
69
75
|
}, [blend, blends, selected]);
|
|
70
76
|
const fillPaint = blends ? blend.interpolate({ inputRange: [0, 1], outputRange: [androidFill.off, androidFill.on] }) : fill;
|
|
71
77
|
const labelPaint = blends ? blend.interpolate({ inputRange: [0, 1], outputRange: [androidColor.off, androidColor.on] }) : color;
|
|
72
|
-
const height = android ? 32 :
|
|
73
|
-
const label = android ? { fontSize: 14, lineHeight: 18 } : { fontSize:
|
|
78
|
+
const height = android ? 32 : glass ? 44 : 40;
|
|
79
|
+
const label = android ? { fontSize: 14, lineHeight: 18 } : { fontSize: 17, lineHeight: 22 };
|
|
74
80
|
const leading = icon;
|
|
75
|
-
|
|
81
|
+
// iOS: a 17pt symbol draws about 20 (the label's size)
|
|
82
|
+
const iconSize = android ? 18 : 20;
|
|
76
83
|
// A menu chip's chevron: Material's 18dp arrow_drop_down, iOS's small chevron.down at the label's weight
|
|
77
|
-
const trailing = trailingIcon ?? (menu ? android ? _jsx(MaterialArrowDropDown, { size: 18 }) : _jsx(ChevronDownSm, { size:
|
|
84
|
+
const trailing = trailingIcon ?? (menu ? android ? _jsx(MaterialArrowDropDown, { size: 18 }) : _jsx(ChevronDownSm, { size: 16 }) : null);
|
|
78
85
|
const leadingColor = color;
|
|
86
|
+
// A symbol alone (Maps' filter button before its chips): a circle as tall as the chip, named by accessibilityLabel
|
|
87
|
+
const symbolOnly = leading != null && (children == null || children === "") && trailing == null && !onRemove;
|
|
79
88
|
// The chip is drawn 32 (34) tall inside a 48dp (44pt) touch target, as Compose's minimum interactive size and the
|
|
80
89
|
// HIG ask: the target is the layout box, the chip a layer inside it, so every press in the target reaches it
|
|
81
90
|
const target = android ? 48 : 44;
|
|
@@ -83,22 +92,24 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
83
92
|
// A capsule, which stays one when a large text size makes it taller
|
|
84
93
|
const radius = 999;
|
|
85
94
|
const [pressed, setPressed] = useState(false);
|
|
86
|
-
|
|
95
|
+
// iOS's glass filter: a glass capsule (its rim and sheen), filled with the accent once chosen
|
|
96
|
+
const glassLayer = glass && !selected ? _jsx(Glass, { pointerEvents: "none", radius: radius, style: [StyleSheet.absoluteFill, { top: inset, bottom: inset }] }) : null;
|
|
97
|
+
const layer = glassLayer ?? (_jsx(Animated.View, { pointerEvents: "none", style: [StyleSheet.absoluteFill, { top: inset, bottom: inset, borderRadius: radius, backgroundColor: fillPaint, borderCurve: "continuous" }], children: android && pressed && !disabled ? (_jsx(View, { style: [StyleSheet.absoluteFill, { borderRadius: radius, backgroundColor: selected ? withAlpha(color, 0.12) : theme.scheme === "dark" ? "rgba(255, 255, 255, 0.05)" : "rgba(0, 0, 0, 0.06)" }] })) : null }));
|
|
87
98
|
const box = {
|
|
88
99
|
// The label's own air inside the chip, then the target's outside it: 48 (44) at the regular size, and taller
|
|
89
100
|
// with the text at a large font scale instead of cutting it (Compose's chips have a minimum height, not a height)
|
|
90
101
|
minHeight: target,
|
|
91
102
|
paddingVertical: inset + (height - label.lineHeight) / 2,
|
|
92
103
|
// Android: 12 at the sides, 8 before an icon and 6 after it
|
|
93
|
-
paddingLeft: leading != null ? (android ? 8 : 12) : android ? 12 :
|
|
94
|
-
// Android: 8 after a trailing icon (Compose's FilterChip), iOS
|
|
95
|
-
paddingRight: onRemove ? 0 : trailing != null ? (android ? 8 :
|
|
104
|
+
paddingLeft: symbolOnly ? (height - iconSize) / 2 : leading != null ? (android ? 8 : 12) : android ? 12 : 16,
|
|
105
|
+
// Android: 8 after a trailing icon (Compose's FilterChip), iOS 12
|
|
106
|
+
paddingRight: symbolOnly ? (height - iconSize) / 2 : onRemove ? 0 : trailing != null ? (android ? 8 : 12) : android ? 12 : 16,
|
|
96
107
|
gap: 6,
|
|
97
108
|
opacity: !android && pressed ? 0.7 : 1,
|
|
98
109
|
};
|
|
99
|
-
const body = (_jsxs(_Fragment, { children: [leading != null ? (_jsx(View, { children: _jsx(IconDefaultsProvider, { size: iconSize, color: leadingColor, children: leading }) })) : null, android ? (
|
|
110
|
+
const body = (_jsxs(_Fragment, { children: [leading != null ? (_jsx(View, { children: _jsx(IconDefaultsProvider, { size: iconSize, color: leadingColor, children: leading }) })) : null, symbolOnly ? null : android ? (
|
|
100
111
|
// Text's own face and tracking, in a color that blends
|
|
101
|
-
_jsx(Animated.Text, { numberOfLines: 1, style: [textStyle(theme, { weight: "regular" }), { fontSize: label.fontSize, lineHeight: label.lineHeight, letterSpacing: theme.tracking(label.fontSize), color: labelPaint }], children: children })) : (_jsx(Text, { color: color, weight: "
|
|
112
|
+
_jsx(Animated.Text, { numberOfLines: 1, style: [textStyle(theme, { weight: "regular" }), { fontSize: label.fontSize, lineHeight: label.lineHeight, letterSpacing: theme.tracking(label.fontSize), color: labelPaint }], children: children })) : (_jsx(Text, { color: color, weight: "regular", numberOfLines: 1, style: { fontSize: label.fontSize, lineHeight: label.lineHeight }, children: children })), trailing != null ? (_jsx(View, { children: _jsx(IconDefaultsProvider, { size: iconSize, color: leadingColor, children: trailing }) })) : null] }));
|
|
102
113
|
const interactive = filter || !!onPress;
|
|
103
114
|
// Android dims a disabled chip, its fill with it, to half (as its other disabled controls)
|
|
104
115
|
const dim = android && disabled ? styles.dim : null;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import { type StyleProp, type ViewStyle } from "react-native";
|
|
3
3
|
export type ChipProps = {
|
|
4
|
-
|
|
4
|
+
/** The label. Leave it out with an `icon` for a chip of the symbol alone, a circle named by `accessibilityLabel`. */
|
|
5
|
+
children?: ReactNode;
|
|
5
6
|
/** A filter chip: chosen or not. Leave it out for an action chip. */
|
|
6
7
|
selected?: boolean;
|
|
7
8
|
defaultSelected?: boolean;
|
|
@@ -21,6 +22,12 @@ export type ChipProps = {
|
|
|
21
22
|
/** Whether the chip's menu is open (`aria-expanded`). */
|
|
22
23
|
expanded?: boolean;
|
|
23
24
|
accessibilityLabel?: string;
|
|
25
|
+
/**
|
|
26
|
+
* iOS: `tag`, a capsule of the gray fill 40pt tall (a tag cloud in a sheet, as Maps' Filters), or `glass`, a glass
|
|
27
|
+
* capsule 44pt tall (a filter in a row over content, as Maps' filters under its search). Android draws its chip with
|
|
28
|
+
* either. @default "tag"
|
|
29
|
+
*/
|
|
30
|
+
appearance?: "tag" | "glass";
|
|
24
31
|
/** An input chip: a cross at the end that calls this. */
|
|
25
32
|
onRemove?: () => void;
|
|
26
33
|
/** @default "Remove" */
|
|
@@ -31,8 +38,9 @@ export type ChipProps = {
|
|
|
31
38
|
};
|
|
32
39
|
/**
|
|
33
40
|
* A compact choice or action. Android: a chip (a 32dp capsule filled with the text color at 5%, Regular 14; a
|
|
34
|
-
* selected one in the Plex primary
|
|
35
|
-
*
|
|
41
|
+
* selected one in the Plex primary). iOS has no chip control: the filter capsules of iOS 26 apps (Maps), measured on
|
|
42
|
+
* an iPhone: a `tag` 40pt tall in the gray fill, or a `glass` capsule 44pt tall, the label 17/22 Regular; a selected
|
|
43
|
+
* one in the app's accent (its tint) with a white label. The web has
|
|
36
44
|
* no Chip; the props follow Toggle-like controls (`selected`, `onSelectedChange`) and Badge's `onRemove`.
|
|
37
45
|
*/
|
|
38
|
-
export declare function Chip({ children, selected: selectedProp, defaultSelected, onSelectedChange, onPress, icon, trailingIcon, menu, expanded, accessibilityLabel, onRemove, removeLabel, disabled, testID, style, }: ChipProps): import("react").JSX.Element;
|
|
46
|
+
export declare function Chip({ children, selected: selectedProp, defaultSelected, onSelectedChange, onPress, icon, trailingIcon, menu, expanded, accessibilityLabel, appearance, onRemove, removeLabel, disabled, testID, style, }: ChipProps): import("react").JSX.Element;
|
package/package.json
CHANGED
|
@@ -86,18 +86,33 @@ export function ActionSheet({ open, onOpenChange, title, message, actions, cance
|
|
|
86
86
|
const { width: windowWidth } = useWindowDimensions()
|
|
87
87
|
const sourced = !theme.isAndroid && source != null && !unplaced
|
|
88
88
|
useEffect(() => {
|
|
89
|
-
if (
|
|
89
|
+
if (theme.isAndroid || source == null) return
|
|
90
|
+
// Closed, the next opening tries its source again
|
|
91
|
+
if (!open) {
|
|
92
|
+
setUnplaced(false)
|
|
93
|
+
return
|
|
94
|
+
}
|
|
90
95
|
let live = true
|
|
91
96
|
// A new opening measures again: the panel never shows at the source's last place first
|
|
92
97
|
setAnchor(null)
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
// A frame at a time: a sheet open as its screen appears waits for its source's layout, up to 120 frames (2s), then
|
|
99
|
+
// stands in the middle
|
|
100
|
+
let frame = 0
|
|
101
|
+
const attempt = (left: number) => {
|
|
102
|
+
frame = requestAnimationFrame(() =>
|
|
103
|
+
measure(source.current as Measurable | null, (box) => {
|
|
104
|
+
if (!live) return
|
|
105
|
+
const placed = box.width > 0 || box.height > 0
|
|
106
|
+
if (!placed && left > 0) return attempt(left - 1)
|
|
107
|
+
setAnchor(placed ? box : null)
|
|
108
|
+
setUnplaced(!placed)
|
|
109
|
+
}),
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
attempt(120)
|
|
99
113
|
return () => {
|
|
100
114
|
live = false
|
|
115
|
+
cancelAnimationFrame(frame)
|
|
101
116
|
}
|
|
102
117
|
}, [open, theme.isAndroid, source, windowWidth, screen])
|
|
103
118
|
if (theme.isAndroid) {
|
|
@@ -186,9 +201,10 @@ export function ActionSheet({ open, onOpenChange, title, message, actions, cance
|
|
|
186
201
|
},
|
|
187
202
|
]}
|
|
188
203
|
>
|
|
189
|
-
{/* iOS 27's action sheet: every action
|
|
204
|
+
{/* iOS 27's action sheet: every action one weight, 17/22, a destructive one in the native red (the danger
|
|
205
|
+
solid). The kit's SF Semibold draws as heavy as Inter's Medium, so Medium, Cancel too */}
|
|
190
206
|
<Text
|
|
191
|
-
weight="
|
|
207
|
+
weight="medium"
|
|
192
208
|
color={item.disabled ? theme.color("--mobile-label-tertiary") : item.destructive ? theme.color("--color-background-danger-solid") : theme.colors.text}
|
|
193
209
|
style={styles.iosLabel}
|
|
194
210
|
>
|
|
@@ -3,6 +3,7 @@ import { Animated, Easing, Platform, Pressable, StyleSheet, View, type StyleProp
|
|
|
3
3
|
import ChevronDownSm from "../../icons/plex/ChevronDownSm"
|
|
4
4
|
import CloseBold from "../../icons/plex/CloseBold"
|
|
5
5
|
import { spaceToggles } from "../../internal/a11y"
|
|
6
|
+
import { Glass } from "../../internal/Glass"
|
|
6
7
|
import { withAlpha } from "../../theme/material"
|
|
7
8
|
import { useTheme } from "../../theme/ThemeProvider"
|
|
8
9
|
import { IconDefaultsProvider } from "../Icon/createIcon"
|
|
@@ -10,7 +11,8 @@ import { MaterialArrowDropDown } from "../Icon/material"
|
|
|
10
11
|
import { Text, textStyle } from "../Text/Text"
|
|
11
12
|
|
|
12
13
|
export type ChipProps = {
|
|
13
|
-
|
|
14
|
+
/** The label. Leave it out with an `icon` for a chip of the symbol alone, a circle named by `accessibilityLabel`. */
|
|
15
|
+
children?: ReactNode
|
|
14
16
|
/** A filter chip: chosen or not. Leave it out for an action chip. */
|
|
15
17
|
selected?: boolean
|
|
16
18
|
defaultSelected?: boolean
|
|
@@ -30,6 +32,12 @@ export type ChipProps = {
|
|
|
30
32
|
/** Whether the chip's menu is open (`aria-expanded`). */
|
|
31
33
|
expanded?: boolean
|
|
32
34
|
accessibilityLabel?: string
|
|
35
|
+
/**
|
|
36
|
+
* iOS: `tag`, a capsule of the gray fill 40pt tall (a tag cloud in a sheet, as Maps' Filters), or `glass`, a glass
|
|
37
|
+
* capsule 44pt tall (a filter in a row over content, as Maps' filters under its search). Android draws its chip with
|
|
38
|
+
* either. @default "tag"
|
|
39
|
+
*/
|
|
40
|
+
appearance?: "tag" | "glass"
|
|
33
41
|
/** An input chip: a cross at the end that calls this. */
|
|
34
42
|
onRemove?: () => void
|
|
35
43
|
/** @default "Remove" */
|
|
@@ -41,8 +49,9 @@ export type ChipProps = {
|
|
|
41
49
|
|
|
42
50
|
/**
|
|
43
51
|
* A compact choice or action. Android: a chip (a 32dp capsule filled with the text color at 5%, Regular 14; a
|
|
44
|
-
* selected one in the Plex primary
|
|
45
|
-
*
|
|
52
|
+
* selected one in the Plex primary). iOS has no chip control: the filter capsules of iOS 26 apps (Maps), measured on
|
|
53
|
+
* an iPhone: a `tag` 40pt tall in the gray fill, or a `glass` capsule 44pt tall, the label 17/22 Regular; a selected
|
|
54
|
+
* one in the app's accent (its tint) with a white label. The web has
|
|
46
55
|
* no Chip; the props follow Toggle-like controls (`selected`, `onSelectedChange`) and Badge's `onRemove`.
|
|
47
56
|
*/
|
|
48
57
|
export function Chip({
|
|
@@ -56,6 +65,7 @@ export function Chip({
|
|
|
56
65
|
menu,
|
|
57
66
|
expanded,
|
|
58
67
|
accessibilityLabel,
|
|
68
|
+
appearance = "tag",
|
|
59
69
|
onRemove,
|
|
60
70
|
removeLabel = "Remove",
|
|
61
71
|
disabled = false,
|
|
@@ -75,6 +85,7 @@ export function Chip({
|
|
|
75
85
|
onPress?.()
|
|
76
86
|
}
|
|
77
87
|
const android = theme.isAndroid
|
|
88
|
+
const glass = !android && appearance === "glass"
|
|
78
89
|
const m = theme.material
|
|
79
90
|
// Android: the label and the fill of either state, which a selection blends between
|
|
80
91
|
const androidColor = { off: m.onSurface, on: theme.color("--color-text-primary-solid") }
|
|
@@ -85,7 +96,7 @@ export function Chip({
|
|
|
85
96
|
? androidColor.on
|
|
86
97
|
: androidColor.off
|
|
87
98
|
: selected
|
|
88
|
-
? theme.color("--color-text-
|
|
99
|
+
? theme.color("--color-text-accent-solid", "#FFFFFF")
|
|
89
100
|
: disabled
|
|
90
101
|
? theme.colors.textDisabled
|
|
91
102
|
: theme.colors.text
|
|
@@ -94,9 +105,12 @@ export function Chip({
|
|
|
94
105
|
? androidFill.on
|
|
95
106
|
: androidFill.off
|
|
96
107
|
: selected
|
|
97
|
-
? //
|
|
98
|
-
|
|
99
|
-
|
|
108
|
+
? // The app's accent, as iOS tints a chosen filter; a disabled selected chip fades to 40%, so it still stands
|
|
109
|
+
// apart from an off one
|
|
110
|
+
withAlpha(theme.colors.accent, disabled ? 0.4 : 1)
|
|
111
|
+
: glass
|
|
112
|
+
? "transparent"
|
|
113
|
+
: theme.color("--color-background-secondary-soft-alpha")
|
|
100
114
|
// Android blends the fill and the label from one state to the other in 120ms, linear; iOS changes at once
|
|
101
115
|
const [blend] = useState(() => new Animated.Value(selected ? 1 : 0))
|
|
102
116
|
const blends = android && !theme.reducedMotion
|
|
@@ -113,13 +127,16 @@ export function Chip({
|
|
|
113
127
|
}, [blend, blends, selected])
|
|
114
128
|
const fillPaint = blends ? blend.interpolate({ inputRange: [0, 1], outputRange: [androidFill.off, androidFill.on] }) : fill
|
|
115
129
|
const labelPaint = blends ? blend.interpolate({ inputRange: [0, 1], outputRange: [androidColor.off, androidColor.on] }) : color
|
|
116
|
-
const height = android ? 32 :
|
|
117
|
-
const label = android ? { fontSize: 14, lineHeight: 18 } : { fontSize:
|
|
130
|
+
const height = android ? 32 : glass ? 44 : 40
|
|
131
|
+
const label = android ? { fontSize: 14, lineHeight: 18 } : { fontSize: 17, lineHeight: 22 }
|
|
118
132
|
const leading = icon
|
|
119
|
-
|
|
133
|
+
// iOS: a 17pt symbol draws about 20 (the label's size)
|
|
134
|
+
const iconSize = android ? 18 : 20
|
|
120
135
|
// A menu chip's chevron: Material's 18dp arrow_drop_down, iOS's small chevron.down at the label's weight
|
|
121
|
-
const trailing = trailingIcon ?? (menu ? android ? <MaterialArrowDropDown size={18} /> : <ChevronDownSm size={
|
|
136
|
+
const trailing = trailingIcon ?? (menu ? android ? <MaterialArrowDropDown size={18} /> : <ChevronDownSm size={16} /> : null)
|
|
122
137
|
const leadingColor = color
|
|
138
|
+
// A symbol alone (Maps' filter button before its chips): a circle as tall as the chip, named by accessibilityLabel
|
|
139
|
+
const symbolOnly = leading != null && (children == null || children === "") && trailing == null && !onRemove
|
|
123
140
|
// The chip is drawn 32 (34) tall inside a 48dp (44pt) touch target, as Compose's minimum interactive size and the
|
|
124
141
|
// HIG ask: the target is the layout box, the chip a layer inside it, so every press in the target reaches it
|
|
125
142
|
const target = android ? 48 : 44
|
|
@@ -127,7 +144,10 @@ export function Chip({
|
|
|
127
144
|
// A capsule, which stays one when a large text size makes it taller
|
|
128
145
|
const radius = 999
|
|
129
146
|
const [pressed, setPressed] = useState(false)
|
|
130
|
-
|
|
147
|
+
// iOS's glass filter: a glass capsule (its rim and sheen), filled with the accent once chosen
|
|
148
|
+
const glassLayer =
|
|
149
|
+
glass && !selected ? <Glass pointerEvents="none" radius={radius} style={[StyleSheet.absoluteFill, { top: inset, bottom: inset }]} /> : null
|
|
150
|
+
const layer = glassLayer ?? (
|
|
131
151
|
<Animated.View pointerEvents="none" style={[StyleSheet.absoluteFill, { top: inset, bottom: inset, borderRadius: radius, backgroundColor: fillPaint, borderCurve: "continuous" }]}>
|
|
132
152
|
{/* Android's press: the list selector over the chip, 6% black and 5% white at night (the dark theme's); over a
|
|
133
153
|
selected chip's solid fill its label's color at 12%, which shows on either scheme */}
|
|
@@ -142,9 +162,9 @@ export function Chip({
|
|
|
142
162
|
minHeight: target,
|
|
143
163
|
paddingVertical: inset + (height - label.lineHeight) / 2,
|
|
144
164
|
// Android: 12 at the sides, 8 before an icon and 6 after it
|
|
145
|
-
paddingLeft: leading != null ? (android ? 8 : 12) : android ? 12 :
|
|
146
|
-
// Android: 8 after a trailing icon (Compose's FilterChip), iOS
|
|
147
|
-
paddingRight: onRemove ? 0 : trailing != null ? (android ? 8 :
|
|
165
|
+
paddingLeft: symbolOnly ? (height - iconSize) / 2 : leading != null ? (android ? 8 : 12) : android ? 12 : 16,
|
|
166
|
+
// Android: 8 after a trailing icon (Compose's FilterChip), iOS 12
|
|
167
|
+
paddingRight: symbolOnly ? (height - iconSize) / 2 : onRemove ? 0 : trailing != null ? (android ? 8 : 12) : android ? 12 : 16,
|
|
148
168
|
gap: 6,
|
|
149
169
|
opacity: !android && pressed ? 0.7 : 1,
|
|
150
170
|
}
|
|
@@ -158,7 +178,7 @@ export function Chip({
|
|
|
158
178
|
</IconDefaultsProvider>
|
|
159
179
|
</View>
|
|
160
180
|
) : null}
|
|
161
|
-
{android ? (
|
|
181
|
+
{symbolOnly ? null : android ? (
|
|
162
182
|
// Text's own face and tracking, in a color that blends
|
|
163
183
|
<Animated.Text
|
|
164
184
|
numberOfLines={1}
|
|
@@ -167,7 +187,7 @@ export function Chip({
|
|
|
167
187
|
{children}
|
|
168
188
|
</Animated.Text>
|
|
169
189
|
) : (
|
|
170
|
-
<Text color={color} weight="
|
|
190
|
+
<Text color={color} weight="regular" numberOfLines={1} style={{ fontSize: label.fontSize, lineHeight: label.lineHeight }}>
|
|
171
191
|
{children}
|
|
172
192
|
</Text>
|
|
173
193
|
)}
|