glacia-native 0.4.0 → 0.5.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/lib/module/Bars.js +269 -0
- package/lib/module/Carousel.js +103 -0
- package/lib/module/Display.js +317 -0
- package/lib/module/Feedback.js +386 -0
- package/lib/module/Forms2.js +454 -0
- package/lib/module/Message.js +88 -0
- package/lib/module/Overlays.js +328 -0
- package/lib/module/Pickers.js +243 -0
- package/lib/module/SegmentedControl.js +5 -1
- package/lib/module/Slider.js +6 -1
- package/lib/module/Switch.js +4 -1
- package/lib/module/TabBar.js +5 -1
- package/lib/module/Text.js +37 -0
- package/lib/module/ai.js +8 -3
- package/lib/module/index.js +79 -1
- package/lib/module/internal/GlassContainer.js +54 -0
- package/lib/module/internal/GlassView.js +31 -7
- package/lib/module/internal/a11y.js +94 -0
- package/lib/module/internal/fallback.js +19 -8
- package/lib/module/internal/glass-routing.js +7 -0
- package/lib/module/internal/haptics.js +54 -0
- package/lib/module/internal/motion.js +10 -1
- package/lib/module/internal/primitives.js +73 -3
- package/lib/module/internal/tokens.js +101 -1
- package/lib/typescript/Bars.d.ts +188 -0
- package/lib/typescript/Carousel.d.ts +47 -0
- package/lib/typescript/Display.d.ts +178 -0
- package/lib/typescript/Feedback.d.ts +196 -0
- package/lib/typescript/Forms2.d.ts +209 -0
- package/lib/typescript/Glass.d.ts +1 -1
- package/lib/typescript/Message.d.ts +71 -0
- package/lib/typescript/Overlays.d.ts +146 -0
- package/lib/typescript/Pickers.d.ts +105 -0
- package/lib/typescript/SegmentedControl.d.ts +2 -0
- package/lib/typescript/Slider.d.ts +2 -0
- package/lib/typescript/Switch.d.ts +2 -0
- package/lib/typescript/TabBar.d.ts +2 -0
- package/lib/typescript/Text.d.ts +28 -0
- package/lib/typescript/index.d.ts +11 -1
- package/lib/typescript/internal/GlassContainer.d.ts +37 -0
- package/lib/typescript/internal/GlassView.d.ts +18 -1
- package/lib/typescript/internal/a11y.d.ts +19 -0
- package/lib/typescript/internal/fallback.d.ts +5 -0
- package/lib/typescript/internal/glass-routing.d.ts +10 -0
- package/lib/typescript/internal/haptics.d.ts +7 -0
- package/lib/typescript/internal/motion.d.ts +4 -0
- package/lib/typescript/internal/primitives.d.ts +21 -0
- package/lib/typescript/internal/tokens.d.ts +114 -0
- package/package.json +2 -2
- package/src/Bars.tsx +797 -0
- package/src/Carousel.tsx +233 -0
- package/src/Display.tsx +778 -0
- package/src/Feedback.tsx +969 -0
- package/src/Forms2.tsx +1014 -0
- package/src/Message.tsx +219 -0
- package/src/Overlays.tsx +685 -0
- package/src/Pickers.tsx +590 -0
- package/src/SegmentedControl.tsx +6 -0
- package/src/Slider.tsx +7 -0
- package/src/Switch.tsx +5 -0
- package/src/TabBar.tsx +6 -0
- package/src/Text.tsx +83 -0
- package/src/ai.tsx +9 -3
- package/src/index.ts +142 -1
- package/src/internal/GlassContainer.tsx +82 -0
- package/src/internal/GlassView.tsx +37 -7
- package/src/internal/a11y.ts +105 -0
- package/src/internal/fallback.tsx +19 -2
- package/src/internal/glass-routing.ts +17 -0
- package/src/internal/haptics.ts +59 -0
- package/src/internal/motion.ts +10 -1
- package/src/internal/primitives.ts +84 -3
- package/src/internal/tokens.ts +110 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FABGroup = exports.AppBar = exports.IconButton = exports.FAB = exports.Chip = exports.SearchBar = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const Glass_1 = require("./Glass");
|
|
7
|
+
const tokens_1 = require("./internal/tokens");
|
|
8
|
+
const primitives_1 = require("./internal/primitives");
|
|
9
|
+
const motion_1 = require("./internal/motion");
|
|
10
|
+
/**
|
|
11
|
+
* A search field for a bar or a screen header.
|
|
12
|
+
*
|
|
13
|
+
* Distinct from NativeAIInput: that is an AI composer with send semantics, this
|
|
14
|
+
* is ordinary app search — magnifier, themed placeholder, and a clear button
|
|
15
|
+
* once there is something to clear.
|
|
16
|
+
*/
|
|
17
|
+
exports.SearchBar = (0, react_1.forwardRef)(function SearchBar({ value: valueProp, defaultValue = "", onChangeText, onSubmit, placeholder = "Search", showCancel = false, onCancel, accessibilityLabel = "Search", style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
18
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
19
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
20
|
+
const { View, Text: RNText, TextInput, Pressable } = (0, primitives_1.primitives)();
|
|
21
|
+
const [internal, setInternal] = (0, react_1.useState)(defaultValue);
|
|
22
|
+
const value = valueProp !== undefined ? valueProp : internal;
|
|
23
|
+
const handleChange = (next) => {
|
|
24
|
+
if (valueProp === undefined)
|
|
25
|
+
setInternal(next);
|
|
26
|
+
onChangeText?.(next);
|
|
27
|
+
};
|
|
28
|
+
const clear = () => handleChange("");
|
|
29
|
+
return ((0, jsx_runtime_1.jsxs)(View, { ref: ref, testID: testID, style: [{ flexDirection: "row", alignItems: "center", gap: 8 }, style], ...props, children: [(0, jsx_runtime_1.jsxs)(Glass_1.Glass, { effect: "regular", isDark: isDark, style: {
|
|
30
|
+
flex: 1,
|
|
31
|
+
flexDirection: "row",
|
|
32
|
+
alignItems: "center",
|
|
33
|
+
gap: 8,
|
|
34
|
+
height: 36,
|
|
35
|
+
borderRadius: tokens_1.radii.pill,
|
|
36
|
+
paddingHorizontal: 12,
|
|
37
|
+
}, children: [(0, jsx_runtime_1.jsx)(RNText, { accessibilityElementsHidden: true, importantForAccessibility: "no", style: { fontSize: 14, color: theme.muted }, children: "\u2315" }), (0, jsx_runtime_1.jsxs)(View, { style: { flex: 1, justifyContent: "center" }, children: [!value && placeholder ? (
|
|
38
|
+
// Themed placeholder: the OS default colour ignores the theme.
|
|
39
|
+
(0, jsx_runtime_1.jsx)(RNText, { pointerEvents: "none", numberOfLines: 1, style: { position: "absolute", left: 0, fontSize: 15, color: theme.muted }, children: placeholder })) : null, (0, jsx_runtime_1.jsx)(TextInput, { accessibilityRole: "search", accessibilityLabel: accessibilityLabel, value: value, onChangeText: handleChange, onSubmitEditing: () => onSubmit?.(value), returnKeyType: "search", autoCorrect: false, placeholder: "", style: {
|
|
40
|
+
fontSize: 15,
|
|
41
|
+
paddingVertical: 4,
|
|
42
|
+
color: theme.foreground,
|
|
43
|
+
// Transparent: the themed placeholder above provides the hint.
|
|
44
|
+
backgroundColor: "transparent",
|
|
45
|
+
} })] }), value.length > 0 && ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: "Clear search", onPress: clear, hitSlop: 8, children: (0, jsx_runtime_1.jsx)(View, { style: {
|
|
46
|
+
width: 16,
|
|
47
|
+
height: 16,
|
|
48
|
+
// A circle from its own size: half the 16pt box.
|
|
49
|
+
borderRadius: 16 / 2,
|
|
50
|
+
backgroundColor: theme.separator,
|
|
51
|
+
alignItems: "center",
|
|
52
|
+
justifyContent: "center",
|
|
53
|
+
}, children: (0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 10, color: theme.muted }, children: "\u00D7" }) }) }))] }), showCancel && ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: "Cancel", onPress: () => {
|
|
54
|
+
clear();
|
|
55
|
+
onCancel?.();
|
|
56
|
+
}, children: (0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 15, color: theme.fill }, children: "Cancel" }) }))] }));
|
|
57
|
+
});
|
|
58
|
+
/**
|
|
59
|
+
* A filter or tag pill.
|
|
60
|
+
*
|
|
61
|
+
* Selected state is a glass pill tinted with `glassActive` — the same selected
|
|
62
|
+
* treatment SegmentedControl and TabBar use, rather than a new colour.
|
|
63
|
+
*/
|
|
64
|
+
exports.Chip = (0, react_1.forwardRef)(function Chip({ label, icon, onClose, onPress, selected: selectedProp, defaultSelected = false, onSelectedChange, disabled = false, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
65
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
66
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
67
|
+
const { View, Text: RNText, Pressable } = (0, primitives_1.primitives)();
|
|
68
|
+
const [internalSelected, setInternalSelected] = (0, react_1.useState)(defaultSelected);
|
|
69
|
+
const selected = selectedProp !== undefined ? selectedProp : internalSelected;
|
|
70
|
+
const selectable = selectedProp !== undefined || onSelectedChange !== undefined || defaultSelected;
|
|
71
|
+
const handlePress = () => {
|
|
72
|
+
if (disabled)
|
|
73
|
+
return;
|
|
74
|
+
if (selectable) {
|
|
75
|
+
const next = !selected;
|
|
76
|
+
if (selectedProp === undefined)
|
|
77
|
+
setInternalSelected(next);
|
|
78
|
+
onSelectedChange?.(next);
|
|
79
|
+
}
|
|
80
|
+
onPress?.();
|
|
81
|
+
};
|
|
82
|
+
const pill = ((0, jsx_runtime_1.jsxs)(Glass_1.Glass, { effect: "regular", isDark: isDark, tintColor: selected ? theme.glassActive : undefined, interactive: !disabled, style: {
|
|
83
|
+
flexDirection: "row",
|
|
84
|
+
alignItems: "center",
|
|
85
|
+
gap: 6,
|
|
86
|
+
height: 30,
|
|
87
|
+
paddingHorizontal: 12,
|
|
88
|
+
borderRadius: tokens_1.radii.pill,
|
|
89
|
+
opacity: disabled ? 0.38 : 1,
|
|
90
|
+
...style,
|
|
91
|
+
}, children: [icon ? (0, jsx_runtime_1.jsx)(View, { children: icon }) : null, (0, jsx_runtime_1.jsx)(RNText, { numberOfLines: 1, style: { fontSize: 13, fontWeight: selected ? "600" : "500", color: selected ? theme.foreground : theme.muted }, children: label }), onClose && ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: `Remove ${label}`, onPress: onClose, hitSlop: 8, children: (0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 11, color: theme.muted }, children: "\u00D7" }) }))] }));
|
|
92
|
+
if (!onPress && !selectable) {
|
|
93
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, accessibilityRole: "text", accessibilityLabel: label, ...props, children: pill }));
|
|
94
|
+
}
|
|
95
|
+
return ((0, jsx_runtime_1.jsx)(Pressable, { ref: ref, testID: testID, accessibilityRole: "button", accessibilityLabel: label, accessibilityState: { selected: selectable ? selected : undefined, disabled }, disabled: disabled, onPress: handlePress, ...props, children: pill }));
|
|
96
|
+
});
|
|
97
|
+
const fabSizes = { md: 56, lg: 64 };
|
|
98
|
+
/**
|
|
99
|
+
* The floating action button.
|
|
100
|
+
*
|
|
101
|
+
* The flagship glass circle of the library: a round `Glass` with `interactive`
|
|
102
|
+
* so the material itself responds to touch. The caller positions it; the
|
|
103
|
+
* component does not assume an edge.
|
|
104
|
+
*/
|
|
105
|
+
exports.FAB = (0, react_1.forwardRef)(function FAB({ onPress, accessibilityLabel, icon, label, size = "md", disabled = false, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
106
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
107
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
108
|
+
const { View, Text: RNText, Pressable } = (0, primitives_1.primitives)();
|
|
109
|
+
const dimension = fabSizes[size];
|
|
110
|
+
const extended = Boolean(label);
|
|
111
|
+
return ((0, jsx_runtime_1.jsx)(Pressable, { ref: ref, testID: testID, accessibilityRole: "button", accessibilityLabel: accessibilityLabel, accessibilityState: { disabled }, disabled: disabled, onPress: disabled ? undefined : onPress, style: ({ pressed }) => ({
|
|
112
|
+
alignSelf: "flex-start",
|
|
113
|
+
opacity: disabled ? 0.38 : pressed ? 0.85 : 1,
|
|
114
|
+
}), ...props, children: (0, jsx_runtime_1.jsxs)(Glass_1.Glass, { effect: "clear", interactive: !disabled, isDark: isDark, style: {
|
|
115
|
+
height: dimension,
|
|
116
|
+
width: extended ? undefined : dimension,
|
|
117
|
+
minWidth: dimension,
|
|
118
|
+
borderRadius: extended ? dimension / 2 : dimension / 2,
|
|
119
|
+
paddingHorizontal: extended ? 20 : 0,
|
|
120
|
+
flexDirection: "row",
|
|
121
|
+
alignItems: "center",
|
|
122
|
+
justifyContent: "center",
|
|
123
|
+
gap: 8,
|
|
124
|
+
...style,
|
|
125
|
+
}, children: [icon ? (0, jsx_runtime_1.jsx)(View, { children: icon }) : null, label ? ((0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 15, fontWeight: "600", color: theme.foreground }, numberOfLines: 1, children: label })) : null] }) }));
|
|
126
|
+
});
|
|
127
|
+
const iconButtonSizes = { sm: 28, md: 36, lg: 44 };
|
|
128
|
+
/**
|
|
129
|
+
* An icon-only button on glass.
|
|
130
|
+
*
|
|
131
|
+
* Button takes an icon alongside a label; this is the icon-only form, which
|
|
132
|
+
* every kit ships for toolbars and bar actions.
|
|
133
|
+
*/
|
|
134
|
+
exports.IconButton = (0, react_1.forwardRef)(function IconButton({ accessibilityLabel, onPress, icon, size = "md", variant = "glass", disabled = false, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
135
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
136
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
137
|
+
const { View, Pressable } = (0, primitives_1.primitives)();
|
|
138
|
+
const dimension = iconButtonSizes[size];
|
|
139
|
+
return ((0, jsx_runtime_1.jsx)(Pressable, { ref: ref, testID: testID, accessibilityRole: "button", accessibilityLabel: accessibilityLabel, accessibilityState: { disabled }, disabled: disabled, onPress: disabled ? undefined : onPress, style: ({ pressed }) => ({ opacity: disabled ? 0.38 : pressed ? 0.8 : 1 }), ...props, children: (0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: variant === "ghost" ? "none" : "regular", interactive: !disabled && variant !== "ghost", isDark: isDark, style: {
|
|
140
|
+
width: dimension,
|
|
141
|
+
height: dimension,
|
|
142
|
+
borderRadius: dimension / 2,
|
|
143
|
+
alignItems: "center",
|
|
144
|
+
justifyContent: "center",
|
|
145
|
+
backgroundColor: variant === "ghost" ? "transparent" : undefined,
|
|
146
|
+
...style,
|
|
147
|
+
}, children: (0, jsx_runtime_1.jsx)(View, { style: { width: dimension * 0.5, height: dimension * 0.5, alignItems: "center", justifyContent: "center" }, children: icon }) }) }));
|
|
148
|
+
});
|
|
149
|
+
/**
|
|
150
|
+
* The top bar.
|
|
151
|
+
*
|
|
152
|
+
* A glass bar across the top of the screen with a leading action, a title and
|
|
153
|
+
* trailing actions — the counterpart to the existing bottom TabBar.
|
|
154
|
+
*
|
|
155
|
+
* `scrolled` mirrors iOS 26's scroll-edge effect. At the top of the screen the
|
|
156
|
+
* bar is quiet: its bottom edge is invisible and the glass blends into the
|
|
157
|
+
* content above it. Once content has scrolled under it, the edge token becomes
|
|
158
|
+
* visible and the surface reads as a distinct layer — the change iOS makes when
|
|
159
|
+
* a navigation bar starts floating over scrolled content.
|
|
160
|
+
*
|
|
161
|
+
* ```
|
|
162
|
+
* const [scrolled, setScrolled] = useState(false);
|
|
163
|
+
* <ScrollView onScroll={(e) => setScrolled(e.nativeEvent.contentOffset.y > 8)}
|
|
164
|
+
* scrollEventThrottle={16}>{...}</ScrollView>
|
|
165
|
+
* <AppBar title="Inbox" scrolled={scrolled} />
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
exports.AppBar = (0, react_1.forwardRef)(function AppBar({ title, subtitle, leading, actions, topInset = 0, scrolled = false, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
169
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
170
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
171
|
+
const { View, Text: RNText, Pressable } = (0, primitives_1.primitives)();
|
|
172
|
+
const actionCount = actions?.length ?? 0;
|
|
173
|
+
const renderAction = (action, key) => ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: action.accessibilityLabel, accessibilityState: { disabled: action.disabled }, disabled: action.disabled, onPress: action.disabled ? undefined : action.onPress, hitSlop: 6, style: { padding: 6, opacity: action.disabled ? 0.38 : 1 }, children: action.icon }, key));
|
|
174
|
+
return ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { ref: ref, effect: "regular", isDark: isDark, testID: testID, style: {
|
|
175
|
+
borderRadius: 0,
|
|
176
|
+
borderTopWidth: 0,
|
|
177
|
+
borderLeftWidth: 0,
|
|
178
|
+
borderRightWidth: 0,
|
|
179
|
+
// Quiet at the top of a screen, defined once content is under it: the
|
|
180
|
+
// bottom edge is the difference iOS draws on a scrolled navigation bar.
|
|
181
|
+
...(scrolled ? { borderBottomWidth: 0.5, borderBottomColor: theme.edge } : { borderBottomWidth: 0 }),
|
|
182
|
+
...style,
|
|
183
|
+
}, ...props, children: (0, jsx_runtime_1.jsxs)(View, { style: {
|
|
184
|
+
paddingTop: topInset,
|
|
185
|
+
paddingHorizontal: 8,
|
|
186
|
+
paddingBottom: 8,
|
|
187
|
+
flexDirection: "row",
|
|
188
|
+
alignItems: "center",
|
|
189
|
+
gap: 4,
|
|
190
|
+
minHeight: 44 + topInset,
|
|
191
|
+
}, children: [leading ? renderAction(leading, "leading") : (0, jsx_runtime_1.jsx)(View, { style: { width: 8 } }), (0, jsx_runtime_1.jsxs)(View, { style: { flex: 1, paddingHorizontal: 4 }, children: [(0, jsx_runtime_1.jsx)(RNText, { accessibilityRole: "header", numberOfLines: 1, style: { fontSize: 17, fontWeight: "600", color: theme.foreground }, children: title }), subtitle ? ((0, jsx_runtime_1.jsx)(RNText, { numberOfLines: 1, style: { fontSize: 12, color: theme.muted }, children: subtitle })) : null] }), actions && actionCount > 0 ? ((0, jsx_runtime_1.jsx)(View, { style: { flexDirection: "row", alignItems: "center" }, children: actions.map((action, index) => renderAction(action, `action-${index}`)) })) : null] }) }));
|
|
192
|
+
});
|
|
193
|
+
// The main button's size, and the mini buttons' — both from the size scale so
|
|
194
|
+
// a mini button is never a hand-tuned multiple of the main one.
|
|
195
|
+
const fabGroupSizes = {
|
|
196
|
+
md: { main: 56, mini: 44 },
|
|
197
|
+
lg: { main: 64, mini: 52 },
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* A main button that expands into a stack of labelled mini buttons.
|
|
201
|
+
*
|
|
202
|
+
* The pattern Paper calls `FAB.Group`: one floating button stands in for a set
|
|
203
|
+
* of actions until it is opened, then the actions appear above it, each on its
|
|
204
|
+
* own glass pill with a label. A scrim behind them takes the next press and
|
|
205
|
+
* closes the group, which is how a floating action set gets out of the way
|
|
206
|
+
* without a dismissal button.
|
|
207
|
+
*
|
|
208
|
+
* The mini buttons rise on the bouncy spring with a small stagger, and the main
|
|
209
|
+
* button's icon rotates 45° — both settle instantly under Reduce Motion.
|
|
210
|
+
*
|
|
211
|
+
* **Merging is an iOS 26+ visual effect.** This component is one glass surface
|
|
212
|
+
* plus one per action; to have them blend into a single connected surface, put
|
|
213
|
+
* the group inside a `GlassContainer` on iOS 26. It works standalone — nothing
|
|
214
|
+
* depends on the container — and that composition is left to the caller rather
|
|
215
|
+
* than forced, because a group outside a container is the correct rendering on
|
|
216
|
+
* every other platform anyway.
|
|
217
|
+
*/
|
|
218
|
+
exports.FABGroup = (0, react_1.forwardRef)(function FABGroup({ actions, icon, closeIcon, open: openProp, defaultOpen = false, onOpenChange, accessibilityLabel = "More actions", size = "md", style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
219
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
220
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
221
|
+
const { View, Text: RNText, Pressable, Animated } = (0, primitives_1.primitives)();
|
|
222
|
+
const [internalOpen, setInternalOpen] = (0, react_1.useState)(defaultOpen);
|
|
223
|
+
const open = openProp !== undefined ? openProp : internalOpen;
|
|
224
|
+
const setOpen = (next) => {
|
|
225
|
+
if (openProp === undefined)
|
|
226
|
+
setInternalOpen(next);
|
|
227
|
+
onOpenChange?.(next);
|
|
228
|
+
};
|
|
229
|
+
// The stack's rise is one value: 0 closed, 1 open. The mini buttons ride it
|
|
230
|
+
// with their own stagger, so they follow the lead rather than all snapping
|
|
231
|
+
// at once.
|
|
232
|
+
const { value: rise, animated } = (0, motion_1.useSpring)(open ? 1 : 0, "bouncy");
|
|
233
|
+
const { main: dimension, mini } = fabGroupSizes[size];
|
|
234
|
+
const closeFirst = closeIcon ?? icon;
|
|
235
|
+
const rotate = animated ? rise.interpolate({ inputRange: [0, 1], outputRange: ["0deg", "45deg"] }) : open ? "45deg" : "0deg";
|
|
236
|
+
return ((0, jsx_runtime_1.jsxs)(View, { ref: ref, testID: testID, style: style, ...props, children: [open ? ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: "Close actions", onPress: () => setOpen(false), style: { position: "absolute", top: -2000, left: -2000, right: -2000, bottom: -2000, backgroundColor: theme.scrim } })) : null, (0, jsx_runtime_1.jsxs)(View, { style: { alignItems: "flex-end", gap: 10 }, children: [open
|
|
237
|
+
? actions.map((action, index) => {
|
|
238
|
+
// Later actions sit higher, so the first is nearest the button.
|
|
239
|
+
const order = actions.length - 1 - index;
|
|
240
|
+
const translateY = animated
|
|
241
|
+
? rise.interpolate({
|
|
242
|
+
inputRange: [0, 1],
|
|
243
|
+
outputRange: [24 + order * 18, 0],
|
|
244
|
+
})
|
|
245
|
+
: 0;
|
|
246
|
+
const opacity = animated ? rise.interpolate({ inputRange: [0, 0.4, 1], outputRange: [0, 0, 1] }) : 1;
|
|
247
|
+
const pill = ((0, jsx_runtime_1.jsxs)(Pressable, { accessibilityRole: "button", accessibilityLabel: action.label, onPress: () => {
|
|
248
|
+
setOpen(false);
|
|
249
|
+
action.onPress();
|
|
250
|
+
}, style: { flexDirection: "row", alignItems: "center", gap: 8 }, children: [(0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", isDark: isDark, style: { borderRadius: tokens_1.radii.pill, paddingHorizontal: 12, paddingVertical: 7 }, children: (0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 13, fontWeight: "600", color: theme.foreground }, numberOfLines: 1, children: action.label }) }), (0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", isDark: isDark, style: {
|
|
251
|
+
width: mini,
|
|
252
|
+
height: mini,
|
|
253
|
+
borderRadius: mini / 2,
|
|
254
|
+
alignItems: "center",
|
|
255
|
+
justifyContent: "center",
|
|
256
|
+
}, children: action.icon })] }));
|
|
257
|
+
if (!animated) {
|
|
258
|
+
return ((0, jsx_runtime_1.jsx)(View, { children: pill }, `${action.label}-${index}`));
|
|
259
|
+
}
|
|
260
|
+
return ((0, jsx_runtime_1.jsx)(Animated.View, { style: { transform: [{ translateY }], opacity }, children: pill }, `${action.label}-${index}`));
|
|
261
|
+
})
|
|
262
|
+
: null, (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: accessibilityLabel, accessibilityState: { expanded: open }, onPress: () => setOpen(!open), children: (0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "clear", interactive: true, isDark: isDark, style: {
|
|
263
|
+
width: dimension,
|
|
264
|
+
height: dimension,
|
|
265
|
+
borderRadius: dimension / 2,
|
|
266
|
+
alignItems: "center",
|
|
267
|
+
justifyContent: "center",
|
|
268
|
+
}, children: animated ? ((0, jsx_runtime_1.jsx)(Animated.View, { style: { transform: [{ rotate }] }, children: open ? closeFirst : icon })) : ((0, jsx_runtime_1.jsx)(View, { children: open ? closeFirst : icon })) }) })] })] }));
|
|
269
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PageControl = exports.Carousel = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const tokens_1 = require("./internal/tokens");
|
|
7
|
+
const primitives_1 = require("./internal/primitives");
|
|
8
|
+
const motion_1 = require("./internal/motion");
|
|
9
|
+
/**
|
|
10
|
+
* A horizontally paging swiper.
|
|
11
|
+
*
|
|
12
|
+
* It rides the resolver's ScrollView with `pagingEnabled`, so the paging feel is
|
|
13
|
+
* the platform's own and the pages are plain content the caller supplies. The
|
|
14
|
+
* active page is derived from the scroll offset, which is also what reports
|
|
15
|
+
* `onIndexChange`.
|
|
16
|
+
*/
|
|
17
|
+
exports.Carousel = (0, react_1.forwardRef)(function Carousel({ slides, index: indexProp, defaultIndex = 0, onIndexChange, gap = 0, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
18
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
19
|
+
const { getScrollView } = (0, primitives_1.primitives)();
|
|
20
|
+
const ScrollView = getScrollView();
|
|
21
|
+
const { View } = (0, primitives_1.primitives)();
|
|
22
|
+
const [internalIndex, setInternalIndex] = (0, react_1.useState)(defaultIndex);
|
|
23
|
+
const index = indexProp !== undefined ? indexProp : internalIndex;
|
|
24
|
+
const viewportWidth = (0, react_1.useRef)(0);
|
|
25
|
+
const scrollRef = (0, react_1.useRef)(null);
|
|
26
|
+
// Derives the page from the offset rather than trusting a counter, so a
|
|
27
|
+
// fast swipe that skips pages still reports the page it landed on.
|
|
28
|
+
const handleScroll = (event) => {
|
|
29
|
+
const { contentOffset, layoutMeasurement } = event?.nativeEvent ?? {};
|
|
30
|
+
const width = layoutMeasurement?.width || viewportWidth.current;
|
|
31
|
+
if (!width || !contentOffset)
|
|
32
|
+
return;
|
|
33
|
+
const next = Math.round(contentOffset.x / width);
|
|
34
|
+
const clamped = Math.min(Math.max(next, 0), Math.max(slides.length - 1, 0));
|
|
35
|
+
if (clamped !== index) {
|
|
36
|
+
if (indexProp === undefined)
|
|
37
|
+
setInternalIndex(clamped);
|
|
38
|
+
onIndexChange?.(clamped);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const pages = slides.map((slide, i) => ((0, jsx_runtime_1.jsx)(View, { style: { width: viewportWidth.current || "100%", paddingRight: gap }, children: slide }, i)));
|
|
42
|
+
// Off-device there is no ScrollView; the pages still render in a row so the
|
|
43
|
+
// component mounts, and the tests drive `handleScroll` through onScroll.
|
|
44
|
+
if (!ScrollView) {
|
|
45
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, style: [{ flexDirection: "row", overflow: "hidden" }, style], ...props, children: pages }));
|
|
46
|
+
}
|
|
47
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, onLayout: (event) => {
|
|
48
|
+
viewportWidth.current = event?.nativeEvent?.layout?.width ?? 0;
|
|
49
|
+
}, style: style, ...props, children: (0, jsx_runtime_1.jsx)(ScrollView, { ref: scrollRef, horizontal: true, pagingEnabled: gap === 0, showsHorizontalScrollIndicator: false, onScroll: handleScroll, scrollEventThrottle: 16, accessibilityRole: "adjustable", accessibilityLabel: "Carousel", accessibilityValue: { min: 0, max: Math.max(slides.length - 1, 0), now: index }, accessibilityActions: [{ name: "increment" }, { name: "decrement" }], onAccessibilityAction: (event) => {
|
|
50
|
+
const step = event?.nativeEvent?.actionName === "increment" ? 1 : -1;
|
|
51
|
+
const next = Math.min(Math.max(index + step, 0), Math.max(slides.length - 1, 0));
|
|
52
|
+
if (next === index)
|
|
53
|
+
return;
|
|
54
|
+
if (indexProp === undefined)
|
|
55
|
+
setInternalIndex(next);
|
|
56
|
+
onIndexChange?.(next);
|
|
57
|
+
}, children: pages }) }));
|
|
58
|
+
});
|
|
59
|
+
const DOT = 7;
|
|
60
|
+
const ACTIVE_DOT = 18;
|
|
61
|
+
/**
|
|
62
|
+
* The page dots.
|
|
63
|
+
*
|
|
64
|
+
* The active dot elongates and the others stay narrow, which is how iOS reads
|
|
65
|
+
* "you are here". The width change runs on the springs token through Animated.
|
|
66
|
+
*/
|
|
67
|
+
exports.PageControl = (0, react_1.forwardRef)(function PageControl({ count, activeIndex: activeProp, defaultActiveIndex = 0, onChange, tint, hidesForSinglePage = false, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
68
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
69
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
70
|
+
const { View, Pressable } = (0, primitives_1.primitives)();
|
|
71
|
+
const [internalIndex, setInternalIndex] = (0, react_1.useState)(defaultActiveIndex);
|
|
72
|
+
const active = activeProp !== undefined ? activeProp : internalIndex;
|
|
73
|
+
if (hidesForSinglePage && count <= 1)
|
|
74
|
+
return null;
|
|
75
|
+
// The accent tints the active dot; the resting dots sit on `glassActive` so
|
|
76
|
+
// selection reads the same way it does in SegmentedControl and TabBar.
|
|
77
|
+
const accent = tint ?? theme.fill;
|
|
78
|
+
const resting = theme.glassActive;
|
|
79
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, accessibilityRole: "tablist", style: [{ flexDirection: "row", alignItems: "center", gap: 6, alignSelf: "center" }, style], ...props, children: Array.from({ length: Math.max(count, 0) }, (_, index) => {
|
|
80
|
+
const isActive = index === active;
|
|
81
|
+
return ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "tab", accessibilityLabel: `Page ${index + 1} of ${count}`, accessibilityState: { selected: isActive }, onPress: () => {
|
|
82
|
+
if (activeProp === undefined)
|
|
83
|
+
setInternalIndex(index);
|
|
84
|
+
onChange?.(index);
|
|
85
|
+
}, hitSlop: 8, children: (0, jsx_runtime_1.jsx)(Dot, { active: isActive, accent: accent, muted: resting }) }, index));
|
|
86
|
+
}) }));
|
|
87
|
+
});
|
|
88
|
+
/** One dot, whose width springs between the resting and active lengths. */
|
|
89
|
+
function Dot({ active, accent, muted }) {
|
|
90
|
+
const { Animated, View } = (0, primitives_1.primitives)();
|
|
91
|
+
const { value: progress, animated } = (0, motion_1.useSpring)(active ? 1 : 0, "snappy");
|
|
92
|
+
const width = animated
|
|
93
|
+
? progress.interpolate({ inputRange: [0, 1], outputRange: [DOT, ACTIVE_DOT] })
|
|
94
|
+
: active
|
|
95
|
+
? ACTIVE_DOT
|
|
96
|
+
: DOT;
|
|
97
|
+
const style = {
|
|
98
|
+
height: DOT,
|
|
99
|
+
borderRadius: DOT / 2,
|
|
100
|
+
backgroundColor: active ? accent : muted,
|
|
101
|
+
};
|
|
102
|
+
return animated ? ((0, jsx_runtime_1.jsx)(Animated.View, { style: { ...style, width } })) : ((0, jsx_runtime_1.jsx)(View, { style: { ...style, width: width } }));
|
|
103
|
+
}
|