@marktiderman/genesis-ui-native 2.1.0 → 2.3.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 (82) hide show
  1. package/README.md +134 -0
  2. package/dist/chunk-7PCWEY6R.js +27 -0
  3. package/dist/chunk-7PCWEY6R.js.map +1 -0
  4. package/dist/chunk-D5RKSPMH.js +24 -0
  5. package/dist/chunk-D5RKSPMH.js.map +1 -0
  6. package/dist/{chunk-5HRGIA6F.js → chunk-EFXCJ5AN.js} +76 -3
  7. package/dist/chunk-EFXCJ5AN.js.map +1 -0
  8. package/dist/{chunk-ULS7I6ZS.js → chunk-ERHGCWTY.js} +81 -12
  9. package/dist/chunk-ERHGCWTY.js.map +1 -0
  10. package/dist/{chunk-3LK5ZJ4M.js → chunk-FIITITXO.js} +67 -108
  11. package/dist/chunk-FIITITXO.js.map +1 -0
  12. package/dist/chunk-FZY2IXOX.js +1559 -0
  13. package/dist/chunk-FZY2IXOX.js.map +1 -0
  14. package/dist/{chunk-TXJT55JC.js → chunk-W7BK3ARU.js} +715 -293
  15. package/dist/chunk-W7BK3ARU.js.map +1 -0
  16. package/dist/components/index.d.ts +143 -17
  17. package/dist/components/index.js +6 -4
  18. package/dist/data/index.d.ts +7 -1
  19. package/dist/data/index.js +31 -6
  20. package/dist/data/index.js.map +1 -1
  21. package/dist/hooks/index.js +2 -1
  22. package/dist/icons/lucide.d.ts +7 -0
  23. package/dist/icons/lucide.js +47 -0
  24. package/dist/icons/lucide.js.map +1 -0
  25. package/dist/index.d.ts +3 -2
  26. package/dist/index.js +7 -6
  27. package/dist/layouts/index.d.ts +399 -7
  28. package/dist/layouts/index.js +3 -3
  29. package/dist/native-modules-BSVaEb3D.d.ts +206 -0
  30. package/package.json +34 -5
  31. package/src/__tests__/fake-modules.tsx +134 -0
  32. package/src/__tests__/native-modules-lists.test.tsx +70 -0
  33. package/src/__tests__/native-modules.test.tsx +631 -0
  34. package/src/components/__tests__/sheet.test.tsx +193 -0
  35. package/src/components/__tests__/toast.test.tsx +15 -0
  36. package/src/components/avatar.tsx +69 -16
  37. package/src/components/date-time-picker.tsx +128 -10
  38. package/src/components/drawer.tsx +158 -68
  39. package/src/components/dropdown-menu.tsx +7 -6
  40. package/src/components/glass-surface.tsx +150 -0
  41. package/src/components/icon.tsx +66 -0
  42. package/src/components/image.tsx +89 -0
  43. package/src/components/index.ts +33 -2
  44. package/src/components/list-item.tsx +29 -9
  45. package/src/components/popover.tsx +12 -9
  46. package/src/components/segmented-control.tsx +7 -1
  47. package/src/components/sheet.tsx +276 -133
  48. package/src/components/skeleton.tsx +75 -53
  49. package/src/components/textarea.tsx +1 -0
  50. package/src/components/toast.tsx +185 -87
  51. package/src/data/NativeResourcePage.tsx +48 -3
  52. package/src/data/__tests__/resource-page-offline.test.tsx +47 -0
  53. package/src/hooks/use-reduced-motion.ts +24 -10
  54. package/src/icon-names.ts +49 -0
  55. package/src/icons/lucide.ts +88 -0
  56. package/src/layouts/__tests__/apple-sign-in.test.tsx +97 -0
  57. package/src/layouts/__tests__/google-sign-in.test.tsx +26 -0
  58. package/src/layouts/__tests__/inbox-page.test.tsx +155 -0
  59. package/src/layouts/__tests__/keyboard-scroll.test.tsx +42 -1
  60. package/src/layouts/__tests__/settings-page-native-look.test.tsx +142 -0
  61. package/src/layouts/__tests__/thread-page.test.tsx +128 -0
  62. package/src/layouts/apple-sign-in.tsx +136 -0
  63. package/src/layouts/auth-screen.tsx +17 -8
  64. package/src/layouts/auth.tsx +29 -19
  65. package/src/layouts/google-sign-in.tsx +42 -0
  66. package/src/layouts/inbox-page.tsx +408 -0
  67. package/src/layouts/index.ts +45 -2
  68. package/src/layouts/keyboard.tsx +61 -9
  69. package/src/layouts/notifications-page.tsx +133 -16
  70. package/src/layouts/screen-container.tsx +6 -2
  71. package/src/layouts/settings-page.tsx +117 -14
  72. package/src/layouts/settings-sub-page.tsx +9 -3
  73. package/src/layouts/thread-page.tsx +444 -0
  74. package/src/native-modules.tsx +186 -0
  75. package/dist/chunk-3LK5ZJ4M.js.map +0 -1
  76. package/dist/chunk-5HRGIA6F.js.map +0 -1
  77. package/dist/chunk-F2TGDKOO.js +0 -43
  78. package/dist/chunk-F2TGDKOO.js.map +0 -1
  79. package/dist/chunk-TXJT55JC.js.map +0 -1
  80. package/dist/chunk-U2SPACTV.js +0 -876
  81. package/dist/chunk-U2SPACTV.js.map +0 -1
  82. package/dist/chunk-ULS7I6ZS.js.map +0 -1
@@ -8,11 +8,15 @@
8
8
  * For full-screen modal flows, prefer a navigation route. For a single
9
9
  * action confirmation, prefer <NativeDialog>.
10
10
  *
11
+ * Slides with Reanimated 4 when the app passes it (`modules.reanimated` on
12
+ * `GenesisModulesProvider`), else with React Native's Animated. Under Reduce
13
+ * Motion it appears in place. The swipe uses React Native's PanResponder in
14
+ * both, so it needs no react-native-gesture-handler.
15
+ *
11
16
  * @stability Beta
12
17
  */
13
- import { useEffect, useMemo, useRef, useState } from "react";
18
+ import { useCallback, useContext, useEffect, useMemo, useRef } from "react";
14
19
  import {
15
- AccessibilityInfo,
16
20
  Animated,
17
21
  Dimensions,
18
22
  Modal,
@@ -20,7 +24,10 @@ import {
20
24
  Pressable,
21
25
  View,
22
26
  } from "react-native";
27
+ import { SafeAreaInsetsContext } from "react-native-safe-area-context";
23
28
  import { cn } from "../utils";
29
+ import { useReducedMotion } from "../hooks/use-reduced-motion";
30
+ import { useGenesisModules, type GenesisReanimatedModule } from "../native-modules";
24
31
 
25
32
  export interface NativeDrawerProps {
26
33
  open: boolean;
@@ -34,63 +41,135 @@ export interface NativeDrawerProps {
34
41
  testID?: string;
35
42
  }
36
43
 
37
- export function NativeDrawer({
38
- open,
39
- onOpenChange,
40
- side = "left",
41
- width,
42
- children,
43
- className,
44
- testID,
45
- }: NativeDrawerProps) {
46
- const screen = Dimensions.get("window");
47
- const drawerWidth = width ?? Math.min(screen.width * 0.8, 360);
48
- const [reducedMotion, setReducedMotion] = useState(false);
49
- const translate = useRef(new Animated.Value(side === "left" ? -drawerWidth : drawerWidth)).current;
44
+ const OPEN_MS = 220;
45
+ const SETTLE_MS = 180;
50
46
 
51
- useEffect(() => {
52
- AccessibilityInfo.isReduceMotionEnabled().then(setReducedMotion);
53
- }, []);
47
+ export function NativeDrawer(props: NativeDrawerProps) {
48
+ const { reanimated } = useGenesisModules();
49
+ return reanimated ? <ReanimatedDrawer {...props} reanimated={reanimated} /> : <AnimatedDrawer {...props} />;
50
+ }
54
51
 
55
- useEffect(() => {
56
- Animated.timing(translate, {
57
- toValue: open ? 0 : side === "left" ? -drawerWidth : drawerWidth,
58
- duration: reducedMotion ? 0 : 220,
59
- useNativeDriver: true,
60
- }).start();
61
- }, [drawerWidth, open, reducedMotion, side, translate]);
52
+ /** Where the panel rests when closed: just off its edge. */
53
+ function closedOffset(side: "left" | "right", width: number) {
54
+ return side === "left" ? -width : width;
55
+ }
62
56
 
57
+ /** A horizontal drag toward the panel's edge: follow it, then dismiss past a third. */
58
+ function useSwipe(
59
+ side: "left" | "right",
60
+ drawerWidth: number,
61
+ onOpenChange: (open: boolean) => void,
62
+ follow: (dx: number) => void,
63
+ settle: () => void
64
+ ) {
63
65
  // useMemo (not useRef.current) so the responder always closes over the
64
66
  // current `side` / `drawerWidth` / `onOpenChange` values. Otherwise the
65
67
  // gesture handler keeps reading mount-time values forever.
66
- const panResponder = useMemo(
68
+ return useMemo(
67
69
  () =>
68
70
  PanResponder.create({
69
71
  onMoveShouldSetPanResponder: (_, g) => Math.abs(g.dx) > 8,
70
- onPanResponderMove: (_, g) => {
71
- if (side === "left") {
72
- translate.setValue(Math.min(0, g.dx));
73
- } else {
74
- translate.setValue(Math.max(0, g.dx));
75
- }
76
- },
72
+ onPanResponderMove: (_, g) => follow(side === "left" ? Math.min(0, g.dx) : Math.max(0, g.dx)),
77
73
  onPanResponderRelease: (_, g) => {
78
- const dismiss =
79
- side === "left" ? g.dx < -drawerWidth / 3 : g.dx > drawerWidth / 3;
80
- if (dismiss) {
81
- onOpenChange(false);
82
- } else {
83
- Animated.timing(translate, {
84
- toValue: 0,
85
- duration: 180,
86
- useNativeDriver: true,
87
- }).start();
88
- }
74
+ const dismiss = side === "left" ? g.dx < -drawerWidth / 3 : g.dx > drawerWidth / 3;
75
+ if (dismiss) onOpenChange(false);
76
+ else settle();
89
77
  },
78
+ // Another responder (a horizontal scroll inside, a system gesture)
79
+ // took the drag: put the panel back rather than leave it half open.
80
+ onPanResponderTerminate: () => settle(),
90
81
  }),
91
- [drawerWidth, onOpenChange, side, translate]
82
+ [drawerWidth, follow, onOpenChange, settle, side]
92
83
  );
84
+ }
85
+
86
+ function ReanimatedDrawer({ reanimated: R, ...props }: NativeDrawerProps & { reanimated: GenesisReanimatedModule }) {
87
+ const { open, side = "left", width } = props;
88
+ const drawerWidth = width ?? Math.min(Dimensions.get("window").width * 0.8, 360);
89
+ const reducedMotion = useReducedMotion();
90
+ const translate = R.useSharedValue(closedOffset(side, drawerWidth));
91
+
92
+ useEffect(() => {
93
+ const to = open ? 0 : closedOffset(side, drawerWidth);
94
+ translate.value = reducedMotion ? to : R.withTiming(to, { duration: OPEN_MS });
95
+ // eslint-disable-next-line react-hooks/exhaustive-deps
96
+ }, [drawerWidth, open, reducedMotion, side]);
97
+
98
+ // `translate` and `R` are stable for the component's life.
99
+ const follow = useCallback((dx: number) => {
100
+ translate.value = dx;
101
+ // eslint-disable-next-line react-hooks/exhaustive-deps
102
+ }, []);
103
+ const settle = useCallback(() => {
104
+ translate.value = reducedMotion ? 0 : R.withTiming(0, { duration: SETTLE_MS });
105
+ // eslint-disable-next-line react-hooks/exhaustive-deps
106
+ }, [reducedMotion]);
107
+ const panResponder = useSwipe(side, drawerWidth, props.onOpenChange, follow, settle);
108
+ const animatedStyle = R.useAnimatedStyle(() => {
109
+ "worklet";
110
+ return { transform: [{ translateX: translate.value }] };
111
+ });
93
112
 
113
+ return <DrawerFrame {...props} side={side} drawerWidth={drawerWidth} Panel={R.default.View} panelStyle={animatedStyle} panHandlers={panResponder.panHandlers} />;
114
+ }
115
+
116
+ function AnimatedDrawer(props: NativeDrawerProps) {
117
+ const { open, side = "left", width } = props;
118
+ const drawerWidth = width ?? Math.min(Dimensions.get("window").width * 0.8, 360);
119
+ const reducedMotion = useReducedMotion();
120
+ const translate = useRef(new Animated.Value(closedOffset(side, drawerWidth))).current;
121
+
122
+ useEffect(() => {
123
+ Animated.timing(translate, {
124
+ toValue: open ? 0 : closedOffset(side, drawerWidth),
125
+ duration: reducedMotion ? 0 : OPEN_MS,
126
+ useNativeDriver: true,
127
+ }).start();
128
+ }, [drawerWidth, open, reducedMotion, side, translate]);
129
+
130
+ const follow = useCallback((dx: number) => translate.setValue(dx), [translate]);
131
+ const settle = useCallback(
132
+ () =>
133
+ Animated.timing(translate, {
134
+ toValue: 0,
135
+ duration: reducedMotion ? 0 : SETTLE_MS,
136
+ useNativeDriver: true,
137
+ }).start(),
138
+ [reducedMotion, translate]
139
+ );
140
+ const panResponder = useSwipe(side, drawerWidth, props.onOpenChange, follow, settle);
141
+
142
+ return (
143
+ <DrawerFrame
144
+ {...props}
145
+ side={side}
146
+ drawerWidth={drawerWidth}
147
+ Panel={Animated.View}
148
+ panelStyle={{ transform: [{ translateX: translate }] }}
149
+ panHandlers={panResponder.panHandlers}
150
+ />
151
+ );
152
+ }
153
+
154
+ function DrawerFrame({
155
+ open,
156
+ onOpenChange,
157
+ side,
158
+ drawerWidth,
159
+ children,
160
+ className,
161
+ testID,
162
+ Panel,
163
+ panelStyle,
164
+ panHandlers,
165
+ }: NativeDrawerProps & {
166
+ side: "left" | "right";
167
+ drawerWidth: number;
168
+ Panel: React.ComponentType<any>;
169
+ panelStyle: unknown;
170
+ panHandlers: unknown;
171
+ }) {
172
+ const insets = useContext(SafeAreaInsetsContext);
94
173
  return (
95
174
  <Modal
96
175
  visible={open}
@@ -98,34 +177,45 @@ export function NativeDrawer({
98
177
  animationType="none"
99
178
  onRequestClose={() => onOpenChange(false)}
100
179
  >
101
- <Pressable
102
- accessibilityLabel="Close drawer"
103
- className="flex-1 bg-black/40"
104
- onPress={() => onOpenChange(false)}
105
- >
106
- <Pressable onPress={() => {}} style={{ flex: 1 }}>
107
- <Animated.View
108
- testID={testID ?? "native-drawer"}
109
- accessibilityViewIsModal
110
- {...panResponder.panHandlers}
111
- style={{
180
+ {/* The backdrop and the panel are siblings: a tap on the backdrop closes,
181
+ a tap on the panel stays in it. (A full-screen pressable around the
182
+ panel used to swallow every backdrop tap.) */}
183
+ <View style={{ flex: 1 }}>
184
+ <Pressable
185
+ testID={`${testID ?? "native-drawer"}-backdrop`}
186
+ accessibilityRole="button"
187
+ accessibilityLabel="Close drawer"
188
+ className="bg-black/40"
189
+ style={{ position: "absolute", top: 0, right: 0, bottom: 0, left: 0 }}
190
+ onPress={() => onOpenChange(false)}
191
+ />
192
+ <Panel
193
+ testID={testID ?? "native-drawer"}
194
+ accessibilityViewIsModal
195
+ {...(panHandlers as object)}
196
+ style={[
197
+ {
112
198
  position: "absolute",
113
199
  top: 0,
114
200
  bottom: 0,
115
201
  [side]: 0,
116
202
  width: drawerWidth,
117
- transform: [{ translateX: translate }],
118
- }}
119
- className={cn(
120
- "border-border bg-background p-4 shadow-lg",
121
- side === "left" ? "border-r" : "border-l",
122
- className
123
- )}
124
- >
125
- <View className="flex-1">{children}</View>
126
- </Animated.View>
127
- </Pressable>
128
- </Pressable>
203
+ },
204
+ panelStyle,
205
+ ]}
206
+ className={cn(
207
+ "border-border bg-background p-4 shadow-lg",
208
+ side === "left" ? "border-r" : "border-l",
209
+ className
210
+ )}
211
+ >
212
+ {/* Clear of the status bar and home indicator: the app's insets (a
213
+ Modal has no SafeAreaProvider of its own), none without one. */}
214
+ <View className="flex-1" style={{ paddingTop: insets?.top ?? 0, paddingBottom: insets?.bottom ?? 0 }}>
215
+ {children}
216
+ </View>
217
+ </Panel>
218
+ </View>
129
219
  </Modal>
130
220
  );
131
221
  }
@@ -6,6 +6,7 @@
6
6
  import React, { createContext, useContext, useState } from "react";
7
7
  import { Modal, Pressable, Text, View } from "react-native";
8
8
  import { cn } from "../utils";
9
+ import { NativeGlassSurface } from "./glass-surface";
9
10
 
10
11
  interface DropdownMenuContextValue {
11
12
  open: boolean;
@@ -73,14 +74,14 @@ function NativeDropdownMenuContent({
73
74
  <View className="flex-1 items-center justify-center">
74
75
  {/* Captures touch to prevent backdrop press from closing menu when tapping content */}
75
76
  <Pressable onPress={() => {}}>
76
- <View
77
- className={cn(
78
- "min-w-[8rem] rounded-md border border-border bg-popover p-1 shadow-md",
79
- className
80
- )}
77
+ {/* Liquid Glass on iOS 26 with `modules.glass`; the popover surface otherwise. */}
78
+ <NativeGlassSurface
79
+ radius={14}
80
+ fallbackClassName="rounded-md border border-border bg-popover shadow-md"
81
+ className={cn("min-w-[8rem] p-1", className)}
81
82
  >
82
83
  {children}
83
- </View>
84
+ </NativeGlassSurface>
84
85
  </Pressable>
85
86
  </View>
86
87
  </Pressable>
@@ -0,0 +1,150 @@
1
+ /**
2
+ * NativeGlassSurface — a floating surface (toast, banner, floating bar) drawn
3
+ * as iOS 26 Liquid Glass when it can be, and as the solid surface it always
4
+ * was otherwise.
5
+ *
6
+ * Glass needs all of: iOS; expo-glass-effect passed as `modules.glass`;
7
+ * `isLiquidGlassAvailable()` (the app was built with the iOS 26 SDK and the
8
+ * device runs it) and `isGlassEffectAPIAvailable()` (the API exists at run
9
+ * time; some iOS 26 betas lack it) both true; and Reduce Transparency off.
10
+ * Otherwise `fallbackClassName` paints the surface.
11
+ *
12
+ * @stability Beta
13
+ */
14
+ import { useEffect, useState, type ReactNode } from "react";
15
+ import { AccessibilityInfo, Platform, View } from "react-native";
16
+ import { cn } from "../utils";
17
+ import { useGenesisModules, type GenesisGlassModule } from "../native-modules";
18
+ import { useThemeMode } from "../hooks/use-theme-mode";
19
+
20
+ const availability = new WeakMap<GenesisGlassModule, boolean>();
21
+
22
+ function glassAvailable(glass: GenesisGlassModule): boolean {
23
+ const known = availability.get(glass);
24
+ if (known !== undefined) return known;
25
+ let ok = false;
26
+ if (typeof glass.isLiquidGlassAvailable !== "function" || typeof glass.isGlassEffectAPIAvailable !== "function" || !glass.GlassView) {
27
+ // An expo-glass-effect without both checks (or not the module namespace)
28
+ // can't say glass is safe to draw: stay solid, and say why.
29
+ warnDev(
30
+ "[genesis] modules.glass needs expo-glass-effect's GlassView, isLiquidGlassAvailable and isGlassEffectAPIAvailable (pass `import * as GlassEffect from \"expo-glass-effect\"`, SDK 54 or later). Surfaces stay solid.",
31
+ );
32
+ } else {
33
+ try {
34
+ ok = Boolean(glass.isLiquidGlassAvailable()) && Boolean(glass.isGlassEffectAPIAvailable());
35
+ } catch {
36
+ ok = false;
37
+ }
38
+ }
39
+ availability.set(glass, ok);
40
+ return ok;
41
+ }
42
+
43
+ declare const __DEV__: boolean | undefined;
44
+
45
+ function warnDev(message: string) {
46
+ if (typeof __DEV__ !== "undefined" && __DEV__) console.warn(message);
47
+ }
48
+
49
+ // The last answer anyone got. Until the first one, the setting is unknown and
50
+ // surfaces stay solid, so nobody with Reduce Transparency on sees glass for a
51
+ // frame; after it, a toast or popover that mounts later starts from it.
52
+ let lastKnownReduceTransparency: boolean | null = null;
53
+
54
+ /** Tests only: forget the last answer. Not exported from the package. */
55
+ export function __resetReduceTransparency() {
56
+ lastKnownReduceTransparency = null;
57
+ }
58
+
59
+ /**
60
+ * True while the user has Reduce Transparency on (iOS), `null` until the
61
+ * first answer. Always false elsewhere, and on a runtime that can't say.
62
+ */
63
+ export function useReduceTransparency(): boolean | null {
64
+ const canAsk = Platform.OS === "ios" && typeof AccessibilityInfo.isReduceTransparencyEnabled === "function";
65
+ const [reduced, setReduced] = useState<boolean | null>(canAsk ? lastKnownReduceTransparency : false);
66
+ useEffect(() => {
67
+ if (!canAsk || typeof AccessibilityInfo.isReduceTransparencyEnabled !== "function") return undefined;
68
+ let mounted = true;
69
+ const set = (v: boolean) => {
70
+ lastKnownReduceTransparency = v;
71
+ if (mounted) setReduced(v);
72
+ };
73
+ AccessibilityInfo.isReduceTransparencyEnabled()
74
+ .then(set)
75
+ // Can't tell: draw glass, as iOS does by default.
76
+ .catch(() => set(false));
77
+ const sub = AccessibilityInfo.addEventListener?.("reduceTransparencyChanged", set);
78
+ return () => {
79
+ mounted = false;
80
+ sub?.remove?.();
81
+ };
82
+ // eslint-disable-next-line react-hooks/exhaustive-deps
83
+ }, []);
84
+ return reduced;
85
+ }
86
+
87
+ /** expo-glass-effect's `GlassView` when Liquid Glass can be drawn here, else `null`. */
88
+ export function useLiquidGlass(): GenesisGlassModule["GlassView"] | null {
89
+ const { glass } = useGenesisModules();
90
+ const reduceTransparency = useReduceTransparency();
91
+ // Solid until Reduce Transparency is known to be off.
92
+ if (Platform.OS !== "ios" || !glass || reduceTransparency !== false) return null;
93
+ return glassAvailable(glass) ? glass.GlassView : null;
94
+ }
95
+
96
+ export interface NativeGlassSurfaceProps {
97
+ children?: ReactNode;
98
+ /**
99
+ * Layout classes (padding, gap, width). Without glass they merge with
100
+ * `fallbackClassName` on one view, so they can override it (`rounded-*`,
101
+ * `bg-*`). On glass they go on the view inside the glass: the glass's shape
102
+ * comes from `radius` alone, and a `bg-*` here paints over the glass.
103
+ */
104
+ className?: string;
105
+ /** The solid look when glass can't be drawn, radius included. Default `"rounded-xl border border-border bg-card"`. */
106
+ fallbackClassName?: string;
107
+ /** The glass's corner radius in points. Default 16. */
108
+ radius?: number;
109
+ /** Glass tint (a color string). */
110
+ tintColor?: string;
111
+ /** Glass reacts to touch. Default false. */
112
+ interactive?: boolean;
113
+ /** Default `"regular"`. */
114
+ glassEffectStyle?: "regular" | "clear";
115
+ testID?: string;
116
+ }
117
+
118
+ export function NativeGlassSurface({
119
+ children,
120
+ className,
121
+ fallbackClassName = "rounded-xl border border-border bg-card",
122
+ radius = 16,
123
+ tintColor,
124
+ interactive = false,
125
+ glassEffectStyle = "regular",
126
+ testID,
127
+ }: NativeGlassSurfaceProps) {
128
+ const GlassView = useLiquidGlass();
129
+ // The app's scheme, not the system's, so the glass matches the text on it.
130
+ const colorScheme = useThemeMode();
131
+ if (GlassView) {
132
+ return (
133
+ <GlassView
134
+ testID={testID}
135
+ style={{ borderRadius: radius, overflow: "hidden" }}
136
+ glassEffectStyle={glassEffectStyle}
137
+ colorScheme={colorScheme}
138
+ tintColor={tintColor}
139
+ isInteractive={interactive}
140
+ >
141
+ <View className={className}>{children}</View>
142
+ </GlassView>
143
+ );
144
+ }
145
+ return (
146
+ <View testID={testID} className={cn(fallbackClassName, className)}>
147
+ {children}
148
+ </View>
149
+ );
150
+ }
@@ -0,0 +1,66 @@
1
+ /**
2
+ * NativeIcon — an icon by what it is for ("settings", "bell"), not by a
3
+ * library's name. On iOS it draws the SF Symbol (expo-symbols' `SymbolView`,
4
+ * passed as `modules.symbol`); on Android and web, and as the SF Symbol's
5
+ * fallback, it draws the icon set given as `modules.icons` (`lucideIcons`
6
+ * from `@marktiderman/genesis-ui-native/icons/lucide`). With neither, it
7
+ * keeps the icon's space empty and warns once in development.
8
+ *
9
+ * Decorative by default (hidden from screen readers). Give `label` when the
10
+ * icon carries meaning on its own, such as an icon-only button's content.
11
+ *
12
+ * @stability Beta
13
+ */
14
+ import { Platform, View, type ColorValue } from "react-native";
15
+ import { useThemeRoles } from "../hooks/use-theme-roles";
16
+ import { SF_SYMBOLS, type NativeIconName } from "../icon-names";
17
+ import { useGenesisModules } from "../native-modules";
18
+
19
+ export interface NativeIconProps {
20
+ name: NativeIconName;
21
+ /** Points. Default 20. */
22
+ size?: number;
23
+ /** Default the theme's label color. */
24
+ color?: ColorValue;
25
+ /** iOS SF Symbol weight. */
26
+ weight?: "ultraLight" | "thin" | "light" | "regular" | "medium" | "semibold" | "bold" | "heavy" | "black";
27
+ /** Read by screen readers. Without it the icon is decorative and hidden from them. */
28
+ label?: string;
29
+ testID?: string;
30
+ }
31
+
32
+ declare const __DEV__: boolean | undefined;
33
+ const warned = new Set<string>();
34
+
35
+ function warnOnce(name: string) {
36
+ if (typeof __DEV__ === "undefined" || !__DEV__ || warned.has(name)) return;
37
+ warned.add(name);
38
+ console.warn(
39
+ `[genesis] NativeIcon "${name}" has nothing to draw with: pass modules.icons (lucideIcons from "@marktiderman/genesis-ui-native/icons/lucide") and, for SF Symbols on iOS, modules.symbol (SymbolView from "expo-symbols") to GenesisModulesProvider.`,
40
+ );
41
+ }
42
+
43
+ export function NativeIcon({ name, size = 20, color, weight, label, testID }: NativeIconProps) {
44
+ const { symbol: SymbolView, icons } = useGenesisModules();
45
+ const roles = useThemeRoles();
46
+ const tint = color ?? roles.label;
47
+ const a11y = label
48
+ ? { accessible: true, accessibilityRole: "image" as const, accessibilityLabel: label }
49
+ : { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants" as const };
50
+ const Fallback = icons?.[name];
51
+ const fallback = Fallback ? <Fallback size={size} color={tint} testID={testID ? `${testID}-fallback` : undefined} /> : null;
52
+
53
+ if (Platform.OS === "ios" && SymbolView) {
54
+ return (
55
+ <View {...a11y} testID={testID} style={{ width: size, height: size }}>
56
+ <SymbolView name={SF_SYMBOLS[name]} size={size} tintColor={tint} weight={weight} fallback={fallback} style={{ width: size, height: size }} />
57
+ </View>
58
+ );
59
+ }
60
+ if (!fallback) warnOnce(name);
61
+ return (
62
+ <View {...a11y} testID={testID} style={{ width: size, height: size, alignItems: "center", justifyContent: "center" }}>
63
+ {fallback}
64
+ </View>
65
+ );
66
+ }
@@ -0,0 +1,89 @@
1
+ /**
2
+ * NativeImage — a remote picture (thumbnail, cover, photo) with caching.
3
+ *
4
+ * Draws with expo-image when the app passes it (`modules.image` on
5
+ * `GenesisModulesProvider`): cached in memory and on disk, an optional
6
+ * blurhash/thumbhash `placeholder`, a cross-fade that Reduce Motion turns
7
+ * off, and a `recyclingKey` (the URL by default) so a recycled FlashList row
8
+ * never flashes the previous picture. Without it, React Native's `Image`.
9
+ *
10
+ * Give it a size (className or `width`/`height`). Decorative unless `alt` is
11
+ * given.
12
+ *
13
+ * @stability Beta
14
+ */
15
+ import { Image, View } from "react-native";
16
+ import { cn } from "../utils";
17
+ import { useReducedMotion } from "../hooks/use-reduced-motion";
18
+ import { useGenesisModules } from "../native-modules";
19
+
20
+ export interface NativeImageProps {
21
+ src: string;
22
+ /** Read by screen readers. Without it the picture is decorative. */
23
+ alt?: string;
24
+ className?: string;
25
+ width?: number;
26
+ height?: number;
27
+ /** Default `"cover"`. */
28
+ contentFit?: "cover" | "contain";
29
+ /** expo-image only: `{ blurhash }` or `{ thumbhash }` shown while loading. */
30
+ placeholder?: { blurhash: string } | { thumbhash: string };
31
+ /** expo-image only: resets the view when it changes (recycled rows). Default `src`. */
32
+ recyclingKey?: string;
33
+ /** expo-image only: load order among images. */
34
+ priority?: "low" | "normal" | "high";
35
+ testID?: string;
36
+ }
37
+
38
+ const FILL = { position: "absolute" as const, top: 0, right: 0, bottom: 0, left: 0 };
39
+
40
+ export function NativeImage({
41
+ src,
42
+ alt,
43
+ className,
44
+ width,
45
+ height,
46
+ contentFit = "cover",
47
+ placeholder,
48
+ recyclingKey,
49
+ priority,
50
+ testID,
51
+ }: NativeImageProps) {
52
+ const { image: ExpoImage } = useGenesisModules();
53
+ const reducedMotion = useReducedMotion();
54
+ const a11y = alt
55
+ ? { accessible: true, accessibilityRole: "image" as const, accessibilityLabel: alt }
56
+ : { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants" as const };
57
+ return (
58
+ <View
59
+ {...a11y}
60
+ testID={testID}
61
+ className={cn("overflow-hidden bg-muted", className)}
62
+ style={width !== undefined || height !== undefined ? { width, height } : undefined}
63
+ >
64
+ {ExpoImage ? (
65
+ <ExpoImage
66
+ testID={testID ? `${testID}-image` : undefined}
67
+ accessible={false}
68
+ source={{ uri: src }}
69
+ style={FILL}
70
+ contentFit={contentFit}
71
+ cachePolicy="memory-disk"
72
+ placeholder={placeholder}
73
+ placeholderContentFit={contentFit}
74
+ transition={reducedMotion ? null : 150}
75
+ recyclingKey={recyclingKey ?? src}
76
+ priority={priority}
77
+ />
78
+ ) : (
79
+ <Image
80
+ testID={testID ? `${testID}-image` : undefined}
81
+ accessible={false}
82
+ source={{ uri: src }}
83
+ style={FILL}
84
+ resizeMode={contentFit}
85
+ />
86
+ )}
87
+ </View>
88
+ );
89
+ }
@@ -26,8 +26,8 @@ export type {
26
26
  NativeToastVariant,
27
27
  } from "./toast";
28
28
 
29
- export { NativeSheet } from "./sheet";
30
- export type { NativeSheetProps } from "./sheet";
29
+ export { NativeSheet, NativeSheetProvider, NativeSheetScrollView } from "./sheet";
30
+ export type { NativeSheetLibrary, NativeSheetProps, NativeSheetProviderProps } from "./sheet";
31
31
 
32
32
  export {
33
33
  NativePopover,
@@ -257,3 +257,34 @@ export type {
257
257
  FlexAlign,
258
258
  FlexJustify,
259
259
  } from "./layout";
260
+
261
+ // --- Optional native modules (FlashList, expo-image, Reanimated, Liquid Glass, SF Symbols, @expo/ui) ---
262
+
263
+ export { GenesisModulesProvider, useGenesisModules } from "../native-modules";
264
+ export type {
265
+ GenesisModules,
266
+ GenesisModulesProviderProps,
267
+ GenesisListComponent,
268
+ GenesisListProps,
269
+ GenesisImageComponent,
270
+ GenesisImageProps,
271
+ GenesisReanimatedModule,
272
+ GenesisGlassModule,
273
+ GenesisSymbolComponent,
274
+ GenesisSymbolProps,
275
+ GenesisIconComponent,
276
+ GenesisIconSet,
277
+ GenesisDatePickerComponent,
278
+ GenesisDatePickerProps,
279
+ } from "../native-modules";
280
+
281
+ export { NativeIcon } from "./icon";
282
+ export type { NativeIconProps } from "./icon";
283
+ export { NATIVE_ICON_NAMES, SF_SYMBOLS } from "../icon-names";
284
+ export type { NativeIconName } from "../icon-names";
285
+
286
+ export { NativeImage } from "./image";
287
+ export type { NativeImageProps } from "./image";
288
+
289
+ export { NativeGlassSurface, useLiquidGlass, useReduceTransparency } from "./glass-surface";
290
+ export type { NativeGlassSurfaceProps } from "./glass-surface";