glacia-native 0.3.4 → 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
package/src/Slider.tsx CHANGED
@@ -1,6 +1,11 @@
1
- import { useState, forwardRef } from "react";
1
+ import { forwardRef, useMemo, useRef, useState } from "react";
2
+ import { measurePreviewWidth } from "./internal/primitives";
3
+ import type { StyleProp, ViewStyle } from "react-native";
4
+
2
5
  import { Glass } from "./Glass";
3
6
  import { colors } from "./internal/tokens";
7
+ import { primitives } from "./internal/primitives";
8
+ import { useIsDark } from "./internal/motion";
4
9
 
5
10
  export interface SliderProps {
6
11
  value?: number;
@@ -11,10 +16,36 @@ export interface SliderProps {
11
16
  onValueChange?: (value: number) => void;
12
17
  disabled?: boolean;
13
18
  accessibilityLabel: string;
14
- style?: any;
19
+ style?: StyleProp<ViewStyle>;
15
20
  isDark?: boolean;
21
+ /** Passed through to the draggable track so it is testable. */
22
+ testID?: string;
23
+ }
24
+
25
+ const TRACK_HEIGHT = 8;
26
+ const THUMB = 22;
27
+ const CONTAINER_HEIGHT = 40;
28
+
29
+ /** Rounds `value` onto the nearest step from `min`, clamped to the range. */
30
+ function quantize(value: number, min: number, max: number, step: number): number {
31
+ if (!Number.isFinite(value)) return min;
32
+ const clamped = Math.min(max, Math.max(min, value));
33
+ if (!(step > 0)) return clamped;
34
+ const stepped = min + Math.round((clamped - min) / step) * step;
35
+ // Round away binary float noise introduced by the division above.
36
+ const decimals = (String(step).split(".")[1] ?? "").length;
37
+ return Number(Math.min(max, Math.max(min, stepped)).toFixed(decimals));
16
38
  }
17
39
 
40
+ /**
41
+ * A continuous value chosen by dragging.
42
+ *
43
+ * The interaction is Glacia's own: the track and thumb are Views and dragging
44
+ * is a PanResponder reading the touch position against the track's measured
45
+ * width. React Native has no DOM `<input type="range">` and the platform
46
+ * sliders are not used, so the control looks and behaves the same on every
47
+ * platform; only the glass material changes.
48
+ */
18
49
  export const Slider = forwardRef<any, SliderProps>(function Slider(
19
50
  {
20
51
  value: valueProp,
@@ -26,72 +57,145 @@ export const Slider = forwardRef<any, SliderProps>(function Slider(
26
57
  disabled = false,
27
58
  accessibilityLabel,
28
59
  style,
29
- isDark = false,
60
+ isDark: isDarkProp,
61
+ testID,
30
62
  ...props
31
63
  },
32
64
  ref,
33
65
  ) {
34
- const [internalValue, setInternalValue] = useState(defaultValue);
35
- const value = valueProp !== undefined ? valueProp : internalValue;
66
+ const isDark = useIsDark(isDarkProp);
36
67
  const themeColors = isDark ? colors.dark : colors.light;
68
+ const { View, Pressable, PanResponder } = primitives();
69
+
70
+ const [internalValue, setInternalValue] = useState(() => quantize(defaultValue, min, max, step));
71
+ const value = valueProp !== undefined ? quantize(valueProp, min, max, step) : internalValue;
72
+
73
+ // Two actions can arrive before React re-renders (increment then decrement,
74
+ // or two drag moves in one frame). The ref holds the newest value so the
75
+ // second one starts from it instead of a stale closure.
76
+ const valueRef = useRef(value);
77
+ valueRef.current = value;
78
+
79
+ // Track width as measured on layout. A drag before layout is a no-op rather
80
+ // than a jump: without a width there is no honest mapping from x to value.
81
+ const widthRef = useRef(0);
37
82
 
38
- const percentage = Math.min(100, Math.max(0, ((value - min) / (max - min)) * 100));
83
+ /** Converts an x position relative to the track into a stepped value. */
84
+ const valueAtX = useMemo(
85
+ () =>
86
+ (x: number): number | null => {
87
+ const width = widthRef.current;
88
+ if (width <= 0 || max === min) return null;
89
+ const ratio = Math.min(1, Math.max(0, x / width));
90
+ return quantize(min + ratio * (max - min), min, max, step);
91
+ },
92
+ [max, min, step],
93
+ );
94
+
95
+ const report = (next: number) => {
96
+ if (next === valueRef.current) return;
97
+ valueRef.current = next;
98
+ if (valueProp === undefined) setInternalValue(next);
99
+ onValueChange?.(next);
100
+ };
101
+
102
+ const panResponder = useMemo(() => {
103
+ if (!PanResponder?.create) return null;
104
+ return PanResponder.create({
105
+ // Claim the gesture only for horizontal movement, so a Slider inside a
106
+ // vertical scroll view does not swallow the scroll.
107
+ onStartShouldSetPanResponder: () => !disabled,
108
+ onMoveShouldSetPanResponder: (_event: any, gesture: any) =>
109
+ !disabled && Math.abs(gesture.dx) > Math.abs(gesture.dy),
110
+ onPanResponderGrant: (event: any) => {
111
+ const next = valueAtX(event.nativeEvent.locationX);
112
+ if (next !== null) report(next);
113
+ },
114
+ onPanResponderMove: (event: any) => {
115
+ const next = valueAtX(event.nativeEvent.locationX);
116
+ if (next !== null) report(next);
117
+ },
118
+ onPanResponderTerminationRequest: () => false,
119
+ });
120
+ // `report` reads the value from a ref, so the responder does not need to be
121
+ // rebuilt on every value change and never acts on a stale render.
122
+ }, [disabled, valueAtX]);
39
123
 
40
- const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
41
- const val = Number(e.target.value);
42
- if (valueProp === undefined) {
43
- setInternalValue(val);
44
- }
45
- onValueChange?.(val);
124
+ /** Steps the value for accessibility actions and hardware keys. */
125
+ const nudge = (direction: 1 | -1) => {
126
+ if (disabled) return;
127
+ const from = valueRef.current;
128
+ report(quantize(from + direction * Math.max(step, (max - min) / 20), min, max, step));
46
129
  };
47
130
 
48
- const containerStyle = {
49
- position: "relative" as const,
50
- height: 40,
51
- justifyContent: "center" as const,
131
+ const percentage = max === min ? 0 : ((value - min) / (max - min)) * 100;
132
+
133
+ const containerStyle: ViewStyle = {
134
+ height: CONTAINER_HEIGHT,
135
+ justifyContent: "center",
52
136
  opacity: disabled ? 0.38 : 1,
53
- ...style,
137
+ ...(style as ViewStyle),
54
138
  };
55
139
 
56
- const trackStyle = {
57
- height: 8,
58
- borderRadius: 4,
140
+ const trackStyle: ViewStyle = {
141
+ height: TRACK_HEIGHT,
142
+ borderRadius: TRACK_HEIGHT / 2,
59
143
  backgroundColor: "rgba(120, 120, 128, 0.2)",
60
- overflow: "hidden" as const,
144
+ overflow: "hidden",
61
145
  width: "100%",
62
146
  };
63
147
 
64
- const fillStyle = {
148
+ const fillStyle: ViewStyle = {
65
149
  height: "100%",
66
- width: `${percentage}%`,
150
+ width: `${Math.min(100, Math.max(0, percentage))}%`,
67
151
  backgroundColor: themeColors.fill,
68
152
  };
69
153
 
154
+ const thumbStyle: ViewStyle = {
155
+ position: "absolute",
156
+ top: (CONTAINER_HEIGHT - THUMB) / 2,
157
+ left: `${Math.min(100, Math.max(0, percentage))}%`,
158
+ width: THUMB,
159
+ height: THUMB,
160
+ marginLeft: -THUMB / 2,
161
+ borderRadius: THUMB / 2,
162
+ backgroundColor: "#FFFFFF",
163
+ borderWidth: 0.5,
164
+ borderColor: "rgba(0, 0, 0, 0.12)",
165
+ };
166
+
70
167
  return (
71
- <div ref={ref} style={containerStyle} {...props}>
72
- <Glass effect="regular" style={trackStyle}>
73
- <div style={fillStyle} />
168
+ <Pressable
169
+ testID={testID}
170
+ accessibilityRole="adjustable"
171
+ accessibilityLabel={accessibilityLabel}
172
+ accessibilityState={{ disabled }}
173
+ accessibilityValue={{ min, max, now: value }}
174
+ accessibilityActions={[{ name: "increment" }, { name: "decrement" }]}
175
+ onAccessibilityAction={(event: any) => {
176
+ if (event?.nativeEvent?.actionName === "increment") nudge(1);
177
+ if (event?.nativeEvent?.actionName === "decrement") nudge(-1);
178
+ }}
179
+ disabled={disabled}
180
+ onLayout={(event: any) => {
181
+ const width = event?.nativeEvent?.layout?.width;
182
+ if (typeof width === "number" && width > 0) widthRef.current = width;
183
+ }}
184
+ // The DOM preview has no layout events, so measure on mount there too;
185
+ // on a device this resolves to nothing and onLayout is the source.
186
+ ref={(node: any) => {
187
+ measurePreviewWidth(node, widthRef);
188
+ if (typeof ref === "function") ref(node);
189
+ else if (ref) ref.current = node;
190
+ }}
191
+ style={containerStyle}
192
+ {...(panResponder ? panResponder.panHandlers : {})}
193
+ {...props}
194
+ >
195
+ <Glass effect="regular" isDark={isDark} style={trackStyle}>
196
+ <View style={fillStyle} />
74
197
  </Glass>
75
- <input
76
- type="range"
77
- min={min}
78
- max={max}
79
- step={step}
80
- value={value}
81
- disabled={disabled}
82
- aria-label={accessibilityLabel}
83
- onChange={handleChange}
84
- style={{
85
- position: "absolute",
86
- top: 0,
87
- left: 0,
88
- width: "100%",
89
- height: "100%",
90
- opacity: 0,
91
- cursor: disabled ? "default" : "pointer",
92
- margin: 0,
93
- }}
94
- />
95
- </div>
198
+ <View style={thumbStyle} pointerEvents="none" />
199
+ </Pressable>
96
200
  );
97
201
  });
package/src/Switch.tsx CHANGED
@@ -1,6 +1,10 @@
1
- import { useState, forwardRef } from "react";
1
+ import { forwardRef, useState } from "react";
2
+ import type { StyleProp, ViewStyle } from "react-native";
3
+
2
4
  import { Glass } from "./Glass";
3
5
  import { colors } from "./internal/tokens";
6
+ import { primitives } from "./internal/primitives";
7
+ import { useIsDark, useSpring } from "./internal/motion";
4
8
 
5
9
  export interface SwitchProps {
6
10
  checked?: boolean;
@@ -8,10 +12,25 @@ export interface SwitchProps {
8
12
  onCheckedChange?: (checked: boolean) => void;
9
13
  disabled?: boolean;
10
14
  accessibilityLabel: string;
11
- style?: any;
15
+ style?: StyleProp<ViewStyle>;
12
16
  isDark?: boolean;
17
+ /** Passed through to the switch track so it is testable. */
18
+ testID?: string;
13
19
  }
14
20
 
21
+ const TRACK_WIDTH = 51;
22
+ const TRACK_HEIGHT = 31;
23
+ const THUMB = 27;
24
+ const TRAVEL = TRACK_WIDTH - THUMB - 4;
25
+
26
+ /**
27
+ * An on/off switch.
28
+ *
29
+ * The track is Glacia's glass; the thumb is one of our own Views, animated on
30
+ * the springs token. The material changes by platform (Apple's glass on
31
+ * iOS 26+, Glacia's tint elsewhere) but the control is always ours — React
32
+ * Native's built-in Switch is never used.
33
+ */
15
34
  export const Switch = forwardRef<any, SwitchProps>(function Switch(
16
35
  {
17
36
  checked: checkedProp,
@@ -20,61 +39,66 @@ export const Switch = forwardRef<any, SwitchProps>(function Switch(
20
39
  disabled = false,
21
40
  accessibilityLabel,
22
41
  style,
23
- isDark = false,
42
+ isDark: isDarkProp,
43
+ testID,
24
44
  ...props
25
45
  },
26
46
  ref,
27
47
  ) {
48
+ const isDark = useIsDark(isDarkProp);
49
+ const themeColors = isDark ? colors.dark : colors.light;
50
+ const { View, Pressable, Animated } = primitives();
28
51
  const [internalChecked, setInternalChecked] = useState(defaultChecked);
29
52
  const isChecked = checkedProp !== undefined ? checkedProp : internalChecked;
30
- const themeColors = isDark ? colors.dark : colors.light;
53
+
54
+ // The thumb's travel is a single number animated on the springs token.
55
+ const { value: offset, animated } = useSpring(isChecked ? TRAVEL : 0, "snappy");
31
56
 
32
57
  const toggle = () => {
33
58
  if (disabled) return;
34
59
  const next = !isChecked;
35
- if (checkedProp === undefined) {
36
- setInternalChecked(next);
37
- }
60
+ if (checkedProp === undefined) setInternalChecked(next);
38
61
  onCheckedChange?.(next);
39
62
  };
40
63
 
41
- const trackStyle = {
42
- width: 51,
43
- height: 31,
44
- borderRadius: 15.5,
64
+ const trackStyle: ViewStyle = {
65
+ width: TRACK_WIDTH,
66
+ height: TRACK_HEIGHT,
67
+ borderRadius: TRACK_HEIGHT / 2,
45
68
  backgroundColor: isChecked ? themeColors.fill : "rgba(120, 120, 128, 0.16)",
46
69
  padding: 2,
47
- justifyContent: "center" as const,
70
+ justifyContent: "center",
48
71
  opacity: disabled ? 0.38 : 1,
49
- transition: "background-color 200ms ease",
50
- ...style,
72
+ ...(style as ViewStyle),
51
73
  };
52
74
 
53
- const thumbStyle = {
54
- width: 27,
55
- height: 27,
56
- borderRadius: 13.5,
75
+ const thumbStyle: ViewStyle = {
76
+ width: THUMB,
77
+ height: THUMB,
78
+ borderRadius: THUMB / 2,
57
79
  backgroundColor: "#FFFFFF",
58
- boxShadow: "0 2px 4px rgba(0, 0, 0, 0.2)",
59
- transform: isChecked ? "translateX(20px)" : "translateX(0px)",
60
- transition: "transform 200ms cubic-bezier(0.25, 0.1, 0.25, 1)",
80
+ // A hairline edge instead of a drop shadow: RN shadows need per-platform
81
+ // props, and the edge reads correctly on a translucent track.
82
+ borderWidth: 0.5,
83
+ borderColor: "rgba(0, 0, 0, 0.12)",
84
+ transform: [{ translateX: animated ? offset : isChecked ? TRAVEL : 0 }],
61
85
  };
62
86
 
63
87
  return (
64
- <div
88
+ <Pressable
65
89
  ref={ref}
66
- role="switch"
67
- aria-checked={isChecked}
68
- aria-label={accessibilityLabel}
69
- aria-disabled={disabled}
70
- tabIndex={disabled ? -1 : 0}
71
- onClick={toggle}
72
- style={{ display: "inline-block", cursor: disabled ? "default" : "pointer" }}
90
+ testID={testID}
91
+ accessibilityRole="switch"
92
+ accessibilityLabel={accessibilityLabel}
93
+ accessibilityState={{ checked: isChecked, disabled }}
94
+ disabled={disabled}
95
+ onPress={toggle}
96
+ style={{ alignSelf: "flex-start" }}
73
97
  {...props}
74
98
  >
75
- <Glass effect="regular" style={trackStyle}>
76
- <div style={thumbStyle} />
99
+ <Glass effect="regular" isDark={isDark} style={trackStyle}>
100
+ {animated ? <Animated.View style={thumbStyle} /> : <View style={thumbStyle} />}
77
101
  </Glass>
78
- </div>
102
+ </Pressable>
79
103
  );
80
104
  });
package/src/TabBar.tsx CHANGED
@@ -1,6 +1,10 @@
1
- import { useState, forwardRef, type ReactNode } from "react";
1
+ import { forwardRef, useState, type ReactNode } from "react";
2
+ import type { StyleProp, ViewStyle } from "react-native";
3
+
2
4
  import { Glass } from "./Glass";
3
5
  import { colors, radii } from "./internal/tokens";
6
+ import { primitives } from "./internal/primitives";
7
+ import { useIsDark, useSpring } from "./internal/motion";
4
8
 
5
9
  export interface TabBarItem {
6
10
  id: string;
@@ -13,10 +17,23 @@ export interface TabBarProps {
13
17
  activeId?: string;
14
18
  defaultActiveId?: string;
15
19
  onTabChange?: (id: string) => void;
16
- style?: any;
20
+ style?: StyleProp<ViewStyle>;
17
21
  isDark?: boolean;
22
+ /** Passed through to the bar so it is testable. */
23
+ testID?: string;
18
24
  }
19
25
 
26
+ const BAR_HEIGHT = 52;
27
+
28
+ /**
29
+ * The bottom bar of an app: a row of tabs on one glass surface.
30
+ *
31
+ * The platform rule is the point of this component. On iOS 26+ the surface is
32
+ * Apple's real Liquid Glass (`UIGlassEffect` via `@callstack/liquid-glass`)
33
+ * with Glacia's own items inside it; on older iOS and on Android it is
34
+ * Glacia's bar. The items are always our Pressables and Texts — no native tab
35
+ * bar is used on any platform.
36
+ */
20
37
  export const TabBar = forwardRef<any, TabBarProps>(function TabBar(
21
38
  {
22
39
  items,
@@ -24,62 +41,115 @@ export const TabBar = forwardRef<any, TabBarProps>(function TabBar(
24
41
  defaultActiveId,
25
42
  onTabChange,
26
43
  style,
27
- isDark = false,
44
+ isDark: isDarkProp,
45
+ testID,
28
46
  ...props
29
47
  },
30
48
  ref,
31
49
  ) {
50
+ const isDark = useIsDark(isDarkProp);
51
+ const themeColors = isDark ? colors.dark : colors.light;
52
+ const { View, Text, Pressable, Animated } = primitives();
53
+
32
54
  const [internalId, setInternalId] = useState(defaultActiveId || items[0]?.id || "");
33
55
  const activeId = activeProp !== undefined ? activeProp : internalId;
34
- const themeColors = isDark ? colors.dark : colors.light;
56
+
57
+ const activeIndex = Math.max(
58
+ 0,
59
+ items.findIndex((item) => item.id === activeId),
60
+ );
61
+ // The active wash slides between equally wide items on the springs token.
62
+ const { value: slide, animated } = useSpring(activeIndex, "snappy");
35
63
 
36
64
  const handleSelect = (id: string) => {
37
- if (activeProp === undefined) {
38
- setInternalId(id);
39
- }
65
+ if (activeProp === undefined) setInternalId(id);
40
66
  onTabChange?.(id);
41
67
  };
42
68
 
43
- const barStyle = {
44
- position: "relative" as const,
45
- display: "flex" as const,
46
- flexDirection: "row" as const,
47
- alignItems: "center" as const,
48
- justifyContent: "space-around" as const,
49
- height: 52,
69
+ const barStyle: ViewStyle = {
70
+ flexDirection: "row",
71
+ alignItems: "center",
72
+ justifyContent: "space-around",
73
+ height: BAR_HEIGHT,
50
74
  paddingHorizontal: 8,
51
75
  borderRadius: radii.xl,
52
- ...style,
76
+ ...(style as ViewStyle),
77
+ };
78
+
79
+ const count = Math.max(items.length, 1);
80
+ const itemWidth = `${100 / count}%`;
81
+
82
+ const indicatorStyle = {
83
+ position: "absolute" as const,
84
+ top: 6,
85
+ bottom: 6,
86
+ left: 8,
87
+ width: itemWidth,
88
+ borderRadius: radii.lg,
89
+ backgroundColor: themeColors.glassActive,
90
+ opacity: 0.75,
53
91
  };
54
92
 
55
93
  return (
56
- <Glass ref={ref} effect="regular" style={barStyle} {...props}>
94
+ <Glass ref={ref} effect="regular" isDark={isDark} style={barStyle} testID={testID} {...props}>
95
+ {/* The selected item's wash, one View behind the labels. */}
96
+ {animated ? (
97
+ <Animated.View
98
+ pointerEvents="none"
99
+ style={{
100
+ ...indicatorStyle,
101
+ transform: [
102
+ {
103
+ translateX: slide.interpolate({
104
+ inputRange: [0, Math.max(count - 1, 1)],
105
+ outputRange: [
106
+ "0%",
107
+ `${((count - 1) * 100) / count}%`,
108
+ ],
109
+ }),
110
+ },
111
+ ],
112
+ }}
113
+ />
114
+ ) : (
115
+ <View
116
+ pointerEvents="none"
117
+ style={{ ...indicatorStyle, left: `${(activeIndex * 100) / count}%` }}
118
+ />
119
+ )}
120
+
57
121
  {items.map((tab) => {
58
122
  const isActive = tab.id === activeId;
59
123
  return (
60
- <button
124
+ <Pressable
61
125
  key={tab.id}
62
- type="button"
63
- onClick={() => handleSelect(tab.id)}
126
+ accessibilityRole="tab"
127
+ accessibilityLabel={tab.label}
128
+ accessibilityState={{ selected: isActive }}
129
+ onPress={() => handleSelect(tab.id)}
64
130
  style={{
65
131
  flex: 1,
66
- display: "flex",
132
+ height: "100%",
67
133
  flexDirection: "column",
68
134
  alignItems: "center",
69
135
  justifyContent: "center",
70
136
  gap: 2,
71
- padding: "4px 8px",
72
- border: 0,
73
- background: "transparent",
74
- color: isActive ? themeColors.fill : themeColors.muted,
75
- fontSize: 11,
76
- fontWeight: isActive ? 600 : 500,
77
- cursor: "pointer",
137
+ paddingHorizontal: 8,
138
+ paddingVertical: 4,
78
139
  }}
79
140
  >
80
- {tab.icon && <span style={{ fontSize: 18 }}>{tab.icon}</span>}
81
- <span>{tab.label}</span>
82
- </button>
141
+ {tab.icon ?? null}
142
+ <Text
143
+ numberOfLines={1}
144
+ style={{
145
+ fontSize: 11,
146
+ fontWeight: isActive ? "600" : "500",
147
+ color: isActive ? themeColors.fill : themeColors.muted,
148
+ }}
149
+ >
150
+ {tab.label}
151
+ </Text>
152
+ </Pressable>
83
153
  );
84
154
  })}
85
155
  </Glass>