glacia-native 0.5.0 → 0.5.1

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 (63) hide show
  1. package/lib/module/Bars.js +95 -2
  2. package/lib/module/Display.js +78 -1
  3. package/lib/module/Feedback.js +221 -7
  4. package/lib/module/Forms2.js +228 -1
  5. package/lib/module/Message.js +88 -0
  6. package/lib/module/Overlays.js +173 -11
  7. package/lib/module/SegmentedControl.js +5 -1
  8. package/lib/module/Slider.js +6 -1
  9. package/lib/module/Switch.js +4 -1
  10. package/lib/module/TabBar.js +5 -1
  11. package/lib/module/ai.js +8 -3
  12. package/lib/module/index.js +23 -2
  13. package/lib/module/internal/GlassContainer.js +54 -0
  14. package/lib/module/internal/GlassView.js +8 -0
  15. package/lib/module/internal/a11y.js +94 -0
  16. package/lib/module/internal/fallback.js +19 -8
  17. package/lib/module/internal/glass-routing.js +7 -0
  18. package/lib/module/internal/haptics.js +54 -0
  19. package/lib/module/internal/motion.js +10 -1
  20. package/lib/module/internal/primitives.js +69 -4
  21. package/lib/module/internal/tokens.js +47 -1
  22. package/lib/typescript/Bars.d.ts +67 -0
  23. package/lib/typescript/Display.d.ts +59 -0
  24. package/lib/typescript/Feedback.d.ts +58 -0
  25. package/lib/typescript/Forms2.d.ts +81 -0
  26. package/lib/typescript/Message.d.ts +71 -0
  27. package/lib/typescript/Overlays.d.ts +41 -0
  28. package/lib/typescript/SegmentedControl.d.ts +2 -0
  29. package/lib/typescript/Slider.d.ts +2 -0
  30. package/lib/typescript/Switch.d.ts +2 -0
  31. package/lib/typescript/TabBar.d.ts +2 -0
  32. package/lib/typescript/index.d.ts +8 -6
  33. package/lib/typescript/internal/GlassContainer.d.ts +37 -0
  34. package/lib/typescript/internal/GlassView.d.ts +8 -0
  35. package/lib/typescript/internal/a11y.d.ts +19 -0
  36. package/lib/typescript/internal/fallback.d.ts +5 -0
  37. package/lib/typescript/internal/glass-routing.d.ts +10 -0
  38. package/lib/typescript/internal/haptics.d.ts +7 -0
  39. package/lib/typescript/internal/motion.d.ts +4 -0
  40. package/lib/typescript/internal/primitives.d.ts +21 -0
  41. package/lib/typescript/internal/tokens.d.ts +53 -0
  42. package/package.json +2 -2
  43. package/src/Bars.tsx +227 -0
  44. package/src/Display.tsx +229 -1
  45. package/src/Feedback.tsx +412 -22
  46. package/src/Forms2.tsx +407 -1
  47. package/src/Message.tsx +219 -0
  48. package/src/Overlays.tsx +244 -33
  49. package/src/SegmentedControl.tsx +6 -0
  50. package/src/Slider.tsx +7 -0
  51. package/src/Switch.tsx +5 -0
  52. package/src/TabBar.tsx +6 -0
  53. package/src/ai.tsx +9 -3
  54. package/src/index.ts +42 -1
  55. package/src/internal/GlassContainer.tsx +82 -0
  56. package/src/internal/GlassView.tsx +8 -0
  57. package/src/internal/a11y.ts +105 -0
  58. package/src/internal/fallback.tsx +19 -2
  59. package/src/internal/glass-routing.ts +17 -0
  60. package/src/internal/haptics.ts +59 -0
  61. package/src/internal/motion.ts +10 -1
  62. package/src/internal/primitives.ts +80 -4
  63. package/src/internal/tokens.ts +48 -0
@@ -0,0 +1,82 @@
1
+ import { forwardRef, type ReactNode } from "react";
2
+ import type { StyleProp, ViewStyle } from "react-native";
3
+
4
+ import { defaultRouter } from "./glass-routing";
5
+ import { primitives } from "./primitives";
6
+ import { useIsDark } from "./motion";
7
+
8
+ export interface NativeGlassContainerProps {
9
+ /**
10
+ * How close two glass surfaces must be before iOS 26 blends them into one
11
+ * connected liquid surface, in points. 0 merges only what touches.
12
+ */
13
+ spacing?: number;
14
+ style?: StyleProp<ViewStyle>;
15
+ children?: ReactNode;
16
+ isDark?: boolean;
17
+ testID?: string;
18
+ [prop: string]: any;
19
+ }
20
+
21
+ /**
22
+ * The installed module's routing decision, memoised so a container and the
23
+ * surfaces inside it always agree about which branch is rendering.
24
+ */
25
+ let cachedRouter: ReturnType<typeof defaultRouter> | null = null;
26
+
27
+ function router(): ReturnType<typeof defaultRouter> {
28
+ if (cachedRouter === null) cachedRouter = defaultRouter();
29
+ return cachedRouter;
30
+ }
31
+
32
+ /** Clears the memoised decision. Only tests call this, to drive both branches. */
33
+ export function resetGlassContainerRouter() {
34
+ cachedRouter = null;
35
+ }
36
+
37
+ /**
38
+ * Groups glass surfaces so iOS 26 can merge them into one surface.
39
+ *
40
+ * On iOS 26, Apple's Liquid Glass is a connected material: two glass elements
41
+ * placed close enough run together into a single shape with one shared edge,
42
+ * rather than reading as two separate panes. `GlassContainer` is the component
43
+ * that opts into that — a bar and the floating button above it, or a pair of
44
+ * adjacent buttons, become one piece of glass.
45
+ *
46
+ * **Merging is an iOS 26+ visual effect and a no-op everywhere else.** On
47
+ * older iOS, Android, Expo Go and the web preview this renders a plain wrapper
48
+ * with identical layout: the children are the same components, drawn at the
49
+ * same positions, they simply keep their own separate edges. Nothing changes
50
+ * shape or shifts, so a container costs nothing on the platforms that cannot
51
+ * blend.
52
+ *
53
+ * Use it only around surfaces that should read as one; glass inside glass is
54
+ * still forbidden, so a container's children are `Glass` surfaces placed side
55
+ * by side, not a panel wrapping another panel.
56
+ */
57
+ export const GlassContainer = forwardRef<any, NativeGlassContainerProps>(
58
+ function GlassContainer(
59
+ { spacing = 0, style, children, isDark: isDarkProp, testID, ...props },
60
+ ref,
61
+ ) {
62
+ const isDark = useIsDark(isDarkProp);
63
+ const decision = router();
64
+ const { View } = primitives();
65
+
66
+ if (decision.supported && decision.LiquidGlassContainerView) {
67
+ const ContentContainer = decision.LiquidGlassContainerView;
68
+ return (
69
+ <ContentContainer ref={ref} spacing={spacing} testID={testID} style={style} {...props}>
70
+ {children}
71
+ </ContentContainer>
72
+ );
73
+ }
74
+
75
+ // Unsupported: a wrapper with the same layout, so nothing shifts.
76
+ return (
77
+ <View ref={ref} testID={testID} style={style} {...props}>
78
+ {children}
79
+ </View>
80
+ );
81
+ },
82
+ );
@@ -54,6 +54,14 @@ export const isGlassSupported = defaultRouter().supported;
54
54
  * Platform Glass View — the single place a glass surface is chosen:
55
55
  * - iOS 26+: Real UIGlassEffect via @callstack/liquid-glass
56
56
  * - iOS < 26 / Android / Expo Go: translucent tint View with identical layout
57
+ *
58
+ * Reduce Transparency is honoured on the fallback branch only: there the
59
+ * translucent tint is replaced by the theme's solid glass colour, with the same
60
+ * radius and the same hairline border, because a translucent surface is what
61
+ * the user asked the system to remove. On iOS 26 the system applies its own
62
+ * treatment to `UIGlassEffect` and this component does not second-guess it —
63
+ * overriding Apple's accessibility treatment would be worse than deferring to
64
+ * it, so the real glass is left exactly as the system renders it.
57
65
  */
58
66
  export const GlassView = forwardRef<any, NativeGlassProps>(function GlassView(
59
67
  {
@@ -0,0 +1,105 @@
1
+ // Accessibility preferences, as the platform reports them.
2
+ //
3
+ // Apple's HIG makes two of these part of wearing Liquid Glass faithfully:
4
+ // - Reduce Transparency: glass is replaced by a solid colour, because a
5
+ // translucent surface is exactly what the user asked the system to remove.
6
+ // - Reduce Motion: animation jumps to its end state instead of playing.
7
+ //
8
+ // React Native exposes both through AccessibilityInfo, but it is resolved at
9
+ // runtime like every other primitive, so the package stays importable where
10
+ // React Native is absent (jsdom tests, web preview). Where the API is missing
11
+ // the hooks answer `false`: the preference is treated as off, which is the
12
+ // behaviour those environments already had.
13
+
14
+ import { useEffect, useState } from "react";
15
+
16
+ import { primitives } from "./primitives";
17
+
18
+ /** Reads a boolean preference once, guarding against a missing or throwing API. */
19
+ function readPreference(
20
+ info: any,
21
+ method: "isReduceTransparencyEnabled" | "isReduceMotionEnabled",
22
+ ): Promise<boolean> {
23
+ try {
24
+ const result = info?.[method]?.();
25
+ // React Native returns a promise; anything unexpected is treated as "off".
26
+ if (result && typeof result.then === "function") {
27
+ return result.then(
28
+ (value: unknown) => Boolean(value),
29
+ () => false,
30
+ );
31
+ }
32
+ return Promise.resolve(Boolean(result));
33
+ } catch {
34
+ return Promise.resolve(false);
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Subscribes to one AccessibilityInfo preference and keeps it in state.
40
+ *
41
+ * The initial read is async, so the hook starts `false` and corrects itself
42
+ * when the platform answers. The subscription is removed on unmount; a
43
+ * listener that outlives the component would leak on every navigation.
44
+ */
45
+ function useAccessibilityPreference(
46
+ method: "isReduceTransparencyEnabled" | "isReduceMotionEnabled",
47
+ event: "reduceTransparencyChanged" | "reduceMotionChanged",
48
+ ): boolean {
49
+ const { AccessibilityInfo } = primitives();
50
+ const [enabled, setEnabled] = useState(false);
51
+
52
+ useEffect(() => {
53
+ if (!AccessibilityInfo) return;
54
+ let cancelled = false;
55
+
56
+ readPreference(AccessibilityInfo, method).then((value) => {
57
+ if (!cancelled) setEnabled(value);
58
+ });
59
+
60
+ let subscription: any = null;
61
+ try {
62
+ subscription = AccessibilityInfo.addEventListener?.(event, (next: boolean) => {
63
+ setEnabled(Boolean(next));
64
+ });
65
+ } catch {
66
+ // An environment without the event still gets the initial read.
67
+ }
68
+
69
+ return () => {
70
+ cancelled = true;
71
+ try {
72
+ subscription?.remove?.();
73
+ } catch {
74
+ // Nothing to clean up if subscribing failed.
75
+ }
76
+ };
77
+ }, [AccessibilityInfo, method, event]);
78
+
79
+ return enabled;
80
+ }
81
+
82
+ /**
83
+ * Whether the user has asked the system to reduce transparency.
84
+ *
85
+ * When true, a glass surface must render a solid colour rather than a
86
+ * translucent one. `GlassView` honours this on the fallback branch; on iOS 26
87
+ * the system applies its own treatment to `UIGlassEffect` and is not
88
+ * second-guessed here.
89
+ *
90
+ * The change event is iOS-only in React Native, so on Android the initial
91
+ * read is the answer.
92
+ */
93
+ export function useReducedTransparency(): boolean {
94
+ return useAccessibilityPreference("isReduceTransparencyEnabled", "reduceTransparencyChanged");
95
+ }
96
+
97
+ /**
98
+ * Whether the user has asked the system to reduce motion.
99
+ *
100
+ * Glacia's own animations settle at their end state instead of playing when
101
+ * this is true.
102
+ */
103
+ export function useReducedMotion(): boolean {
104
+ return useAccessibilityPreference("isReduceMotionEnabled", "reduceMotionChanged");
105
+ }
@@ -3,6 +3,7 @@ import type { StyleProp, ViewStyle } from "react-native";
3
3
 
4
4
  import { colors, radii } from "./tokens";
5
5
  import { primitives } from "./primitives";
6
+ import { useReducedTransparency } from "./a11y";
6
7
 
7
8
  export interface FallbackGlassProps {
8
9
  effect?: "clear" | "regular" | "none";
@@ -11,6 +12,11 @@ export interface FallbackGlassProps {
11
12
  style?: StyleProp<ViewStyle>;
12
13
  children?: ReactNode;
13
14
  isDark?: boolean;
15
+ /**
16
+ * Force the solid treatment. Normally read from the system's Reduce
17
+ * Transparency preference; this exists so a test can pin it.
18
+ */
19
+ reducedTransparency?: boolean;
14
20
  }
15
21
 
16
22
  /**
@@ -28,6 +34,7 @@ export const FallbackGlassView = forwardRef<any, FallbackGlassProps>(function Fa
28
34
  style,
29
35
  children,
30
36
  isDark = false,
37
+ reducedTransparency,
31
38
  ...props
32
39
  },
33
40
  ref,
@@ -35,8 +42,18 @@ export const FallbackGlassView = forwardRef<any, FallbackGlassProps>(function Fa
35
42
  const themeColors = isDark ? colors.dark : colors.light;
36
43
  const { View } = primitives();
37
44
 
38
- const bg =
39
- effect === "none"
45
+ // Reduce Transparency means the translucent material is replaced by a solid
46
+ // colour — the point of the preference is to remove see-through surfaces.
47
+ const systemReduced = useReducedTransparency();
48
+ const solid = reducedTransparency ?? systemReduced;
49
+
50
+ const bg = solid
51
+ ? effect === "none"
52
+ ? "transparent"
53
+ : tintColor && effect === "clear"
54
+ ? tintColor
55
+ : themeColors.glassSolid
56
+ : effect === "none"
40
57
  ? "transparent"
41
58
  : effect === "clear"
42
59
  ? isDark
@@ -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,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
+ }
@@ -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);
@@ -28,6 +28,11 @@ export interface RNPrimitives {
28
28
  Circle: any;
29
29
  Rect: any;
30
30
  Polygon: any;
31
+ /** Gradient and clipping nodes, for the colour picker's hue track. */
32
+ Defs: any;
33
+ LinearGradient: any;
34
+ Stop: any;
35
+ ClipPath: any;
31
36
  SvgText: any;
32
37
  TextInput: any;
33
38
  Modal: any;
@@ -46,6 +51,19 @@ export interface RNPrimitives {
46
51
  PanResponder: any;
47
52
  /** React Native's useColorScheme, or null outside a native runtime. */
48
53
  useColorScheme: (() => "light" | "dark" | null | undefined) | null;
54
+ /**
55
+ * React Native's AccessibilityInfo, or null outside a native runtime. Read
56
+ * for the Reduce Transparency and Reduce Motion preferences.
57
+ */
58
+ AccessibilityInfo: any;
59
+ /** React Native's Vibration, or null outside a native runtime. */
60
+ Vibration: any;
61
+ /**
62
+ * React Native's useWindowDimensions, or a fixed reader off-device. Snap
63
+ * points are fractions of the window, so the sheet needs the height before
64
+ * it can resolve them.
65
+ */
66
+ useWindowDimensions: () => { width: number; height: number };
49
67
  }
50
68
 
51
69
  /**
@@ -242,15 +260,23 @@ function resolve(): RNPrimitives {
242
260
 
243
261
  /** An image that reads its remote source in the DOM preview. */
244
262
  function imageFallback(props: any) {
245
- const { source, accessibilityLabel, style, onError } = props ?? {};
263
+ const { source, accessibilityLabel, accessibilityRole, style, onError, onLoad, testID, ...rest } = props ?? {};
246
264
  const { createElement } = require("react");
265
+ const source_ = typeof source === "number" ? undefined : source?.uri;
247
266
  return createElement("img", {
248
- src: source?.uri,
267
+ src: source_,
268
+ // `alt` covers the visible-description case; `aria-label` is what queries
269
+ // and screen readers in the preview read, so both are set.
249
270
  alt: accessibilityLabel ?? "",
271
+ "aria-label": accessibilityLabel,
272
+ "aria-role": accessibilityRole,
273
+ "data-testid": testID,
250
274
  style: toDomStyle(style),
251
- // A broken source must reach the component the same way it does on a
252
- // device, or a fallback (initials, placeholder) can never render.
275
+ // Load and error must reach the component the way they do on a device,
276
+ // or the placeholder and the fallback can never render in the preview.
253
277
  onError,
278
+ onLoad,
279
+ ...rest,
254
280
  });
255
281
  }
256
282
 
@@ -268,6 +294,10 @@ function resolve(): RNPrimitives {
268
294
  Circle: svg?.Circle ?? fallback("circle"),
269
295
  Rect: svg?.Rect ?? fallback("rect"),
270
296
  Polygon: svg?.Polygon ?? fallback("polygon"),
297
+ Defs: svg?.Defs ?? fallback("defs"),
298
+ LinearGradient: svg?.LinearGradient ?? fallback("linearGradient"),
299
+ Stop: svg?.Stop ?? fallback("stop"),
300
+ ClipPath: svg?.ClipPath ?? fallback("clipPath"),
271
301
  // TextInput is not an SVG primitive, but resolving it here keeps every
272
302
  // component on one runtime-resolution path instead of two.
273
303
  TextInput: rn?.TextInput ?? fallback("input"),
@@ -285,6 +315,19 @@ function resolve(): RNPrimitives {
285
315
  isNative: Boolean(rn?.View),
286
316
  PanResponder: rn?.PanResponder ?? panResponderShim(),
287
317
  useColorScheme: rn?.useColorScheme ?? null,
318
+ // AccessibilityInfo and Vibration are only meaningful on a device; both
319
+ // are null off it, and their callers already treat absence as "off".
320
+ AccessibilityInfo: rn?.AccessibilityInfo ?? null,
321
+ Vibration: rn?.Vibration ?? null,
322
+ // Off-device there is no window; the DOM preview reports the viewport when
323
+ // it can and a conventional phone size otherwise. Snap points are
324
+ // fractions, so any consistent height yields the same proportions.
325
+ useWindowDimensions:
326
+ rn?.useWindowDimensions ??
327
+ (() => {
328
+ const view: any = typeof globalThis !== "undefined" ? (globalThis as any).window : undefined;
329
+ return { width: view?.innerWidth ?? 390, height: view?.innerHeight ?? 800 };
330
+ }),
288
331
  };
289
332
  }
290
333
 
@@ -443,6 +486,32 @@ const LENGTH_PROPS = new Set([
443
486
  ]);
444
487
 
445
488
  /** Converts an RN style object to DOM-compatible CSS. */
489
+ /**
490
+ * Rewrites React Native's `transform` array into a CSS transform string.
491
+ *
492
+ * The preview is a browser, and a browser does not understand
493
+ * `[{ translateX: 12 }, { scale: 2 }]`; React Native's Shape controls and
494
+ * glass offsets would silently not move. Translating the entries here keeps the
495
+ * preview faithful to what a device shows.
496
+ */
497
+ function transformToCss(entries: any): string | undefined {
498
+ if (!Array.isArray(entries)) return typeof entries === "string" ? entries : undefined;
499
+ const parts: string[] = [];
500
+ for (const entry of entries) {
501
+ if (!entry || typeof entry !== "object") continue;
502
+ for (const [key, raw] of Object.entries(entry)) {
503
+ const value = typeof (raw as any)?.__getValue === "function" ? (raw as any).__getValue() : raw;
504
+ if (typeof value !== "number") continue;
505
+ if (key === "translateX") parts.push(`translateX(${value}px)`);
506
+ else if (key === "translateY") parts.push(`translateY(${value}px)`);
507
+ else if (key === "scale") parts.push(`scale(${value})`);
508
+ else if (key === "rotate") parts.push(`rotate(${value}deg)`);
509
+ else if (key === "rotateZ") parts.push(`rotateZ(${value}deg)`);
510
+ }
511
+ }
512
+ return parts.length > 0 ? parts.join(" ") : undefined;
513
+ }
514
+
446
515
  function toDomStyle(style: any): any {
447
516
  if (!style) return style;
448
517
  const list = Array.isArray(style) ? style : [style];
@@ -455,6 +524,13 @@ function toDomStyle(style: any): any {
455
524
  // Animated values resolve to plain numbers off-device.
456
525
  const resolved =
457
526
  typeof (value as any)?.interpolate === "function" ? (value as any).__getValue?.() : value;
527
+ if (key === "transform") {
528
+ const css = transformToCss(resolved);
529
+ // Only set it when there is something to say; an empty transform would
530
+ // override an earlier entry in a style array.
531
+ if (css) merged[key] = css;
532
+ continue;
533
+ }
458
534
  merged[key] =
459
535
  typeof resolved === "number" && LENGTH_PROPS.has(key) ? `${resolved}px` : resolved;
460
536
  }
@@ -28,6 +28,35 @@ export const typeScale = {
28
28
  caption: { fontSize: 12, lineHeight: 16, fontWeight: "400" as const },
29
29
  };
30
30
 
31
+ /**
32
+ * The default colour palette for ColorPicker.
33
+ *
34
+ * A palette is data, not a theme colour — it is the same twelve hues in light
35
+ * and dark — so it lives here rather than in either theme. Keeping it in the
36
+ * token module is also what lets the conformance guard require that component
37
+ * code contains no colour literal at all.
38
+ */
39
+ export const palette = {
40
+ default: [
41
+ "#FF3B30", "#FF9500", "#FFCC00", "#34C759", "#32ADE6", "#007AFF",
42
+ "#5856D6", "#AF52DE", "#FF2D55", "#A2845E", "#8E8E93", "#1C1C1E",
43
+ ],
44
+ /** The colour a picker starts on when the caller gives none. */
45
+ fallback: "#007AFF",
46
+ };
47
+
48
+ /**
49
+ * Control sizes in points, for components whose dimension is not a radius.
50
+ *
51
+ * Rating's stars are the reason this exists: a star has a size and the size
52
+ * must come from the scale rather than from a literal in the component.
53
+ */
54
+ export const controlSizes = {
55
+ star: { sm: 14, md: 20, lg: 28 },
56
+ swatch: { sm: 28, md: 36, lg: 44 },
57
+ picker: { track: 28 },
58
+ };
59
+
31
60
  /**
32
61
  * Theme colours in the form React Native accepts.
33
62
  *
@@ -54,6 +83,20 @@ export const colors = {
54
83
  // Text and icons drawn on top of a filled (tinted) surface.
55
84
  onTint: "#FFFFFF",
56
85
  skeleton: "rgba(60, 60, 67, 0.12)",
86
+ /**
87
+ * The solid colour glass becomes when the user has asked the system to
88
+ * reduce transparency. Apple's rule is that a translucent surface is
89
+ * replaced by an opaque one, not merely tinted differently.
90
+ */
91
+ glassSolid: "#F2F2F7",
92
+ /**
93
+ * Neutral colours used by pickers and fields: the field's own wash, and
94
+ * the far end of a saturation gradient (the point of no saturation).
95
+ */
96
+ fieldWash: "rgba(120, 120, 128, 0.12)",
97
+ /** A flat neutral surface: incoming message bubbles, file chips. */
98
+ wash: "rgba(120, 120, 128, 0.12)",
99
+ neutralTop: "#FFFFFF",
57
100
  // Chart axis and grid lines: low-contrast, so they never compete with data.
58
101
  axis: "#3C3C43",
59
102
  },
@@ -72,6 +115,11 @@ export const colors = {
72
115
  scrim: "rgba(0, 0, 0, 0.6)",
73
116
  onTint: "#FFFFFF",
74
117
  skeleton: "rgba(235, 235, 245, 0.14)",
118
+ glassSolid: "#1C1C1E",
119
+ fieldWash: "rgba(120, 120, 128, 0.12)",
120
+ /** A flat neutral surface: incoming message bubbles, file chips. */
121
+ wash: "rgba(120, 120, 128, 0.12)",
122
+ neutralTop: "#FFFFFF",
75
123
  axis: "#EBEBF5",
76
124
  },
77
125
  };