glacia-native 0.3.5 → 0.5.0

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.
Files changed (121) hide show
  1. package/lib/module/Bars.js +176 -0
  2. package/lib/module/Button.js +15 -2
  3. package/lib/module/Card.js +29 -14
  4. package/lib/module/Carousel.js +103 -0
  5. package/lib/module/Dialog.js +43 -32
  6. package/lib/module/Display.js +240 -0
  7. package/lib/module/Feedback.js +172 -0
  8. package/lib/module/Form.js +51 -12
  9. package/lib/module/Forms2.js +227 -0
  10. package/lib/module/Glass.js +11 -2
  11. package/lib/module/Input.js +19 -7
  12. package/lib/module/Overlays.js +166 -0
  13. package/lib/module/Pickers.js +243 -0
  14. package/lib/module/SegmentedControl.js +65 -21
  15. package/lib/module/Slider.js +121 -25
  16. package/lib/module/Switch.js +33 -15
  17. package/lib/module/TabBar.js +63 -25
  18. package/lib/module/Table.js +24 -6
  19. package/lib/module/Tabs.js +55 -33
  20. package/lib/module/Text.js +37 -0
  21. package/lib/module/ai.js +49 -20
  22. package/lib/module/charts/BarChart.js +4 -2
  23. package/lib/module/charts/FunnelChart.js +4 -2
  24. package/lib/module/charts/HeatmapChart.js +4 -2
  25. package/lib/module/charts/LineChart.js +4 -2
  26. package/lib/module/charts/PlotChart.js +11 -3
  27. package/lib/module/charts/RadarChart.js +4 -2
  28. package/lib/module/charts/RingChart.js +4 -2
  29. package/lib/module/charts/ScatterChart.js +20 -3
  30. package/lib/module/charts/WaterfallChart.js +12 -3
  31. package/lib/module/charts/advanced.js +12 -6
  32. package/lib/module/charts/extra.js +6 -3
  33. package/lib/module/index.js +58 -1
  34. package/lib/module/internal/GlassView.js +31 -17
  35. package/lib/module/internal/fallback.js +14 -3
  36. package/lib/module/internal/glass-routing.js +56 -0
  37. package/lib/module/internal/motion.js +55 -0
  38. package/lib/module/internal/primitives.js +413 -0
  39. package/lib/module/internal/tokens.js +55 -1
  40. package/lib/typescript/Bars.d.ts +121 -0
  41. package/lib/typescript/Button.d.ts +11 -1
  42. package/lib/typescript/Card.d.ts +20 -8
  43. package/lib/typescript/Carousel.d.ts +47 -0
  44. package/lib/typescript/Dialog.d.ts +19 -6
  45. package/lib/typescript/Display.d.ts +119 -0
  46. package/lib/typescript/Feedback.d.ts +138 -0
  47. package/lib/typescript/Form.d.ts +27 -11
  48. package/lib/typescript/Forms2.d.ts +128 -0
  49. package/lib/typescript/Glass.d.ts +10 -1
  50. package/lib/typescript/Input.d.ts +11 -1
  51. package/lib/typescript/Overlays.d.ts +105 -0
  52. package/lib/typescript/Pickers.d.ts +105 -0
  53. package/lib/typescript/SegmentedControl.d.ts +11 -1
  54. package/lib/typescript/Slider.d.ts +13 -1
  55. package/lib/typescript/Switch.d.ts +12 -1
  56. package/lib/typescript/TabBar.d.ts +13 -1
  57. package/lib/typescript/Table.d.ts +14 -5
  58. package/lib/typescript/Tabs.d.ts +8 -5
  59. package/lib/typescript/Text.d.ts +28 -0
  60. package/lib/typescript/ai.d.ts +12 -9
  61. package/lib/typescript/charts/BarChart.d.ts +1 -1
  62. package/lib/typescript/charts/FunnelChart.d.ts +1 -1
  63. package/lib/typescript/charts/HeatmapChart.d.ts +1 -1
  64. package/lib/typescript/charts/LineChart.d.ts +1 -1
  65. package/lib/typescript/charts/PlotChart.d.ts +1 -1
  66. package/lib/typescript/charts/RadarChart.d.ts +1 -1
  67. package/lib/typescript/charts/RingChart.d.ts +1 -1
  68. package/lib/typescript/charts/ScatterChart.d.ts +1 -1
  69. package/lib/typescript/charts/WaterfallChart.d.ts +1 -1
  70. package/lib/typescript/charts/advanced.d.ts +5 -5
  71. package/lib/typescript/charts/extra.d.ts +2 -2
  72. package/lib/typescript/index.d.ts +9 -1
  73. package/lib/typescript/internal/GlassView.d.ts +21 -4
  74. package/lib/typescript/internal/fallback.d.ts +10 -1
  75. package/lib/typescript/internal/glass-routing.d.ts +30 -0
  76. package/lib/typescript/internal/motion.d.ts +19 -0
  77. package/lib/typescript/internal/primitives.d.ts +41 -0
  78. package/lib/typescript/internal/tokens.d.ts +61 -0
  79. package/package.json +2 -2
  80. package/src/Bars.tsx +570 -0
  81. package/src/Button.tsx +47 -22
  82. package/src/Card.tsx +52 -31
  83. package/src/Carousel.tsx +233 -0
  84. package/src/Dialog.tsx +99 -64
  85. package/src/Display.tsx +550 -0
  86. package/src/Feedback.tsx +579 -0
  87. package/src/Form.tsx +90 -25
  88. package/src/Forms2.tsx +608 -0
  89. package/src/Glass.tsx +24 -1
  90. package/src/Input.tsx +33 -12
  91. package/src/Overlays.tsx +474 -0
  92. package/src/Pickers.tsx +590 -0
  93. package/src/SegmentedControl.tsx +104 -32
  94. package/src/Slider.tsx +151 -47
  95. package/src/Switch.tsx +56 -32
  96. package/src/TabBar.tsx +100 -30
  97. package/src/Table.tsx +38 -14
  98. package/src/Tabs.tsx +85 -32
  99. package/src/Text.tsx +83 -0
  100. package/src/ai.tsx +77 -31
  101. package/src/charts/BarChart.tsx +4 -2
  102. package/src/charts/FunnelChart.tsx +4 -2
  103. package/src/charts/HeatmapChart.tsx +4 -2
  104. package/src/charts/LineChart.tsx +4 -2
  105. package/src/charts/PlotChart.tsx +23 -3
  106. package/src/charts/RadarChart.tsx +4 -2
  107. package/src/charts/RingChart.tsx +4 -2
  108. package/src/charts/ScatterChart.tsx +24 -3
  109. package/src/charts/WaterfallChart.tsx +21 -3
  110. package/src/charts/advanced.tsx +12 -6
  111. package/src/charts/extra.tsx +6 -3
  112. package/src/index.ts +101 -1
  113. package/src/internal/GlassView.tsx +51 -19
  114. package/src/internal/fallback.tsx +23 -8
  115. package/src/internal/glass-routing.ts +68 -0
  116. package/src/internal/motion.ts +60 -0
  117. package/src/internal/primitives.ts +482 -0
  118. package/src/internal/tokens.ts +62 -0
  119. package/lib/module/charts/primitives.js +0 -212
  120. package/lib/typescript/charts/primitives.d.ts +0 -23
  121. package/src/charts/primitives.ts +0 -262
@@ -0,0 +1,550 @@
1
+ import { forwardRef, useEffect, useRef, useState, type ReactNode } from "react";
2
+ import type { StyleProp, ViewStyle } from "react-native";
3
+
4
+ import { Glass } from "./Glass";
5
+ import { colors, radii } from "./internal/tokens";
6
+ import { primitives } from "./internal/primitives";
7
+ import { useIsDark, useSpring } from "./internal/motion";
8
+
9
+ // ---------------------------------------------------------------------------
10
+ // Avatar
11
+
12
+ export type AvatarSize = "sm" | "md" | "lg";
13
+
14
+ export interface AvatarProps {
15
+ /** Image to show. When absent, or when it fails to load, initials render. */
16
+ source?: { uri: string } | number;
17
+ /** The person's name: initials are derived from it when no image loads. */
18
+ name?: string;
19
+ size?: AvatarSize;
20
+ /** Draws a status dot in the corner. */
21
+ status?: "online" | "offline" | "busy";
22
+ style?: StyleProp<ViewStyle>;
23
+ isDark?: boolean;
24
+ testID?: string;
25
+ }
26
+
27
+ const avatarSizes: Record<AvatarSize, number> = { sm: 28, md: 40, lg: 64 };
28
+
29
+ /** First letters of the first and last word, as an avatar fallback. */
30
+ export function initialsOf(name: string): string {
31
+ const words = name.trim().split(/\s+/).filter(Boolean);
32
+ if (words.length === 0) return "";
33
+ if (words.length === 1) return words[0]!.slice(0, 2).toUpperCase();
34
+ return (words[0]![0]! + words[words.length - 1]![0]!).toUpperCase();
35
+ }
36
+
37
+ /**
38
+ * A person or entity: their picture, or their initials when there is none.
39
+ *
40
+ * The frame is Glacia's glass so it belongs to the same family as the rest of
41
+ * the library; the initials sit on it in the theme's foreground colour.
42
+ */
43
+ export const Avatar = forwardRef<any, AvatarProps>(function Avatar(
44
+ { source, name, size = "md", status, style, isDark: isDarkProp, testID, ...props },
45
+ ref,
46
+ ) {
47
+ const isDark = useIsDark(isDarkProp);
48
+ const theme = isDark ? colors.dark : colors.light;
49
+ const { View, Text, Image } = primitives();
50
+
51
+ // A broken remote image falls back to initials rather than an empty circle.
52
+ const [failed, setFailed] = useState(false);
53
+ const dimension = avatarSizes[size];
54
+ const initials = name ? initialsOf(name) : "";
55
+
56
+ const statusColor =
57
+ status === "online" ? theme.on : status === "busy" ? theme.destructive : theme.muted;
58
+ const dot = Math.max(8, Math.round(dimension * 0.26));
59
+
60
+ return (
61
+ <View
62
+ ref={ref}
63
+ testID={testID}
64
+ accessible
65
+ accessibilityRole="image"
66
+ accessibilityLabel={name ? `Avatar of ${name}` : "Avatar"}
67
+ style={{ width: dimension, height: dimension, ...(style as ViewStyle) }}
68
+ {...props}
69
+ >
70
+ <Glass
71
+ effect="regular"
72
+ isDark={isDark}
73
+ style={{
74
+ width: dimension,
75
+ height: dimension,
76
+ borderRadius: dimension / 2,
77
+ alignItems: "center",
78
+ justifyContent: "center",
79
+ overflow: "hidden",
80
+ }}
81
+ >
82
+ {source && !failed ? (
83
+ <Image
84
+ source={source}
85
+ accessibilityLabel={name ?? "Avatar"}
86
+ onError={() => setFailed(true)}
87
+ style={{ width: dimension, height: dimension }}
88
+ />
89
+ ) : (
90
+ <Text
91
+ style={{
92
+ fontSize: Math.round(dimension * 0.38),
93
+ fontWeight: "600",
94
+ color: theme.foreground,
95
+ }}
96
+ >
97
+ {initials}
98
+ </Text>
99
+ )}
100
+ </Glass>
101
+
102
+ {status && (
103
+ <View
104
+ style={{
105
+ position: "absolute",
106
+ right: 0,
107
+ bottom: 0,
108
+ width: dot,
109
+ height: dot,
110
+ borderRadius: dot / 2,
111
+ backgroundColor: statusColor,
112
+ borderWidth: 1.5,
113
+ borderColor: theme.glassActive,
114
+ }}
115
+ />
116
+ )}
117
+ </View>
118
+ );
119
+ });
120
+
121
+ // ---------------------------------------------------------------------------
122
+ // Badge
123
+
124
+ export interface BadgeProps {
125
+ /** The count or short label. Omit to render a plain dot. */
126
+ children?: ReactNode;
127
+ /** Draws the badge in the destructive tone (unread, errors). */
128
+ tone?: "fill" | "destructive" | "success" | "muted";
129
+ /** The element to overlay. Supplying it puts the badge in the corner. */
130
+ overlay?: ReactNode;
131
+ style?: StyleProp<ViewStyle>;
132
+ isDark?: boolean;
133
+ testID?: string;
134
+ }
135
+
136
+ /**
137
+ * A small count or dot.
138
+ *
139
+ * Deliberately not glass: a badge is a micro-element, and a translucent 16pt
140
+ * chip loses its contrast against whatever it sits on. It uses the solid theme
141
+ * tint instead, which is what makes it legible in both themes.
142
+ */
143
+ export const Badge = forwardRef<any, BadgeProps>(function Badge(
144
+ { children, tone = "fill", overlay, style, isDark: isDarkProp, testID, ...props },
145
+ ref,
146
+ ) {
147
+ const isDark = useIsDark(isDarkProp);
148
+ const theme = isDark ? colors.dark : colors.light;
149
+ const { View, Text } = primitives();
150
+
151
+ const background =
152
+ tone === "destructive"
153
+ ? theme.destructive
154
+ : tone === "success"
155
+ ? theme.on
156
+ : tone === "muted"
157
+ ? theme.muted
158
+ : theme.fill;
159
+
160
+ const isDot = children == null;
161
+ const height = isDot ? 10 : 18;
162
+
163
+ const badge = (
164
+ <View
165
+ ref={ref}
166
+ testID={testID}
167
+ accessibilityRole="text"
168
+ accessibilityLabel={isDot ? undefined : String(children)}
169
+ style={{
170
+ minWidth: height,
171
+ height,
172
+ borderRadius: height / 2,
173
+ paddingHorizontal: isDot ? 0 : 6,
174
+ alignItems: "center",
175
+ justifyContent: "center",
176
+ backgroundColor: background,
177
+ ...(style as ViewStyle),
178
+ }}
179
+ {...props}
180
+ >
181
+ {!isDot && (
182
+ <Text style={{ fontSize: 11, fontWeight: "700", color: theme.onTint }} numberOfLines={1}>
183
+ {children}
184
+ </Text>
185
+ )}
186
+ </View>
187
+ );
188
+
189
+ if (overlay === undefined) return badge;
190
+
191
+ // Overlaid: the badge floats at the top-right of whatever it decorates, which
192
+ // needs a positioned box around the child rather than a bare fragment.
193
+ return (
194
+ <View style={{ alignSelf: "flex-start" }}>
195
+ {overlay}
196
+ <View style={{ position: "absolute", top: -4, right: -4 }}>{badge}</View>
197
+ </View>
198
+ );
199
+ });
200
+
201
+ // ---------------------------------------------------------------------------
202
+ // Separator
203
+
204
+ export interface SeparatorProps {
205
+ orientation?: "horizontal" | "vertical";
206
+ /** Inset from the leading edge, matching a list row's leading accessory. */
207
+ inset?: number;
208
+ style?: StyleProp<ViewStyle>;
209
+ isDark?: boolean;
210
+ testID?: string;
211
+ }
212
+
213
+ /**
214
+ * A hairline divider in the theme's separator colour.
215
+ *
216
+ * A plain View rather than a Glass: a 1pt rule is not a surface, and glass on
217
+ * a line has nothing to refract.
218
+ */
219
+ export const Separator = forwardRef<any, SeparatorProps>(function Separator(
220
+ { orientation = "horizontal", inset = 0, style, isDark: isDarkProp, testID, ...props },
221
+ ref,
222
+ ) {
223
+ const isDark = useIsDark(isDarkProp);
224
+ const theme = isDark ? colors.dark : colors.light;
225
+ const { View } = primitives();
226
+
227
+ const separatorStyle: ViewStyle =
228
+ orientation === "horizontal"
229
+ ? { height: 0.5, alignSelf: "stretch", marginLeft: inset, backgroundColor: theme.separator }
230
+ : { width: 0.5, alignSelf: "stretch", backgroundColor: theme.separator };
231
+
232
+ return (
233
+ <View
234
+ ref={ref}
235
+ testID={testID}
236
+ accessibilityRole="none"
237
+ style={{ ...separatorStyle, ...(style as ViewStyle) }}
238
+ {...props}
239
+ />
240
+ );
241
+ });
242
+
243
+ // ---------------------------------------------------------------------------
244
+ // Skeleton
245
+
246
+ export interface SkeletonProps {
247
+ /** Rectangles for cards and rows, circles for avatars, lines for a run of text. */
248
+ shape?: "rect" | "circle" | "line";
249
+ width?: number | string;
250
+ height?: number;
251
+ style?: StyleProp<ViewStyle>;
252
+ isDark?: boolean;
253
+ testID?: string;
254
+ }
255
+
256
+ /**
257
+ * A loading placeholder.
258
+ *
259
+ * The pulse is opacity only and slow, on the gentle spring, so it reads as
260
+ * "loading" without motion that could bother someone sensitive to movement.
261
+ * Nothing about it is essential to understanding the screen, so it is hidden
262
+ * from screen readers rather than announced.
263
+ */
264
+ export const Skeleton = forwardRef<any, SkeletonProps>(function Skeleton(
265
+ { shape = "rect", width, height, style, isDark: isDarkProp, testID, ...props },
266
+ ref,
267
+ ) {
268
+ const isDark = useIsDark(isDarkProp);
269
+ const theme = isDark ? colors.dark : colors.light;
270
+ const { View, Animated } = primitives();
271
+
272
+ const { value: pulse, animated } = useSpring(1, "gentle");
273
+ const opacity = animated
274
+ ? pulse.interpolate({ inputRange: [0, 1], outputRange: [0.35, 1] })
275
+ : 1;
276
+
277
+ const resolvedWidth = width ?? (shape === "line" ? "100%" : shape === "circle" ? 40 : 120);
278
+ const resolvedHeight = height ?? (shape === "line" ? 12 : shape === "circle" ? 40 : 80);
279
+ const radius =
280
+ shape === "circle" ? Math.min(resolvedHeight, 9999) / 2 : shape === "line" ? radii.sm : radii.md;
281
+
282
+ const skeletonStyle: ViewStyle = {
283
+ width: resolvedWidth as any,
284
+ height: resolvedHeight,
285
+ borderRadius: radius,
286
+ backgroundColor: theme.skeleton,
287
+ ...(style as ViewStyle),
288
+ };
289
+
290
+ const a11y = { accessibilityRole: "none" as const, accessible: false, testID };
291
+
292
+ return animated ? (
293
+ <Animated.View ref={ref} style={{ ...skeletonStyle, opacity }} {...a11y} {...props} />
294
+ ) : (
295
+ <View ref={ref} style={skeletonStyle} {...a11y} {...props} />
296
+ );
297
+ });
298
+
299
+ // ---------------------------------------------------------------------------
300
+ // Spinner
301
+
302
+ export type SpinnerSize = "sm" | "md" | "lg";
303
+
304
+ export interface SpinnerProps {
305
+ size?: SpinnerSize;
306
+ /** Spinner colour; defaults to the theme's muted foreground. */
307
+ tint?: string;
308
+ /** Announced to screen readers, since a spinner alone has no text. */
309
+ accessibilityLabel?: string;
310
+ style?: StyleProp<ViewStyle>;
311
+ isDark?: boolean;
312
+ testID?: string;
313
+ }
314
+
315
+ const spinnerSizes: Record<SpinnerSize, number> = { sm: 16, md: 22, lg: 32 };
316
+
317
+ /**
318
+ * A loading spinner, drawn by Glacia.
319
+ *
320
+ * An SVG arc that rotates on the gentle spring through Animated — not the
321
+ * platform's ActivityIndicator, so it looks the same on every platform and
322
+ * wears the theme's colour instead of inheriting the system tint.
323
+ */
324
+ export const Spinner = forwardRef<any, SpinnerProps>(function Spinner(
325
+ {
326
+ size = "md",
327
+ tint,
328
+ accessibilityLabel = "Loading",
329
+ style,
330
+ isDark: isDarkProp,
331
+ testID,
332
+ ...props
333
+ },
334
+ ref,
335
+ ) {
336
+ const isDark = useIsDark(isDarkProp);
337
+ const theme = isDark ? colors.dark : colors.light;
338
+ const { View, Svg, Circle, Animated } = primitives();
339
+
340
+ const dimension = spinnerSizes[size];
341
+ const stroke = Math.max(2, Math.round(dimension / 9));
342
+ const color = tint ?? theme.muted;
343
+ // An arc, not a full ring: a complete circle rotating looks static.
344
+ const circumference = 2 * Math.PI * ((dimension - stroke) / 2);
345
+ const dash = circumference * 0.28;
346
+
347
+ // A continuous spin never settles, so it is driven by Animated.timing on a
348
+ // loop rather than the spring hook, which is built for one-off targets.
349
+ const { Animated: AnimatedAPI, isNative } = primitives();
350
+ const spinning = isNative && Boolean(AnimatedAPI?.timing);
351
+
352
+ const rotation = useRef<any>(null);
353
+ if (rotation.current === null) {
354
+ rotation.current = spinning ? new AnimatedAPI.Value(0) : null;
355
+ }
356
+
357
+ useEffect(() => {
358
+ if (!spinning || !rotation.current) return;
359
+ rotation.current.setValue(0);
360
+ const loop = AnimatedAPI.loop(
361
+ AnimatedAPI.timing(rotation.current, {
362
+ toValue: 1,
363
+ duration: 900,
364
+ useNativeDriver: true,
365
+ }),
366
+ );
367
+ loop.start?.();
368
+ return () => loop.stop?.();
369
+ }, [AnimatedAPI, spinning]);
370
+
371
+ const spinStyle = spinning
372
+ ? {
373
+ transform: [
374
+ {
375
+ rotate: rotation.current.interpolate({
376
+ inputRange: [0, 1],
377
+ outputRange: ["0deg", "360deg"],
378
+ }),
379
+ },
380
+ ],
381
+ }
382
+ : undefined;
383
+
384
+ const svg = (
385
+ <Svg width={dimension} height={dimension} viewBox={`0 0 ${dimension} ${dimension}`}>
386
+ <Circle
387
+ cx={dimension / 2}
388
+ cy={dimension / 2}
389
+ r={(dimension - stroke) / 2}
390
+ stroke={theme.skeleton}
391
+ strokeWidth={stroke}
392
+ fill="none"
393
+ />
394
+ <Circle
395
+ cx={dimension / 2}
396
+ cy={dimension / 2}
397
+ r={(dimension - stroke) / 2}
398
+ stroke={color}
399
+ strokeWidth={stroke}
400
+ fill="none"
401
+ strokeLinecap="round"
402
+ strokeDasharray={`${dash} ${circumference - dash}`}
403
+ />
404
+ </Svg>
405
+ );
406
+
407
+ return (
408
+ <View
409
+ ref={ref}
410
+ testID={testID}
411
+ accessibilityRole="progressbar"
412
+ accessibilityLabel={accessibilityLabel}
413
+ style={[{ width: dimension, height: dimension }, style as ViewStyle]}
414
+ {...props}
415
+ >
416
+ {spinning ? <Animated.View style={spinStyle}>{svg}</Animated.View> : svg}
417
+ </View>
418
+ );
419
+ });
420
+
421
+ // ---------------------------------------------------------------------------
422
+ // Progress
423
+
424
+ export type ProgressVariant = "bar" | "ring";
425
+
426
+ export interface ProgressProps {
427
+ /** 0–100. Values outside the range are clamped rather than drawn wrong. */
428
+ value: number;
429
+ variant?: ProgressVariant;
430
+ /** Overrides the fill colour; defaults to the theme accent. */
431
+ tint?: string;
432
+ /** Announced by screen readers, e.g. "Uploading photo". */
433
+ accessibilityLabel?: string;
434
+ style?: StyleProp<ViewStyle>;
435
+ isDark?: boolean;
436
+ testID?: string;
437
+ }
438
+
439
+ const RING = 64;
440
+
441
+ /**
442
+ * Progress, linear or circular.
443
+ *
444
+ * The track is a glass surface, so it refracts what it sits on exactly like the
445
+ * rest of the library; the fill is the theme accent. Both forms report
446
+ * `progressbar` with a value, which is the contract NativeTask relies on
447
+ * internally — this component generalises it.
448
+ */
449
+ export const Progress = forwardRef<any, ProgressProps>(function Progress(
450
+ {
451
+ value,
452
+ variant = "bar",
453
+ tint,
454
+ accessibilityLabel,
455
+ style,
456
+ isDark: isDarkProp,
457
+ testID,
458
+ ...props
459
+ },
460
+ ref,
461
+ ) {
462
+ const isDark = useIsDark(isDarkProp);
463
+ const theme = isDark ? colors.dark : colors.light;
464
+ const { View, Text, Svg, Circle } = primitives();
465
+
466
+ const clamped = Math.min(Math.max(value, 0), 100);
467
+ const fill = tint ?? theme.fill;
468
+ const a11y = {
469
+ accessibilityRole: "progressbar" as const,
470
+ accessibilityValue: { min: 0, max: 100, now: Math.round(clamped) },
471
+ accessibilityLabel,
472
+ testID,
473
+ };
474
+
475
+ if (variant === "ring") {
476
+ const stroke = 6;
477
+ const radius = (RING - stroke) / 2;
478
+ const circumference = 2 * Math.PI * radius;
479
+ return (
480
+ <View
481
+ ref={ref}
482
+ style={[{ width: RING, height: RING }, style as ViewStyle]}
483
+ {...a11y}
484
+ {...props}
485
+ >
486
+ <Svg width={RING} height={RING} viewBox={`0 0 ${RING} ${RING}`}>
487
+ <Circle
488
+ cx={RING / 2}
489
+ cy={RING / 2}
490
+ r={radius}
491
+ stroke={theme.skeleton}
492
+ strokeWidth={stroke}
493
+ fill="none"
494
+ />
495
+ <Circle
496
+ cx={RING / 2}
497
+ cy={RING / 2}
498
+ r={radius}
499
+ stroke={fill}
500
+ strokeWidth={stroke}
501
+ fill="none"
502
+ strokeLinecap="round"
503
+ strokeDasharray={`${(clamped / 100) * circumference} ${circumference}`}
504
+ // Start the arc at twelve o'clock, the way progress dials read.
505
+ transform={`rotate(-90 ${RING / 2} ${RING / 2})`}
506
+ />
507
+ </Svg>
508
+ <View
509
+ style={{
510
+ position: "absolute",
511
+ width: RING,
512
+ height: RING,
513
+ alignItems: "center",
514
+ justifyContent: "center",
515
+ }}
516
+ >
517
+ <Text style={{ fontSize: 13, fontWeight: "600", color: theme.foreground }}>
518
+ {`${Math.round(clamped)}%`}
519
+ </Text>
520
+ </View>
521
+ </View>
522
+ );
523
+ }
524
+
525
+ return (
526
+ <Glass
527
+ ref={ref}
528
+ effect="regular"
529
+ isDark={isDark}
530
+ style={{
531
+ height: 8,
532
+ borderRadius: radii.pill,
533
+ overflow: "hidden",
534
+ justifyContent: "center",
535
+ ...(style as ViewStyle),
536
+ }}
537
+ {...a11y}
538
+ {...props}
539
+ >
540
+ <View
541
+ style={{
542
+ width: `${clamped}%`,
543
+ height: 8,
544
+ borderRadius: radii.pill,
545
+ backgroundColor: fill,
546
+ }}
547
+ />
548
+ </Glass>
549
+ );
550
+ });