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
@@ -1,33 +1,92 @@
1
1
  import { forwardRef, type ReactNode } from "react";
2
2
  import type { StyleProp, ViewStyle } from "react-native";
3
3
 
4
- import { colors, radii } from "./tokens";
4
+ import { colors, material, radii } from "./tokens";
5
5
  import { primitives } from "./primitives";
6
+ import { useReducedTransparency } from "./a11y";
7
+ import { blurProps, resolveBlurView } from "./blur";
8
+ import { SurfaceGlow } from "./glow";
9
+ import { isFlatProfile, materialFor, type SurfaceProfile } from "./material";
10
+ import { GlassRim } from "./rim";
6
11
 
7
12
  export interface FallbackGlassProps {
8
13
  effect?: "clear" | "regular" | "none";
14
+ /**
15
+ * Which of the web's six lenses this surface is. The profile decides the
16
+ * blur strength, rim brightness and top highlight, so a dialog and a badge
17
+ * no longer share one flat recipe.
18
+ */
19
+ surface?: SurfaceProfile;
9
20
  tintColor?: string;
21
+ /** True while the surface is held; fades the specular glow in. */
22
+ pressed?: boolean;
10
23
  testID?: string;
11
24
  style?: StyleProp<ViewStyle>;
12
25
  children?: ReactNode;
13
26
  isDark?: boolean;
27
+ /**
28
+ * Force the solid treatment. Normally read from the system's Reduce
29
+ * Transparency preference; this exists so a test can pin it.
30
+ */
31
+ reducedTransparency?: boolean;
32
+ }
33
+
34
+ const fill = { position: "absolute", top: 0, left: 0, right: 0, bottom: 0 } as const;
35
+
36
+ /** Layout and paint properties that belong to the surface itself. */
37
+ const HOISTED = new Set([
38
+ "backgroundColor",
39
+ "shadowColor",
40
+ "shadowOpacity",
41
+ "shadowRadius",
42
+ "shadowOffset",
43
+ "elevation",
44
+ ]);
45
+
46
+ /** Merges a style prop into one object; a function style is not resolvable here. */
47
+ function flattenStyle(style: any): ViewStyle {
48
+ if (!style) return {};
49
+ if (Array.isArray(style)) {
50
+ return style.reduce<ViewStyle>((acc, entry) => ({ ...acc, ...flattenStyle(entry) }), {});
51
+ }
52
+ if (typeof style === "function") return {};
53
+ return style as ViewStyle;
14
54
  }
15
55
 
16
56
  /**
17
57
  * Glacia's own glass surface for every platform where Apple's material is not
18
58
  * available: Android, iOS before 26, and Expo Go.
19
59
  *
20
- * It renders the resolver's real React Native `View` with the same shape and
21
- * layout as the native glass, so switching branches never shifts the layout.
60
+ * The material is the web one, rebuilt in layers, because a single flat View
61
+ * could never read as glass:
62
+ *
63
+ * 1. backdrop blur (`expo-blur` / `@react-native-community/blur` when either
64
+ * is installed — a real `UIVisualEffectView` on iOS 17),
65
+ * 2. the tint token on top of the blurred backdrop,
66
+ * 3. a painted rim light, brightest on the top edge, so corners read as curved,
67
+ * 4. a soft highlight just inside the top edge,
68
+ * 5. the 0.5px edge line, and
69
+ * 6. a drop shadow on the surface itself (outside the clipped layer).
70
+ *
71
+ * All of that lives in an absolutely-positioned, clipped layer behind the
72
+ * children. The caller's style stays on the outer View, so heights, padding and
73
+ * flex behaviour are byte-identical to the old flat implementation and
74
+ * switching branches never shifts the layout.
75
+ *
76
+ * Reduce Transparency still replaces the whole thing with a solid colour: the
77
+ * preference exists precisely to remove see-through surfaces.
22
78
  */
23
79
  export const FallbackGlassView = forwardRef<any, FallbackGlassProps>(function FallbackGlassView(
24
80
  {
25
81
  effect = "regular",
82
+ surface = "panel",
26
83
  tintColor,
84
+ pressed,
27
85
  testID,
28
86
  style,
29
87
  children,
30
88
  isDark = false,
89
+ reducedTransparency,
31
90
  ...props
32
91
  },
33
92
  ref,
@@ -35,26 +94,122 @@ export const FallbackGlassView = forwardRef<any, FallbackGlassProps>(function Fa
35
94
  const themeColors = isDark ? colors.dark : colors.light;
36
95
  const { View } = primitives();
37
96
 
38
- const bg =
39
- effect === "none"
40
- ? "transparent"
97
+ // Reduce Transparency means the translucent material is replaced by a solid
98
+ // colour — the point of the preference is to remove see-through surfaces.
99
+ const systemReduced = useReducedTransparency();
100
+ const solid = reducedTransparency ?? systemReduced;
101
+
102
+ const flat = flattenStyle(style);
103
+ const radius = typeof flat.borderRadius === "number" ? flat.borderRadius : radii.md;
104
+ const explicitBackground =
105
+ typeof flat.backgroundColor === "string" ? flat.backgroundColor : undefined;
106
+
107
+ // `effect="none"` is a deliberate "no surface here" (a ghost button); it
108
+ // paints nothing at all, exactly as before.
109
+ const bare = effect === "none";
110
+ const layered = !solid && !bare;
111
+
112
+ const profile = materialFor(surface, bare ? "regular" : effect, isDark);
113
+ const blur = layered ? resolveBlurView() : null;
114
+
115
+ const surfaceStyle: ViewStyle = { ...flat };
116
+ for (const key of HOISTED) delete (surfaceStyle as any)[key];
117
+ // The edge is the web's 0.5px inset line. A component that draws only one
118
+ // edge (AppBar's scroll edge) keeps its own widths; a component that asked
119
+ // for a 1px box border is brought back to the hairline.
120
+ const perEdge = ["borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth"].some(
121
+ (key) => typeof (flat as any)[key] === "number",
122
+ );
123
+ if (typeof flat.borderWidth === "number") {
124
+ surfaceStyle.borderWidth = Math.min(flat.borderWidth, 0.5);
125
+ } else if (!perEdge) {
126
+ surfaceStyle.borderWidth = 0.5;
127
+ }
128
+ surfaceStyle.borderColor = flat.borderColor ?? themeColors.edge;
129
+ surfaceStyle.borderRadius = radius;
130
+
131
+ if (solid) {
132
+ // The solid path is the old single flat view: opaque, no layers, and the
133
+ // caller's own background (a filled button) still wins over the token.
134
+ surfaceStyle.backgroundColor =
135
+ flat.backgroundColor ??
136
+ (effect === "clear" && tintColor ? tintColor : themeColors.glassSolid);
137
+ surfaceStyle.overflow = "hidden";
138
+ } else if (bare) {
139
+ surfaceStyle.backgroundColor = flat.backgroundColor ?? "transparent";
140
+ surfaceStyle.overflow = "hidden";
141
+ } else {
142
+ // Layered material. An opaque background is a filled control, not glass:
143
+ // it still gets a rim so it does not read as a sticker, but no blur tint.
144
+ const opaque = Boolean(explicitBackground);
145
+ const tint = opaque
146
+ ? explicitBackground
41
147
  : effect === "clear"
42
148
  ? isDark
43
149
  ? "rgba(28, 28, 30, 0.35)"
44
150
  : "rgba(255, 255, 255, 0.35)"
45
151
  : tintColor || themeColors.glass;
46
152
 
47
- const containerStyle: ViewStyle = {
48
- backgroundColor: bg,
49
- borderColor: themeColors.edge,
50
- borderWidth: 0.5,
51
- borderRadius: radii.md,
52
- overflow: "hidden",
53
- ...(style as ViewStyle),
54
- };
153
+ const rim = opaque ? profile.rim * 0.5 : profile.rim;
154
+ const highlight = opaque ? profile.highlight * 0.5 : profile.highlight;
155
+ const blurrable = Boolean(blur) && !opaque;
156
+
157
+ const shadowOpacity =
158
+ typeof flat.shadowOpacity === "number" ? flat.shadowOpacity : profile.shadowOpacity;
159
+ const shadowRadius =
160
+ typeof flat.shadowRadius === "number" ? flat.shadowRadius : profile.shadowRadius;
161
+ const shadowHeight =
162
+ typeof flat.shadowOffset?.height === "number"
163
+ ? flat.shadowOffset.height
164
+ : profile.shadowOffsetY;
165
+ // The hint family (badges, tooltips) sits flush with the page on the web.
166
+ const lifts = !isFlatProfile(surface) && shadowOpacity > 0;
167
+
168
+ return (
169
+ <View
170
+ ref={ref}
171
+ testID={testID}
172
+ style={[
173
+ surfaceStyle,
174
+ lifts
175
+ ? {
176
+ shadowColor: material.shadowColor,
177
+ shadowOpacity,
178
+ shadowRadius,
179
+ shadowOffset: { width: 0, height: shadowHeight },
180
+ elevation: typeof flat.elevation === "number" ? flat.elevation : profile.elevation,
181
+ }
182
+ : null,
183
+ ]}
184
+ {...props}
185
+ >
186
+ {/* The material layer carries a derived testID so a test can assert on
187
+ the blur/tint/rim stack rather than on the outer layout box. */}
188
+ <View
189
+ testID={testID ? `${testID}-material` : undefined}
190
+ style={[fill, { borderRadius: radius, overflow: "hidden" }]}
191
+ pointerEvents="none"
192
+ >
193
+ {blurrable && blur ? (
194
+ <blur.View
195
+ {...blurProps(blur.kind, profile.blur, isDark)}
196
+ style={[fill, { borderRadius: radius }]}
197
+ />
198
+ ) : null}
199
+ <View
200
+ testID={testID ? `${testID}-tint` : undefined}
201
+ style={[fill, { backgroundColor: tint }]}
202
+ />
203
+ <GlassRim radius={radius} rim={rim} highlight={highlight} />
204
+ {pressed !== undefined ? <SurfaceGlow active={pressed} /> : null}
205
+ </View>
206
+ {children}
207
+ </View>
208
+ );
209
+ }
55
210
 
56
211
  return (
57
- <View ref={ref} testID={testID} style={containerStyle} {...props}>
212
+ <View ref={ref} testID={testID} style={surfaceStyle} {...props}>
58
213
  {children}
59
214
  </View>
60
215
  );
@@ -16,6 +16,11 @@ declare const require: any;
16
16
 
17
17
  export interface LiquidGlassModule {
18
18
  LiquidGlassView?: any;
19
+ /**
20
+ * The container that merges nearby glass elements into one connected
21
+ * surface. Exported by `@callstack/liquid-glass` alongside the view.
22
+ */
23
+ LiquidGlassContainerView?: any;
19
24
  isLiquidGlassSupported?: boolean;
20
25
  }
21
26
 
@@ -25,6 +30,11 @@ export interface GlassRouter {
25
30
  supported: boolean;
26
31
  /** Apple's `LiquidGlassView`, or null when the fallback renders instead. */
27
32
  LiquidGlassView: any;
33
+ /**
34
+ * Apple's `LiquidGlassContainerView` — the surface that merges neighbouring
35
+ * glass — or null when the fallback wrapper renders instead.
36
+ */
37
+ LiquidGlassContainerView: any;
28
38
  }
29
39
 
30
40
  /**
@@ -35,9 +45,16 @@ export interface GlassRouter {
35
45
  */
36
46
  export function routerFor(module: LiquidGlassModule | null | undefined): GlassRouter {
37
47
  const view = module?.LiquidGlassView ?? null;
48
+ const container = module?.LiquidGlassContainerView ?? null;
38
49
  return {
50
+ // A module that reports support but lacks the container still renders real
51
+ // glass; the container is only needed by GlassContainer, which falls back
52
+ // when it is missing.
39
53
  supported: Boolean(module?.isLiquidGlassSupported) && Boolean(view),
40
54
  LiquidGlassView: view,
55
+ // The container merges only when the material itself is available; a
56
+ // container without the view would have nothing to merge.
57
+ LiquidGlassContainerView: container,
41
58
  };
42
59
  }
43
60
 
@@ -0,0 +1,62 @@
1
+ // The specular press highlight, painted as a radial glow.
2
+ //
3
+ // The web material fades a 240px radial white highlight in under the finger
4
+ // for 220ms whenever a glass control is held. That is what makes a press feel
5
+ // like touching a lens rather than a flat sticker. The fallback had only an
6
+ // opacity dip, so controls never looked held.
7
+ //
8
+ // The glow lives inside the clipped material layer, so it follows the same
9
+ // radius as the surface and can never spill outside it.
10
+
11
+ import { useId } from "react";
12
+
13
+ import { useSpring } from "./motion";
14
+ import { primitives } from "./primitives";
15
+ import { material } from "./tokens";
16
+
17
+ const fill = { position: "absolute", top: 0, left: 0, right: 0, bottom: 0 } as const;
18
+
19
+ export interface SurfaceGlowProps {
20
+ /** True while the surface is held. */
21
+ active: boolean;
22
+ }
23
+
24
+ /**
25
+ * A radial highlight that fades in while `active`.
26
+ *
27
+ * Motion uses the package's spring tokens and respects Reduce Motion: with the
28
+ * preference on, the glow appears at its end state rather than fading.
29
+ */
30
+ export function SurfaceGlow({ active }: SurfaceGlowProps) {
31
+ const { Svg, Defs, RadialGradient, Stop, Rect, Animated } = primitives();
32
+ const { value, animated } = useSpring(active ? 1 : 0, "snappy");
33
+ const gradientId = `glow-${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;
34
+
35
+ const painting = (
36
+ <Svg width="100%" height="100%" style={fill} pointerEvents="none">
37
+ <Defs>
38
+ <RadialGradient id={gradientId} cx="50%" cy="50%" r="50%">
39
+ <Stop offset="0" stopColor={material.rimColor} stopOpacity={material.glow} />
40
+ <Stop offset="1" stopColor={material.rimColor} stopOpacity={0} />
41
+ </RadialGradient>
42
+ </Defs>
43
+ <Rect x="0" y="0" width="100%" height="100%" fill={`url(#${gradientId})`} />
44
+ </Svg>
45
+ );
46
+
47
+ // Off-device there is no Animated API; the settled state is what a preview
48
+ // should show, exactly as `useSpring` documents.
49
+ if (!animated) {
50
+ return (
51
+ <Animated.View style={[fill, { opacity: active ? 1 : 0 }]} pointerEvents="none">
52
+ {painting}
53
+ </Animated.View>
54
+ );
55
+ }
56
+
57
+ return (
58
+ <Animated.View style={[fill, { opacity: value }]} pointerEvents="none">
59
+ {painting}
60
+ </Animated.View>
61
+ );
62
+ }
@@ -0,0 +1,59 @@
1
+ // Haptic feedback for controls.
2
+ //
3
+ // Native iOS controls tick as you move them — a switch toggling, a segment
4
+ // being chosen. Glacia's controls are drawn by the library, so they have to
5
+ // ask for that tick themselves.
6
+ //
7
+ // There is no single React Native API for it, and Glacia does not take a
8
+ // dependency for one. Instead this tries, in order, the APIs that ship with
9
+ // common Expo and React Native projects, and does nothing where none is
10
+ // present. A missing tick must never break a control, so every call is
11
+ // wrapped: these helpers cannot throw.
12
+
13
+ import { primitives } from "./primitives";
14
+
15
+ declare const require: any;
16
+
17
+ /** The selection-tick implementation, resolved once. */
18
+ type Tick = () => void;
19
+
20
+ function resolveTick(): Tick | null {
21
+ // Expo's haptics module, when the app has it installed.
22
+ try {
23
+ const expo = require("expo-haptics");
24
+ if (expo?.selectionAsync) {
25
+ return () => {
26
+ expo.selectionAsync().catch?.(() => {});
27
+ };
28
+ }
29
+ } catch {
30
+ // Not an Expo project, or expo-haptics is not installed: try the next one.
31
+ }
32
+
33
+ // React Native's own Vibration API: a 10 ms buzz is the closest thing to a
34
+ // selection tick that ships with core. It is a coarser feel, but it is real
35
+ // feedback on a device that has no better module.
36
+ const { Vibration } = primitives();
37
+ if (Vibration?.vibrate) {
38
+ return () => {
39
+ Vibration.vibrate(10);
40
+ };
41
+ }
42
+
43
+ return null;
44
+ }
45
+
46
+ /**
47
+ * One selection tick, for a control whose value just changed by one step.
48
+ *
49
+ * Silent where no haptics API is available (the DOM preview, a test run, a
50
+ * device without a vibration motor). Never throws.
51
+ */
52
+ export function hapticSelection(): void {
53
+ try {
54
+ const tick = resolveTick();
55
+ tick?.();
56
+ } catch {
57
+ // Haptics are a nicety; a failure here must not surface to the user.
58
+ }
59
+ }
@@ -0,0 +1,105 @@
1
+ // The selected lens: one raised surface, without a second glass material.
2
+ //
3
+ // Every selected thing in the fallback — a list row, a menu option, a chosen
4
+ // weekday, the tab bar's indicator — is the web's "lens": the selected tint,
5
+ // lifted by a shadow, with the same painted rim as the surfaces around it.
6
+ //
7
+ // It cannot be a `Glass`. Glass inside a glass panel is glass-on-glass, which
8
+ // the material rules forbid, and the surfaces these sit in are already glass.
9
+ // So the lens is painted directly: tint, shadow, rim. Same look, no stacking.
10
+
11
+ import type { ReactNode } from "react";
12
+ import type { StyleProp, ViewStyle } from "react-native";
13
+
14
+ import { colors, material, radii } from "./tokens";
15
+ import { primitives } from "./primitives";
16
+ import { GlassRim } from "./rim";
17
+
18
+ const fill = { position: "absolute", top: 0, left: 0, right: 0, bottom: 0 } as const;
19
+
20
+ /**
21
+ * How far a lens sits above its row.
22
+ *
23
+ * Shallower than a panel's shadow: a lens is inside a surface that already
24
+ * floats, so it needs contact, not altitude.
25
+ */
26
+ export function lensShadow(isDark?: boolean): ViewStyle {
27
+ return {
28
+ shadowColor: material.shadowColor,
29
+ shadowOpacity: isDark ? 0 : 0.1,
30
+ shadowRadius: 8,
31
+ shadowOffset: { width: 0, height: 2 },
32
+ } as ViewStyle;
33
+ }
34
+
35
+ /**
36
+ * The rim of a lens, on its own.
37
+ *
38
+ * For indicators that are already animated views and cannot become a
39
+ * `SelectedLens`: they keep their own transform, and this paints the light on
40
+ * top of whatever tint they already have.
41
+ */
42
+ export function LensRim({ radius, isDark }: { radius: number; isDark?: boolean }) {
43
+ const { View } = primitives();
44
+ const rim = (isDark ? material.rim.dark : material.rim.light) * 0.66;
45
+ return (
46
+ <View style={{ ...fill, overflow: "hidden", borderRadius: radius }} pointerEvents="none">
47
+ <GlassRim radius={radius} rim={rim} highlight={material.highlight * 0.7} />
48
+ </View>
49
+ );
50
+ }
51
+
52
+ export interface SelectedLensProps {
53
+ /** The lens shape. A circle is simply a radius of half the side. */
54
+ radius: number;
55
+ isDark?: boolean;
56
+ style?: StyleProp<ViewStyle>;
57
+ children?: ReactNode;
58
+ testID?: string;
59
+ }
60
+
61
+ /**
62
+ * A selected state, drawn as the web's lens.
63
+ *
64
+ * Rendered as an absolutely positioned overlay so it never changes the layout
65
+ * of the row it marks: parents keep their padding and press handling, and the
66
+ * content paints above it by sibling order.
67
+ */
68
+ export function SelectedLens({ radius, isDark, style, children, testID }: SelectedLensProps) {
69
+ const { View } = primitives();
70
+ const theme = isDark ? colors.dark : colors.light;
71
+
72
+ return (
73
+ <View
74
+ testID={testID}
75
+ pointerEvents="none"
76
+ style={[
77
+ {
78
+ borderRadius: radius,
79
+ backgroundColor: theme.glassActive,
80
+ ...lensShadow(isDark),
81
+ },
82
+ style as ViewStyle,
83
+ ]}
84
+ >
85
+ {/* A tighter rim than a panel's: small surfaces catch less light. */}
86
+ <LensRim radius={radius} isDark={isDark} />
87
+ {children}
88
+ </View>
89
+ );
90
+ }
91
+
92
+ /** The lens overlay for a row: inset from the panel's edges, full width inside. */
93
+ export function rowLensStyle(radius: number, inset = 6): ViewStyle {
94
+ return {
95
+ position: "absolute",
96
+ top: 2,
97
+ bottom: 2,
98
+ left: inset,
99
+ right: inset,
100
+ borderRadius: radius,
101
+ };
102
+ }
103
+
104
+ /** A pill lens filling its own box, for indicators pinned to a control. */
105
+ export const lensFill = { ...fill, borderRadius: radii.pill } as const;
@@ -0,0 +1,92 @@
1
+ // The fallback's material recipe — the web engine's surface profiles, in
2
+ // React Native terms.
3
+ //
4
+ // The web fits a different lens per component family (panel, control, field,
5
+ // overlay, hint, rail). The fallback had a single flat surface for all of
6
+ // them, which is why a dialog and a badge looked identical. This module turns
7
+ // each profile into the numbers the layered fallback needs: how strongly the
8
+ // backdrop is blurred, how bright the rim is, how much light sits inside the
9
+ // top edge, and whether the surface is lifted by a shadow.
10
+ //
11
+ // Nothing here renders. It is a table plus one resolver, so the fallback
12
+ // component stays a layout and the profiles stay reviewable against the web.
13
+
14
+ import { material } from "./tokens";
15
+
16
+ /** The six surfaces the web engine distinguishes. */
17
+ export type SurfaceProfile = "panel" | "control" | "field" | "overlay" | "hint" | "rail";
18
+
19
+ /**
20
+ * The web profile values this mapping is derived from.
21
+ *
22
+ * Kept in the same order and with the same names as the engine's table so the
23
+ * two can be diffed by eye: bend drives the blur strength, depth the inner
24
+ * highlight, and dome the rim brightness (the dome is the part of the lens
25
+ * that catches the light).
26
+ */
27
+ const webProfiles: Record<
28
+ SurfaceProfile,
29
+ { bend: number; depth: number; dome: number }
30
+ > = {
31
+ panel: { bend: 0.45, depth: 0.25, dome: 0.5 },
32
+ control: { bend: 0.55, depth: 0.3, dome: 0.6 },
33
+ field: { bend: 0.35, depth: 0.2, dome: 0.34 },
34
+ overlay: { bend: 0.5, depth: 0.34, dome: 0.66 },
35
+ hint: { bend: 0.28, depth: 0.22, dome: 0.3 },
36
+ rail: { bend: 0.4, depth: 0.22, dome: 0.4 },
37
+ };
38
+
39
+ /** A resolved material for one surface, in the units React Native accepts. */
40
+ export interface ResolvedMaterial {
41
+ /** Backdrop blur intensity on expo-blur's 0–100 scale. */
42
+ blur: number;
43
+ /** Alpha of the rim's brightest (top) stop. */
44
+ rim: number;
45
+ /** Alpha of the highlight inside the top edge. */
46
+ highlight: number;
47
+ /** How far the surface is lifted, from the theme's shadow tokens. */
48
+ shadowOpacity: number;
49
+ shadowRadius: number;
50
+ shadowOffsetY: number;
51
+ /** Android's equivalent of the iOS shadow. */
52
+ elevation: number;
53
+ }
54
+
55
+ /** The reference profile: the panel is the base lens the others scale from. */
56
+ const BASE_BLUR = 24;
57
+ const BASE_DOME = webProfiles.panel.dome;
58
+ const BASE_DEPTH = webProfiles.panel.depth;
59
+
60
+ /**
61
+ * The material for one surface.
62
+ *
63
+ * The `clear` effect is the same stack with a thinner lens — less blur and a
64
+ * fainter rim — which is what the web means by clear. Reduce Transparency is
65
+ * handled before this call: it replaces the whole stack with a solid colour.
66
+ */
67
+ export function materialFor(
68
+ profile: SurfaceProfile = "panel",
69
+ effect: "clear" | "regular" | "none" = "regular",
70
+ isDark = false,
71
+ ): ResolvedMaterial {
72
+ const lens = webProfiles[profile];
73
+ const thin = effect === "clear" ? 0.55 : 1;
74
+ const rimBase = isDark ? material.rim.dark : material.rim.light;
75
+
76
+ return {
77
+ blur: Math.round(BASE_BLUR * (lens.bend / webProfiles.panel.bend) * thin),
78
+ rim: rimBase * (lens.dome / BASE_DOME) * thin,
79
+ highlight: material.highlight * (lens.depth / BASE_DEPTH) * thin,
80
+ // The web drops every surface by 1px; overlays carry their own, deeper
81
+ // shadow from the component's style, which the fallback prefers when set.
82
+ shadowOpacity: isDark ? 0 : material.shadowOpacity.light,
83
+ shadowRadius: 3,
84
+ shadowOffsetY: 1,
85
+ elevation: isDark ? 0 : 1,
86
+ };
87
+ }
88
+
89
+ /** Whether a surface is a shadowed one at all (the hint family sits flat). */
90
+ export function isFlatProfile(profile: SurfaceProfile): boolean {
91
+ return profile === "hint";
92
+ }
@@ -6,9 +6,13 @@
6
6
  // does not pass `isDark`, so a theme-aware app needs no extra prop threading.
7
7
  // - `useSpring` animates a number towards its target with the package's spring
8
8
  // tokens through React Native's Animated API. No CSS, no timers of our own.
9
+ // - Motion respects the system's Reduce Motion preference: when it is on, the
10
+ // value settles at its target instead of animating. Doing it here means every
11
+ // animation built on `useSpring` complies without repeating the check.
9
12
 
10
13
  import { useEffect, useRef } from "react";
11
14
 
15
+ import { useReducedMotion } from "./a11y";
12
16
  import { primitives } from "./primitives";
13
17
  import { springs } from "./tokens";
14
18
 
@@ -31,10 +35,15 @@ export type SpringName = keyof typeof springs;
31
35
  * on this platform. A caller that gets `animated === false` renders the target
32
36
  * directly, so the DOM preview and tests show the settled state rather than an
33
37
  * animation the environment cannot advance.
38
+ *
39
+ * Reduce Motion turns this into the same case: `animated` is false and the
40
+ * value is already at its target, so the component jumps to its end state
41
+ * rather than playing a transition the user asked not to see.
34
42
  */
35
43
  export function useSpring(target: number, spring: SpringName = "snappy") {
36
44
  const { Animated, isNative } = primitives();
37
- const animated = Boolean(isNative && Animated?.Value && Animated?.spring);
45
+ const reducedMotion = useReducedMotion();
46
+ const animated = Boolean(isNative && Animated?.Value && Animated?.spring) && !reducedMotion;
38
47
 
39
48
  // Off-device there is no Animated; a plain ref keeps the call sites identical.
40
49
  const value = useRef<any>(null);