glacia-native 0.3.5 → 0.4.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 (91) hide show
  1. package/lib/module/Button.js +15 -2
  2. package/lib/module/Card.js +29 -14
  3. package/lib/module/Dialog.js +43 -32
  4. package/lib/module/Form.js +51 -12
  5. package/lib/module/Glass.js +11 -2
  6. package/lib/module/Input.js +19 -7
  7. package/lib/module/SegmentedControl.js +65 -21
  8. package/lib/module/Slider.js +121 -25
  9. package/lib/module/Switch.js +33 -15
  10. package/lib/module/TabBar.js +63 -25
  11. package/lib/module/Table.js +24 -6
  12. package/lib/module/Tabs.js +55 -33
  13. package/lib/module/ai.js +49 -20
  14. package/lib/module/charts/BarChart.js +4 -2
  15. package/lib/module/charts/FunnelChart.js +4 -2
  16. package/lib/module/charts/HeatmapChart.js +4 -2
  17. package/lib/module/charts/LineChart.js +4 -2
  18. package/lib/module/charts/PlotChart.js +11 -3
  19. package/lib/module/charts/RadarChart.js +4 -2
  20. package/lib/module/charts/RingChart.js +4 -2
  21. package/lib/module/charts/ScatterChart.js +20 -3
  22. package/lib/module/charts/WaterfallChart.js +12 -3
  23. package/lib/module/charts/advanced.js +12 -6
  24. package/lib/module/charts/extra.js +6 -3
  25. package/lib/module/internal/GlassView.js +17 -19
  26. package/lib/module/internal/fallback.js +14 -3
  27. package/lib/module/internal/glass-routing.js +56 -0
  28. package/lib/module/internal/motion.js +55 -0
  29. package/lib/module/internal/primitives.js +408 -0
  30. package/lib/typescript/Button.d.ts +11 -1
  31. package/lib/typescript/Card.d.ts +20 -8
  32. package/lib/typescript/Dialog.d.ts +19 -6
  33. package/lib/typescript/Form.d.ts +27 -11
  34. package/lib/typescript/Glass.d.ts +9 -0
  35. package/lib/typescript/Input.d.ts +11 -1
  36. package/lib/typescript/SegmentedControl.d.ts +11 -1
  37. package/lib/typescript/Slider.d.ts +13 -1
  38. package/lib/typescript/Switch.d.ts +12 -1
  39. package/lib/typescript/TabBar.d.ts +13 -1
  40. package/lib/typescript/Table.d.ts +14 -5
  41. package/lib/typescript/Tabs.d.ts +8 -5
  42. package/lib/typescript/ai.d.ts +12 -9
  43. package/lib/typescript/charts/BarChart.d.ts +1 -1
  44. package/lib/typescript/charts/FunnelChart.d.ts +1 -1
  45. package/lib/typescript/charts/HeatmapChart.d.ts +1 -1
  46. package/lib/typescript/charts/LineChart.d.ts +1 -1
  47. package/lib/typescript/charts/PlotChart.d.ts +1 -1
  48. package/lib/typescript/charts/RadarChart.d.ts +1 -1
  49. package/lib/typescript/charts/RingChart.d.ts +1 -1
  50. package/lib/typescript/charts/ScatterChart.d.ts +1 -1
  51. package/lib/typescript/charts/WaterfallChart.d.ts +1 -1
  52. package/lib/typescript/charts/advanced.d.ts +5 -5
  53. package/lib/typescript/charts/extra.d.ts +2 -2
  54. package/lib/typescript/internal/GlassView.d.ts +11 -3
  55. package/lib/typescript/internal/fallback.d.ts +10 -1
  56. package/lib/typescript/internal/glass-routing.d.ts +30 -0
  57. package/lib/typescript/internal/motion.d.ts +19 -0
  58. package/lib/typescript/internal/primitives.d.ts +41 -0
  59. package/package.json +2 -2
  60. package/src/Button.tsx +47 -22
  61. package/src/Card.tsx +52 -31
  62. package/src/Dialog.tsx +99 -64
  63. package/src/Form.tsx +90 -25
  64. package/src/Glass.tsx +24 -1
  65. package/src/Input.tsx +33 -12
  66. package/src/SegmentedControl.tsx +104 -32
  67. package/src/Slider.tsx +151 -47
  68. package/src/Switch.tsx +56 -32
  69. package/src/TabBar.tsx +100 -30
  70. package/src/Table.tsx +38 -14
  71. package/src/Tabs.tsx +85 -32
  72. package/src/ai.tsx +77 -31
  73. package/src/charts/BarChart.tsx +4 -2
  74. package/src/charts/FunnelChart.tsx +4 -2
  75. package/src/charts/HeatmapChart.tsx +4 -2
  76. package/src/charts/LineChart.tsx +4 -2
  77. package/src/charts/PlotChart.tsx +23 -3
  78. package/src/charts/RadarChart.tsx +4 -2
  79. package/src/charts/RingChart.tsx +4 -2
  80. package/src/charts/ScatterChart.tsx +24 -3
  81. package/src/charts/WaterfallChart.tsx +21 -3
  82. package/src/charts/advanced.tsx +12 -6
  83. package/src/charts/extra.tsx +6 -3
  84. package/src/internal/GlassView.tsx +31 -21
  85. package/src/internal/fallback.tsx +23 -8
  86. package/src/internal/glass-routing.ts +68 -0
  87. package/src/internal/motion.ts +60 -0
  88. package/src/internal/primitives.ts +477 -0
  89. package/lib/module/charts/primitives.js +0 -212
  90. package/lib/typescript/charts/primitives.d.ts +0 -23
  91. package/src/charts/primitives.ts +0 -262
@@ -3,47 +3,143 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Slider = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
+ const primitives_1 = require("./internal/primitives");
6
7
  const Glass_1 = require("./Glass");
7
8
  const tokens_1 = require("./internal/tokens");
8
- exports.Slider = (0, react_1.forwardRef)(function Slider({ value: valueProp, defaultValue = 50, min = 0, max = 100, step = 1, onValueChange, disabled = false, accessibilityLabel, style, isDark = false, ...props }, ref) {
9
- const [internalValue, setInternalValue] = (0, react_1.useState)(defaultValue);
10
- const value = valueProp !== undefined ? valueProp : internalValue;
9
+ const primitives_2 = require("./internal/primitives");
10
+ const motion_1 = require("./internal/motion");
11
+ const TRACK_HEIGHT = 8;
12
+ const THUMB = 22;
13
+ const CONTAINER_HEIGHT = 40;
14
+ /** Rounds `value` onto the nearest step from `min`, clamped to the range. */
15
+ function quantize(value, min, max, step) {
16
+ if (!Number.isFinite(value))
17
+ return min;
18
+ const clamped = Math.min(max, Math.max(min, value));
19
+ if (!(step > 0))
20
+ return clamped;
21
+ const stepped = min + Math.round((clamped - min) / step) * step;
22
+ // Round away binary float noise introduced by the division above.
23
+ const decimals = (String(step).split(".")[1] ?? "").length;
24
+ return Number(Math.min(max, Math.max(min, stepped)).toFixed(decimals));
25
+ }
26
+ /**
27
+ * A continuous value chosen by dragging.
28
+ *
29
+ * The interaction is Glacia's own: the track and thumb are Views and dragging
30
+ * is a PanResponder reading the touch position against the track's measured
31
+ * width. React Native has no DOM `<input type="range">` and the platform
32
+ * sliders are not used, so the control looks and behaves the same on every
33
+ * platform; only the glass material changes.
34
+ */
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) {
36
+ const isDark = (0, motion_1.useIsDark)(isDarkProp);
11
37
  const themeColors = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
12
- const percentage = Math.min(100, Math.max(0, ((value - min) / (max - min)) * 100));
13
- const handleChange = (e) => {
14
- const val = Number(e.target.value);
15
- if (valueProp === undefined) {
16
- setInternalValue(val);
17
- }
18
- onValueChange?.(val);
38
+ const { View, Pressable, PanResponder } = (0, primitives_2.primitives)();
39
+ const [internalValue, setInternalValue] = (0, react_1.useState)(() => quantize(defaultValue, min, max, step));
40
+ const value = valueProp !== undefined ? quantize(valueProp, min, max, step) : internalValue;
41
+ // Two actions can arrive before React re-renders (increment then decrement,
42
+ // or two drag moves in one frame). The ref holds the newest value so the
43
+ // second one starts from it instead of a stale closure.
44
+ const valueRef = (0, react_1.useRef)(value);
45
+ valueRef.current = value;
46
+ // Track width as measured on layout. A drag before layout is a no-op rather
47
+ // than a jump: without a width there is no honest mapping from x to value.
48
+ const widthRef = (0, react_1.useRef)(0);
49
+ /** Converts an x position relative to the track into a stepped value. */
50
+ const valueAtX = (0, react_1.useMemo)(() => (x) => {
51
+ const width = widthRef.current;
52
+ if (width <= 0 || max === min)
53
+ return null;
54
+ const ratio = Math.min(1, Math.max(0, x / width));
55
+ return quantize(min + ratio * (max - min), min, max, step);
56
+ }, [max, min, step]);
57
+ const report = (next) => {
58
+ if (next === valueRef.current)
59
+ return;
60
+ valueRef.current = next;
61
+ if (valueProp === undefined)
62
+ setInternalValue(next);
63
+ onValueChange?.(next);
19
64
  };
65
+ const panResponder = (0, react_1.useMemo)(() => {
66
+ if (!PanResponder?.create)
67
+ return null;
68
+ return PanResponder.create({
69
+ // Claim the gesture only for horizontal movement, so a Slider inside a
70
+ // vertical scroll view does not swallow the scroll.
71
+ onStartShouldSetPanResponder: () => !disabled,
72
+ onMoveShouldSetPanResponder: (_event, gesture) => !disabled && Math.abs(gesture.dx) > Math.abs(gesture.dy),
73
+ onPanResponderGrant: (event) => {
74
+ const next = valueAtX(event.nativeEvent.locationX);
75
+ if (next !== null)
76
+ report(next);
77
+ },
78
+ onPanResponderMove: (event) => {
79
+ const next = valueAtX(event.nativeEvent.locationX);
80
+ if (next !== null)
81
+ report(next);
82
+ },
83
+ onPanResponderTerminationRequest: () => false,
84
+ });
85
+ // `report` reads the value from a ref, so the responder does not need to be
86
+ // rebuilt on every value change and never acts on a stale render.
87
+ }, [disabled, valueAtX]);
88
+ /** Steps the value for accessibility actions and hardware keys. */
89
+ const nudge = (direction) => {
90
+ if (disabled)
91
+ return;
92
+ const from = valueRef.current;
93
+ report(quantize(from + direction * Math.max(step, (max - min) / 20), min, max, step));
94
+ };
95
+ const percentage = max === min ? 0 : ((value - min) / (max - min)) * 100;
20
96
  const containerStyle = {
21
- position: "relative",
22
- height: 40,
97
+ height: CONTAINER_HEIGHT,
23
98
  justifyContent: "center",
24
99
  opacity: disabled ? 0.38 : 1,
25
100
  ...style,
26
101
  };
27
102
  const trackStyle = {
28
- height: 8,
29
- borderRadius: 4,
103
+ height: TRACK_HEIGHT,
104
+ borderRadius: TRACK_HEIGHT / 2,
30
105
  backgroundColor: "rgba(120, 120, 128, 0.2)",
31
106
  overflow: "hidden",
32
107
  width: "100%",
33
108
  };
34
109
  const fillStyle = {
35
110
  height: "100%",
36
- width: `${percentage}%`,
111
+ width: `${Math.min(100, Math.max(0, percentage))}%`,
37
112
  backgroundColor: themeColors.fill,
38
113
  };
39
- return ((0, jsx_runtime_1.jsxs)("div", { ref: ref, style: containerStyle, ...props, children: [(0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", style: trackStyle, children: (0, jsx_runtime_1.jsx)("div", { style: fillStyle }) }), (0, jsx_runtime_1.jsx)("input", { type: "range", min: min, max: max, step: step, value: value, disabled: disabled, "aria-label": accessibilityLabel, onChange: handleChange, style: {
40
- position: "absolute",
41
- top: 0,
42
- left: 0,
43
- width: "100%",
44
- height: "100%",
45
- opacity: 0,
46
- cursor: disabled ? "default" : "pointer",
47
- margin: 0,
48
- } })] }));
114
+ const thumbStyle = {
115
+ position: "absolute",
116
+ top: (CONTAINER_HEIGHT - THUMB) / 2,
117
+ 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",
123
+ borderWidth: 0.5,
124
+ borderColor: "rgba(0, 0, 0, 0.12)",
125
+ };
126
+ 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
+ if (event?.nativeEvent?.actionName === "increment")
128
+ nudge(1);
129
+ if (event?.nativeEvent?.actionName === "decrement")
130
+ nudge(-1);
131
+ }, disabled: disabled, onLayout: (event) => {
132
+ const width = event?.nativeEvent?.layout?.width;
133
+ if (typeof width === "number" && width > 0)
134
+ widthRef.current = width;
135
+ },
136
+ // The DOM preview has no layout events, so measure on mount there too;
137
+ // on a device this resolves to nothing and onLayout is the source.
138
+ ref: (node) => {
139
+ (0, primitives_1.measurePreviewWidth)(node, widthRef);
140
+ if (typeof ref === "function")
141
+ ref(node);
142
+ else if (ref)
143
+ ref.current = node;
144
+ }, style: containerStyle, ...(panResponder ? panResponder.panHandlers : {}), ...props, children: [(0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", isDark: isDark, style: trackStyle, children: (0, jsx_runtime_1.jsx)(View, { style: fillStyle }) }), (0, jsx_runtime_1.jsx)(View, { style: thumbStyle, pointerEvents: "none" })] }));
49
145
  });
@@ -5,38 +5,56 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
6
  const Glass_1 = require("./Glass");
7
7
  const tokens_1 = require("./internal/tokens");
8
- exports.Switch = (0, react_1.forwardRef)(function Switch({ checked: checkedProp, defaultChecked = false, onCheckedChange, disabled = false, accessibilityLabel, style, isDark = false, ...props }, ref) {
8
+ const primitives_1 = require("./internal/primitives");
9
+ const motion_1 = require("./internal/motion");
10
+ const TRACK_WIDTH = 51;
11
+ const TRACK_HEIGHT = 31;
12
+ const THUMB = 27;
13
+ const TRAVEL = TRACK_WIDTH - THUMB - 4;
14
+ /**
15
+ * An on/off switch.
16
+ *
17
+ * The track is Glacia's glass; the thumb is one of our own Views, animated on
18
+ * the springs token. The material changes by platform (Apple's glass on
19
+ * iOS 26+, Glacia's tint elsewhere) but the control is always ours — React
20
+ * Native's built-in Switch is never used.
21
+ */
22
+ exports.Switch = (0, react_1.forwardRef)(function Switch({ checked: checkedProp, defaultChecked = false, onCheckedChange, disabled = false, accessibilityLabel, style, isDark: isDarkProp, testID, ...props }, ref) {
23
+ const isDark = (0, motion_1.useIsDark)(isDarkProp);
24
+ const themeColors = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
25
+ const { View, Pressable, Animated } = (0, primitives_1.primitives)();
9
26
  const [internalChecked, setInternalChecked] = (0, react_1.useState)(defaultChecked);
10
27
  const isChecked = checkedProp !== undefined ? checkedProp : internalChecked;
11
- const themeColors = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
28
+ // The thumb's travel is a single number animated on the springs token.
29
+ const { value: offset, animated } = (0, motion_1.useSpring)(isChecked ? TRAVEL : 0, "snappy");
12
30
  const toggle = () => {
13
31
  if (disabled)
14
32
  return;
15
33
  const next = !isChecked;
16
- if (checkedProp === undefined) {
34
+ if (checkedProp === undefined)
17
35
  setInternalChecked(next);
18
- }
19
36
  onCheckedChange?.(next);
20
37
  };
21
38
  const trackStyle = {
22
- width: 51,
23
- height: 31,
24
- borderRadius: 15.5,
39
+ width: TRACK_WIDTH,
40
+ height: TRACK_HEIGHT,
41
+ borderRadius: TRACK_HEIGHT / 2,
25
42
  backgroundColor: isChecked ? themeColors.fill : "rgba(120, 120, 128, 0.16)",
26
43
  padding: 2,
27
44
  justifyContent: "center",
28
45
  opacity: disabled ? 0.38 : 1,
29
- transition: "background-color 200ms ease",
30
46
  ...style,
31
47
  };
32
48
  const thumbStyle = {
33
- width: 27,
34
- height: 27,
35
- borderRadius: 13.5,
49
+ width: THUMB,
50
+ height: THUMB,
51
+ borderRadius: THUMB / 2,
36
52
  backgroundColor: "#FFFFFF",
37
- boxShadow: "0 2px 4px rgba(0, 0, 0, 0.2)",
38
- transform: isChecked ? "translateX(20px)" : "translateX(0px)",
39
- transition: "transform 200ms cubic-bezier(0.25, 0.1, 0.25, 1)",
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.
55
+ borderWidth: 0.5,
56
+ borderColor: "rgba(0, 0, 0, 0.12)",
57
+ transform: [{ translateX: animated ? offset : isChecked ? TRAVEL : 0 }],
40
58
  };
41
- return ((0, jsx_runtime_1.jsx)("div", { ref: ref, role: "switch", "aria-checked": isChecked, "aria-label": accessibilityLabel, "aria-disabled": disabled, tabIndex: disabled ? -1 : 0, onClick: toggle, style: { display: "inline-block", cursor: disabled ? "default" : "pointer" }, ...props, children: (0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", style: trackStyle, children: (0, jsx_runtime_1.jsx)("div", { style: thumbStyle }) }) }));
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 }) }) }));
42
60
  });
@@ -5,43 +5,81 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
6
  const Glass_1 = require("./Glass");
7
7
  const tokens_1 = require("./internal/tokens");
8
- exports.TabBar = (0, react_1.forwardRef)(function TabBar({ items, activeId: activeProp, defaultActiveId, onTabChange, style, isDark = false, ...props }, ref) {
8
+ const primitives_1 = require("./internal/primitives");
9
+ const motion_1 = require("./internal/motion");
10
+ const BAR_HEIGHT = 52;
11
+ /**
12
+ * The bottom bar of an app: a row of tabs on one glass surface.
13
+ *
14
+ * The platform rule is the point of this component. On iOS 26+ the surface is
15
+ * Apple's real Liquid Glass (`UIGlassEffect` via `@callstack/liquid-glass`)
16
+ * with Glacia's own items inside it; on older iOS and on Android it is
17
+ * Glacia's bar. The items are always our Pressables and Texts — no native tab
18
+ * bar is used on any platform.
19
+ */
20
+ exports.TabBar = (0, react_1.forwardRef)(function TabBar({ items, activeId: activeProp, defaultActiveId, onTabChange, style, isDark: isDarkProp, testID, ...props }, ref) {
21
+ const isDark = (0, motion_1.useIsDark)(isDarkProp);
22
+ const themeColors = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
23
+ const { View, Text, Pressable, Animated } = (0, primitives_1.primitives)();
9
24
  const [internalId, setInternalId] = (0, react_1.useState)(defaultActiveId || items[0]?.id || "");
10
25
  const activeId = activeProp !== undefined ? activeProp : internalId;
11
- const themeColors = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
26
+ const activeIndex = Math.max(0, items.findIndex((item) => item.id === activeId));
27
+ // The active wash slides between equally wide items on the springs token.
28
+ const { value: slide, animated } = (0, motion_1.useSpring)(activeIndex, "snappy");
12
29
  const handleSelect = (id) => {
13
- if (activeProp === undefined) {
30
+ if (activeProp === undefined)
14
31
  setInternalId(id);
15
- }
16
32
  onTabChange?.(id);
17
33
  };
18
34
  const barStyle = {
19
- position: "relative",
20
- display: "flex",
21
35
  flexDirection: "row",
22
36
  alignItems: "center",
23
37
  justifyContent: "space-around",
24
- height: 52,
38
+ height: BAR_HEIGHT,
25
39
  paddingHorizontal: 8,
26
40
  borderRadius: tokens_1.radii.xl,
27
41
  ...style,
28
42
  };
29
- return ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { ref: ref, effect: "regular", style: barStyle, ...props, children: items.map((tab) => {
30
- const isActive = tab.id === activeId;
31
- return ((0, jsx_runtime_1.jsxs)("button", { type: "button", onClick: () => handleSelect(tab.id), style: {
32
- flex: 1,
33
- display: "flex",
34
- flexDirection: "column",
35
- alignItems: "center",
36
- justifyContent: "center",
37
- gap: 2,
38
- padding: "4px 8px",
39
- border: 0,
40
- background: "transparent",
41
- color: isActive ? themeColors.fill : themeColors.muted,
42
- fontSize: 11,
43
- fontWeight: isActive ? 600 : 500,
44
- cursor: "pointer",
45
- }, children: [tab.icon && (0, jsx_runtime_1.jsx)("span", { style: { fontSize: 18 }, children: tab.icon }), (0, jsx_runtime_1.jsx)("span", { children: tab.label })] }, tab.id));
46
- }) }));
43
+ const count = Math.max(items.length, 1);
44
+ const itemWidth = `${100 / count}%`;
45
+ const indicatorStyle = {
46
+ position: "absolute",
47
+ top: 6,
48
+ bottom: 6,
49
+ left: 8,
50
+ width: itemWidth,
51
+ borderRadius: tokens_1.radii.lg,
52
+ backgroundColor: themeColors.glassActive,
53
+ opacity: 0.75,
54
+ };
55
+ return ((0, jsx_runtime_1.jsxs)(Glass_1.Glass, { ref: ref, effect: "regular", isDark: isDark, style: barStyle, testID: testID, ...props, children: [animated ? ((0, jsx_runtime_1.jsx)(Animated.View, { pointerEvents: "none", style: {
56
+ ...indicatorStyle,
57
+ transform: [
58
+ {
59
+ translateX: slide.interpolate({
60
+ inputRange: [0, Math.max(count - 1, 1)],
61
+ outputRange: [
62
+ "0%",
63
+ `${((count - 1) * 100) / count}%`,
64
+ ],
65
+ }),
66
+ },
67
+ ],
68
+ } })) : ((0, jsx_runtime_1.jsx)(View, { pointerEvents: "none", style: { ...indicatorStyle, left: `${(activeIndex * 100) / count}%` } })), items.map((tab) => {
69
+ const isActive = tab.id === activeId;
70
+ return ((0, jsx_runtime_1.jsxs)(Pressable, { accessibilityRole: "tab", accessibilityLabel: tab.label, accessibilityState: { selected: isActive }, onPress: () => handleSelect(tab.id), style: {
71
+ flex: 1,
72
+ height: "100%",
73
+ flexDirection: "column",
74
+ alignItems: "center",
75
+ justifyContent: "center",
76
+ gap: 2,
77
+ paddingHorizontal: 8,
78
+ paddingVertical: 4,
79
+ }, children: [tab.icon ?? null, (0, jsx_runtime_1.jsx)(Text, { numberOfLines: 1, style: {
80
+ fontSize: 11,
81
+ fontWeight: isActive ? "600" : "500",
82
+ color: isActive ? themeColors.fill : themeColors.muted,
83
+ }, children: tab.label })] }, tab.id));
84
+ })] }));
47
85
  });
@@ -4,7 +4,8 @@ exports.NativeTable = NativeTable;
4
4
  exports.NativeScrollArea = NativeScrollArea;
5
5
  const jsx_runtime_1 = require("react/jsx-runtime");
6
6
  const tokens_1 = require("./internal/tokens");
7
- const primitives_1 = require("./charts/primitives");
7
+ const primitives_1 = require("./internal/primitives");
8
+ const motion_1 = require("./internal/motion");
8
9
  /**
9
10
  * Tabular data laid out for a phone.
10
11
  *
@@ -13,7 +14,8 @@ const primitives_1 = require("./charts/primitives");
13
14
  * are laid out as labelled pairs beneath it, which keeps every value readable
14
15
  * without horizontal scrolling.
15
16
  */
16
- function NativeTable({ columns, rows, onRowPress, caption, isDark = false, style, emptyMessage = "No rows to display", }) {
17
+ function NativeTable({ columns, rows, onRowPress, caption, isDark: isDarkProp, style, emptyMessage = "No rows to display", testID, }) {
18
+ const isDark = (0, motion_1.useIsDark)(isDarkProp);
17
19
  const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
18
20
  const { View, Text, Pressable } = (0, primitives_1.primitives)();
19
21
  if (rows.length === 0) {
@@ -23,12 +25,12 @@ function NativeTable({ columns, rows, onRowPress, caption, isDark = false, style
23
25
  const primaryKey = columns.find((column) => column.primary)?.key ?? columns[0]?.key;
24
26
  const primaryColumn = columns.find((column) => column.key === primaryKey);
25
27
  const detailColumns = columns.filter((column) => column.key !== primaryKey);
26
- return ((0, jsx_runtime_1.jsxs)(View, { style: style, children: [caption && ((0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 11, color: theme.muted, marginBottom: 8 }, children: caption })), rows.map((row) => {
28
+ return ((0, jsx_runtime_1.jsxs)(View, { style: style, testID: testID, children: [caption && ((0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 11, color: theme.muted, marginBottom: 8 }, children: caption })), rows.map((row) => {
27
29
  const RowWrapper = onRowPress ? Pressable : View;
28
30
  const wrapperProps = onRowPress
29
31
  ? {
30
32
  accessibilityRole: "button",
31
- accessibilityLabel: String(row.cells[primaryKey ?? ""] ?? ""),
33
+ accessibilityLabel: rowAccessibilityLabel(row, primaryKey),
32
34
  onPress: () => onRowPress(row),
33
35
  }
34
36
  : { accessibilityRole: "text" };
@@ -53,6 +55,21 @@ function NativeTable({ columns, rows, onRowPress, caption, isDark = false, style
53
55
  }, children: row.cells[column.key] ?? "" })] }, column.key))) }))] }, row.id));
54
56
  })] }));
55
57
  }
58
+ /**
59
+ * What screen readers announce for a pressable row.
60
+ *
61
+ * A cell can be any element, and `String(cell)` of an element announces
62
+ * "[object Object]". So: an explicit row label wins, then a textual primary
63
+ * cell, then a neutral fallback.
64
+ */
65
+ function rowAccessibilityLabel(row, primaryKey) {
66
+ if (row.accessibilityLabel)
67
+ return row.accessibilityLabel;
68
+ const primary = primaryKey ? row.cells[primaryKey] : undefined;
69
+ if (typeof primary === "string" || typeof primary === "number")
70
+ return String(primary);
71
+ return "Row";
72
+ }
56
73
  /**
57
74
  * A bounded scroll region.
58
75
  *
@@ -60,7 +77,8 @@ function NativeTable({ columns, rows, onRowPress, caption, isDark = false, style
60
77
  * scroll indicator is the one users already recognise, and it stays correct
61
78
  * under momentum, bouncing and accessibility settings.
62
79
  */
63
- function NativeScrollArea({ children, maxHeight, bordered = false, horizontal = false, isDark = false, style, accessibilityLabel, }) {
80
+ function NativeScrollArea({ children, maxHeight, bordered = false, horizontal = false, isDark: isDarkProp, style, accessibilityLabel, }) {
81
+ const isDark = (0, motion_1.useIsDark)(isDarkProp);
64
82
  const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
65
83
  const { View, getScrollView } = (0, primitives_1.primitives)();
66
84
  const ScrollView = getScrollView();
@@ -75,7 +93,7 @@ function NativeScrollArea({ children, maxHeight, bordered = false, horizontal =
75
93
  if (!ScrollView) {
76
94
  // Off-device there is no ScrollView; render the content in a clipped box so
77
95
  // layout still matches instead of dropping children.
78
- return ((0, jsx_runtime_1.jsx)(View, { accessibilityLabel: accessibilityLabel, style: { ...containerStyle, overflow: "auto" }, children: children }));
96
+ return ((0, jsx_runtime_1.jsx)(View, { accessibilityLabel: accessibilityLabel, style: containerStyle, children: children }));
79
97
  }
80
98
  return ((0, jsx_runtime_1.jsx)(View, { style: containerStyle, children: (0, jsx_runtime_1.jsx)(ScrollView, { horizontal: horizontal, showsVerticalScrollIndicator: true, showsHorizontalScrollIndicator: horizontal, accessibilityLabel: accessibilityLabel, children: children }) }));
81
99
  }
@@ -5,55 +5,77 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
6
  const Glass_1 = require("./Glass");
7
7
  const tokens_1 = require("./internal/tokens");
8
+ const primitives_1 = require("./internal/primitives");
9
+ const motion_1 = require("./internal/motion");
8
10
  /**
9
11
  * A row of tabs on a glass rail, in the reference implementation's style: the
10
12
  * selected tab is a lifted inner pane rather than a flat highlight.
11
13
  *
12
- * Follows the same conventions as the other native components — no browser
13
- * APIs and no CSS — so it renders on iOS and Android. On iOS 26 the rail is
14
- * real glass through `@callstack/liquid-glass`; elsewhere it is a translucent
15
- * tint of the same shape with no layout shift.
14
+ * Same conventions as every other component here — React Native primitives
15
+ * only, no browser APIs. The rail is Apple's real glass on iOS 26+ and
16
+ * Glacia's translucent fallback of the same shape on older iOS and Android, so
17
+ * the layout never shifts between platforms.
16
18
  */
17
- exports.Tabs = (0, react_1.forwardRef)(function Tabs({ items, activeId: activeProp, defaultActiveId, onTabChange, style, isDark = false, ...props }, ref) {
19
+ exports.Tabs = (0, react_1.forwardRef)(function Tabs({ items, activeId: activeProp, defaultActiveId, onTabChange, style, isDark: isDarkProp, testID, ...props }, ref) {
20
+ const isDark = (0, motion_1.useIsDark)(isDarkProp);
21
+ const themeColors = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
22
+ const { View, Text, Pressable, Animated } = (0, primitives_1.primitives)();
18
23
  const [internalId, setInternalId] = (0, react_1.useState)(defaultActiveId || items[0]?.id || "");
19
24
  const activeId = activeProp !== undefined ? activeProp : internalId;
20
- const themeColors = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
25
+ const activeIndex = Math.max(0, items.findIndex((tab) => tab.id === activeId));
26
+ const { value: slide, animated } = (0, motion_1.useSpring)(activeIndex, "snappy");
21
27
  const handleSelect = (id) => {
22
28
  if (activeProp === undefined)
23
29
  setInternalId(id);
24
30
  onTabChange?.(id);
25
31
  };
26
- return ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { ref: ref, effect: "regular", style: {
27
- display: "flex",
32
+ const count = Math.max(items.length, 1);
33
+ const itemWidth = `${100 / count}%`;
34
+ // The selection is a lens, not a fill: a lifted pane on the rail.
35
+ const paneStyle = {
36
+ position: "absolute",
37
+ top: 4,
38
+ bottom: 4,
39
+ left: 4,
40
+ width: itemWidth,
41
+ borderRadius: tokens_1.radii.pill,
42
+ backgroundColor: isDark ? "rgba(255,255,255,0.16)" : "rgba(255,255,255,0.72)",
43
+ borderWidth: 0.5,
44
+ borderColor: themeColors.edge,
45
+ };
46
+ return ((0, jsx_runtime_1.jsxs)(Glass_1.Glass, { ref: ref, effect: "regular", isDark: isDark, style: {
28
47
  flexDirection: "row",
29
48
  alignItems: "center",
49
+ alignSelf: "flex-start",
30
50
  gap: 2,
31
51
  padding: 4,
32
52
  borderRadius: tokens_1.radii.pill,
33
53
  ...style,
34
- }, ...props, children: items.map((tab) => {
35
- const isActive = tab.id === activeId;
36
- return ((0, jsx_runtime_1.jsxs)("button", { type: "button", onClick: () => handleSelect(tab.id), "aria-selected": isActive, role: "tab", style: {
37
- flex: 1,
38
- display: "flex",
39
- flexDirection: "row",
40
- alignItems: "center",
41
- justifyContent: "center",
42
- gap: 6,
43
- padding: "8px 12px",
44
- border: 0,
45
- borderRadius: tokens_1.radii.pill,
46
- // The selection is a lens, not a fill: a lifted pane on the rail.
47
- background: isActive
48
- ? isDark
49
- ? "rgba(255,255,255,0.16)"
50
- : "rgba(255,255,255,0.72)"
51
- : "transparent",
52
- color: isActive ? themeColors.foreground : themeColors.muted,
53
- fontSize: 13,
54
- fontWeight: isActive ? 600 : 500,
55
- cursor: "pointer",
56
- whiteSpace: "nowrap",
57
- }, children: [tab.icon && (0, jsx_runtime_1.jsx)("span", { style: { fontSize: 14 }, children: tab.icon }), (0, jsx_runtime_1.jsx)("span", { children: tab.label })] }, tab.id));
58
- }) }));
54
+ }, testID: testID, ...props, children: [animated ? ((0, jsx_runtime_1.jsx)(Animated.View, { pointerEvents: "none", style: {
55
+ ...paneStyle,
56
+ transform: [
57
+ {
58
+ translateX: slide.interpolate({
59
+ inputRange: [0, Math.max(count - 1, 1)],
60
+ outputRange: ["0%", `${((count - 1) * 100) / count}%`],
61
+ }),
62
+ },
63
+ ],
64
+ } })) : ((0, jsx_runtime_1.jsx)(View, { pointerEvents: "none", style: { ...paneStyle, left: `${(activeIndex * 100) / count}%` } })), items.map((tab) => {
65
+ const isActive = tab.id === activeId;
66
+ return ((0, jsx_runtime_1.jsxs)(Pressable, { accessibilityRole: "tab", accessibilityLabel: tab.label, accessibilityState: { selected: isActive }, onPress: () => handleSelect(tab.id), style: {
67
+ flex: 1,
68
+ height: 36,
69
+ flexDirection: "row",
70
+ alignItems: "center",
71
+ justifyContent: "center",
72
+ gap: 6,
73
+ paddingHorizontal: 12,
74
+ borderRadius: tokens_1.radii.pill,
75
+ }, children: [tab.icon ?? null, (0, jsx_runtime_1.jsx)(Text, { numberOfLines: 1, style: {
76
+ fontSize: 13,
77
+ fontWeight: isActive ? "600" : "500",
78
+ color: isActive ? themeColors.foreground : themeColors.muted,
79
+ }, children: tab.label })] }, tab.id));
80
+ })] }));
59
81
  });