glacia-native 0.5.0 → 0.5.2

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 (100) hide show
  1. package/LICENSE +29 -4
  2. package/README.md +27 -0
  3. package/lib/module/Bars.js +103 -9
  4. package/lib/module/Button.js +11 -8
  5. package/lib/module/Card.js +2 -2
  6. package/lib/module/Dialog.js +16 -17
  7. package/lib/module/Display.js +86 -8
  8. package/lib/module/Feedback.js +244 -21
  9. package/lib/module/Form.js +29 -33
  10. package/lib/module/Forms2.js +257 -13
  11. package/lib/module/Glass.js +2 -2
  12. package/lib/module/Input.js +12 -10
  13. package/lib/module/Message.js +84 -0
  14. package/lib/module/Overlays.js +195 -17
  15. package/lib/module/Pickers.js +16 -16
  16. package/lib/module/SegmentedControl.js +24 -11
  17. package/lib/module/Slider.js +24 -10
  18. package/lib/module/Switch.js +25 -10
  19. package/lib/module/TabBar.js +23 -13
  20. package/lib/module/Table.js +4 -3
  21. package/lib/module/Tabs.js +3 -2
  22. package/lib/module/ai.js +26 -18
  23. package/lib/module/charts/BarChart.js +11 -3
  24. package/lib/module/index.js +23 -2
  25. package/lib/module/internal/GlassContainer.js +54 -0
  26. package/lib/module/internal/GlassView.js +10 -2
  27. package/lib/module/internal/a11y.js +94 -0
  28. package/lib/module/internal/blur.js +78 -0
  29. package/lib/module/internal/fallback.js +120 -19
  30. package/lib/module/internal/glass-routing.js +7 -0
  31. package/lib/module/internal/glow.js +36 -0
  32. package/lib/module/internal/haptics.js +54 -0
  33. package/lib/module/internal/lens.js +70 -0
  34. package/lib/module/internal/material.js +64 -0
  35. package/lib/module/internal/motion.js +10 -1
  36. package/lib/module/internal/primitives.js +70 -4
  37. package/lib/module/internal/rim.js +35 -0
  38. package/lib/module/internal/tokens.js +80 -2
  39. package/lib/typescript/Bars.d.ts +67 -0
  40. package/lib/typescript/Display.d.ts +59 -0
  41. package/lib/typescript/Feedback.d.ts +58 -0
  42. package/lib/typescript/Forms2.d.ts +81 -0
  43. package/lib/typescript/Message.d.ts +67 -0
  44. package/lib/typescript/Overlays.d.ts +41 -0
  45. package/lib/typescript/SegmentedControl.d.ts +2 -0
  46. package/lib/typescript/Slider.d.ts +2 -0
  47. package/lib/typescript/Switch.d.ts +2 -0
  48. package/lib/typescript/TabBar.d.ts +2 -0
  49. package/lib/typescript/index.d.ts +9 -6
  50. package/lib/typescript/internal/GlassContainer.d.ts +37 -0
  51. package/lib/typescript/internal/GlassView.d.ts +21 -0
  52. package/lib/typescript/internal/a11y.d.ts +19 -0
  53. package/lib/typescript/internal/blur.d.ts +24 -0
  54. package/lib/typescript/internal/fallback.d.ts +32 -2
  55. package/lib/typescript/internal/glass-routing.d.ts +10 -0
  56. package/lib/typescript/internal/glow.d.ts +11 -0
  57. package/lib/typescript/internal/haptics.d.ts +7 -0
  58. package/lib/typescript/internal/lens.d.ts +47 -0
  59. package/lib/typescript/internal/material.d.ts +27 -0
  60. package/lib/typescript/internal/motion.d.ts +4 -0
  61. package/lib/typescript/internal/primitives.d.ts +23 -0
  62. package/lib/typescript/internal/rim.d.ts +16 -0
  63. package/lib/typescript/internal/tokens.d.ts +89 -0
  64. package/package.json +12 -3
  65. package/src/Bars.tsx +239 -2
  66. package/src/Button.tsx +16 -9
  67. package/src/Card.tsx +2 -2
  68. package/src/Dialog.tsx +37 -26
  69. package/src/Display.tsx +237 -6
  70. package/src/Feedback.tsx +448 -35
  71. package/src/Form.tsx +60 -40
  72. package/src/Forms2.tsx +455 -8
  73. package/src/Glass.tsx +4 -0
  74. package/src/Input.tsx +15 -11
  75. package/src/Message.tsx +218 -0
  76. package/src/Overlays.tsx +269 -39
  77. package/src/Pickers.tsx +11 -6
  78. package/src/SegmentedControl.tsx +39 -9
  79. package/src/Slider.tsx +26 -10
  80. package/src/Switch.tsx +29 -10
  81. package/src/TabBar.tsx +39 -12
  82. package/src/Table.tsx +4 -3
  83. package/src/Tabs.tsx +5 -0
  84. package/src/ai.tsx +37 -23
  85. package/src/charts/BarChart.tsx +41 -3
  86. package/src/index.ts +43 -1
  87. package/src/internal/GlassContainer.tsx +82 -0
  88. package/src/internal/GlassView.tsx +25 -0
  89. package/src/internal/a11y.ts +105 -0
  90. package/src/internal/blur.ts +90 -0
  91. package/src/internal/fallback.tsx +170 -15
  92. package/src/internal/glass-routing.ts +17 -0
  93. package/src/internal/glow.tsx +62 -0
  94. package/src/internal/haptics.ts +59 -0
  95. package/src/internal/lens.tsx +105 -0
  96. package/src/internal/material.ts +92 -0
  97. package/src/internal/motion.ts +10 -1
  98. package/src/internal/primitives.ts +83 -4
  99. package/src/internal/rim.tsx +79 -0
  100. package/src/internal/tokens.ts +82 -1
@@ -2,12 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Drawer = exports.Sheet = exports.Menu = void 0;
4
4
  exports.anchorPopover = anchorPopover;
5
+ exports.resolveSnapPoint = resolveSnapPoint;
6
+ exports.nearestSnapPoint = nearestSnapPoint;
5
7
  const jsx_runtime_1 = require("react/jsx-runtime");
6
8
  const react_1 = require("react");
7
9
  const Glass_1 = require("./Glass");
8
10
  const tokens_1 = require("./internal/tokens");
9
11
  const primitives_1 = require("./internal/primitives");
10
12
  const motion_1 = require("./internal/motion");
13
+ const haptics_1 = require("./internal/haptics");
11
14
  /**
12
15
  * Registers Android's hardware back while an overlay is open.
13
16
  *
@@ -66,10 +69,21 @@ exports.Menu = (0, react_1.forwardRef)(function Menu({ trigger, items, open: ope
66
69
  useBackDismiss(open, dismiss);
67
70
  const { value: enter, animated } = (0, motion_1.useSpring)(open ? 1 : 0, "snappy");
68
71
  const scale = animated ? enter.interpolate({ inputRange: [0, 1], outputRange: [0.96, 1] }) : 1;
69
- const popover = ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", isDark: isDark, testID: testID ? `${testID}-popover` : undefined, style: { width, borderRadius: tokens_1.radii.md, paddingVertical: 4, overflow: "hidden", ...style }, children: items.map((item, index) => ((0, jsx_runtime_1.jsxs)(Pressable, { accessibilityRole: "button", accessibilityLabel: item.accessibilityLabel ?? item.label, accessibilityState: { disabled: item.disabled }, disabled: item.disabled, onPress: () => {
72
+ const popover = ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", surface: "overlay", isDark: isDark, testID: testID ? `${testID}-popover` : undefined, style: {
73
+ width,
74
+ borderRadius: tokens_1.radii.lg,
75
+ paddingVertical: 4,
76
+ // The web menu is deliberately near-solid so its labels stay legible
77
+ // over any backdrop, and it floats on a real shadow.
78
+ backgroundColor: theme.surface,
79
+ shadowOpacity: 0.12,
80
+ shadowRadius: 40,
81
+ shadowOffset: { width: 0, height: 12 },
82
+ ...style,
83
+ }, children: items.map((item, index) => ((0, jsx_runtime_1.jsxs)(Pressable, { accessibilityRole: "button", accessibilityLabel: item.accessibilityLabel ?? item.label, accessibilityState: { disabled: item.disabled }, disabled: item.disabled, onPress: () => {
70
84
  setOpen(false);
71
85
  item.onPress();
72
- }, style: { flexDirection: "row", alignItems: "center", gap: 10, paddingVertical: 10, paddingHorizontal: 12, opacity: item.disabled ? 0.38 : 1 }, children: [item.icon ? (0, jsx_runtime_1.jsx)(View, { children: item.icon }) : null, (0, jsx_runtime_1.jsx)(RNText, { numberOfLines: 1, style: { fontSize: 15, color: item.destructive ? theme.destructive : theme.foreground }, children: item.label })] }, `${item.label}-${index}`))) }));
86
+ }, style: { flexDirection: "row", alignItems: "center", gap: 10, minHeight: 40, paddingVertical: 8, paddingHorizontal: 12, opacity: item.disabled ? 0.38 : 1 }, children: [item.icon ? (0, jsx_runtime_1.jsx)(View, { children: item.icon }) : null, (0, jsx_runtime_1.jsx)(RNText, { numberOfLines: 1, style: { fontSize: 15, color: item.destructive ? theme.destructive : theme.foreground }, children: item.label })] }, `${item.label}-${index}`))) }));
73
87
  return ((0, jsx_runtime_1.jsxs)(View, { ref: ref, style: { alignSelf: "flex-start" }, ...props, children: [(0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: accessibilityLabel, accessibilityState: { expanded: open }, onPress: () => setOpen(!open), children: trigger }), (0, jsx_runtime_1.jsx)(Modal, { visible: open, transparent: true, animationType: "fade", onRequestClose: dismiss, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: "Close menu", onPress: dismiss, style: { flex: 1, backgroundColor: theme.scrim }, children: (0, jsx_runtime_1.jsx)(View, { style: { flex: 1, alignItems: "center", justifyContent: "center", padding: 24 }, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "none", onPress: () => { }, children: animated ? ((0, jsx_runtime_1.jsx)(AnimatedScale, { scale: scale, children: popover })) : (popover) }) }) }) })] }));
74
88
  });
75
89
  /** Wraps a popover in the entrance scale, which must land on an Animated.View. */
@@ -85,10 +99,38 @@ function AnimatedScale({ scale, children }) {
85
99
  * specialisation of this shape; Sheet is for arbitrary content — a form, a
86
100
  * calendar, a detail panel.
87
101
  */
88
- exports.Sheet = (0, react_1.forwardRef)(function Sheet({ open: openProp, defaultOpen = false, onOpenChange, title, children, footer, dismissOnBackdropPress = true, showHandle = true, style, isDark: isDarkProp, testID, ...props }, ref) {
102
+ /**
103
+ * Turns a snap point into a pixel height.
104
+ *
105
+ * A number under 1 is a fraction of the window; anything else is points. The
106
+ * result is clamped so a sheet can never be taller than the space it has.
107
+ */
108
+ function resolveSnapPoint(point, windowHeight) {
109
+ const height = point > 0 && point < 1 ? point * windowHeight : point;
110
+ return Math.max(0, Math.min(height, windowHeight));
111
+ }
112
+ /**
113
+ * Picks the snap point nearest to where the user let go.
114
+ *
115
+ * `height` is how tall the sheet currently is. Ties go to the smaller sheet,
116
+ * so a small flick does not jump the panel to full height.
117
+ */
118
+ function nearestSnapPoint(heights, height) {
119
+ let best = 0;
120
+ let bestDistance = Number.POSITIVE_INFINITY;
121
+ heights.forEach((candidate, index) => {
122
+ const distance = Math.abs(candidate - height);
123
+ if (distance < bestDistance) {
124
+ bestDistance = distance;
125
+ best = index;
126
+ }
127
+ });
128
+ return best;
129
+ }
130
+ exports.Sheet = (0, react_1.forwardRef)(function Sheet({ open: openProp, defaultOpen = false, onOpenChange, title, children, footer, dismissOnBackdropPress = true, showHandle = true, snapPoints, initialSnapIndex = 0, snapIndex: snapIndexProp, onSnapIndexChange, dismissOnSnapToBottom = false, draggable = true, haptics = true, style, isDark: isDarkProp, testID, ...props }, ref) {
89
131
  const isDark = (0, motion_1.useIsDark)(isDarkProp);
90
132
  const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
91
- const { View, Text: RNText, Pressable, Modal } = (0, primitives_1.primitives)();
133
+ const { View, Text: RNText, Pressable, Modal, PanResponder, useWindowDimensions } = (0, primitives_1.primitives)();
92
134
  const [internalOpen, setInternalOpen] = (0, react_1.useState)(defaultOpen);
93
135
  const open = openProp !== undefined ? openProp : internalOpen;
94
136
  const setOpen = (0, react_1.useCallback)((next) => {
@@ -98,30 +140,128 @@ exports.Sheet = (0, react_1.forwardRef)(function Sheet({ open: openProp, default
98
140
  }, [openProp, onOpenChange]);
99
141
  const dismiss = (0, react_1.useCallback)(() => setOpen(false), [setOpen]);
100
142
  useBackDismiss(open, dismiss);
101
- // 0 is fully dismissed, 1 fully presented; the panel rides up this value.
143
+ // Snap points in pixels, smallest first so index 0 is the shortest sheet.
144
+ const windowHeight = useWindowDimensions?.().height ?? 800;
145
+ const heights = (0, react_1.useMemo)(() => {
146
+ if (!snapPoints || snapPoints.length === 0)
147
+ return [];
148
+ return snapPoints.map((point) => resolveSnapPoint(point, windowHeight)).sort((a, b) => a - b);
149
+ }, [snapPoints, windowHeight]);
150
+ const [internalSnap, setInternalSnap] = (0, react_1.useState)(initialSnapIndex);
151
+ const snapIndex = snapIndexProp !== undefined ? snapIndexProp : internalSnap;
152
+ const activeHeight = heights.length > 0 ? heights[Math.min(snapIndex, heights.length - 1)] : null;
153
+ // Drag offset in pixels: 0 is resting at the active snap point, positive is
154
+ // dragged down. It resets to 0 after a release, because the settle either
155
+ // changes the snap index or dismisses.
156
+ const dragRef = (0, react_1.useRef)(0);
157
+ const [drag, setDrag] = (0, react_1.useState)(0);
102
158
  const { value: rise, animated } = (0, motion_1.useSpring)(open ? 1 : 0, "gentle");
103
- const translateY = animated ? rise.interpolate({ inputRange: [0, 1], outputRange: [420, 0] }) : 0;
104
- return ((0, jsx_runtime_1.jsx)(Modal, { visible: open, transparent: true, animationType: "fade", onRequestClose: dismiss, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: "Close sheet", onPress: dismissOnBackdropPress ? dismiss : undefined, style: { flex: 1, justifyContent: "flex-end", backgroundColor: theme.scrim }, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "none", onPress: () => { }, style: { width: "100%" }, children: animated ? ((0, jsx_runtime_1.jsx)(SheetRise, { translateY: translateY, children: (0, jsx_runtime_1.jsx)(SheetPanel, { title: title, footer: footer, showHandle: showHandle, isDark: isDark, testID: testID, style: style, children: children }) })) : ((0, jsx_runtime_1.jsx)(SheetPanel, { title: title, footer: footer, showHandle: showHandle, isDark: isDark, testID: testID, style: style, children: children })) }) }) }));
159
+ const slideIn = animated ? rise.interpolate({ inputRange: [0, 1], outputRange: [420, 0] }) : 0;
160
+ const heightsRef = (0, react_1.useRef)(heights);
161
+ heightsRef.current = heights;
162
+ const activeHeightRef = (0, react_1.useRef)(activeHeight);
163
+ activeHeightRef.current = activeHeight;
164
+ const snapIndexRef = (0, react_1.useRef)(snapIndex);
165
+ snapIndexRef.current = snapIndex;
166
+ const goToSnap = (0, react_1.useCallback)((index) => {
167
+ if (snapIndexProp === undefined)
168
+ setInternalSnap(index);
169
+ onSnapIndexChange?.(index);
170
+ if (haptics)
171
+ (0, haptics_1.hapticSelection)();
172
+ }, [snapIndexProp, onSnapIndexChange, haptics]);
173
+ /**
174
+ * The release decision.
175
+ *
176
+ * Below the lowest snap point the sheet dismisses when allowed, otherwise it
177
+ * snaps back; anywhere else it settles at the nearest point, with a fast
178
+ * downward flick counting as a step towards the smaller sheet.
179
+ */
180
+ const release = (0, react_1.useCallback)((dy, vy) => {
181
+ const list = heightsRef.current;
182
+ const current = list[snapIndexRef.current] ?? activeHeightRef.current ?? 0;
183
+ const restingAfterDrag = current - dy;
184
+ if (list.length === 0) {
185
+ // No snap points: a decisive downward drag dismisses.
186
+ if (dy > 120 || vy > 0.8)
187
+ dismiss();
188
+ return;
189
+ }
190
+ const lowest = list[0];
191
+ const belowLowest = restingAfterDrag < lowest - 40;
192
+ if (belowLowest && dismissOnSnapToBottom) {
193
+ dismiss();
194
+ return;
195
+ }
196
+ // A fast flick moves one step in its direction before distance decides.
197
+ let index = nearestSnapPoint(list, restingAfterDrag);
198
+ if (vy > 0.5)
199
+ index = Math.max(0, Math.min(index, snapIndexRef.current - 1));
200
+ if (vy < -0.5)
201
+ index = Math.max(index, Math.min(snapIndexRef.current + 1, list.length - 1));
202
+ if (index !== snapIndexRef.current)
203
+ goToSnap(index);
204
+ }, [dismiss, dismissOnSnapToBottom, goToSnap]);
205
+ const panResponder = (0, react_1.useMemo)(() => {
206
+ if (!draggable || !PanResponder?.create)
207
+ return null;
208
+ return PanResponder.create({
209
+ // Vertical drags belong to the sheet; horizontal ones are left alone.
210
+ onStartShouldSetPanResponder: () => false,
211
+ onMoveShouldSetPanResponder: (_event, gesture) => Math.abs(gesture.dy) > Math.abs(gesture.dx) && Math.abs(gesture.dy) > 6,
212
+ onPanResponderGrant: () => {
213
+ dragRef.current = 0;
214
+ },
215
+ onPanResponderMove: (_event, gesture) => {
216
+ // Dragging up past the tallest point has nowhere to go; clamp at 0.
217
+ const next = Math.max(-40, gesture.dy);
218
+ dragRef.current = next;
219
+ setDrag(next);
220
+ },
221
+ onPanResponderRelease: (_event, gesture) => {
222
+ release(gesture.dy, gesture.vy);
223
+ dragRef.current = 0;
224
+ setDrag(0);
225
+ },
226
+ onPanResponderTerminate: () => {
227
+ dragRef.current = 0;
228
+ setDrag(0);
229
+ },
230
+ onPanResponderTerminationRequest: () => false,
231
+ });
232
+ }, [draggable, PanResponder, release]);
233
+ // Reduce Motion is honoured by useSpring: when it is on, `animated` is false
234
+ // and the panel is already in position, so the sheet opens and snaps without
235
+ // a transition.
236
+ const translateY = drag !== 0 ? drag : animated ? slideIn : 0;
237
+ const panel = ((0, jsx_runtime_1.jsx)(SheetPanel, { title: title, footer: footer, showHandle: showHandle, isDark: isDark, testID: testID, style: style, height: activeHeight, children: children }));
238
+ return ((0, jsx_runtime_1.jsx)(Modal, { visible: open, transparent: true, animationType: "fade", onRequestClose: dismiss, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: "Close sheet", onPress: dismissOnBackdropPress ? dismiss : undefined, style: { flex: 1, justifyContent: "flex-end", backgroundColor: theme.scrim }, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "none", onPress: () => { }, style: { width: "100%" }, ...(panResponder ? panResponder.panHandlers : {}), children: animated || drag !== 0 ? ((0, jsx_runtime_1.jsx)(SheetRise, { translateY: translateY, children: panel })) : (panel) }) }) }));
105
239
  });
106
240
  function SheetRise({ translateY, children }) {
107
241
  const { Animated } = (0, primitives_1.primitives)();
108
242
  return (0, jsx_runtime_1.jsx)(Animated.View, { style: { transform: [{ translateY }] }, children: children });
109
243
  }
110
244
  /** The panel itself: a glass surface with a handle, a title and a footer. */
111
- function SheetPanel({ title, footer, showHandle, isDark, testID, style, children, }) {
245
+ function SheetPanel({ title, footer, showHandle, isDark, testID, style, height, children, }) {
112
246
  const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
113
247
  const { View, Text: RNText } = (0, primitives_1.primitives)();
114
- return ((0, jsx_runtime_1.jsxs)(Glass_1.Glass, { effect: "regular", isDark: isDark, testID: testID, style: {
248
+ return ((0, jsx_runtime_1.jsxs)(Glass_1.Glass, { effect: "regular", surface: "overlay", isDark: isDark, testID: testID, style: {
115
249
  borderTopLeftRadius: tokens_1.radii.xl,
116
250
  borderTopRightRadius: tokens_1.radii.xl,
117
251
  borderBottomLeftRadius: 0,
118
252
  borderBottomRightRadius: 0,
119
- paddingBottom: 20,
120
- maxHeight: 560,
253
+ paddingBottom: 24,
254
+ // The web sheet carries a deep, soft shadow so it reads as a layer
255
+ // above the page rather than a rectangle painted on it.
256
+ shadowOpacity: 0.5,
257
+ shadowRadius: 40,
258
+ shadowOffset: { width: 0, height: 0 },
259
+ // A snap point fixes the height; without one the panel is natural.
260
+ ...(height != null ? { height } : { maxHeight: 560 }),
121
261
  ...style,
122
262
  }, children: [showHandle ? ((0, jsx_runtime_1.jsx)(View, { style: { alignItems: "center", paddingTop: 8, paddingBottom: 4 }, children: (0, jsx_runtime_1.jsx)(View, { accessibilityElementsHidden: true,
123
263
  // A capsule: the radius is half the handle's own height.
124
- style: { width: 36, height: 5, borderRadius: 5 / 2, backgroundColor: theme.separator } }) })) : null, title ? ((0, jsx_runtime_1.jsx)(View, { style: { paddingHorizontal: 20, paddingVertical: 10 }, children: (0, jsx_runtime_1.jsx)(RNText, { accessibilityRole: "heading", style: { fontSize: 17, fontWeight: "600", color: theme.foreground }, children: title }) })) : null, (0, jsx_runtime_1.jsx)(View, { style: { paddingHorizontal: 20 }, children: children }), footer ? (0, jsx_runtime_1.jsx)(View, { style: { paddingHorizontal: 20, paddingTop: 12, gap: 8 }, children: footer }) : null] }));
264
+ style: { width: 36, height: 5, borderRadius: 5 / 2, backgroundColor: theme.separator } }) })) : null, title ? ((0, jsx_runtime_1.jsx)(View, { style: { paddingHorizontal: 24, paddingVertical: 10 }, children: (0, jsx_runtime_1.jsx)(RNText, { accessibilityRole: "heading", style: { fontSize: 17, fontWeight: "600", color: theme.foreground }, children: title }) })) : null, (0, jsx_runtime_1.jsx)(View, { style: { paddingHorizontal: 24 }, children: children }), footer ? (0, jsx_runtime_1.jsx)(View, { style: { paddingHorizontal: 24, paddingTop: 12, gap: 8 }, children: footer }) : null] }));
125
265
  }
126
266
  /**
127
267
  * A side navigation drawer.
@@ -129,11 +269,16 @@ function SheetPanel({ title, footer, showHandle, isDark, testID, style, children
129
269
  * The same overlay discipline as Sheet — scrim, spring slide, Android back —
130
270
  * but anchored to a side edge, with a square panel that runs the full height.
131
271
  * The caller supplies the content, typically a List.
272
+ *
273
+ * Dragging the panel towards its own edge follows the finger; releasing past
274
+ * the halfway point, or with enough outward velocity, closes it, and a drag
275
+ * that stays inside springs it back open. Reduce Motion is honoured: with it
276
+ * on, the drawer appears and disappears without sliding.
132
277
  */
133
- exports.Drawer = (0, react_1.forwardRef)(function Drawer({ open: openProp, defaultOpen = false, onOpenChange, side = "left", width = 280, children, dismissOnBackdropPress = true, style, isDark: isDarkProp, testID, ...props }, ref) {
278
+ exports.Drawer = (0, react_1.forwardRef)(function Drawer({ open: openProp, defaultOpen = false, onOpenChange, side = "left", width = 280, children, dismissOnBackdropPress = true, draggable = true, haptics = true, style, isDark: isDarkProp, testID, ...props }, ref) {
134
279
  const isDark = (0, motion_1.useIsDark)(isDarkProp);
135
280
  const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
136
- const { View, Pressable, Modal } = (0, primitives_1.primitives)();
281
+ const { View, Pressable, Modal, PanResponder } = (0, primitives_1.primitives)();
137
282
  const [internalOpen, setInternalOpen] = (0, react_1.useState)(defaultOpen);
138
283
  const open = openProp !== undefined ? openProp : internalOpen;
139
284
  const setOpen = (0, react_1.useCallback)((next) => {
@@ -145,10 +290,43 @@ exports.Drawer = (0, react_1.forwardRef)(function Drawer({ open: openProp, defau
145
290
  useBackDismiss(open, dismiss);
146
291
  const { value: slide, animated } = (0, motion_1.useSpring)(open ? 1 : 0, "gentle");
147
292
  // Slide in from off-screen: negative from the left, positive from the right.
148
- const translateX = animated
293
+ const slideIn = animated
149
294
  ? slide.interpolate({ inputRange: [0, 1], outputRange: [side === "left" ? -width : width, 0] })
150
295
  : 0;
151
- const panel = ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", isDark: isDark, testID: testID, style: {
296
+ // The drag is measured in the drawer's own closing direction, so a drag
297
+ // towards the anchored edge is always positive whichever side it is on.
298
+ const [drag, setDrag] = (0, react_1.useState)(0);
299
+ const panResponder = (0, react_1.useMemo)(() => {
300
+ if (!draggable || !PanResponder?.create)
301
+ return null;
302
+ const outward = side === "left" ? -1 : 1;
303
+ return PanResponder.create({
304
+ onStartShouldSetPanResponder: () => false,
305
+ onMoveShouldSetPanResponder: (_event, gesture) =>
306
+ // Only a horizontal drag towards the edge is ours; the other way has
307
+ // nowhere to go and should not fight content inside the panel.
308
+ Math.abs(gesture.dx) > Math.abs(gesture.dy) && gesture.dx * outward > 6,
309
+ onPanResponderMove: (_event, gesture) => {
310
+ setDrag(Math.max(0, gesture.dx * outward));
311
+ },
312
+ onPanResponderRelease: (_event, gesture) => {
313
+ const travelled = Math.max(0, gesture.dx * outward);
314
+ const thrown = gesture.vx * outward > 0.4;
315
+ setDrag(0);
316
+ if (travelled > width / 2 || thrown) {
317
+ if (haptics)
318
+ (0, haptics_1.hapticSelection)();
319
+ dismiss();
320
+ }
321
+ },
322
+ onPanResponderTerminate: () => setDrag(0),
323
+ onPanResponderTerminationRequest: () => false,
324
+ });
325
+ // `dismiss` is stable; the gesture only needs rebuilding when its shape
326
+ // (side or width) changes.
327
+ }, [draggable, PanResponder, side, width, haptics, dismiss]);
328
+ const translateX = drag !== 0 ? (side === "left" ? -drag : drag) : animated ? slideIn : 0;
329
+ const panel = ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", surface: "overlay", isDark: isDark, testID: testID, style: {
152
330
  width,
153
331
  height: "100%",
154
332
  borderRadius: 0,
@@ -158,7 +336,7 @@ exports.Drawer = (0, react_1.forwardRef)(function Drawer({ open: openProp, defau
158
336
  return ((0, jsx_runtime_1.jsx)(Modal, { visible: open, transparent: true, animationType: "fade", onRequestClose: dismiss, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: "Close drawer", onPress: dismissOnBackdropPress ? dismiss : undefined, style: { flex: 1, backgroundColor: theme.scrim }, children: (0, jsx_runtime_1.jsx)(View, { style: {
159
337
  flex: 1,
160
338
  alignItems: side === "left" ? "flex-start" : "flex-end",
161
- }, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "none", onPress: () => { }, style: { height: "100%" }, children: animated ? (0, jsx_runtime_1.jsx)(DrawerSlide, { translateX: translateX, children: panel }) : panel }) }) }) }));
339
+ }, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "none", onPress: () => { }, style: { height: "100%" }, ...(panResponder ? panResponder.panHandlers : {}), children: animated || drag !== 0 ? (0, jsx_runtime_1.jsx)(DrawerSlide, { translateX: translateX, children: panel }) : panel }) }) }) }));
162
340
  });
163
341
  function DrawerSlide({ translateX, children }) {
164
342
  const { Animated } = (0, primitives_1.primitives)();
@@ -13,6 +13,7 @@ const Overlays_1 = require("./Overlays");
13
13
  const tokens_1 = require("./internal/tokens");
14
14
  const primitives_1 = require("./internal/primitives");
15
15
  const motion_1 = require("./internal/motion");
16
+ const lens_1 = require("./internal/lens");
16
17
  // ---------------------------------------------------------------------------
17
18
  // Date helpers
18
19
  //
@@ -99,21 +100,22 @@ exports.Calendar = (0, react_1.forwardRef)(function Calendar({ value, onChange,
99
100
  const selected = sameDay(cell.date, value);
100
101
  const isToday = sameDay(cell.date, today);
101
102
  const disabled = isDisabled(cell.date);
102
- return ((0, jsx_runtime_1.jsx)(View, { style: { flex: 1, alignItems: "center", paddingVertical: 2 }, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: cell.date.toDateString(), accessibilityState: { selected, disabled }, disabled: disabled, onPress: () => onChange?.(startOfDay(cell.date)), style: {
103
+ return ((0, jsx_runtime_1.jsx)(View, { style: { flex: 1, alignItems: "center", paddingVertical: 2 }, children: (0, jsx_runtime_1.jsxs)(Pressable, { accessibilityRole: "button", accessibilityLabel: cell.date.toDateString(), accessibilityState: { selected, disabled }, disabled: disabled, onPress: () => onChange?.(startOfDay(cell.date)), style: {
103
104
  width: cellSize,
104
105
  height: cellSize,
105
106
  borderRadius: cellSize / 2,
106
107
  alignItems: "center",
107
108
  justifyContent: "center",
108
- backgroundColor: selected ? theme.glassActive : "transparent",
109
- borderWidth: isToday && !selected ? 0.5 : selected ? 1 : 0,
109
+ backgroundColor: "transparent",
110
+ // Today is ringed; the selection is a lens on top of it.
111
+ borderWidth: isToday && !selected ? 0.5 : 0,
110
112
  borderColor: isToday && !selected ? theme.fill : theme.edge,
111
113
  opacity: disabled ? 0.28 : cell.outside ? 0.45 : 1,
112
- }, children: (0, jsx_runtime_1.jsx)(RNText, { style: {
113
- fontSize: 14,
114
- fontWeight: selected ? "600" : "400",
115
- color: selected ? theme.foreground : theme.foreground,
116
- }, children: String(cell.date.getDate()) }) }) }, cell.key));
114
+ }, children: [selected ? ((0, jsx_runtime_1.jsx)(lens_1.SelectedLens, { radius: cellSize / 2, isDark: isDark, style: lens_1.lensFill })) : null, (0, jsx_runtime_1.jsx)(RNText, { style: {
115
+ fontSize: 14,
116
+ fontWeight: selected ? "600" : "400",
117
+ color: selected ? theme.foreground : theme.foreground,
118
+ }, children: String(cell.date.getDate()) })] }) }, cell.key));
117
119
  }) }, row)))] }));
118
120
  });
119
121
  /**
@@ -201,7 +203,7 @@ exports.TimePicker = (0, react_1.forwardRef)(function TimePicker({ open: openPro
201
203
  setHour(picked % 12 === 0 ? (isPm ? 12 : 0) : isPm ? picked + 12 : picked);
202
204
  }, "Hour"), (0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 22, color: theme.muted }, children: ":" }), column(minutes, minute, setMinute, "Minute"), use12Hour && ((0, jsx_runtime_1.jsx)(View, { style: { flex: 1, gap: 6 }, children: ["AM", "PM"].map((label) => {
203
205
  const active = label === "PM" ? isPm : !isPm;
204
- return ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: label, accessibilityState: { selected: active }, onPress: () => {
206
+ return ((0, jsx_runtime_1.jsxs)(Pressable, { accessibilityRole: "button", accessibilityLabel: label, accessibilityState: { selected: active }, onPress: () => {
205
207
  const nextPm = label === "PM";
206
208
  if (nextPm === isPm)
207
209
  return;
@@ -211,10 +213,8 @@ exports.TimePicker = (0, react_1.forwardRef)(function TimePicker({ open: openPro
211
213
  borderRadius: tokens_1.radii.sm,
212
214
  alignItems: "center",
213
215
  justifyContent: "center",
214
- backgroundColor: active ? theme.glassActive : "transparent",
215
- borderWidth: 0.5,
216
- borderColor: active ? theme.edge : "transparent",
217
- }, children: (0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 14, fontWeight: active ? "600" : "500", color: active ? theme.foreground : theme.muted }, children: label }) }, label));
216
+ backgroundColor: "transparent",
217
+ }, children: [active ? (0, jsx_runtime_1.jsx)(lens_1.SelectedLens, { radius: tokens_1.radii.sm, isDark: isDark, style: lens_1.lensFill }) : null, (0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 14, fontWeight: active ? "600" : "500", color: active ? theme.foreground : theme.muted }, children: label })] }, label));
218
218
  }) }))] }) }));
219
219
  });
220
220
  /** One scrollable column of the time drums. */
@@ -225,13 +225,13 @@ function ScrollColumn({ items, selected, onPick, isDark, pad, }) {
225
225
  const { View, Text: RNText, Pressable } = (0, primitives_1.primitives)();
226
226
  const rows = items.map((item) => {
227
227
  const active = item === selected;
228
- return ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: String(item).padStart(pad, "0"), accessibilityState: { selected: active }, onPress: () => onPick(item), style: {
228
+ return ((0, jsx_runtime_1.jsxs)(Pressable, { accessibilityRole: "button", accessibilityLabel: String(item).padStart(pad, "0"), accessibilityState: { selected: active }, onPress: () => onPick(item), style: {
229
229
  height: 34,
230
230
  alignItems: "center",
231
231
  justifyContent: "center",
232
232
  borderRadius: tokens_1.radii.sm,
233
- backgroundColor: active ? theme.glassActive : "transparent",
234
- }, children: (0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 17, fontWeight: active ? "600" : "400", color: active ? theme.foreground : theme.muted }, children: String(item).padStart(pad, "0") }) }, item));
233
+ backgroundColor: "transparent",
234
+ }, children: [active ? (0, jsx_runtime_1.jsx)(lens_1.SelectedLens, { radius: tokens_1.radii.sm, isDark: isDark, style: lens_1.lensFill }) : null, (0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 17, fontWeight: active ? "600" : "400", color: active ? theme.foreground : theme.muted }, children: String(item).padStart(pad, "0") })] }, item));
235
235
  });
236
236
  if (!ScrollView) {
237
237
  // Off-device: no ScrollView, so the column is clipped to its height rather
@@ -7,7 +7,11 @@ const Glass_1 = require("./Glass");
7
7
  const tokens_1 = require("./internal/tokens");
8
8
  const primitives_1 = require("./internal/primitives");
9
9
  const motion_1 = require("./internal/motion");
10
- const SEGMENT_HEIGHT = 30;
10
+ const haptics_1 = require("./internal/haptics");
11
+ const lens_1 = require("./internal/lens");
12
+ // The web segment is 32 high inside a 2pt inset, on a pill container, with the
13
+ // selected pill itself a pill: 500/400 weights, not a bold selected label.
14
+ const SEGMENT_HEIGHT = 32;
11
15
  /**
12
16
  * A row of mutually exclusive segments on one glass container.
13
17
  *
@@ -15,17 +19,21 @@ const SEGMENT_HEIGHT = 30;
15
19
  * The pill's colours come from the theme tokens, so it reads correctly in both
16
20
  * light and dark instead of assuming a white-on-light palette.
17
21
  */
18
- exports.SegmentedControl = (0, react_1.forwardRef)(function SegmentedControl({ values, selectedIndex: selectedProp, defaultIndex = 0, onValueChange, style, isDark: isDarkProp, testID, ...props }, ref) {
22
+ exports.SegmentedControl = (0, react_1.forwardRef)(function SegmentedControl({ values, selectedIndex: selectedProp, defaultIndex = 0, onValueChange, haptics = true, style, isDark: isDarkProp, testID, ...props }, ref) {
19
23
  const isDark = (0, motion_1.useIsDark)(isDarkProp);
20
24
  const themeColors = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
21
25
  const { View, Text, Pressable, Animated } = (0, primitives_1.primitives)();
22
26
  const [internalIndex, setInternalIndex] = (0, react_1.useState)(defaultIndex);
27
+ const [held, setHeld] = (0, react_1.useState)(false);
23
28
  const activeIndex = selectedProp !== undefined ? selectedProp : internalIndex;
24
29
  const safeIndex = Math.min(Math.max(activeIndex, 0), Math.max(values.length - 1, 0));
25
30
  // The pill slides between equal-width segments, so a ratio is enough: 0 is
26
31
  // the first segment, values.length - 1 the last.
27
32
  const { value: slide, animated } = (0, motion_1.useSpring)(safeIndex, "snappy");
28
33
  const handleSelect = (index) => {
34
+ // Only a change ticks: re-pressing the current segment is not a selection.
35
+ if (haptics && index !== safeIndex)
36
+ (0, haptics_1.hapticSelection)();
29
37
  if (selectedProp === undefined)
30
38
  setInternalIndex(index);
31
39
  const val = values[index];
@@ -40,8 +48,10 @@ exports.SegmentedControl = (0, react_1.forwardRef)(function SegmentedControl({ v
40
48
  alignItems: "center",
41
49
  alignSelf: "flex-start",
42
50
  padding: 2,
43
- borderRadius: tokens_1.radii.md,
44
- backgroundColor: "rgba(118, 118, 128, 0.12)",
51
+ borderRadius: tokens_1.radii.pill,
52
+ // The web lays the segment track tint over glass; the fallback paints the
53
+ // same tint as the flat track the web sees through the glass.
54
+ backgroundColor: themeColors.fieldWash,
45
55
  ...style,
46
56
  };
47
57
  const pillTranslate = animated
@@ -51,30 +61,33 @@ exports.SegmentedControl = (0, react_1.forwardRef)(function SegmentedControl({ v
51
61
  outputRange: ["0%", `${((count - 1) * 100) / count}%`],
52
62
  })
53
63
  : `${(safeIndex * 100) / count}%`;
54
- return ((0, jsx_runtime_1.jsxs)(Glass_1.Glass, { ref: ref, effect: "regular", isDark: isDark, style: containerStyle, testID: testID, ...props, children: [animated ? ((0, jsx_runtime_1.jsx)(Animated.View, { style: {
64
+ return ((0, jsx_runtime_1.jsxs)(Glass_1.Glass, { ref: ref, effect: "regular", surface: "rail", pressed: held, isDark: isDark, style: containerStyle, testID: testID, ...props, children: [animated ? ((0, jsx_runtime_1.jsx)(Animated.View, { style: {
55
65
  position: "absolute",
56
66
  top: 2,
57
67
  left: 2,
58
68
  width: pillWidth,
59
69
  height: SEGMENT_HEIGHT,
60
- borderRadius: tokens_1.radii.sm,
70
+ borderRadius: tokens_1.radii.pill,
61
71
  backgroundColor: themeColors.glassActive,
62
72
  borderWidth: 0.5,
63
73
  borderColor: themeColors.edge,
74
+ // The thumb is a lens: lifted off the rail, with its own rim.
75
+ ...(0, lens_1.lensShadow)(isDark),
64
76
  transform: [{ translateX: pillTranslate }],
65
- }, pointerEvents: "none" })) : ((0, jsx_runtime_1.jsx)(View, { style: {
77
+ }, pointerEvents: "none", children: (0, jsx_runtime_1.jsx)(lens_1.LensRim, { radius: tokens_1.radii.pill, isDark: isDark }) })) : ((0, jsx_runtime_1.jsx)(View, { style: {
66
78
  position: "absolute",
67
79
  top: 2,
68
80
  left: `${2 + (safeIndex * 100) / count}%`,
69
81
  width: pillWidth,
70
82
  height: SEGMENT_HEIGHT,
71
- borderRadius: tokens_1.radii.sm,
83
+ borderRadius: tokens_1.radii.pill,
72
84
  backgroundColor: themeColors.glassActive,
73
85
  borderWidth: 0.5,
74
86
  borderColor: themeColors.edge,
75
- }, pointerEvents: "none" })), values.map((label, idx) => {
87
+ ...(0, lens_1.lensShadow)(isDark),
88
+ }, pointerEvents: "none", children: (0, jsx_runtime_1.jsx)(lens_1.LensRim, { radius: tokens_1.radii.pill, isDark: isDark }) })), values.map((label, idx) => {
76
89
  const isSelected = idx === safeIndex;
77
- return ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "tab", accessibilityLabel: label, accessibilityState: { selected: isSelected }, onPress: () => handleSelect(idx), style: {
90
+ return ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "tab", accessibilityLabel: label, accessibilityState: { selected: isSelected }, onPress: () => handleSelect(idx), onPressIn: () => setHeld(true), onPressOut: () => setHeld(false), style: {
78
91
  flex: 1,
79
92
  height: SEGMENT_HEIGHT,
80
93
  alignItems: "center",
@@ -83,7 +96,7 @@ exports.SegmentedControl = (0, react_1.forwardRef)(function SegmentedControl({ v
83
96
  borderRadius: tokens_1.radii.sm,
84
97
  }, children: (0, jsx_runtime_1.jsx)(Text, { numberOfLines: 1, style: {
85
98
  fontSize: 13,
86
- fontWeight: isSelected ? "600" : "500",
99
+ fontWeight: isSelected ? "500" : "400",
87
100
  color: isSelected ? themeColors.foreground : themeColors.muted,
88
101
  }, children: label }) }, label));
89
102
  })] }));
@@ -8,8 +8,11 @@ const Glass_1 = require("./Glass");
8
8
  const tokens_1 = require("./internal/tokens");
9
9
  const primitives_2 = require("./internal/primitives");
10
10
  const motion_1 = require("./internal/motion");
11
- const TRACK_HEIGHT = 8;
12
- const THUMB = 22;
11
+ const haptics_1 = require("./internal/haptics");
12
+ // The web slider: a 6pt track and a glass-lens thumb rather than a small dot.
13
+ const TRACK_HEIGHT = 6;
14
+ const THUMB_WIDTH = 36;
15
+ const THUMB_HEIGHT = 24;
13
16
  const CONTAINER_HEIGHT = 40;
14
17
  /** Rounds `value` onto the nearest step from `min`, clamped to the range. */
15
18
  function quantize(value, min, max, step) {
@@ -32,7 +35,7 @@ function quantize(value, min, max, step) {
32
35
  * sliders are not used, so the control looks and behaves the same on every
33
36
  * platform; only the glass material changes.
34
37
  */
35
- exports.Slider = (0, react_1.forwardRef)(function Slider({ value: valueProp, defaultValue = 50, min = 0, max = 100, step = 1, onValueChange, disabled = false, accessibilityLabel, style, isDark: isDarkProp, testID, ...props }, ref) {
38
+ exports.Slider = (0, react_1.forwardRef)(function Slider({ value: valueProp, defaultValue = 50, min = 0, max = 100, step = 1, onValueChange, disabled = false, haptics = true, accessibilityLabel, style, isDark: isDarkProp, testID, ...props }, ref) {
36
39
  const isDark = (0, motion_1.useIsDark)(isDarkProp);
37
40
  const themeColors = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
38
41
  const { View, Pressable, PanResponder } = (0, primitives_2.primitives)();
@@ -55,8 +58,12 @@ exports.Slider = (0, react_1.forwardRef)(function Slider({ value: valueProp, def
55
58
  return quantize(min + ratio * (max - min), min, max, step);
56
59
  }, [max, min, step]);
57
60
  const report = (next) => {
61
+ // Only a real step change ticks: a drag that stays inside one step is not
62
+ // a selection, and reporting the same value twice must not buzz twice.
58
63
  if (next === valueRef.current)
59
64
  return;
65
+ if (haptics)
66
+ (0, haptics_1.hapticSelection)();
60
67
  valueRef.current = next;
61
68
  if (valueProp === undefined)
62
69
  setInternalValue(next);
@@ -113,15 +120,22 @@ exports.Slider = (0, react_1.forwardRef)(function Slider({ value: valueProp, def
113
120
  };
114
121
  const thumbStyle = {
115
122
  position: "absolute",
116
- top: (CONTAINER_HEIGHT - THUMB) / 2,
123
+ top: (CONTAINER_HEIGHT - THUMB_HEIGHT) / 2,
117
124
  left: `${Math.min(100, Math.max(0, percentage))}%`,
118
- width: THUMB,
119
- height: THUMB,
120
- marginLeft: -THUMB / 2,
121
- borderRadius: THUMB / 2,
122
- backgroundColor: "#FFFFFF",
125
+ width: THUMB_WIDTH,
126
+ height: THUMB_HEIGHT,
127
+ marginLeft: -THUMB_WIDTH / 2,
128
+ borderRadius: THUMB_HEIGHT / 2,
129
+ backgroundColor: themeColors.onTint,
123
130
  borderWidth: 0.5,
124
- borderColor: "rgba(0, 0, 0, 0.12)",
131
+ borderColor: themeColors.edge,
132
+ // The same lens shadow stack the Switch thumb carries: the web thumb is a
133
+ // lens with real depth, not a white dot painted on the track.
134
+ shadowColor: tokens_1.material.shadowColor,
135
+ shadowOpacity: 0.2,
136
+ shadowRadius: 8,
137
+ shadowOffset: { width: 0, height: 3 },
138
+ elevation: 3,
125
139
  };
126
140
  return ((0, jsx_runtime_1.jsxs)(Pressable, { testID: testID, accessibilityRole: "adjustable", accessibilityLabel: accessibilityLabel, accessibilityState: { disabled }, accessibilityValue: { min, max, now: value }, accessibilityActions: [{ name: "increment" }, { name: "decrement" }], onAccessibilityAction: (event) => {
127
141
  if (event?.nativeEvent?.actionName === "increment")
@@ -7,9 +7,13 @@ const Glass_1 = require("./Glass");
7
7
  const tokens_1 = require("./internal/tokens");
8
8
  const primitives_1 = require("./internal/primitives");
9
9
  const motion_1 = require("./internal/motion");
10
- const TRACK_WIDTH = 51;
11
- const TRACK_HEIGHT = 31;
12
- const THUMB = 27;
10
+ const haptics_1 = require("./internal/haptics");
11
+ // The web switch's geometry: a 60 x 25 track with a 21pt thumb, which the web
12
+ // draws at 160 x 67 and scales down by 0.375. The thumb is a lens, not a dot:
13
+ // it carries the same shadow stack as the slider's.
14
+ const TRACK_WIDTH = 60;
15
+ const TRACK_HEIGHT = 25;
16
+ const THUMB = 21;
13
17
  const TRAVEL = TRACK_WIDTH - THUMB - 4;
14
18
  /**
15
19
  * An on/off switch.
@@ -19,11 +23,12 @@ const TRAVEL = TRACK_WIDTH - THUMB - 4;
19
23
  * iOS 26+, Glacia's tint elsewhere) but the control is always ours — React
20
24
  * Native's built-in Switch is never used.
21
25
  */
22
- exports.Switch = (0, react_1.forwardRef)(function Switch({ checked: checkedProp, defaultChecked = false, onCheckedChange, disabled = false, accessibilityLabel, style, isDark: isDarkProp, testID, ...props }, ref) {
26
+ exports.Switch = (0, react_1.forwardRef)(function Switch({ checked: checkedProp, defaultChecked = false, onCheckedChange, disabled = false, haptics = true, accessibilityLabel, style, isDark: isDarkProp, testID, ...props }, ref) {
23
27
  const isDark = (0, motion_1.useIsDark)(isDarkProp);
24
28
  const themeColors = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
25
29
  const { View, Pressable, Animated } = (0, primitives_1.primitives)();
26
30
  const [internalChecked, setInternalChecked] = (0, react_1.useState)(defaultChecked);
31
+ const [held, setHeld] = (0, react_1.useState)(false);
27
32
  const isChecked = checkedProp !== undefined ? checkedProp : internalChecked;
28
33
  // The thumb's travel is a single number animated on the springs token.
29
34
  const { value: offset, animated } = (0, motion_1.useSpring)(isChecked ? TRAVEL : 0, "snappy");
@@ -31,6 +36,8 @@ exports.Switch = (0, react_1.forwardRef)(function Switch({ checked: checkedProp,
31
36
  if (disabled)
32
37
  return;
33
38
  const next = !isChecked;
39
+ if (haptics)
40
+ (0, haptics_1.hapticSelection)();
34
41
  if (checkedProp === undefined)
35
42
  setInternalChecked(next);
36
43
  onCheckedChange?.(next);
@@ -49,12 +56,20 @@ exports.Switch = (0, react_1.forwardRef)(function Switch({ checked: checkedProp,
49
56
  width: THUMB,
50
57
  height: THUMB,
51
58
  borderRadius: THUMB / 2,
52
- backgroundColor: "#FFFFFF",
53
- // A hairline edge instead of a drop shadow: RN shadows need per-platform
54
- // props, and the edge reads correctly on a translucent track.
59
+ backgroundColor: themeColors.onTint,
55
60
  borderWidth: 0.5,
56
- borderColor: "rgba(0, 0, 0, 0.12)",
57
- transform: [{ translateX: animated ? offset : isChecked ? TRAVEL : 0 }],
61
+ borderColor: themeColors.edge,
62
+ // The lens's lift: a soft shadow under the thumb, and a slight growth
63
+ // while it is held, matching the web thumb.
64
+ shadowColor: tokens_1.material.shadowColor,
65
+ shadowOpacity: 0.2,
66
+ shadowRadius: 8,
67
+ shadowOffset: { width: 0, height: 3 },
68
+ elevation: 3,
69
+ transform: [
70
+ { translateX: animated ? offset : isChecked ? TRAVEL : 0 },
71
+ { scale: held ? 1.06 : 1 },
72
+ ],
58
73
  };
59
- return ((0, jsx_runtime_1.jsx)(Pressable, { ref: ref, testID: testID, accessibilityRole: "switch", accessibilityLabel: accessibilityLabel, accessibilityState: { checked: isChecked, disabled }, disabled: disabled, onPress: toggle, style: { alignSelf: "flex-start" }, ...props, children: (0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", isDark: isDark, style: trackStyle, children: animated ? (0, jsx_runtime_1.jsx)(Animated.View, { style: thumbStyle }) : (0, jsx_runtime_1.jsx)(View, { style: thumbStyle }) }) }));
74
+ return ((0, jsx_runtime_1.jsx)(Pressable, { ref: ref, testID: testID, accessibilityRole: "switch", accessibilityLabel: accessibilityLabel, accessibilityState: { checked: isChecked, disabled }, disabled: disabled, onPress: toggle, onPressIn: () => setHeld(true), onPressOut: () => setHeld(false), style: { alignSelf: "flex-start" }, ...props, children: (0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", surface: "control", isDark: isDark, style: trackStyle, children: animated ? (0, jsx_runtime_1.jsx)(Animated.View, { style: thumbStyle }) : (0, jsx_runtime_1.jsx)(View, { style: thumbStyle }) }) }));
60
75
  });