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
@@ -7,6 +7,11 @@ export interface FallbackGlassProps {
7
7
  style?: StyleProp<ViewStyle>;
8
8
  children?: ReactNode;
9
9
  isDark?: boolean;
10
+ /**
11
+ * Force the solid treatment. Normally read from the system's Reduce
12
+ * Transparency preference; this exists so a test can pin it.
13
+ */
14
+ reducedTransparency?: boolean;
10
15
  }
11
16
  /**
12
17
  * Glacia's own glass surface for every platform where Apple's material is not
@@ -1,5 +1,10 @@
1
1
  export interface LiquidGlassModule {
2
2
  LiquidGlassView?: any;
3
+ /**
4
+ * The container that merges nearby glass elements into one connected
5
+ * surface. Exported by `@callstack/liquid-glass` alongside the view.
6
+ */
7
+ LiquidGlassContainerView?: any;
3
8
  isLiquidGlassSupported?: boolean;
4
9
  }
5
10
  /** The routing decision for one glass surface. */
@@ -8,6 +13,11 @@ export interface GlassRouter {
8
13
  supported: boolean;
9
14
  /** Apple's `LiquidGlassView`, or null when the fallback renders instead. */
10
15
  LiquidGlassView: any;
16
+ /**
17
+ * Apple's `LiquidGlassContainerView` — the surface that merges neighbouring
18
+ * glass — or null when the fallback wrapper renders instead.
19
+ */
20
+ LiquidGlassContainerView: any;
11
21
  }
12
22
  /**
13
23
  * Reads a liquid-glass module and decides which branch renders.
@@ -0,0 +1,7 @@
1
+ /**
2
+ * One selection tick, for a control whose value just changed by one step.
3
+ *
4
+ * Silent where no haptics API is available (the DOM preview, a test run, a
5
+ * device without a vibration motor). Never throws.
6
+ */
7
+ export declare function hapticSelection(): void;
@@ -12,6 +12,10 @@ export type SpringName = keyof typeof springs;
12
12
  * on this platform. A caller that gets `animated === false` renders the target
13
13
  * directly, so the DOM preview and tests show the settled state rather than an
14
14
  * animation the environment cannot advance.
15
+ *
16
+ * Reduce Motion turns this into the same case: `animated` is false and the
17
+ * value is already at its target, so the component jumps to its end state
18
+ * rather than playing a transition the user asked not to see.
15
19
  */
16
20
  export declare function useSpring(target: number, spring?: SpringName): {
17
21
  value: any;
@@ -10,6 +10,11 @@ export interface RNPrimitives {
10
10
  Circle: any;
11
11
  Rect: any;
12
12
  Polygon: any;
13
+ /** Gradient and clipping nodes, for the colour picker's hue track. */
14
+ Defs: any;
15
+ LinearGradient: any;
16
+ Stop: any;
17
+ ClipPath: any;
13
18
  SvgText: any;
14
19
  TextInput: any;
15
20
  Modal: any;
@@ -28,6 +33,22 @@ export interface RNPrimitives {
28
33
  PanResponder: any;
29
34
  /** React Native's useColorScheme, or null outside a native runtime. */
30
35
  useColorScheme: (() => "light" | "dark" | null | undefined) | null;
36
+ /**
37
+ * React Native's AccessibilityInfo, or null outside a native runtime. Read
38
+ * for the Reduce Transparency and Reduce Motion preferences.
39
+ */
40
+ AccessibilityInfo: any;
41
+ /** React Native's Vibration, or null outside a native runtime. */
42
+ Vibration: any;
43
+ /**
44
+ * React Native's useWindowDimensions, or a fixed reader off-device. Snap
45
+ * points are fractions of the window, so the sheet needs the height before
46
+ * it can resolve them.
47
+ */
48
+ useWindowDimensions: () => {
49
+ width: number;
50
+ height: number;
51
+ };
31
52
  }
32
53
  /**
33
54
  * Records an element's width for gesture maths when the environment has no
@@ -55,6 +55,40 @@ export declare const typeScale: {
55
55
  fontWeight: "400";
56
56
  };
57
57
  };
58
+ /**
59
+ * The default colour palette for ColorPicker.
60
+ *
61
+ * A palette is data, not a theme colour — it is the same twelve hues in light
62
+ * and dark — so it lives here rather than in either theme. Keeping it in the
63
+ * token module is also what lets the conformance guard require that component
64
+ * code contains no colour literal at all.
65
+ */
66
+ export declare const palette: {
67
+ default: string[];
68
+ /** The colour a picker starts on when the caller gives none. */
69
+ fallback: string;
70
+ };
71
+ /**
72
+ * Control sizes in points, for components whose dimension is not a radius.
73
+ *
74
+ * Rating's stars are the reason this exists: a star has a size and the size
75
+ * must come from the scale rather than from a literal in the component.
76
+ */
77
+ export declare const controlSizes: {
78
+ star: {
79
+ sm: number;
80
+ md: number;
81
+ lg: number;
82
+ };
83
+ swatch: {
84
+ sm: number;
85
+ md: number;
86
+ lg: number;
87
+ };
88
+ picker: {
89
+ track: number;
90
+ };
91
+ };
58
92
  /**
59
93
  * Theme colours in the form React Native accepts.
60
94
  *
@@ -79,6 +113,20 @@ export declare const colors: {
79
113
  scrim: string;
80
114
  onTint: string;
81
115
  skeleton: string;
116
+ /**
117
+ * The solid colour glass becomes when the user has asked the system to
118
+ * reduce transparency. Apple's rule is that a translucent surface is
119
+ * replaced by an opaque one, not merely tinted differently.
120
+ */
121
+ glassSolid: string;
122
+ /**
123
+ * Neutral colours used by pickers and fields: the field's own wash, and
124
+ * the far end of a saturation gradient (the point of no saturation).
125
+ */
126
+ fieldWash: string;
127
+ /** A flat neutral surface: incoming message bubbles, file chips. */
128
+ wash: string;
129
+ neutralTop: string;
82
130
  axis: string;
83
131
  };
84
132
  dark: {
@@ -96,6 +144,11 @@ export declare const colors: {
96
144
  scrim: string;
97
145
  onTint: string;
98
146
  skeleton: string;
147
+ glassSolid: string;
148
+ fieldWash: string;
149
+ /** A flat neutral surface: incoming message bubbles, file chips. */
150
+ wash: string;
151
+ neutralTop: string;
99
152
  axis: string;
100
153
  };
101
154
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glacia-native",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Liquid Glass UI components for React Native — real iOS 26 glass, with a clean fallback on Android and older iOS.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -27,7 +27,7 @@
27
27
  "react-native-svg": ">=13"
28
28
  },
29
29
  "dependencies": {
30
- "glacia-tokens": "0.5.0"
30
+ "glacia-tokens": "0.5.1"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@testing-library/react": "^16.3.3",
package/src/Bars.tsx CHANGED
@@ -473,6 +473,15 @@ export interface AppBarProps {
473
473
  * knows its insets, and passing a number keeps this component dependency-free.
474
474
  */
475
475
  topInset?: number;
476
+ /**
477
+ * Whether content has scrolled under the bar.
478
+ *
479
+ * iOS bars sit quiet at the top of a screen and gain a defined edge once
480
+ * content passes beneath them, so the bar reads as a layer over the content
481
+ * rather than as part of it. Wire this to a ScrollView's scroll offset — see
482
+ * the component's documentation for the two-line version.
483
+ */
484
+ scrolled?: boolean;
476
485
  style?: StyleProp<ViewStyle>;
477
486
  isDark?: boolean;
478
487
  testID?: string;
@@ -483,6 +492,19 @@ export interface AppBarProps {
483
492
  *
484
493
  * A glass bar across the top of the screen with a leading action, a title and
485
494
  * trailing actions — the counterpart to the existing bottom TabBar.
495
+ *
496
+ * `scrolled` mirrors iOS 26's scroll-edge effect. At the top of the screen the
497
+ * bar is quiet: its bottom edge is invisible and the glass blends into the
498
+ * content above it. Once content has scrolled under it, the edge token becomes
499
+ * visible and the surface reads as a distinct layer — the change iOS makes when
500
+ * a navigation bar starts floating over scrolled content.
501
+ *
502
+ * ```
503
+ * const [scrolled, setScrolled] = useState(false);
504
+ * <ScrollView onScroll={(e) => setScrolled(e.nativeEvent.contentOffset.y > 8)}
505
+ * scrollEventThrottle={16}>{...}</ScrollView>
506
+ * <AppBar title="Inbox" scrolled={scrolled} />
507
+ * ```
486
508
  */
487
509
  export const AppBar = forwardRef<any, AppBarProps>(function AppBar(
488
510
  {
@@ -491,6 +513,7 @@ export const AppBar = forwardRef<any, AppBarProps>(function AppBar(
491
513
  leading,
492
514
  actions,
493
515
  topInset = 0,
516
+ scrolled = false,
494
517
  style,
495
518
  isDark: isDarkProp,
496
519
  testID,
@@ -529,6 +552,9 @@ export const AppBar = forwardRef<any, AppBarProps>(function AppBar(
529
552
  borderTopWidth: 0,
530
553
  borderLeftWidth: 0,
531
554
  borderRightWidth: 0,
555
+ // Quiet at the top of a screen, defined once content is under it: the
556
+ // bottom edge is the difference iOS draws on a scrolled navigation bar.
557
+ ...(scrolled ? { borderBottomWidth: 0.5, borderBottomColor: theme.edge } : { borderBottomWidth: 0 }),
532
558
  ...(style as ViewStyle),
533
559
  }}
534
560
  {...props}
@@ -568,3 +594,204 @@ export const AppBar = forwardRef<any, AppBarProps>(function AppBar(
568
594
  </Glass>
569
595
  );
570
596
  });
597
+
598
+ // ---------------------------------------------------------------------------
599
+ // FABGroup
600
+
601
+ export interface FABGroupAction {
602
+ /** A leading node, typically an SVG icon the caller supplies. */
603
+ icon: ReactNode;
604
+ /** The action's name, shown on its mini button. */
605
+ label: string;
606
+ onPress: () => void;
607
+ }
608
+
609
+ export interface FABGroupProps {
610
+ /** The actions, listed top to bottom as they appear when expanded. */
611
+ actions: FABGroupAction[];
612
+ /** The icon on the main button. Rotates 45° while open. */
613
+ icon: ReactNode;
614
+ /** The icon on the main button while open. Defaults to the closed one. */
615
+ closeIcon?: ReactNode;
616
+ /** Controlled open state. Omit and the group keeps its own. */
617
+ open?: boolean;
618
+ defaultOpen?: boolean;
619
+ onOpenChange?: (open: boolean) => void;
620
+ /** The main button's accessible name. */
621
+ accessibilityLabel?: string;
622
+ size?: "md" | "lg";
623
+ style?: StyleProp<ViewStyle>;
624
+ isDark?: boolean;
625
+ testID?: string;
626
+ }
627
+
628
+ // The main button's size, and the mini buttons' — both from the size scale so
629
+ // a mini button is never a hand-tuned multiple of the main one.
630
+ const fabGroupSizes = {
631
+ md: { main: 56, mini: 44 },
632
+ lg: { main: 64, mini: 52 },
633
+ };
634
+
635
+ /**
636
+ * A main button that expands into a stack of labelled mini buttons.
637
+ *
638
+ * The pattern Paper calls `FAB.Group`: one floating button stands in for a set
639
+ * of actions until it is opened, then the actions appear above it, each on its
640
+ * own glass pill with a label. A scrim behind them takes the next press and
641
+ * closes the group, which is how a floating action set gets out of the way
642
+ * without a dismissal button.
643
+ *
644
+ * The mini buttons rise on the bouncy spring with a small stagger, and the main
645
+ * button's icon rotates 45° — both settle instantly under Reduce Motion.
646
+ *
647
+ * **Merging is an iOS 26+ visual effect.** This component is one glass surface
648
+ * plus one per action; to have them blend into a single connected surface, put
649
+ * the group inside a `GlassContainer` on iOS 26. It works standalone — nothing
650
+ * depends on the container — and that composition is left to the caller rather
651
+ * than forced, because a group outside a container is the correct rendering on
652
+ * every other platform anyway.
653
+ */
654
+ export const FABGroup = forwardRef<any, FABGroupProps>(function FABGroup(
655
+ {
656
+ actions,
657
+ icon,
658
+ closeIcon,
659
+ open: openProp,
660
+ defaultOpen = false,
661
+ onOpenChange,
662
+ accessibilityLabel = "More actions",
663
+ size = "md",
664
+ style,
665
+ isDark: isDarkProp,
666
+ testID,
667
+ ...props
668
+ },
669
+ ref,
670
+ ) {
671
+ const isDark = useIsDark(isDarkProp);
672
+ const theme = isDark ? colors.dark : colors.light;
673
+ const { View, Text: RNText, Pressable, Animated } = primitives();
674
+
675
+ const [internalOpen, setInternalOpen] = useState(defaultOpen);
676
+ const open = openProp !== undefined ? openProp : internalOpen;
677
+
678
+ const setOpen = (next: boolean) => {
679
+ if (openProp === undefined) setInternalOpen(next);
680
+ onOpenChange?.(next);
681
+ };
682
+
683
+ // The stack's rise is one value: 0 closed, 1 open. The mini buttons ride it
684
+ // with their own stagger, so they follow the lead rather than all snapping
685
+ // at once.
686
+ const { value: rise, animated } = useSpring(open ? 1 : 0, "bouncy");
687
+
688
+ const { main: dimension, mini } = fabGroupSizes[size];
689
+ const closeFirst = closeIcon ?? icon;
690
+
691
+ const rotate = animated ? rise.interpolate({ inputRange: [0, 1], outputRange: ["0deg", "45deg"] }) : open ? "45deg" : "0deg";
692
+
693
+ return (
694
+ <View ref={ref} testID={testID} style={style} {...props}>
695
+ {open ? (
696
+ <Pressable
697
+ accessibilityRole="button"
698
+ accessibilityLabel="Close actions"
699
+ onPress={() => setOpen(false)}
700
+ style={{ position: "absolute", top: -2000, left: -2000, right: -2000, bottom: -2000, backgroundColor: theme.scrim }}
701
+ />
702
+ ) : null}
703
+
704
+ <View style={{ alignItems: "flex-end", gap: 10 }}>
705
+ {open
706
+ ? actions.map((action, index) => {
707
+ // Later actions sit higher, so the first is nearest the button.
708
+ const order = actions.length - 1 - index;
709
+ const translateY = animated
710
+ ? rise.interpolate({
711
+ inputRange: [0, 1],
712
+ outputRange: [24 + order * 18, 0],
713
+ })
714
+ : 0;
715
+ const opacity = animated ? rise.interpolate({ inputRange: [0, 0.4, 1], outputRange: [0, 0, 1] }) : 1;
716
+
717
+ const pill = (
718
+ <Pressable
719
+ accessibilityRole="button"
720
+ accessibilityLabel={action.label}
721
+ onPress={() => {
722
+ setOpen(false);
723
+ action.onPress();
724
+ }}
725
+ style={{ flexDirection: "row", alignItems: "center", gap: 8 }}
726
+ >
727
+ <Glass
728
+ effect="regular"
729
+ isDark={isDark}
730
+ style={{ borderRadius: radii.pill, paddingHorizontal: 12, paddingVertical: 7 }}
731
+ >
732
+ <RNText style={{ fontSize: 13, fontWeight: "600", color: theme.foreground }} numberOfLines={1}>
733
+ {action.label}
734
+ </RNText>
735
+ </Glass>
736
+ <Glass
737
+ effect="regular"
738
+ isDark={isDark}
739
+ style={{
740
+ width: mini,
741
+ height: mini,
742
+ borderRadius: mini / 2,
743
+ alignItems: "center",
744
+ justifyContent: "center",
745
+ }}
746
+ >
747
+ {action.icon}
748
+ </Glass>
749
+ </Pressable>
750
+ );
751
+
752
+ if (!animated) {
753
+ return (
754
+ <View key={`${action.label}-${index}`}>{pill}</View>
755
+ );
756
+ }
757
+
758
+ return (
759
+ <Animated.View
760
+ key={`${action.label}-${index}`}
761
+ style={{ transform: [{ translateY }], opacity }}
762
+ >
763
+ {pill}
764
+ </Animated.View>
765
+ );
766
+ })
767
+ : null}
768
+
769
+ <Pressable
770
+ accessibilityRole="button"
771
+ accessibilityLabel={accessibilityLabel}
772
+ accessibilityState={{ expanded: open }}
773
+ onPress={() => setOpen(!open)}
774
+ >
775
+ <Glass
776
+ effect="clear"
777
+ interactive
778
+ isDark={isDark}
779
+ style={{
780
+ width: dimension,
781
+ height: dimension,
782
+ borderRadius: dimension / 2,
783
+ alignItems: "center",
784
+ justifyContent: "center",
785
+ }}
786
+ >
787
+ {animated ? (
788
+ <Animated.View style={{ transform: [{ rotate }] }}>{open ? closeFirst : icon}</Animated.View>
789
+ ) : (
790
+ <View>{open ? closeFirst : icon}</View>
791
+ )}
792
+ </Glass>
793
+ </Pressable>
794
+ </View>
795
+ </View>
796
+ );
797
+ });
package/src/Display.tsx CHANGED
@@ -2,7 +2,7 @@ import { forwardRef, useEffect, useRef, useState, type ReactNode } from "react";
2
2
  import type { StyleProp, ViewStyle } from "react-native";
3
3
 
4
4
  import { Glass } from "./Glass";
5
- import { colors, radii } from "./internal/tokens";
5
+ import { colors, controlSizes, radii } from "./internal/tokens";
6
6
  import { primitives } from "./internal/primitives";
7
7
  import { useIsDark, useSpring } from "./internal/motion";
8
8
 
@@ -548,3 +548,231 @@ export const Progress = forwardRef<any, ProgressProps>(function Progress(
548
548
  </Glass>
549
549
  );
550
550
  });
551
+
552
+ // ---------------------------------------------------------------------------
553
+ // Rating
554
+
555
+ /** The five-pointed star, as a path in a unit box. */
556
+ const STAR_PATH =
557
+ "M12 2.4l2.95 5.98 6.6.96-4.78 4.66 1.13 6.57L12 17.46l-5.9 3.11 1.13-6.57L2.45 9.34l6.6-.96z";
558
+
559
+ export interface RatingProps {
560
+ /** How many stars are filled. Fractions render a partially filled star. */
561
+ value: number;
562
+ /** The number of stars. Defaults to five. */
563
+ max?: number;
564
+ size?: "sm" | "md" | "lg";
565
+ /** Makes the stars tappable. Omit for a read-only rating. */
566
+ onChange?: (value: number) => void;
567
+ disabled?: boolean;
568
+ /** The accessible name, e.g. "Rating". */
569
+ accessibilityLabel?: string;
570
+ style?: StyleProp<ViewStyle>;
571
+ isDark?: boolean;
572
+ testID?: string;
573
+ }
574
+
575
+ /**
576
+ * A star rating.
577
+ *
578
+ * The stars are drawn as SVG paths from the resolver, so nothing is a
579
+ * platform control. A fractional value fills part of a star: 3.5 draws three
580
+ * full stars and one half, the half produced by clipping the filled star at the
581
+ * fraction's width rather than by rounding — a 4.5-star average must look like
582
+ * a 4.5-star average.
583
+ *
584
+ * Read-only unless `onChange` is given. With it, each star is tappable, the
585
+ * value is exposed as an adjustable control (increment/decrement through
586
+ * accessibility actions), and each star has its own label so a screen reader
587
+ * can name the exact rating it sets.
588
+ */
589
+ export const Rating = forwardRef<any, RatingProps>(function Rating(
590
+ {
591
+ value,
592
+ max = 5,
593
+ size = "md",
594
+ onChange,
595
+ disabled = false,
596
+ accessibilityLabel = "Rating",
597
+ style,
598
+ isDark: isDarkProp,
599
+ testID,
600
+ ...props
601
+ },
602
+ ref,
603
+ ) {
604
+ const isDark = useIsDark(isDarkProp);
605
+ const theme = isDark ? colors.dark : colors.light;
606
+ const { View, Pressable, Svg, Path, Defs, ClipPath, Rect } = primitives();
607
+ const starSize = controlSizes.star[size];
608
+ const interactive = Boolean(onChange) && !disabled;
609
+ const clamped = Math.max(0, Math.min(value, max));
610
+
611
+ const setValue = (next: number) => {
612
+ const bounded = Math.max(0, Math.min(next, max));
613
+ onChange?.(bounded);
614
+ };
615
+
616
+ const star = (index: number) => {
617
+ // How much of this star is filled: 1 for a full star, 0 for empty, and the
618
+ // remainder for the one the value lands inside.
619
+ const filled = Math.max(0, Math.min(1, clamped - index));
620
+ const half = filled > 0 && filled < 1;
621
+
622
+ const glyph = (
623
+ <Svg width={starSize} height={starSize} viewBox="0 0 24 24">
624
+ {half ? (
625
+ <Defs>
626
+ {/* The clip is what makes a fractional star possible: the filled
627
+ star is cut at the fraction's width. */}
628
+ <ClipPath id={`rating-clip-${index}`}>
629
+ <Rect x="0" y="0" width={24 * filled} height={24} />
630
+ </ClipPath>
631
+ </Defs>
632
+ ) : null}
633
+ {/* The empty star is always drawn, so the shape is complete. */}
634
+ <Path d={STAR_PATH} fill={theme.separator} />
635
+ {filled > 0 ? (
636
+ <Path
637
+ d={STAR_PATH}
638
+ fill={theme.fill}
639
+ {...(half ? { clipPath: `url(#rating-clip-${index})` } : {})}
640
+ />
641
+ ) : null}
642
+ </Svg>
643
+ );
644
+
645
+ if (!interactive) return <View key={index}>{glyph}</View>;
646
+
647
+ return (
648
+ <Pressable
649
+ key={index}
650
+ accessibilityRole="button"
651
+ accessibilityLabel={`${index + 1} of ${max} stars`}
652
+ accessibilityState={{ selected: clamped === index + 1 }}
653
+ onPress={() => setValue(index + 1)}
654
+ hitSlop={4}
655
+ >
656
+ {glyph}
657
+ </Pressable>
658
+ );
659
+ };
660
+
661
+ const stars = Array.from({ length: Math.max(1, max) }, (_unused, index) => star(index));
662
+
663
+ if (!interactive && !onChange) {
664
+ return (
665
+ <View
666
+ ref={ref}
667
+ testID={testID}
668
+ accessibilityRole="text"
669
+ accessibilityLabel={`${accessibilityLabel}, ${clamped} of ${max}`}
670
+ style={{ flexDirection: "row", alignItems: "center", gap: 2, ...(style as ViewStyle) }}
671
+ {...props}
672
+ >
673
+ {stars}
674
+ </View>
675
+ );
676
+ }
677
+
678
+ return (
679
+ <View
680
+ ref={ref}
681
+ testID={testID}
682
+ accessibilityRole="adjustable"
683
+ accessibilityLabel={accessibilityLabel}
684
+ accessibilityState={{ disabled }}
685
+ accessibilityValue={{ min: 0, max, now: clamped }}
686
+ accessibilityActions={[{ name: "increment" }, { name: "decrement" }]}
687
+ onAccessibilityAction={(event: any) => {
688
+ if (disabled) return;
689
+ if (event?.nativeEvent?.actionName === "increment") setValue(clamped + 1);
690
+ if (event?.nativeEvent?.actionName === "decrement") setValue(clamped - 1);
691
+ }}
692
+ style={{ flexDirection: "row", alignItems: "center", gap: 2, opacity: disabled ? 0.38 : 1, ...(style as ViewStyle) }}
693
+ {...props}
694
+ >
695
+ {stars}
696
+ </View>
697
+ );
698
+ });
699
+
700
+ // ---------------------------------------------------------------------------
701
+ // Image
702
+
703
+ export interface NativeImageProps {
704
+ /** The image to show. */
705
+ source: { uri: string } | number;
706
+ /** A description for screen readers. Required: an image with no name is a hole. */
707
+ accessibilityLabel: string;
708
+ /** Shown behind the image while it loads; a Skeleton when omitted. */
709
+ placeholder?: ReactNode;
710
+ /** Shown when the image fails to load. */
711
+ fallback?: ReactNode;
712
+ /** Fades the image in when it loads. Honours Reduce Motion. */
713
+ fadeIn?: boolean;
714
+ style?: StyleProp<ViewStyle>;
715
+ isDark?: boolean;
716
+ testID?: string;
717
+ }
718
+
719
+ /**
720
+ * A plain image, with the loading and error states every app ends up writing.
721
+ *
722
+ * Three states, because an image on a phone is three states: loading (a
723
+ * Skeleton behind it), loaded (a fade in), and failed (the caller's fallback).
724
+ * Aspect ratio comes from `style`, so a caller sets `aspectRatio` and the height
725
+ * follows.
726
+ *
727
+ * This is the plain one; `NativeImageGeneration` is the AI-specific cousin and
728
+ * keeps its own state machine.
729
+ */
730
+ export const NativeImage = forwardRef<any, NativeImageProps>(function NativeImage(
731
+ {
732
+ source,
733
+ accessibilityLabel,
734
+ placeholder,
735
+ fallback,
736
+ fadeIn = true,
737
+ style,
738
+ isDark: isDarkProp,
739
+ testID,
740
+ ...props
741
+ },
742
+ ref,
743
+ ) {
744
+ const isDark = useIsDark(isDarkProp);
745
+ const { View, Image: RNImage, Animated } = primitives();
746
+ const [failed, setFailed] = useState(false);
747
+ const [loaded, setLoaded] = useState(false);
748
+ const { value: fade, animated } = useSpring(loaded ? 1 : 0, "gentle");
749
+
750
+ const boxStyle: ViewStyle = { overflow: "hidden", ...(style as ViewStyle) };
751
+
752
+ if (failed && fallback) {
753
+ return (
754
+ <View ref={ref} testID={testID} style={boxStyle} {...props}>
755
+ {fallback}
756
+ </View>
757
+ );
758
+ }
759
+
760
+ const imageStyle: ViewStyle = { width: "100%", height: "100%" };
761
+ const opacity = fadeIn && animated ? fade : 1;
762
+
763
+ return (
764
+ <View ref={ref} testID={testID} style={boxStyle} {...props}>
765
+ {/* The placeholder sits under the image, so the box never collapses and
766
+ the fade reveals rather than jumps. */}
767
+ {!loaded ? <View style={{ position: "absolute", top: 0, left: 0, right: 0, bottom: 0 }}>{placeholder ?? <Skeleton shape="rect" isDark={isDark} />}</View> : null}
768
+ <RNImage
769
+ accessibilityRole="image"
770
+ accessibilityLabel={accessibilityLabel}
771
+ source={source}
772
+ onLoad={() => setLoaded(true)}
773
+ onError={() => setFailed(true)}
774
+ style={[imageStyle, animated ? { opacity } : null]}
775
+ />
776
+ </View>
777
+ );
778
+ });