glacia-native 0.5.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 +95 -2
- package/lib/module/Display.js +78 -1
- package/lib/module/Feedback.js +221 -7
- package/lib/module/Forms2.js +228 -1
- package/lib/module/Message.js +88 -0
- package/lib/module/Overlays.js +173 -11
- 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/ai.js +8 -3
- package/lib/module/index.js +23 -2
- package/lib/module/internal/GlassContainer.js +54 -0
- package/lib/module/internal/GlassView.js +8 -0
- 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 +69 -4
- package/lib/module/internal/tokens.js +47 -1
- package/lib/typescript/Bars.d.ts +67 -0
- package/lib/typescript/Display.d.ts +59 -0
- package/lib/typescript/Feedback.d.ts +58 -0
- package/lib/typescript/Forms2.d.ts +81 -0
- package/lib/typescript/Message.d.ts +71 -0
- package/lib/typescript/Overlays.d.ts +41 -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/index.d.ts +8 -6
- package/lib/typescript/internal/GlassContainer.d.ts +37 -0
- package/lib/typescript/internal/GlassView.d.ts +8 -0
- 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 +53 -0
- package/package.json +2 -2
- package/src/Bars.tsx +227 -0
- package/src/Display.tsx +229 -1
- package/src/Feedback.tsx +412 -22
- package/src/Forms2.tsx +407 -1
- package/src/Message.tsx +219 -0
- package/src/Overlays.tsx +244 -33
- 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/ai.tsx +9 -3
- package/src/index.ts +42 -1
- package/src/internal/GlassContainer.tsx +82 -0
- package/src/internal/GlassView.tsx +8 -0
- 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 +80 -4
- package/src/internal/tokens.ts +48 -0
package/lib/module/Bars.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AppBar = exports.IconButton = exports.FAB = exports.Chip = exports.SearchBar = void 0;
|
|
3
|
+
exports.FABGroup = exports.AppBar = exports.IconButton = exports.FAB = exports.Chip = exports.SearchBar = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const Glass_1 = require("./Glass");
|
|
@@ -151,8 +151,21 @@ exports.IconButton = (0, react_1.forwardRef)(function IconButton({ accessibility
|
|
|
151
151
|
*
|
|
152
152
|
* A glass bar across the top of the screen with a leading action, a title and
|
|
153
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
|
+
* ```
|
|
154
167
|
*/
|
|
155
|
-
exports.AppBar = (0, react_1.forwardRef)(function AppBar({ title, subtitle, leading, actions, topInset = 0, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
168
|
+
exports.AppBar = (0, react_1.forwardRef)(function AppBar({ title, subtitle, leading, actions, topInset = 0, scrolled = false, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
156
169
|
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
157
170
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
158
171
|
const { View, Text: RNText, Pressable } = (0, primitives_1.primitives)();
|
|
@@ -163,6 +176,9 @@ exports.AppBar = (0, react_1.forwardRef)(function AppBar({ title, subtitle, lead
|
|
|
163
176
|
borderTopWidth: 0,
|
|
164
177
|
borderLeftWidth: 0,
|
|
165
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 }),
|
|
166
182
|
...style,
|
|
167
183
|
}, ...props, children: (0, jsx_runtime_1.jsxs)(View, { style: {
|
|
168
184
|
paddingTop: topInset,
|
|
@@ -174,3 +190,80 @@ exports.AppBar = (0, react_1.forwardRef)(function AppBar({ title, subtitle, lead
|
|
|
174
190
|
minHeight: 44 + topInset,
|
|
175
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] }) }));
|
|
176
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
|
+
});
|
package/lib/module/Display.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Progress = exports.Spinner = exports.Skeleton = exports.Separator = exports.Badge = exports.Avatar = void 0;
|
|
3
|
+
exports.NativeImage = exports.Rating = exports.Progress = exports.Spinner = exports.Skeleton = exports.Separator = exports.Badge = exports.Avatar = void 0;
|
|
4
4
|
exports.initialsOf = initialsOf;
|
|
5
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
6
|
const react_1 = require("react");
|
|
@@ -238,3 +238,80 @@ exports.Progress = (0, react_1.forwardRef)(function Progress({ value, variant =
|
|
|
238
238
|
backgroundColor: fill,
|
|
239
239
|
} }) }));
|
|
240
240
|
});
|
|
241
|
+
// ---------------------------------------------------------------------------
|
|
242
|
+
// Rating
|
|
243
|
+
/** The five-pointed star, as a path in a unit box. */
|
|
244
|
+
const STAR_PATH = "M12 2.4l2.95 5.98 6.6.96-4.78 4.66 1.13 6.57L12 17.46l-5.9 3.11 1.13-6.57L2.45 9.34l6.6-.96z";
|
|
245
|
+
/**
|
|
246
|
+
* A star rating.
|
|
247
|
+
*
|
|
248
|
+
* The stars are drawn as SVG paths from the resolver, so nothing is a
|
|
249
|
+
* platform control. A fractional value fills part of a star: 3.5 draws three
|
|
250
|
+
* full stars and one half, the half produced by clipping the filled star at the
|
|
251
|
+
* fraction's width rather than by rounding — a 4.5-star average must look like
|
|
252
|
+
* a 4.5-star average.
|
|
253
|
+
*
|
|
254
|
+
* Read-only unless `onChange` is given. With it, each star is tappable, the
|
|
255
|
+
* value is exposed as an adjustable control (increment/decrement through
|
|
256
|
+
* accessibility actions), and each star has its own label so a screen reader
|
|
257
|
+
* can name the exact rating it sets.
|
|
258
|
+
*/
|
|
259
|
+
exports.Rating = (0, react_1.forwardRef)(function Rating({ value, max = 5, size = "md", onChange, disabled = false, accessibilityLabel = "Rating", style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
260
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
261
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
262
|
+
const { View, Pressable, Svg, Path, Defs, ClipPath, Rect } = (0, primitives_1.primitives)();
|
|
263
|
+
const starSize = tokens_1.controlSizes.star[size];
|
|
264
|
+
const interactive = Boolean(onChange) && !disabled;
|
|
265
|
+
const clamped = Math.max(0, Math.min(value, max));
|
|
266
|
+
const setValue = (next) => {
|
|
267
|
+
const bounded = Math.max(0, Math.min(next, max));
|
|
268
|
+
onChange?.(bounded);
|
|
269
|
+
};
|
|
270
|
+
const star = (index) => {
|
|
271
|
+
// How much of this star is filled: 1 for a full star, 0 for empty, and the
|
|
272
|
+
// remainder for the one the value lands inside.
|
|
273
|
+
const filled = Math.max(0, Math.min(1, clamped - index));
|
|
274
|
+
const half = filled > 0 && filled < 1;
|
|
275
|
+
const glyph = ((0, jsx_runtime_1.jsxs)(Svg, { width: starSize, height: starSize, viewBox: "0 0 24 24", children: [half ? ((0, jsx_runtime_1.jsx)(Defs, { children: (0, jsx_runtime_1.jsx)(ClipPath, { id: `rating-clip-${index}`, children: (0, jsx_runtime_1.jsx)(Rect, { x: "0", y: "0", width: 24 * filled, height: 24 }) }) })) : null, (0, jsx_runtime_1.jsx)(Path, { d: STAR_PATH, fill: theme.separator }), filled > 0 ? ((0, jsx_runtime_1.jsx)(Path, { d: STAR_PATH, fill: theme.fill, ...(half ? { clipPath: `url(#rating-clip-${index})` } : {}) })) : null] }));
|
|
276
|
+
if (!interactive)
|
|
277
|
+
return (0, jsx_runtime_1.jsx)(View, { children: glyph }, index);
|
|
278
|
+
return ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: `${index + 1} of ${max} stars`, accessibilityState: { selected: clamped === index + 1 }, onPress: () => setValue(index + 1), hitSlop: 4, children: glyph }, index));
|
|
279
|
+
};
|
|
280
|
+
const stars = Array.from({ length: Math.max(1, max) }, (_unused, index) => star(index));
|
|
281
|
+
if (!interactive && !onChange) {
|
|
282
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, accessibilityRole: "text", accessibilityLabel: `${accessibilityLabel}, ${clamped} of ${max}`, style: { flexDirection: "row", alignItems: "center", gap: 2, ...style }, ...props, children: stars }));
|
|
283
|
+
}
|
|
284
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, accessibilityRole: "adjustable", accessibilityLabel: accessibilityLabel, accessibilityState: { disabled }, accessibilityValue: { min: 0, max, now: clamped }, accessibilityActions: [{ name: "increment" }, { name: "decrement" }], onAccessibilityAction: (event) => {
|
|
285
|
+
if (disabled)
|
|
286
|
+
return;
|
|
287
|
+
if (event?.nativeEvent?.actionName === "increment")
|
|
288
|
+
setValue(clamped + 1);
|
|
289
|
+
if (event?.nativeEvent?.actionName === "decrement")
|
|
290
|
+
setValue(clamped - 1);
|
|
291
|
+
}, style: { flexDirection: "row", alignItems: "center", gap: 2, opacity: disabled ? 0.38 : 1, ...style }, ...props, children: stars }));
|
|
292
|
+
});
|
|
293
|
+
/**
|
|
294
|
+
* A plain image, with the loading and error states every app ends up writing.
|
|
295
|
+
*
|
|
296
|
+
* Three states, because an image on a phone is three states: loading (a
|
|
297
|
+
* Skeleton behind it), loaded (a fade in), and failed (the caller's fallback).
|
|
298
|
+
* Aspect ratio comes from `style`, so a caller sets `aspectRatio` and the height
|
|
299
|
+
* follows.
|
|
300
|
+
*
|
|
301
|
+
* This is the plain one; `NativeImageGeneration` is the AI-specific cousin and
|
|
302
|
+
* keeps its own state machine.
|
|
303
|
+
*/
|
|
304
|
+
exports.NativeImage = (0, react_1.forwardRef)(function NativeImage({ source, accessibilityLabel, placeholder, fallback, fadeIn = true, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
305
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
306
|
+
const { View, Image: RNImage, Animated } = (0, primitives_1.primitives)();
|
|
307
|
+
const [failed, setFailed] = (0, react_1.useState)(false);
|
|
308
|
+
const [loaded, setLoaded] = (0, react_1.useState)(false);
|
|
309
|
+
const { value: fade, animated } = (0, motion_1.useSpring)(loaded ? 1 : 0, "gentle");
|
|
310
|
+
const boxStyle = { overflow: "hidden", ...style };
|
|
311
|
+
if (failed && fallback) {
|
|
312
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, style: boxStyle, ...props, children: fallback }));
|
|
313
|
+
}
|
|
314
|
+
const imageStyle = { width: "100%", height: "100%" };
|
|
315
|
+
const opacity = fadeIn && animated ? fade : 1;
|
|
316
|
+
return ((0, jsx_runtime_1.jsxs)(View, { ref: ref, testID: testID, style: boxStyle, ...props, children: [!loaded ? (0, jsx_runtime_1.jsx)(View, { style: { position: "absolute", top: 0, left: 0, right: 0, bottom: 0 }, children: placeholder ?? (0, jsx_runtime_1.jsx)(exports.Skeleton, { shape: "rect", isDark: isDark }) }) : null, (0, jsx_runtime_1.jsx)(RNImage, { accessibilityRole: "image", accessibilityLabel: accessibilityLabel, source: source, onLoad: () => setLoaded(true), onError: () => setFailed(true), style: [imageStyle, animated ? { opacity } : null] })] }));
|
|
317
|
+
});
|
package/lib/module/Feedback.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Accordion = exports.ListSection = exports.List = exports.ListItem = exports.Banner = exports.Toast = void 0;
|
|
3
|
+
exports.Accordion = exports.ListSection = exports.List = exports.ListItem = exports.Banner = exports.ToastViewport = exports.Toast = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const Glass_1 = require("./Glass");
|
|
@@ -8,6 +8,7 @@ const Display_1 = require("./Display");
|
|
|
8
8
|
const tokens_1 = require("./internal/tokens");
|
|
9
9
|
const primitives_1 = require("./internal/primitives");
|
|
10
10
|
const motion_1 = require("./internal/motion");
|
|
11
|
+
const haptics_1 = require("./internal/haptics");
|
|
11
12
|
/**
|
|
12
13
|
* A transient message on a glass pill.
|
|
13
14
|
*
|
|
@@ -66,6 +67,97 @@ function Entrance({ animated, rise, fade, children, }) {
|
|
|
66
67
|
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
|
|
67
68
|
return ((0, jsx_runtime_1.jsx)(Animated.View, { style: { transform: [{ translateY: rise }], opacity: fade }, children: children }));
|
|
68
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* A queue of toasts, stacked the way Sonner stacks them.
|
|
72
|
+
*
|
|
73
|
+
* Three at a time is the practical limit: beyond that the messages stop being
|
|
74
|
+
* read and start covering the screen. Extras wait in the order they arrived, so
|
|
75
|
+
* no message is lost and the newest is never hidden behind a backlog.
|
|
76
|
+
*
|
|
77
|
+
* Each toast is independently dismissible — its own timer, its own action, and
|
|
78
|
+
* a swipe up. Swiping one up removes only that one.
|
|
79
|
+
*
|
|
80
|
+
* The single `Toast` keeps working unchanged: this is the host for when an app
|
|
81
|
+
* has several messages at once, not a replacement. A caller that shows one
|
|
82
|
+
* message continues to use `Toast` directly.
|
|
83
|
+
*/
|
|
84
|
+
exports.ToastViewport = (0, react_1.forwardRef)(function ToastViewport({ toasts, onDismiss, max = 3, position = "bottom", style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
85
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
86
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
87
|
+
const { View, PanResponder } = (0, primitives_1.primitives)();
|
|
88
|
+
// The visible window is the newest `max`, so a burst shows the latest
|
|
89
|
+
// messages rather than a stale backlog. Earlier ones remain queued in the
|
|
90
|
+
// caller's array and appear as the visible ones leave.
|
|
91
|
+
//
|
|
92
|
+
// A host is often rendered for the whole life of a screen and simply has no
|
|
93
|
+
// messages yet, so an absent queue means empty rather than a crash.
|
|
94
|
+
const visible = (toasts ?? []).slice(0, Math.max(0, max));
|
|
95
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, pointerEvents: "box-none", style: {
|
|
96
|
+
position: "absolute",
|
|
97
|
+
left: 0,
|
|
98
|
+
right: 0,
|
|
99
|
+
alignItems: "center",
|
|
100
|
+
gap: 8,
|
|
101
|
+
...(position === "top" ? { top: 16 } : { bottom: 16 }),
|
|
102
|
+
...style,
|
|
103
|
+
}, ...props, children: visible.map((toast) => ((0, jsx_runtime_1.jsx)(SwipeableToast, { toast: toast, isDark: isDark, onDismiss: () => onDismiss(toast.id), theme: theme }, toast.id))) }));
|
|
104
|
+
});
|
|
105
|
+
/**
|
|
106
|
+
* One toast inside the viewport, with the swipe-up dismissal.
|
|
107
|
+
*
|
|
108
|
+
* Wrapping the existing Toast would have meant threading the gesture through
|
|
109
|
+
* its props, so the viewport renders the same pill with the gesture attached —
|
|
110
|
+
* the styling lives in one place (`Toast`), and this adds only the drag.
|
|
111
|
+
*/
|
|
112
|
+
function SwipeableToast({ toast, isDark, onDismiss, theme, }) {
|
|
113
|
+
const { View, Text: RNText, Pressable, PanResponder, Animated } = (0, primitives_1.primitives)();
|
|
114
|
+
const [lift, setLift] = (0, react_1.useState)(0);
|
|
115
|
+
const dismissRef = (0, react_1.useRef)(onDismiss);
|
|
116
|
+
dismissRef.current = onDismiss;
|
|
117
|
+
const duration = toast.duration ?? 4000;
|
|
118
|
+
(0, react_1.useEffect)(() => {
|
|
119
|
+
if (duration <= 0)
|
|
120
|
+
return;
|
|
121
|
+
const timer = setTimeout(() => dismissRef.current(), duration);
|
|
122
|
+
return () => clearTimeout(timer);
|
|
123
|
+
}, [duration]);
|
|
124
|
+
const panResponder = (0, react_1.useMemo)(() => {
|
|
125
|
+
if (!PanResponder?.create)
|
|
126
|
+
return null;
|
|
127
|
+
return PanResponder.create({
|
|
128
|
+
onMoveShouldSetPanResponder: (_event, gesture) =>
|
|
129
|
+
// Only an upward swipe removes a toast; downward drags are ignored.
|
|
130
|
+
gesture.dy < -8 && Math.abs(gesture.dy) > Math.abs(gesture.dx),
|
|
131
|
+
onPanResponderMove: (_event, gesture) => setLift(Math.min(0, gesture.dy)),
|
|
132
|
+
onPanResponderRelease: (_event, gesture) => {
|
|
133
|
+
// A quick flick or a long drag removes it; anything less springs back.
|
|
134
|
+
if (gesture.dy < -40 || gesture.vy < -0.5) {
|
|
135
|
+
dismissRef.current();
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
setLift(0);
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
onPanResponderTerminate: () => setLift(0),
|
|
142
|
+
});
|
|
143
|
+
}, [PanResponder]);
|
|
144
|
+
const tone = toast.tone ?? "neutral";
|
|
145
|
+
const accent = tone === "neutral" ? theme.foreground : (0, tokens_1.toneColor)(theme, tone);
|
|
146
|
+
const pill = ((0, jsx_runtime_1.jsxs)(Glass_1.Glass, { effect: "regular", isDark: isDark, style: {
|
|
147
|
+
flexDirection: "row",
|
|
148
|
+
alignItems: "center",
|
|
149
|
+
gap: 10,
|
|
150
|
+
paddingVertical: 10,
|
|
151
|
+
paddingHorizontal: 14,
|
|
152
|
+
borderRadius: tokens_1.radii.pill,
|
|
153
|
+
maxWidth: 420,
|
|
154
|
+
borderColor: tone === "neutral" ? theme.edge : accent,
|
|
155
|
+
}, children: [toast.icon ? (0, jsx_runtime_1.jsx)(View, { children: toast.icon }) : null, (0, jsx_runtime_1.jsx)(RNText, { accessibilityRole: "alert", accessibilityLiveRegion: "polite", style: { fontSize: 14, color: theme.foreground, flexShrink: 1 }, children: toast.message }), toast.action ? ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: toast.action.label, onPress: () => {
|
|
156
|
+
toast.action?.onPress();
|
|
157
|
+
onDismiss();
|
|
158
|
+
}, style: { paddingHorizontal: 4 }, children: (0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 14, fontWeight: "600", color: theme.fill }, children: toast.action.label }) })) : null] }));
|
|
159
|
+
return ((0, jsx_runtime_1.jsx)(View, { style: { transform: [{ translateY: lift }], opacity: lift === 0 ? 1 : Math.max(0.4, 1 + lift / 120) }, ...(panResponder ? panResponder.panHandlers : {}), children: pill }));
|
|
160
|
+
}
|
|
69
161
|
/**
|
|
70
162
|
* An inline alert.
|
|
71
163
|
*
|
|
@@ -81,6 +173,14 @@ exports.Banner = (0, react_1.forwardRef)(function Banner({ title, message, tone
|
|
|
81
173
|
const accent = (0, tokens_1.toneColor)(theme, tone);
|
|
82
174
|
return ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { ref: ref, effect: "regular", isDark: isDark, testID: testID, style: { borderRadius: tokens_1.radii.md, borderColor: accent, ...style }, ...props, children: (0, jsx_runtime_1.jsxs)(View, { style: { flexDirection: "row", alignItems: "flex-start", gap: 10, padding: 12 }, children: [icon ? (0, jsx_runtime_1.jsx)(View, { style: { paddingTop: 1 }, children: icon }) : null, (0, jsx_runtime_1.jsxs)(View, { style: { flex: 1, gap: 2 }, children: [title && ((0, jsx_runtime_1.jsx)(RNText, { accessibilityRole: "heading", style: { fontSize: 14, fontWeight: "600", color: theme.foreground }, children: title })), (0, jsx_runtime_1.jsx)(RNText, { accessibilityRole: "alert", style: { fontSize: 13, color: theme.muted, lineHeight: 18 }, children: message }), action && ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: action.label, onPress: action.onPress, style: { alignSelf: "flex-start", paddingTop: 6 }, children: (0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 13, fontWeight: "600", color: accent }, children: action.label }) }))] }), onDismiss && ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: "Dismiss", onPress: onDismiss, hitSlop: 8, style: { padding: 2 }, children: (0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 15, color: theme.muted }, children: "\u00D7" }) }))] }) }));
|
|
83
175
|
});
|
|
176
|
+
/**
|
|
177
|
+
* Tracks which row of a List is open, so opening one closes the rest.
|
|
178
|
+
*
|
|
179
|
+
* A list with two open rows looks broken; iOS Mail and every kit that copied
|
|
180
|
+
* it keep at most one. The List provides the registry and each swipeable row
|
|
181
|
+
* registers its own close function.
|
|
182
|
+
*/
|
|
183
|
+
const OpenRowContext = (0, react_1.createContext)(null);
|
|
84
184
|
/**
|
|
85
185
|
* One row of a List.
|
|
86
186
|
*
|
|
@@ -89,12 +189,102 @@ exports.Banner = (0, react_1.forwardRef)(function Banner({ title, message, tone
|
|
|
89
189
|
* itself as a button. The chevron is decoration and is hidden from screen
|
|
90
190
|
* readers, since the row's own role already says it is tappable.
|
|
91
191
|
*/
|
|
92
|
-
exports.ListItem = (0, react_1.forwardRef)(function ListItem({ leading, title, description, trailing, chevron, onPress, disabled = false, selected = false, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
192
|
+
exports.ListItem = (0, react_1.forwardRef)(function ListItem({ leading, title, description, trailing, chevron, onPress, disabled = false, selected = false, swipeActions, leadingSwipeActions, swipeActionWidth = 78, swipeable = true, haptics = true, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
93
193
|
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
94
194
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
95
|
-
const { View, Text: RNText, Pressable } = (0, primitives_1.primitives)();
|
|
195
|
+
const { View, Text: RNText, Pressable, PanResponder } = (0, primitives_1.primitives)();
|
|
196
|
+
const rowGroup = (0, react_1.useContext)(OpenRowContext);
|
|
96
197
|
const interactive = Boolean(onPress) && !disabled;
|
|
97
198
|
const showChevron = interactive && chevron !== false && trailing === undefined;
|
|
199
|
+
const trailActions = swipeActions?.filter(Boolean) ?? [];
|
|
200
|
+
const leadActions = leadingSwipeActions?.filter(Boolean) ?? [];
|
|
201
|
+
const canSwipe = swipeable && !disabled && (trailActions.length > 0 || leadActions.length > 0);
|
|
202
|
+
// The row's own identity, so a List can close its siblings.
|
|
203
|
+
const rowId = (0, react_1.useRef)(`row-${Math.random().toString(36).slice(2)}`);
|
|
204
|
+
// 0 is closed; a positive offset reveals trailing actions, negative leading.
|
|
205
|
+
const [offset, setOffset] = (0, react_1.useState)(0);
|
|
206
|
+
const offsetRef = (0, react_1.useRef)(0);
|
|
207
|
+
offsetRef.current = offset;
|
|
208
|
+
// A gesture that moved is a swipe, not a tap: the press that follows the
|
|
209
|
+
// release must not fire the row's onPress.
|
|
210
|
+
const swipedRef = (0, react_1.useRef)(false);
|
|
211
|
+
const trailingWidth = trailActions.length * swipeActionWidth;
|
|
212
|
+
const leadingWidth = leadActions.length * swipeActionWidth;
|
|
213
|
+
const close = () => setOffset(0);
|
|
214
|
+
// When another row opens, this one closes.
|
|
215
|
+
(0, react_1.useEffect)(() => {
|
|
216
|
+
if (rowGroup && rowGroup.openId !== rowId.current && offsetRef.current !== 0) {
|
|
217
|
+
setOffset(0);
|
|
218
|
+
}
|
|
219
|
+
}, [rowGroup?.openId]);
|
|
220
|
+
const settle = (next) => {
|
|
221
|
+
setOffset(next);
|
|
222
|
+
if (rowGroup) {
|
|
223
|
+
rowGroup.setOpenId(next !== 0 ? rowId.current : null);
|
|
224
|
+
}
|
|
225
|
+
if (next !== 0 && haptics && offsetRef.current === 0)
|
|
226
|
+
(0, haptics_1.hapticSelection)();
|
|
227
|
+
};
|
|
228
|
+
const panResponder = (0, react_1.useMemo)(() => {
|
|
229
|
+
if (!canSwipe || !PanResponder?.create)
|
|
230
|
+
return null;
|
|
231
|
+
return PanResponder.create({
|
|
232
|
+
// A horizontal drag claims the gesture; a vertical one stays with the
|
|
233
|
+
// surrounding scroll view.
|
|
234
|
+
onMoveShouldSetPanResponder: (_event, gesture) => Math.abs(gesture.dx) > Math.abs(gesture.dy) && Math.abs(gesture.dx) > 8,
|
|
235
|
+
onPanResponderGrant: () => {
|
|
236
|
+
swipedRef.current = false;
|
|
237
|
+
},
|
|
238
|
+
onPanResponderMove: (_event, gesture) => {
|
|
239
|
+
if (Math.abs(gesture.dx) > 4)
|
|
240
|
+
swipedRef.current = true;
|
|
241
|
+
const from = offsetRef.current;
|
|
242
|
+
let next = from + gesture.dx;
|
|
243
|
+
// Do not drag past what the actions actually occupy; a small
|
|
244
|
+
// overshoot makes the edge feel elastic rather than hard.
|
|
245
|
+
next = Math.min(next, trailingWidth + 24);
|
|
246
|
+
next = Math.max(next, -(leadingWidth + 24));
|
|
247
|
+
setOffset(next);
|
|
248
|
+
},
|
|
249
|
+
onPanResponderRelease: (_event, gesture) => {
|
|
250
|
+
const released = offsetRef.current;
|
|
251
|
+
// Beyond half an action, or with a decisive flick, it stays open;
|
|
252
|
+
// otherwise it falls back closed.
|
|
253
|
+
if (gesture.dx > 0 && trailActions.length > 0) {
|
|
254
|
+
settle(released > trailingWidth / 2 || gesture.vx > 0.5 ? trailingWidth : 0);
|
|
255
|
+
}
|
|
256
|
+
else if (gesture.dx < 0 && leadActions.length > 0) {
|
|
257
|
+
settle(released < -leadingWidth / 2 || gesture.vx < -0.5 ? -leadingWidth : 0);
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
settle(offsetRef.current > 0 ? Math.min(offsetRef.current, trailingWidth) : Math.max(offsetRef.current, -leadingWidth));
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
onPanResponderTerminate: () => settle(0),
|
|
264
|
+
onPanResponderTerminationRequest: () => false,
|
|
265
|
+
});
|
|
266
|
+
// The responder reads from refs, so it never acts on a stale offset.
|
|
267
|
+
}, [canSwipe, PanResponder, trailingWidth, leadingWidth, trailActions.length, leadActions.length]);
|
|
268
|
+
/**
|
|
269
|
+
* Runs an action and closes the row.
|
|
270
|
+
*
|
|
271
|
+
* The action is dispatched first so its own feedback is not delayed by the
|
|
272
|
+
* close, then the row resets — the reveal should not outlive the press.
|
|
273
|
+
*/
|
|
274
|
+
const runAction = (action) => {
|
|
275
|
+
action.onPress();
|
|
276
|
+
settle(0);
|
|
277
|
+
if (rowGroup)
|
|
278
|
+
rowGroup.setOpenId(null);
|
|
279
|
+
};
|
|
280
|
+
const guardPress = (handler) => () => {
|
|
281
|
+
// Swallow the press that ends a swipe.
|
|
282
|
+
if (swipedRef.current) {
|
|
283
|
+
swipedRef.current = false;
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
handler?.();
|
|
287
|
+
};
|
|
98
288
|
const content = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [leading ? (0, jsx_runtime_1.jsx)(View, { style: { marginRight: 12 }, children: leading }) : null, (0, jsx_runtime_1.jsxs)(View, { style: { flex: 1, gap: 2 }, children: [(0, jsx_runtime_1.jsx)(RNText, { numberOfLines: 1, style: { fontSize: 16, color: theme.foreground, fontWeight: "400" }, children: title }), description ? ((0, jsx_runtime_1.jsx)(RNText, { numberOfLines: 2, style: { fontSize: 13, color: theme.muted, lineHeight: 17 }, children: description })) : null] }), trailing ? (0, jsx_runtime_1.jsx)(View, { style: { marginLeft: 8 }, children: trailing }) : null, showChevron ? ((0, jsx_runtime_1.jsx)(RNText, { accessibilityElementsHidden: true, importantForAccessibility: "no", style: { marginLeft: 6, fontSize: 17, color: theme.muted }, children: "\u203A" })) : null] }));
|
|
99
289
|
const rowStyle = {
|
|
100
290
|
flexDirection: "row",
|
|
@@ -106,10 +296,30 @@ exports.ListItem = (0, react_1.forwardRef)(function ListItem({ leading, title, d
|
|
|
106
296
|
opacity: disabled ? 0.38 : 1,
|
|
107
297
|
...style,
|
|
108
298
|
};
|
|
109
|
-
|
|
110
|
-
|
|
299
|
+
const rowInner = !interactive ? ((0, jsx_runtime_1.jsx)(View, { accessibilityRole: "text", accessibilityState: { disabled }, style: rowStyle, children: content })) : ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: description ? `${title}, ${description}` : title, accessibilityState: { selected, disabled }, disabled: disabled, onPress: guardPress(onPress), style: ({ pressed }) => ({ ...rowStyle, opacity: pressed ? 0.7 : rowStyle.opacity }), children: content }));
|
|
300
|
+
if (!canSwipe) {
|
|
301
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, style: { overflow: "hidden" }, ...props, children: rowInner }));
|
|
111
302
|
}
|
|
112
|
-
|
|
303
|
+
/** The tinted tray behind the row: glass-tinted actions, flat not glass. */
|
|
304
|
+
const tray = (actions, edge) => ((0, jsx_runtime_1.jsx)(View, { style: {
|
|
305
|
+
position: "absolute",
|
|
306
|
+
top: 0,
|
|
307
|
+
bottom: 0,
|
|
308
|
+
[edge]: 0,
|
|
309
|
+
flexDirection: "row",
|
|
310
|
+
}, children: actions.map((action, index) => ((0, jsx_runtime_1.jsxs)(Pressable, { accessibilityRole: "button", accessibilityLabel: action.label, onPress: () => runAction(action), style: {
|
|
311
|
+
width: swipeActionWidth,
|
|
312
|
+
alignItems: "center",
|
|
313
|
+
justifyContent: "center",
|
|
314
|
+
gap: 3,
|
|
315
|
+
backgroundColor: action.color ?? theme.glassActive,
|
|
316
|
+
}, children: [action.icon, (0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 12, color: theme.foreground }, numberOfLines: 1, children: action.label })] }, `${action.label}-${index}`))) }));
|
|
317
|
+
return ((0, jsx_runtime_1.jsxs)(View, { ref: ref, testID: testID, accessibilityRole: "none", style: { overflow: "hidden" }, ...props, children: [leadActions.length > 0 ? tray(leadActions, "right") : null, trailActions.length > 0 ? tray(trailActions, "left") : null, (0, jsx_runtime_1.jsx)(View, { style: {
|
|
318
|
+
transform: [{ translateX: offset }],
|
|
319
|
+
// The row rides over its tray while it is open, so the actions are
|
|
320
|
+
// uncovered rather than shown alongside.
|
|
321
|
+
backgroundColor: "transparent",
|
|
322
|
+
}, ...(panResponder ? panResponder.panHandlers : {}), children: rowInner })] }));
|
|
113
323
|
});
|
|
114
324
|
/**
|
|
115
325
|
* A grouped list of rows — the backbone of settings and profile screens.
|
|
@@ -122,7 +332,11 @@ exports.List = (0, react_1.forwardRef)(function List({ children, inset = false,
|
|
|
122
332
|
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
123
333
|
const { View } = (0, primitives_1.primitives)();
|
|
124
334
|
const rows = Array.isArray(children) ? children.filter(Boolean) : children == null ? [] : [children];
|
|
125
|
-
|
|
335
|
+
// At most one swipeable row is open at a time, so a list never shows two
|
|
336
|
+
// trays at once.
|
|
337
|
+
const [openId, setOpenId] = (0, react_1.useState)(null);
|
|
338
|
+
const group = (0, react_1.useMemo)(() => ({ openId, setOpenId }), [openId]);
|
|
339
|
+
const body = ((0, jsx_runtime_1.jsx)(OpenRowContext.Provider, { value: group, children: (0, jsx_runtime_1.jsx)(View, { style: { gap: 2 }, children: rows.map((row, index) => ((0, jsx_runtime_1.jsxs)(View, { children: [index > 0 ? (0, jsx_runtime_1.jsx)(Display_1.Separator, { isDark: isDark, inset: inset ? 14 : 0 }) : null, row] }, index))) }) }));
|
|
126
340
|
if (!inset) {
|
|
127
341
|
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, style: style, ...props, children: body }));
|
|
128
342
|
}
|