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,590 @@
1
+ import { forwardRef, useMemo, useState } from "react";
2
+ import type { StyleProp, ViewStyle } from "react-native";
3
+
4
+ import { Glass } from "./Glass";
5
+ import { Button } from "./Button";
6
+ import { Sheet } from "./Overlays";
7
+ import { colors, radii } from "./internal/tokens";
8
+ import { primitives } from "./internal/primitives";
9
+ import { useIsDark } from "./internal/motion";
10
+
11
+ // ---------------------------------------------------------------------------
12
+ // Date helpers
13
+ //
14
+ // Kept pure and exported so a caller (and the tests) can reason about the same
15
+ // calendar maths the grid uses. Dates are compared by day, never by instant,
16
+ // which is the bug that makes a picker select "yesterday" near midnight.
17
+
18
+ /** Midnight on the same calendar day, so two picks compare equal. */
19
+ export function startOfDay(date: Date): Date {
20
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
21
+ }
22
+
23
+ export function sameDay(a: Date | undefined, b: Date | undefined): boolean {
24
+ if (!a || !b) return false;
25
+ return (
26
+ a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate()
27
+ );
28
+ }
29
+
30
+ export interface CalendarCell {
31
+ date: Date;
32
+ /** True for days outside the displayed month, shown to fill the grid. */
33
+ outside: boolean;
34
+ key: string;
35
+ }
36
+
37
+ /**
38
+ * The six-row month grid.
39
+ *
40
+ * Always six rows so the calendar does not change height as months change,
41
+ * which would make the surrounding layout jump between February and March.
42
+ */
43
+ export function monthGrid(year: number, month: number, weekStartsOn: 0 | 1 = 0): CalendarCell[] {
44
+ const first = new Date(year, month, 1);
45
+ // getDay() is 0 for Sunday; the offset is how many leading cells to add.
46
+ const offset = (first.getDay() - weekStartsOn + 7) % 7;
47
+ const cells: CalendarCell[] = [];
48
+ for (let i = 0; i < 42; i += 1) {
49
+ const date = new Date(year, month, 1 - offset + i);
50
+ cells.push({
51
+ date,
52
+ outside: date.getMonth() !== month,
53
+ key: `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`,
54
+ });
55
+ }
56
+ return cells;
57
+ }
58
+
59
+ export const WEEKDAYS = ["S", "M", "T", "W", "T", "F", "S"];
60
+
61
+ export const MONTHS = [
62
+ "January",
63
+ "February",
64
+ "March",
65
+ "April",
66
+ "May",
67
+ "June",
68
+ "July",
69
+ "August",
70
+ "September",
71
+ "October",
72
+ "November",
73
+ "December",
74
+ ];
75
+
76
+ // ---------------------------------------------------------------------------
77
+ // Calendar
78
+
79
+ export interface CalendarProps {
80
+ /** Controlled selection. */
81
+ value?: Date;
82
+ /** Fires when a day is tapped. */
83
+ onChange?: (date: Date) => void;
84
+ /** Days before this are dimmed and cannot be picked. */
85
+ minDate?: Date;
86
+ /** Days after this are dimmed and cannot be picked. */
87
+ maxDate?: Date;
88
+ /** Which month to open on when there is no value. */
89
+ initialMonth?: Date;
90
+ /** 0 starts the week on Sunday, 1 on Monday. */
91
+ weekStartsOn?: 0 | 1;
92
+ style?: StyleProp<ViewStyle>;
93
+ isDark?: boolean;
94
+ testID?: string;
95
+ }
96
+
97
+ /**
98
+ * A month calendar, built from Glacia's own views.
99
+ *
100
+ * No native date picker anywhere: the grid, the weekday header and the month
101
+ * navigation are ours, so the calendar looks the same on iOS and Android and
102
+ * wears the library's tokens. The selected day is a `glassActive` fill, today
103
+ * carries a ring, and disabled days are dimmed.
104
+ */
105
+ export const Calendar = forwardRef<any, CalendarProps>(function Calendar(
106
+ {
107
+ value,
108
+ onChange,
109
+ minDate,
110
+ maxDate,
111
+ initialMonth,
112
+ weekStartsOn = 0,
113
+ style,
114
+ isDark: isDarkProp,
115
+ testID,
116
+ ...props
117
+ },
118
+ ref,
119
+ ) {
120
+ const isDark = useIsDark(isDarkProp);
121
+ const theme = isDark ? colors.dark : colors.light;
122
+ const { View, Text: RNText, Pressable } = primitives();
123
+
124
+ const anchor = value ?? initialMonth ?? new Date();
125
+ const [month, setMonth] = useState({ year: anchor.getFullYear(), month: anchor.getMonth() });
126
+
127
+ const cells = useMemo(() => monthGrid(month.year, month.month, weekStartsOn), [month, weekStartsOn]);
128
+ const today = startOfDay(new Date());
129
+
130
+ const isDisabled = (date: Date) => {
131
+ const day = startOfDay(date);
132
+ if (minDate && day < startOfDay(minDate)) return true;
133
+ if (maxDate && day > startOfDay(maxDate)) return true;
134
+ return false;
135
+ };
136
+
137
+ const shift = (delta: number) => {
138
+ setMonth((current) => {
139
+ const next = new Date(current.year, current.month + delta, 1);
140
+ return { year: next.getFullYear(), month: next.getMonth() };
141
+ });
142
+ };
143
+
144
+ const cellSize = 38;
145
+
146
+ return (
147
+ <View
148
+ ref={ref}
149
+ testID={testID}
150
+ accessibilityRole="none"
151
+ style={[{ alignSelf: "stretch" }, style as ViewStyle]}
152
+ {...props}
153
+ >
154
+ {/* Month navigation. */}
155
+ <View style={{ flexDirection: "row", alignItems: "center", justifyContent: "space-between", paddingBottom: 8 }}>
156
+ <Pressable
157
+ accessibilityRole="button"
158
+ accessibilityLabel="Previous month"
159
+ onPress={() => shift(-1)}
160
+ hitSlop={8}
161
+ style={{ padding: 6 }}
162
+ >
163
+ <RNText style={{ fontSize: 17, color: theme.foreground }}>{"\u2039"}</RNText>
164
+ </Pressable>
165
+ <RNText accessibilityRole="heading" style={{ fontSize: 16, fontWeight: "600", color: theme.foreground }}>
166
+ {`${MONTHS[month.month]} ${month.year}`}
167
+ </RNText>
168
+ <Pressable
169
+ accessibilityRole="button"
170
+ accessibilityLabel="Next month"
171
+ onPress={() => shift(1)}
172
+ hitSlop={8}
173
+ style={{ padding: 6 }}
174
+ >
175
+ <RNText style={{ fontSize: 17, color: theme.foreground }}>{"\u203A"}</RNText>
176
+ </Pressable>
177
+ </View>
178
+
179
+ {/* Weekday header, derived from the same weekStartsOn as the grid. */}
180
+ <View style={{ flexDirection: "row" }}>
181
+ {Array.from({ length: 7 }, (_, i) => (
182
+ <View key={i} style={{ flex: 1, alignItems: "center", paddingVertical: 4 }}>
183
+ <RNText
184
+ accessibilityElementsHidden
185
+ style={{ fontSize: 11, fontWeight: "600", color: theme.muted }}
186
+ >
187
+ {WEEKDAYS[(i + weekStartsOn) % 7]}
188
+ </RNText>
189
+ </View>
190
+ ))}
191
+ </View>
192
+
193
+ {/* The grid: six rows of seven. */}
194
+ {Array.from({ length: 6 }, (_, row) => (
195
+ <View key={row} style={{ flexDirection: "row" }}>
196
+ {cells.slice(row * 7, row * 7 + 7).map((cell) => {
197
+ const selected = sameDay(cell.date, value);
198
+ const isToday = sameDay(cell.date, today);
199
+ const disabled = isDisabled(cell.date);
200
+ return (
201
+ <View key={cell.key} style={{ flex: 1, alignItems: "center", paddingVertical: 2 }}>
202
+ <Pressable
203
+ accessibilityRole="button"
204
+ accessibilityLabel={cell.date.toDateString()}
205
+ accessibilityState={{ selected, disabled }}
206
+ disabled={disabled}
207
+ onPress={() => onChange?.(startOfDay(cell.date))}
208
+ style={{
209
+ width: cellSize,
210
+ height: cellSize,
211
+ borderRadius: cellSize / 2,
212
+ alignItems: "center",
213
+ justifyContent: "center",
214
+ backgroundColor: selected ? theme.glassActive : "transparent",
215
+ borderWidth: isToday && !selected ? 0.5 : selected ? 1 : 0,
216
+ borderColor: isToday && !selected ? theme.fill : theme.edge,
217
+ opacity: disabled ? 0.28 : cell.outside ? 0.45 : 1,
218
+ }}
219
+ >
220
+ <RNText
221
+ style={{
222
+ fontSize: 14,
223
+ fontWeight: selected ? "600" : "400",
224
+ color: selected ? theme.foreground : theme.foreground,
225
+ }}
226
+ >
227
+ {String(cell.date.getDate())}
228
+ </RNText>
229
+ </Pressable>
230
+ </View>
231
+ );
232
+ })}
233
+ </View>
234
+ ))}
235
+ </View>
236
+ );
237
+ });
238
+
239
+ // ---------------------------------------------------------------------------
240
+ // DatePicker
241
+
242
+ export interface DatePickerProps {
243
+ /** Controlled visibility. Omit and the picker keeps its own. */
244
+ open?: boolean;
245
+ defaultOpen?: boolean;
246
+ onOpenChange?: (open: boolean) => void;
247
+ /** The committed date. */
248
+ value?: Date;
249
+ /** Fires only when the user confirms, never on a mere browse. */
250
+ onConfirm?: (date: Date) => void;
251
+ onCancel?: () => void;
252
+ title?: string;
253
+ confirmLabel?: string;
254
+ cancelLabel?: string;
255
+ minDate?: Date;
256
+ maxDate?: Date;
257
+ style?: StyleProp<ViewStyle>;
258
+ isDark?: boolean;
259
+ testID?: string;
260
+ }
261
+
262
+ /**
263
+ * A date picker: the Calendar presented in a Sheet.
264
+ *
265
+ * Browsing months does not commit anything — the pending date is local until
266
+ * the user confirms, so an accidental swipe of the calendar cannot change a
267
+ * saved value.
268
+ */
269
+ export const DatePicker = forwardRef<any, DatePickerProps>(function DatePicker(
270
+ {
271
+ open: openProp,
272
+ defaultOpen = false,
273
+ onOpenChange,
274
+ value,
275
+ onConfirm,
276
+ onCancel,
277
+ title = "Select date",
278
+ confirmLabel = "Confirm",
279
+ cancelLabel = "Cancel",
280
+ minDate,
281
+ maxDate,
282
+ style,
283
+ isDark: isDarkProp,
284
+ testID,
285
+ ...props
286
+ },
287
+ ref,
288
+ ) {
289
+ const isDark = useIsDark(isDarkProp);
290
+ const [internalOpen, setInternalOpen] = useState(defaultOpen);
291
+ const open = openProp !== undefined ? openProp : internalOpen;
292
+
293
+ const [pending, setPending] = useState<Date | undefined>(value);
294
+
295
+ const setOpen = (next: boolean) => {
296
+ if (openProp === undefined) setInternalOpen(next);
297
+ onOpenChange?.(next);
298
+ };
299
+
300
+ return (
301
+ <Sheet
302
+ ref={ref}
303
+ open={open}
304
+ onOpenChange={setOpen}
305
+ title={title}
306
+ isDark={isDark}
307
+ testID={testID}
308
+ style={style}
309
+ footer={
310
+ <>
311
+ <Button
312
+ variant="ghost"
313
+ accessibilityLabel={cancelLabel}
314
+ onPress={() => {
315
+ // Cancelling restores the committed value for the next open.
316
+ setPending(value);
317
+ onCancel?.();
318
+ setOpen(false);
319
+ }}
320
+ >
321
+ {cancelLabel}
322
+ </Button>
323
+ <Button
324
+ variant="filled"
325
+ accessibilityLabel={confirmLabel}
326
+ disabled={pending === undefined}
327
+ onPress={() => {
328
+ if (pending) onConfirm?.(pending);
329
+ setOpen(false);
330
+ }}
331
+ >
332
+ {confirmLabel}
333
+ </Button>
334
+ </>
335
+ }
336
+ {...props}
337
+ >
338
+ <Calendar
339
+ value={pending}
340
+ onChange={setPending}
341
+ minDate={minDate}
342
+ maxDate={maxDate}
343
+ isDark={isDark}
344
+ initialMonth={value}
345
+ />
346
+ </Sheet>
347
+ );
348
+ });
349
+
350
+ // ---------------------------------------------------------------------------
351
+ // TimePicker
352
+
353
+ export interface TimePickerProps {
354
+ open?: boolean;
355
+ defaultOpen?: boolean;
356
+ onOpenChange?: (open: boolean) => void;
357
+ /** The committed time, as "HH:MM" (24-hour). */
358
+ value?: string;
359
+ /** Fires only on confirm. */
360
+ onConfirm?: (time: string) => void;
361
+ onCancel?: () => void;
362
+ /** Show an AM/PM column and present times in 12-hour form. */
363
+ use12Hour?: boolean;
364
+ title?: string;
365
+ confirmLabel?: string;
366
+ cancelLabel?: string;
367
+ minuteStep?: number;
368
+ style?: StyleProp<ViewStyle>;
369
+ isDark?: boolean;
370
+ testID?: string;
371
+ }
372
+
373
+ /** Splits "HH:MM" into parts, falling back to a sane default. */
374
+ export function parseTime(value: string | undefined): { hour: number; minute: number } {
375
+ const match = /^(\d{1,2}):(\d{2})$/.exec(value ?? "");
376
+ if (!match) return { hour: 9, minute: 0 };
377
+ return {
378
+ hour: Math.min(Math.max(Number(match[1]), 0), 23),
379
+ minute: Math.min(Math.max(Number(match[2]), 0), 59),
380
+ };
381
+ }
382
+
383
+ /** Formats parts back to zero-padded "HH:MM". */
384
+ export function formatTime(hour: number, minute: number): string {
385
+ return `${String(hour).padStart(2, "0")}:${String(minute).padStart(2, "0")}`;
386
+ }
387
+
388
+ /**
389
+ * A time picker: tappable hour/minute drums inside a Sheet.
390
+ *
391
+ * The drums are ordinary Pressables drawn by Glacia — not a native picker
392
+ * widget. Tapping a value selects it; the whole column scrolls in the Sheet.
393
+ */
394
+ export const TimePicker = forwardRef<any, TimePickerProps>(function TimePicker(
395
+ {
396
+ open: openProp,
397
+ defaultOpen = false,
398
+ onOpenChange,
399
+ value,
400
+ onConfirm,
401
+ onCancel,
402
+ use12Hour = false,
403
+ title = "Select time",
404
+ confirmLabel = "Confirm",
405
+ cancelLabel = "Cancel",
406
+ minuteStep = 1,
407
+ style,
408
+ isDark: isDarkProp,
409
+ testID,
410
+ ...props
411
+ },
412
+ ref,
413
+ ) {
414
+ const isDark = useIsDark(isDarkProp);
415
+ const theme = isDark ? colors.dark : colors.light;
416
+ const { View, Text: RNText, Pressable } = primitives();
417
+
418
+ const [internalOpen, setInternalOpen] = useState(defaultOpen);
419
+ const open = openProp !== undefined ? openProp : internalOpen;
420
+
421
+ const initial = parseTime(value);
422
+ const [hour, setHour] = useState(initial.hour);
423
+ const [minute, setMinute] = useState(initial.minute);
424
+
425
+ const setOpen = (next: boolean) => {
426
+ if (openProp === undefined) setInternalOpen(next);
427
+ onOpenChange?.(next);
428
+ };
429
+
430
+ const hours = Array.from({ length: 24 }, (_, i) => i);
431
+ const minutes = Array.from({ length: Math.ceil(60 / minuteStep) }, (_, i) => i * minuteStep);
432
+
433
+ // In 12-hour mode the column shows 1–12; the stored hour stays 24-hour.
434
+ const displayHour = use12Hour ? (hour % 12 === 0 ? 12 : hour % 12) : hour;
435
+ const isPm = hour >= 12;
436
+
437
+ const column = (items: number[], selected: number, onPick: (value: number) => void, label: string, pad = 2) => (
438
+ <View style={{ height: 168, flex: 1 }} accessibilityRole="none" accessibilityLabel={label}>
439
+ <ScrollColumn
440
+ items={items}
441
+ selected={selected}
442
+ onPick={onPick}
443
+ isDark={isDark}
444
+ pad={pad}
445
+ />
446
+ </View>
447
+ );
448
+
449
+ return (
450
+ <Sheet
451
+ ref={ref}
452
+ open={open}
453
+ onOpenChange={setOpen}
454
+ title={title}
455
+ isDark={isDark}
456
+ testID={testID}
457
+ style={style}
458
+ footer={
459
+ <>
460
+ <Button
461
+ variant="ghost"
462
+ accessibilityLabel={cancelLabel}
463
+ onPress={() => {
464
+ setHour(initial.hour);
465
+ setMinute(initial.minute);
466
+ onCancel?.();
467
+ setOpen(false);
468
+ }}
469
+ >
470
+ {cancelLabel}
471
+ </Button>
472
+ <Button
473
+ variant="filled"
474
+ accessibilityLabel={confirmLabel}
475
+ onPress={() => {
476
+ onConfirm?.(formatTime(hour, minute));
477
+ setOpen(false);
478
+ }}
479
+ >
480
+ {confirmLabel}
481
+ </Button>
482
+ </>
483
+ }
484
+ {...props}
485
+ >
486
+ <View style={{ flexDirection: "row", gap: 8, alignItems: "center" }}>
487
+ {column(use12Hour ? Array.from({ length: 12 }, (_, i) => i + 1) : hours, displayHour, (picked) => {
488
+ if (!use12Hour) {
489
+ setHour(picked);
490
+ return;
491
+ }
492
+ // Keep the current half of the day when the hour column changes.
493
+ setHour(picked % 12 === 0 ? (isPm ? 12 : 0) : isPm ? picked + 12 : picked);
494
+ }, "Hour")}
495
+ <RNText style={{ fontSize: 22, color: theme.muted }}>{":"}</RNText>
496
+ {column(minutes, minute, setMinute, "Minute")}
497
+ {use12Hour && (
498
+ <View style={{ flex: 1, gap: 6 }}>
499
+ {["AM", "PM"].map((label) => {
500
+ const active = label === "PM" ? isPm : !isPm;
501
+ return (
502
+ <Pressable
503
+ key={label}
504
+ accessibilityRole="button"
505
+ accessibilityLabel={label}
506
+ accessibilityState={{ selected: active }}
507
+ onPress={() => {
508
+ const nextPm = label === "PM";
509
+ if (nextPm === isPm) return;
510
+ setHour((current) => (nextPm ? (current % 12) + 12 : current % 12));
511
+ }}
512
+ style={{
513
+ height: 34,
514
+ borderRadius: radii.sm,
515
+ alignItems: "center",
516
+ justifyContent: "center",
517
+ backgroundColor: active ? theme.glassActive : "transparent",
518
+ borderWidth: 0.5,
519
+ borderColor: active ? theme.edge : "transparent",
520
+ }}
521
+ >
522
+ <RNText style={{ fontSize: 14, fontWeight: active ? "600" : "500", color: active ? theme.foreground : theme.muted }}>
523
+ {label}
524
+ </RNText>
525
+ </Pressable>
526
+ );
527
+ })}
528
+ </View>
529
+ )}
530
+ </View>
531
+ </Sheet>
532
+ );
533
+ });
534
+
535
+ /** One scrollable column of the time drums. */
536
+ function ScrollColumn({
537
+ items,
538
+ selected,
539
+ onPick,
540
+ isDark,
541
+ pad,
542
+ }: {
543
+ items: number[];
544
+ selected: number;
545
+ onPick: (value: number) => void;
546
+ isDark: boolean;
547
+ pad: number;
548
+ }) {
549
+ const theme = isDark ? colors.dark : colors.light;
550
+ const { getScrollView } = primitives();
551
+ const ScrollView = getScrollView();
552
+ const { View, Text: RNText, Pressable } = primitives();
553
+
554
+ const rows = items.map((item) => {
555
+ const active = item === selected;
556
+ return (
557
+ <Pressable
558
+ key={item}
559
+ accessibilityRole="button"
560
+ accessibilityLabel={String(item).padStart(pad, "0")}
561
+ accessibilityState={{ selected: active }}
562
+ onPress={() => onPick(item)}
563
+ style={{
564
+ height: 34,
565
+ alignItems: "center",
566
+ justifyContent: "center",
567
+ borderRadius: radii.sm,
568
+ backgroundColor: active ? theme.glassActive : "transparent",
569
+ }}
570
+ >
571
+ <RNText style={{ fontSize: 17, fontWeight: active ? "600" : "400", color: active ? theme.foreground : theme.muted }}>
572
+ {String(item).padStart(pad, "0")}
573
+ </RNText>
574
+ </Pressable>
575
+ );
576
+ });
577
+
578
+ if (!ScrollView) {
579
+ // Off-device: no ScrollView, so the column is clipped to its height rather
580
+ // than truncated. Every value stays present and selectable, which is what
581
+ // the real drum shows once it can scroll.
582
+ return <View style={{ gap: 2, overflow: "hidden", height: 168 }}>{rows}</View>;
583
+ }
584
+
585
+ return (
586
+ <ScrollView showsVerticalScrollIndicator={false} style={{ flex: 1 }}>
587
+ <View style={{ gap: 2 }}>{rows}</View>
588
+ </ScrollView>
589
+ );
590
+ }