@marktiderman/genesis-ui-native 2.2.0 → 2.3.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 (79) hide show
  1. package/README.md +82 -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-2WCXMJL6.js → chunk-FIITITXO.js} +67 -108
  9. package/dist/chunk-FIITITXO.js.map +1 -0
  10. package/dist/chunk-H4Q7COTI.js +1587 -0
  11. package/dist/chunk-H4Q7COTI.js.map +1 -0
  12. package/dist/{chunk-TXJT55JC.js → chunk-Q445I7WO.js} +715 -324
  13. package/dist/chunk-Q445I7WO.js.map +1 -0
  14. package/dist/{chunk-ULS7I6ZS.js → chunk-W2UBJ56D.js} +99 -12
  15. package/dist/chunk-W2UBJ56D.js.map +1 -0
  16. package/dist/components/index.d.ts +146 -18
  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 +60 -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 +329 -4
  28. package/dist/layouts/index.js +3 -3
  29. package/dist/native-modules-BGO2MnFF.d.ts +219 -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 +71 -0
  33. package/src/__tests__/native-modules.test.tsx +631 -0
  34. package/src/components/__tests__/refresh-control.test.tsx +35 -0
  35. package/src/components/__tests__/sheet.test.tsx +193 -0
  36. package/src/components/__tests__/toast.test.tsx +15 -0
  37. package/src/components/avatar.tsx +69 -16
  38. package/src/components/date-time-picker.tsx +128 -10
  39. package/src/components/drawer.tsx +158 -68
  40. package/src/components/dropdown-menu.tsx +7 -6
  41. package/src/components/glass-surface.tsx +150 -0
  42. package/src/components/icon.tsx +66 -0
  43. package/src/components/image.tsx +89 -0
  44. package/src/components/index.ts +33 -2
  45. package/src/components/list-item.tsx +29 -9
  46. package/src/components/popover.tsx +12 -9
  47. package/src/components/refresh-control.tsx +11 -45
  48. package/src/components/segmented-control.tsx +7 -1
  49. package/src/components/sheet.tsx +276 -133
  50. package/src/components/skeleton.tsx +75 -53
  51. package/src/components/toast.tsx +185 -87
  52. package/src/data/NativeResourcePage.tsx +48 -3
  53. package/src/data/__tests__/resource-page-offline.test.tsx +47 -0
  54. package/src/hooks/use-reduced-motion.ts +24 -10
  55. package/src/icon-names.ts +62 -0
  56. package/src/icons/lucide.ts +114 -0
  57. package/src/layouts/__tests__/google-sign-in.test.tsx +26 -0
  58. package/src/layouts/__tests__/inbox-page.test.tsx +200 -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/auth-screen.tsx +6 -3
  63. package/src/layouts/google-sign-in.tsx +42 -0
  64. package/src/layouts/inbox-page.tsx +455 -0
  65. package/src/layouts/index.ts +37 -2
  66. package/src/layouts/keyboard.tsx +61 -9
  67. package/src/layouts/notifications-page.tsx +133 -16
  68. package/src/layouts/settings-page.tsx +117 -14
  69. package/src/layouts/settings-sub-page.tsx +9 -3
  70. package/src/layouts/thread-page.tsx +444 -0
  71. package/src/native-modules.tsx +186 -0
  72. package/dist/chunk-2WCXMJL6.js.map +0 -1
  73. package/dist/chunk-5HRGIA6F.js.map +0 -1
  74. package/dist/chunk-F2TGDKOO.js +0 -43
  75. package/dist/chunk-F2TGDKOO.js.map +0 -1
  76. package/dist/chunk-FZTUSM56.js +0 -935
  77. package/dist/chunk-FZTUSM56.js.map +0 -1
  78. package/dist/chunk-TXJT55JC.js.map +0 -1
  79. package/dist/chunk-ULS7I6ZS.js.map +0 -1
@@ -1,11 +1,17 @@
1
1
  /**
2
2
  * Skeleton — loading placeholder block.
3
3
  *
4
+ * Pulses with Reanimated 4 when the app passes it (`modules.reanimated` on
5
+ * `GenesisModulesProvider`), else with React Native's Animated. While Reduce
6
+ * Motion is on it holds still at a legible opacity.
7
+ *
4
8
  * @stability Stable
5
9
  */
6
- import { useEffect, useRef, useState } from "react";
7
- import { AccessibilityInfo, Animated, Easing } from "react-native";
10
+ import { useEffect, useRef } from "react";
11
+ import { Animated, Easing } from "react-native";
8
12
  import { cn } from "../utils";
13
+ import { useReducedMotion } from "../hooks/use-reduced-motion";
14
+ import { useGenesisModules, type GenesisReanimatedModule } from "../native-modules";
9
15
 
10
16
  export interface NativeSkeletonProps {
11
17
  className?: string;
@@ -21,60 +27,82 @@ export interface NativeSkeletonProps {
21
27
  testID?: string;
22
28
  }
23
29
 
24
- function NativeSkeleton({
25
- className,
26
- width,
27
- height,
28
- size,
29
- circle,
30
- ...props
31
- }: NativeSkeletonProps) {
32
- const opacity = useRef(new Animated.Value(0.3)).current;
33
- const [reduceMotion, setReduceMotion] = useState(false);
30
+ const PULSE_MS = 1000;
31
+ const LOW = 0.3;
32
+ const HIGH = 1;
33
+ // Held still under Reduce Motion (visual-regression flow
34
+ // `screenshot-reduced-motion.yaml`; Apple HIG / WCAG 2.3.3).
35
+ const STILL = 0.6;
36
+
37
+ function sizeStyles({ width, height, size }: NativeSkeletonProps): Array<{ width?: number; height?: number }> {
38
+ const w = width ?? size;
39
+ const h = height ?? size;
40
+ const styles: Array<{ width?: number; height?: number }> = [];
41
+ if (w !== undefined) styles.push({ width: w });
42
+ if (h !== undefined) styles.push({ height: h });
43
+ return styles;
44
+ }
45
+
46
+ function skeletonClass({ className, circle }: NativeSkeletonProps) {
47
+ return cn("rounded-md bg-muted", circle && "rounded-full", className);
48
+ }
49
+
50
+ function NativeSkeleton(props: NativeSkeletonProps) {
51
+ const { reanimated } = useGenesisModules();
52
+ return reanimated ? <ReanimatedSkeleton {...props} reanimated={reanimated} /> : <AnimatedSkeleton {...props} />;
53
+ }
34
54
 
55
+ function ReanimatedSkeleton({ reanimated: R, ...props }: NativeSkeletonProps & { reanimated: GenesisReanimatedModule }) {
56
+ const reduceMotion = useReducedMotion();
57
+ const opacity = R.useSharedValue(LOW);
35
58
  useEffect(() => {
36
- let cancelled = false;
37
- AccessibilityInfo.isReduceMotionEnabled()
38
- .then((enabled) => {
39
- if (!cancelled) setReduceMotion(enabled);
40
- })
41
- .catch(() => {
42
- // Defensive: some RN runtimes (web, older Android) reject when
43
- // the AccessibilityManager isn't wired up. Fall back to "no
44
- // reduce-motion" so the skeleton still animates rather than
45
- // crashing the host screen with an unhandled rejection.
46
- if (!cancelled) setReduceMotion(false);
47
- });
48
- const sub = AccessibilityInfo.addEventListener(
49
- "reduceMotionChanged",
50
- (enabled) => setReduceMotion(enabled),
51
- );
52
- return () => {
53
- cancelled = true;
54
- sub.remove();
55
- };
56
- }, []);
59
+ R.cancelAnimation(opacity);
60
+ if (reduceMotion) {
61
+ opacity.value = STILL;
62
+ return undefined;
63
+ }
64
+ opacity.value = LOW;
65
+ opacity.value = R.withRepeat(R.withTiming(HIGH, { duration: PULSE_MS, easing: R.Easing.inOut(R.Easing.ease) }), -1, true);
66
+ return () => R.cancelAnimation(opacity);
67
+ // `R` and `opacity` are stable for the component's life.
68
+ // eslint-disable-next-line react-hooks/exhaustive-deps
69
+ }, [reduceMotion]);
70
+ const animatedStyle = R.useAnimatedStyle(() => {
71
+ "worklet";
72
+ return { opacity: opacity.value };
73
+ });
74
+ const AnimatedView = R.default.View;
75
+ return (
76
+ <AnimatedView
77
+ className={skeletonClass(props)}
78
+ style={[animatedStyle, ...sizeStyles(props)]}
79
+ testID={props.testID}
80
+ accessibilityElementsHidden
81
+ importantForAccessibility="no-hide-descendants"
82
+ />
83
+ );
84
+ }
85
+
86
+ function AnimatedSkeleton(props: NativeSkeletonProps) {
87
+ const opacity = useRef(new Animated.Value(LOW)).current;
88
+ const reduceMotion = useReducedMotion();
57
89
 
58
90
  useEffect(() => {
59
91
  if (reduceMotion) {
60
- // Hold the skeleton at a static, legible opacity instead of
61
- // pulsing — required by visual-regression flow `screenshot-
62
- // reduced-motion.yaml` and by users with vestibular-motion
63
- // sensitivity (Apple HIG / WCAG 2.3.3).
64
- opacity.setValue(0.6);
92
+ opacity.setValue(STILL);
65
93
  return;
66
94
  }
67
95
  const animation = Animated.loop(
68
96
  Animated.sequence([
69
97
  Animated.timing(opacity, {
70
- toValue: 1,
71
- duration: 1000,
98
+ toValue: HIGH,
99
+ duration: PULSE_MS,
72
100
  easing: Easing.inOut(Easing.ease),
73
101
  useNativeDriver: true,
74
102
  }),
75
103
  Animated.timing(opacity, {
76
- toValue: 0.3,
77
- duration: 1000,
104
+ toValue: LOW,
105
+ duration: PULSE_MS,
78
106
  easing: Easing.inOut(Easing.ease),
79
107
  useNativeDriver: true,
80
108
  }),
@@ -86,17 +114,11 @@ function NativeSkeleton({
86
114
 
87
115
  return (
88
116
  <Animated.View
89
- className={cn(
90
- "rounded-md bg-muted",
91
- circle && "rounded-full",
92
- className
93
- )}
94
- style={[
95
- { opacity },
96
- (width ?? size) !== undefined ? { width: width ?? size } : undefined,
97
- (height ?? size) !== undefined ? { height: height ?? size } : undefined,
98
- ].filter(Boolean) as any[]}
99
- {...props}
117
+ className={skeletonClass(props)}
118
+ style={[{ opacity }, ...sizeStyles(props)] as any[]}
119
+ testID={props.testID}
120
+ accessibilityElementsHidden
121
+ importantForAccessibility="no-hide-descendants"
100
122
  />
101
123
  );
102
124
  }
@@ -6,11 +6,18 @@
6
6
  * <NativeAlert> or <NativeBanner>) or for destructive confirmations
7
7
  * (use <NativeDialog>).
8
8
  *
9
- * Wrap the app in <NativeToastProvider>. Components anywhere in the tree
9
+ * `GenesisNativeApp` (genesis-native) mounts <NativeToastProvider> for you, at the top; elsewhere,
10
+ * wrap the app in it (its own default position is the bottom). Components anywhere in the tree
10
11
  * call `useToast()` and invoke `toast.show({ title, description, variant })`.
11
12
  * Toasts are queued — the next one shows once the current one dismisses
12
13
  * (or the user dismisses early).
13
14
  *
15
+ * Animates with Reanimated 4 when the app passes it (`modules.reanimated`
16
+ * on `GenesisModulesProvider`), else with React Native's Animated; either
17
+ * way it appears without motion while Reduce Motion is on. A default toast
18
+ * is Liquid Glass on iOS 26 when `modules.glass` (expo-glass-effect) is
19
+ * given and the device can draw it.
20
+ *
14
21
  * @stability Beta
15
22
  */
16
23
  import {
@@ -22,14 +29,13 @@ import {
22
29
  useRef,
23
30
  useState,
24
31
  } from "react";
25
- import {
26
- AccessibilityInfo,
27
- Animated,
28
- Pressable,
29
- Text,
30
- View,
31
- } from "react-native";
32
+ import { Animated, Pressable, Text } from "react-native";
33
+ import { SafeAreaInsetsContext } from "react-native-safe-area-context";
32
34
  import { cn } from "../utils";
35
+ import { useReducedMotion } from "../hooks/use-reduced-motion";
36
+ import { useThemeMode } from "../hooks/use-theme-mode";
37
+ import { useGenesisModules, type GenesisReanimatedModule } from "../native-modules";
38
+ import { useLiquidGlass } from "./glass-surface";
33
39
 
34
40
  export type NativeToastVariant = "default" | "success" | "destructive";
35
41
 
@@ -73,22 +79,7 @@ export function NativeToastProvider({
73
79
  disableAnimation = false,
74
80
  }: NativeToastProviderProps) {
75
81
  const [queue, setQueue] = useState<ToastInstance[]>([]);
76
- const [reducedMotion, setReducedMotion] = useState(false);
77
-
78
- useEffect(() => {
79
- let mounted = true;
80
- AccessibilityInfo.isReduceMotionEnabled().then((v) => {
81
- if (mounted) setReducedMotion(v);
82
- });
83
- const sub = AccessibilityInfo.addEventListener(
84
- "reduceMotionChanged",
85
- (v) => mounted && setReducedMotion(v)
86
- );
87
- return () => {
88
- mounted = false;
89
- sub.remove();
90
- };
91
- }, []);
82
+ const reducedMotion = useReducedMotion();
92
83
 
93
84
  const dismiss = useCallback((id?: number) => {
94
85
  setQueue((q) => (id == null ? q.slice(1) : q.filter((t) => t.id !== id)));
@@ -127,10 +118,37 @@ interface ToastViewProps {
127
118
  onDismiss: () => void;
128
119
  }
129
120
 
130
- function ToastView({ toast, position, animate, onDismiss }: ToastViewProps) {
131
- const opacity = useRef(new Animated.Value(animate ? 0 : 1)).current;
132
- const offset = useRef(new Animated.Value(animate ? 16 : 0)).current;
121
+ type GlassComponent = NonNullable<ReturnType<typeof useLiquidGlass>>;
122
+
123
+ interface ToastFrameProps extends ToastViewProps {
124
+ /** GlassView when this toast is drawn as Liquid Glass. */
125
+ glass: GlassComponent | null;
126
+ }
127
+
128
+ const ENTER_MS = 180;
129
+
130
+ // Reanimated 4 when the app passed it, else React Native's Animated. Two
131
+ // components rather than one with a branch, so each keeps a fixed hook order.
132
+ function ToastView(props: ToastViewProps) {
133
+ const { reanimated } = useGenesisModules();
134
+ const GlassView = useLiquidGlass();
135
+ const glass = (props.toast.variant ?? "default") === "default" ? GlassView : null;
136
+ return reanimated ? (
137
+ <ReanimatedToastView {...props} glass={glass} reanimated={reanimated} />
138
+ ) : (
139
+ <AnimatedToastView {...props} glass={glass} />
140
+ );
141
+ }
142
+
143
+ /**
144
+ * Glass slides in without fading: Liquid Glass doesn't draw under a parent
145
+ * whose opacity is below 1 (Expo's glass-effect docs, after Apple's).
146
+ */
147
+ function fades(animate: boolean, glass: GlassComponent | null) {
148
+ return animate && !glass;
149
+ }
133
150
 
151
+ function useAutoDismiss(toast: ToastInstance, onDismiss: () => void) {
134
152
  // Hold the latest onDismiss in a ref so the auto-dismiss timer below does
135
153
  // not re-arm on every parent render (the inline `() => dismiss(current.id)`
136
154
  // gets a fresh identity each render). Keying the timer effect off
@@ -139,81 +157,161 @@ function ToastView({ toast, position, animate, onDismiss }: ToastViewProps) {
139
157
  useEffect(() => {
140
158
  onDismissRef.current = onDismiss;
141
159
  }, [onDismiss]);
142
-
143
160
  useEffect(() => {
144
- if (animate) {
145
- Animated.parallel([
146
- Animated.timing(opacity, {
147
- toValue: 1,
148
- duration: 180,
149
- useNativeDriver: true,
150
- }),
151
- Animated.timing(offset, {
152
- toValue: 0,
153
- duration: 180,
154
- useNativeDriver: true,
155
- }),
156
- ]).start();
157
- }
158
-
159
161
  const duration = toast.duration ?? 3500;
160
162
  if (duration > 0) {
161
163
  const t = setTimeout(() => onDismissRef.current(), duration);
162
164
  return () => clearTimeout(t);
163
165
  }
164
166
  return undefined;
165
- }, [animate, offset, opacity, toast.duration]);
167
+ }, [toast.duration]);
168
+ }
166
169
 
167
- const variantClasses: Record<NativeToastVariant, string> = {
168
- default: "bg-foreground",
169
- success: "bg-primary",
170
- destructive: "bg-destructive",
171
- };
172
- const textClass: Record<NativeToastVariant, string> = {
173
- default: "text-background",
174
- success: "text-primary-foreground",
175
- destructive: "text-destructive-foreground",
176
- };
170
+ /**
171
+ * A top toast sits below the safe area's top (the status bar, the Dynamic Island), which the
172
+ * `top-12` class alone doesn't clear on every phone. Without a SafeAreaProvider, the class stays.
173
+ */
174
+ function useEdgeStyle(position: "top" | "bottom") {
175
+ const insets = useContext(SafeAreaInsetsContext);
176
+ return position === "top" && insets ? { top: insets.top + 8 } : null;
177
+ }
177
178
 
178
- const variant = toast.variant ?? "default";
179
- const positionClass =
180
- position === "top" ? "top-12 self-center" : "bottom-10 self-center";
179
+ /** Slides in from the edge it sits on. */
180
+ function startOffset(position: "top" | "bottom") {
181
+ return position === "top" ? -16 : 16;
182
+ }
183
+
184
+ function ReanimatedToastView({
185
+ toast,
186
+ position,
187
+ animate,
188
+ onDismiss,
189
+ glass,
190
+ reanimated: R,
191
+ }: ToastFrameProps & { reanimated: GenesisReanimatedModule }) {
192
+ const fade = fades(animate, glass);
193
+ const opacity = R.useSharedValue(fade ? 0 : 1);
194
+ const offset = R.useSharedValue(animate ? startOffset(position) : 0);
195
+ useAutoDismiss(toast, onDismiss);
196
+ useEffect(() => {
197
+ if (!animate) return;
198
+ const easing = R.Easing.out(R.Easing.cubic);
199
+ if (fade) opacity.value = R.withTiming(1, { duration: ENTER_MS, easing });
200
+ offset.value = R.withTiming(0, { duration: ENTER_MS, easing });
201
+ // Once per toast: each toast mounts under its own key.
202
+ // eslint-disable-next-line react-hooks/exhaustive-deps
203
+ }, []);
204
+ const animatedStyle = R.useAnimatedStyle(() => {
205
+ "worklet";
206
+ return { opacity: opacity.value, transform: [{ translateY: offset.value }] };
207
+ });
208
+ const AnimatedView = R.default.View;
209
+ const edge = useEdgeStyle(position);
210
+ return (
211
+ <AnimatedView {...regionProps(toast)} className={regionClass(position)} style={edge ? [edge, animatedStyle] : animatedStyle}>
212
+ <ToastBody toast={toast} onDismiss={onDismiss} glass={glass} />
213
+ </AnimatedView>
214
+ );
215
+ }
216
+
217
+ function AnimatedToastView({ toast, position, animate, onDismiss, glass }: ToastFrameProps) {
218
+ const fade = fades(animate, glass);
219
+ const opacity = useRef(new Animated.Value(fade ? 0 : 1)).current;
220
+ const offset = useRef(new Animated.Value(animate ? startOffset(position) : 0)).current;
221
+ useAutoDismiss(toast, onDismiss);
222
+ const edge = useEdgeStyle(position);
223
+
224
+ useEffect(() => {
225
+ if (!animate) return;
226
+ const slide = Animated.timing(offset, {
227
+ toValue: 0,
228
+ duration: ENTER_MS,
229
+ useNativeDriver: true,
230
+ });
231
+ const fadeIn = Animated.timing(opacity, {
232
+ toValue: 1,
233
+ duration: ENTER_MS,
234
+ useNativeDriver: true,
235
+ });
236
+ Animated.parallel(fade ? [fadeIn, slide] : [slide]).start();
237
+ // Once per toast: each toast mounts under its own key.
238
+ // eslint-disable-next-line react-hooks/exhaustive-deps
239
+ }, []);
181
240
 
182
241
  return (
183
242
  <Animated.View
184
- accessible
185
- accessibilityRole="alert"
186
- accessibilityLiveRegion="polite"
187
- accessibilityLabel={
188
- toast.description ? `${toast.title}. ${toast.description}` : toast.title
189
- }
243
+ {...regionProps(toast)}
244
+ className={regionClass(position)}
245
+ style={[edge, { opacity, transform: [{ translateY: offset }] }]}
246
+ >
247
+ <ToastBody toast={toast} onDismiss={onDismiss} glass={glass} />
248
+ </Animated.View>
249
+ );
250
+ }
251
+
252
+ function regionProps(toast: ToastInstance) {
253
+ return {
254
+ accessible: true,
255
+ accessibilityRole: "alert",
256
+ accessibilityLiveRegion: "polite" as const,
257
+ accessibilityLabel: toast.description ? `${toast.title}. ${toast.description}` : toast.title,
258
+ };
259
+ }
260
+
261
+ function regionClass(position: "top" | "bottom") {
262
+ return cn("absolute left-4 right-4 items-center", position === "top" ? "top-12 self-center" : "bottom-10 self-center");
263
+ }
264
+
265
+ const variantClasses: Record<NativeToastVariant, string> = {
266
+ default: "bg-foreground",
267
+ success: "bg-primary",
268
+ destructive: "bg-destructive",
269
+ };
270
+ const textClass: Record<NativeToastVariant, string> = {
271
+ default: "text-background",
272
+ success: "text-primary-foreground",
273
+ destructive: "text-destructive-foreground",
274
+ };
275
+
276
+ /**
277
+ * The toast itself. A default toast is Liquid Glass where it can be drawn,
278
+ * with label-colored text; success and destructive keep their solid color,
279
+ * which carries their meaning.
280
+ */
281
+ function ToastBody({ toast, onDismiss, glass: Glass }: { toast: ToastInstance; onDismiss: () => void; glass: GlassComponent | null }) {
282
+ const colorScheme = useThemeMode();
283
+ const variant = toast.variant ?? "default";
284
+ const text = Glass ? "text-foreground" : textClass[variant];
285
+ const testID = toast.testID ?? "native-toast";
286
+ const pressable = (
287
+ <Pressable
288
+ testID={testID}
289
+ accessibilityRole="button"
290
+ accessibilityLabel="Dismiss notification"
291
+ accessibilityHint="Dismisses this toast"
292
+ onPress={onDismiss}
190
293
  className={cn(
191
- "absolute left-4 right-4 items-center",
192
- positionClass
294
+ "min-h-[44px] min-w-[200px] px-4 py-3",
295
+ Glass ? undefined : cn("rounded-lg shadow-lg", variantClasses[variant])
193
296
  )}
194
- style={{ opacity, transform: [{ translateY: offset }] }}
195
297
  >
196
- <Pressable
197
- testID={toast.testID ?? "native-toast"}
198
- accessibilityRole="button"
199
- accessibilityLabel="Dismiss notification"
200
- accessibilityHint="Dismisses this toast"
201
- onPress={onDismiss}
202
- className={cn(
203
- "min-h-[44px] min-w-[200px] rounded-lg px-4 py-3 shadow-lg",
204
- variantClasses[variant]
205
- )}
206
- >
207
- <Text className={cn("text-base font-semibold", textClass[variant])}>
208
- {toast.title}
209
- </Text>
210
- {toast.description ? (
211
- <Text className={cn("mt-0.5 text-sm", textClass[variant], "opacity-90")}>
212
- {toast.description}
213
- </Text>
214
- ) : null}
215
- </Pressable>
216
- </Animated.View>
298
+ <Text className={cn("text-base font-semibold", text)}>{toast.title}</Text>
299
+ {toast.description ? (
300
+ <Text className={cn("mt-0.5 text-sm", text, "opacity-90")}>{toast.description}</Text>
301
+ ) : null}
302
+ </Pressable>
303
+ );
304
+ if (!Glass) return pressable;
305
+ return (
306
+ <Glass
307
+ testID={`${testID}-glass`}
308
+ glassEffectStyle="regular"
309
+ colorScheme={colorScheme}
310
+ isInteractive
311
+ style={{ borderRadius: 16, overflow: "hidden" }}
312
+ >
313
+ {pressable}
314
+ </Glass>
217
315
  );
218
316
  }
219
317
 
@@ -19,6 +19,7 @@ import { NativeButton } from "../components/button";
19
19
  import { NativeSkeleton } from "../components/skeleton";
20
20
  import { NativeDataFilters } from "./NativeDataFilters";
21
21
  import { NativeEmptyState } from "./NativeEmptyState";
22
+ import { useGenesisModules } from "../native-modules";
22
23
 
23
24
  // ---------------------------------------------------------------------------
24
25
  // Types
@@ -60,6 +61,12 @@ export interface NativeResourcePageProps<T extends BaseRecord = BaseRecord> {
60
61
  // Slots
61
62
  headerRight?: ReactNode;
62
63
  emptyState?: ReactNode;
64
+ /**
65
+ * Shown while the list has nothing saved and its fetch is paused because
66
+ * the device is offline (`networkMode: "offlineFirst"`), instead of an empty
67
+ * list that says there is nothing. Default: a one-line offline message.
68
+ */
69
+ offlineState?: ReactNode;
63
70
  }
64
71
 
65
72
  // ---------------------------------------------------------------------------
@@ -188,11 +195,13 @@ function NativeResourcePage<T extends BaseRecord = BaseRecord>({
188
195
  createLabel = "New",
189
196
  headerRight,
190
197
  emptyState,
198
+ offlineState,
191
199
  }: NativeResourcePageProps<T>) {
192
200
  // -------------------------------------------------------------------------
193
201
  // State
194
202
  // -------------------------------------------------------------------------
195
203
 
204
+ const { list: FlashList } = useGenesisModules();
196
205
  const [search, setSearchLocal] = useState("");
197
206
  const [selectedStatuses, setSelectedStatuses] = useState<string[]>([]);
198
207
 
@@ -266,6 +275,8 @@ function NativeResourcePage<T extends BaseRecord = BaseRecord>({
266
275
  const items: T[] = list.data?.data ?? [];
267
276
  const isLoading = list.isLoading;
268
277
  const hasError = list.isError;
278
+ // Paused offline with nothing saved: not loading (no request in flight), not empty either.
279
+ const isOfflineEmpty = list.isPaused && list.data === undefined;
269
280
 
270
281
  // -------------------------------------------------------------------------
271
282
  // Resolve card fields
@@ -410,7 +421,17 @@ function NativeResourcePage<T extends BaseRecord = BaseRecord>({
410
421
 
411
422
  const ListEmptyComponent = useMemo(
412
423
  () =>
413
- isLoading ? null : (
424
+ isLoading ? null : isOfflineEmpty ? (
425
+ // In the list, under its header, so search and filters stay usable offline: clearing a
426
+ // search brings back the saved rows.
427
+ <View testID="native-resource-offline" className="flex-1 items-center justify-center px-4 py-12 gap-4">
428
+ {offlineState ?? (
429
+ <NativeText preset="body" className="text-muted-foreground text-center">
430
+ You're offline. This list loads when you're back online.
431
+ </NativeText>
432
+ )}
433
+ </View>
434
+ ) : (
414
435
  <>
415
436
  {emptyState ?? (
416
437
  <NativeEmptyState
@@ -420,7 +441,7 @@ function NativeResourcePage<T extends BaseRecord = BaseRecord>({
420
441
  )}
421
442
  </>
422
443
  ),
423
- [isLoading, emptyState, hasActiveFilters, handleClearFilters]
444
+ [isLoading, isOfflineEmpty, offlineState, emptyState, hasActiveFilters, handleClearFilters]
424
445
  );
425
446
 
426
447
  // -------------------------------------------------------------------------
@@ -454,15 +475,39 @@ function NativeResourcePage<T extends BaseRecord = BaseRecord>({
454
475
  );
455
476
  }
456
477
 
478
+ // FlashList v2 (`modules.list`) when the app passed it: it recycles rows
479
+ // and sizes them itself (no `estimatedItemSize` in v2). Its content
480
+ // container takes padding only, so `flexGrow` (which centers the empty
481
+ // state in a FlatList) is FlatList's alone.
482
+ if (FlashList) {
483
+ return (
484
+ <FlashList
485
+ testID="native-resource-page-list"
486
+ data={items}
487
+ keyExtractor={keyExtractor}
488
+ renderItem={renderFlatListItem}
489
+ ListHeaderComponent={ListHeaderComponent}
490
+ ListEmptyComponent={ListEmptyComponent}
491
+ contentContainerStyle={{ paddingBottom: 24 }}
492
+ // offlineFirst: as FlatList below, the spinner follows the fetch, not the paused promise.
493
+ refreshing={refreshing && !list.isPaused}
494
+ onRefresh={handleRefresh}
495
+ />
496
+ );
497
+ }
498
+
457
499
  return (
458
500
  <FlatList<T>
501
+ testID="native-resource-page-list"
459
502
  data={items}
460
503
  keyExtractor={keyExtractor}
461
504
  renderItem={renderFlatListItem}
462
505
  ListHeaderComponent={ListHeaderComponent}
463
506
  ListEmptyComponent={ListEmptyComponent}
464
507
  contentContainerStyle={{ flexGrow: 1, paddingBottom: 24 }}
465
- refreshing={refreshing}
508
+ // offlineFirst: a refetch offline pauses (its promise waits for the network), so the
509
+ // spinner follows the fetch, not the promise; it comes back if the fetch resumes.
510
+ refreshing={refreshing && !list.isPaused}
466
511
  onRefresh={handleRefresh}
467
512
  />
468
513
  );
@@ -0,0 +1,47 @@
1
+ // @feat:native-app-shell
2
+ import { render, screen } from "@testing-library/react";
3
+ import { beforeEach, describe, expect, it, vi } from "vitest";
4
+
5
+ // The list's TanStack state, set per test. offlineFirst leaves a query with nothing saved
6
+ // `pending` and paused while offline: not loading, and not an empty list either.
7
+ const list = vi.hoisted(() => ({ current: {} as Record<string, unknown> }));
8
+ vi.mock("@marktiderman/genesis-core/hooks", () => ({
9
+ useResource: () => ({ list: list.current, setSearch: () => {}, setFilters: () => {} }),
10
+ }));
11
+
12
+ import { NativeResourcePage } from "../NativeResourcePage";
13
+
14
+ const base = { isLoading: false, isError: false, isPaused: false, isRefetching: false, data: undefined, error: null, refetch: vi.fn() };
15
+
16
+ describe("NativeResourcePage offline", () => {
17
+ beforeEach(() => {
18
+ list.current = { ...base };
19
+ });
20
+
21
+ it("says it is offline, not empty, while a list with nothing saved is paused", () => {
22
+ list.current = { ...base, isPaused: true };
23
+ render(<NativeResourcePage resource="clients" title="Clients" emptyState={<span>No clients yet</span>} />);
24
+ expect(screen.getByTestId("native-resource-offline").textContent).toContain("offline");
25
+ expect(screen.queryByText("No clients yet")).toBeNull();
26
+ });
27
+
28
+ it("keeps the search above the offline message, so clearing a search offline is still possible", () => {
29
+ list.current = { ...base, isPaused: true };
30
+ render(<NativeResourcePage resource="clients" title="Clients" searchFields={["name"]} searchPlaceholder="Search clients" />);
31
+ expect(screen.getByTestId("native-resource-offline")).toBeTruthy();
32
+ expect(screen.getByPlaceholderText("Search clients")).toBeTruthy();
33
+ });
34
+
35
+ it("keeps showing saved rows while paused", () => {
36
+ list.current = { ...base, isPaused: true, data: { data: [{ id: "1", name: "Ada" }], total: 1 } };
37
+ render(<NativeResourcePage resource="clients" title="Clients" cardFields={["name"]} />);
38
+ expect(screen.queryByTestId("native-resource-offline")).toBeNull();
39
+ expect(screen.getByText("Ada")).toBeTruthy();
40
+ });
41
+
42
+ it("takes the app's own offline state", () => {
43
+ list.current = { ...base, isPaused: true };
44
+ render(<NativeResourcePage resource="clients" title="Clients" offlineState={<span>Reconnect to see clients</span>} />);
45
+ expect(screen.getByText("Reconnect to see clients")).toBeTruthy();
46
+ });
47
+ });