@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
@@ -0,0 +1,444 @@
1
+ /**
2
+ * ThreadPage — one conversation: messages oldest first, a composer at the
3
+ * bottom that stays above the keyboard, attachments, a read receipt, and
4
+ * "load earlier" paging.
5
+ *
6
+ * Generic: a support ticket with staff replies, a direct message, a comment
7
+ * thread. Mine are on the trailing side in the tint, theirs on the leading
8
+ * side on `surface`, over the `groupedBackground` page (SettingsPage's iOS
9
+ * palette).
10
+ *
11
+ * Keyboard: with `KeyboardScrollProvider` (the native app shell's
12
+ * `keyboardScroll`, react-native-keyboard-controller's
13
+ * `KeyboardAwareScrollView`), the messages and the composer scroll together
14
+ * and the composer is kept above the keyboard. Without it, a
15
+ * `KeyboardAvoidingView` does the same on iOS. Either way the thread stays
16
+ * scrolled to the newest message as it grows.
17
+ *
18
+ * Read-only: pass `composer={null}` (a closed ticket, a viewer) and an
19
+ * optional `closedNotice`.
20
+ *
21
+ * Slots: `message`, `attachment`, `readReceipt`, `composer`,
22
+ * `composerAccessory` (beside the input: attach a screenshot), `header`
23
+ * (above the messages: what the thread is about), `earlier` and `empty`.
24
+ *
25
+ * @stability Beta
26
+ */
27
+ import { createElement, useEffect, useRef, type ReactNode } from "react";
28
+ import { renderSlot, type SlotPropsFor, type Slots } from "@marktiderman/genesis-core/slots";
29
+ import { ActivityIndicator, Image, KeyboardAvoidingView, Platform, Pressable, ScrollView, TextInput, View } from "react-native";
30
+ import { SafeAreaView } from "react-native-safe-area-context";
31
+ import { useThemeRoles } from "../hooks/use-theme-roles";
32
+ import { NativeButton } from "../components/button";
33
+ import { NativeEmptyState } from "../components/empty-state";
34
+ import { NativeText } from "../components/text";
35
+ import { composeHeaderOptions, type ScreenHeaderProps } from "./screen-container";
36
+ import { useKeyboardScroll } from "./keyboard";
37
+
38
+ export interface ThreadAttachment {
39
+ id: string;
40
+ /** An image URI (a signed URL, a file:// path). */
41
+ uri: string;
42
+ width?: number;
43
+ height?: number;
44
+ accessibilityLabel?: string;
45
+ onPress?: () => void;
46
+ }
47
+
48
+ export interface ThreadMessage {
49
+ id: string;
50
+ body: string;
51
+ /** Sent by the person using the app: trailing side, tint. */
52
+ mine: boolean;
53
+ /** Shown over theirs ("Support"); never over mine. */
54
+ authorName?: string;
55
+ timestamp: string | Date;
56
+ /** An optimistic message: `sending`, then `sent`, or `failed` with `onRetry`. */
57
+ status?: "sending" | "sent" | "failed";
58
+ onRetry?: () => void;
59
+ attachments?: ThreadAttachment[];
60
+ }
61
+
62
+ export interface ThreadComposer {
63
+ value: string;
64
+ onChangeText: (text: string) => void;
65
+ onSend: () => void;
66
+ /** A send is in flight: the button spins and won't send twice. */
67
+ sending?: boolean;
68
+ placeholder?: string;
69
+ sendLabel?: string;
70
+ /** Turns the send button off (besides an empty or blank value). */
71
+ disabled?: boolean;
72
+ maxLength?: number;
73
+ }
74
+
75
+ /** What the default parts say. */
76
+ export interface ThreadLabels {
77
+ /** Who "mine" is, to VoiceOver. */
78
+ you: string;
79
+ sending: string;
80
+ notSent: string;
81
+ retryHint: string;
82
+ }
83
+
84
+ const DEFAULT_LABELS: ThreadLabels = { you: "You", sending: "Sending", notSent: "Not sent. Tap to retry.", retryHint: "Double tap to send again" };
85
+
86
+ export type ThreadPageSlotMap = {
87
+ message: ThreadMessage & { testID: string; timeLabel: string; showReadReceipt: boolean; labels: ThreadLabels };
88
+ attachment: ThreadAttachment & { testID: string; mine: boolean };
89
+ readReceipt: { label: string; testID: string };
90
+ /** `accessory` is the `composerAccessory` slot, already rendered. */
91
+ composer: ThreadComposer & { testID: string; accessory?: ReactNode };
92
+ composerAccessory: { testID: string };
93
+ header: { testID: string };
94
+ earlier: { loading: boolean; onPress: () => void; label: string; testID: string };
95
+ empty: { title: string; body: string; testID: string };
96
+ };
97
+
98
+ export interface ThreadPageProps extends ScreenHeaderProps {
99
+ /** Oldest first. */
100
+ messages: ThreadMessage[];
101
+ /** `null`: read-only, no composer. */
102
+ composer: ThreadComposer | null;
103
+ /** Shown instead of the composer when it is `null` ("This conversation is closed"). */
104
+ closedNotice?: string;
105
+ /** Above the messages (what the thread is about). Prefer `slots.header` for a component. */
106
+ header?: ReactNode;
107
+ /**
108
+ * When the other side last read the thread. My newest message sent before
109
+ * it shows the read receipt.
110
+ */
111
+ readAt?: string | Date | null;
112
+ readLabel?: string;
113
+ /** There are older messages: shows a "load earlier" button at the top. */
114
+ hasEarlier?: boolean;
115
+ onLoadEarlier?: () => void;
116
+ loadingEarlier?: boolean;
117
+ earlierLabel?: string;
118
+ emptyTitle?: string;
119
+ emptyBody?: string;
120
+ formatTime?: (date: Date) => string;
121
+ /** The words the defaults say, for translating. */
122
+ labels?: Partial<ThreadLabels>;
123
+ slots?: Slots<ThreadPageSlotMap>;
124
+ slotProps?: SlotPropsFor<ThreadPageSlotMap>;
125
+ /** testID on the root. Default `"thread-page"`. */
126
+ testID?: string;
127
+ }
128
+
129
+ /** `<Stack.Screen options>` for a ThreadPage: a standard (not large) title, like Messages. */
130
+ export function getThreadPageStackOptions(props: ScreenHeaderProps & { headerTitle?: string }): Record<string, unknown> {
131
+ return composeHeaderOptions({
132
+ headerTitle: props.headerTitle ?? "Conversation",
133
+ large: props.large ?? false,
134
+ scrollEdgeBehavior: props.scrollEdgeBehavior,
135
+ headerLeft: props.headerLeft,
136
+ headerRight: props.headerRight,
137
+ headerOptions: props.headerOptions,
138
+ });
139
+ }
140
+
141
+ const toDate = (value: string | Date) => (typeof value === "string" ? new Date(value) : value);
142
+
143
+ function defaultTime(date: Date): string {
144
+ return date.toLocaleString(undefined, { month: "short", day: "numeric", hour: "numeric", minute: "2-digit" });
145
+ }
146
+
147
+ /** The newest of my messages the other side has read, or null. */
148
+ export function readReceiptFor(messages: readonly ThreadMessage[], readAt: string | Date | null | undefined): string | null {
149
+ if (!readAt) return null;
150
+ const read = toDate(readAt).getTime();
151
+ for (let i = messages.length - 1; i >= 0; i--) {
152
+ const m = messages[i]!;
153
+ if (m.mine && m.status !== "sending" && m.status !== "failed" && toDate(m.timestamp).getTime() <= read) return m.id;
154
+ }
155
+ return null;
156
+ }
157
+
158
+ interface ScrollLike {
159
+ scrollToEnd?: (options?: { animated?: boolean }) => void;
160
+ }
161
+
162
+ export function ThreadPage({
163
+ messages,
164
+ composer,
165
+ closedNotice,
166
+ header,
167
+ readAt,
168
+ readLabel = "Read",
169
+ hasEarlier = false,
170
+ onLoadEarlier,
171
+ loadingEarlier = false,
172
+ earlierLabel = "Load earlier messages",
173
+ emptyTitle,
174
+ emptyBody,
175
+ formatTime = defaultTime,
176
+ labels: labelOverrides,
177
+ slots = {},
178
+ slotProps = {},
179
+ testID = "thread-page",
180
+ }: ThreadPageProps) {
181
+ const colors = useThemeRoles();
182
+ const KeyboardScroll = useKeyboardScroll();
183
+ const scrollRef = useRef<ScrollLike | null>(null);
184
+ const receiptFor = readReceiptFor(messages, readAt);
185
+ const labels: ThreadLabels = { ...DEFAULT_LABELS, ...labelOverrides };
186
+ const newest = messages[messages.length - 1]?.id;
187
+
188
+ // Keep the newest message in view when one arrives (or is sent).
189
+ useEffect(() => {
190
+ scrollRef.current?.scrollToEnd?.({ animated: true });
191
+ }, [newest]);
192
+
193
+ const body = (
194
+ <View style={{ flexGrow: 1 }}>
195
+ {header ?? renderSlot(Nothing, slots.header, { testID: `${testID}-header` }, slotProps.header)}
196
+ {hasEarlier && onLoadEarlier
197
+ ? renderSlot(
198
+ DefaultEarlier,
199
+ slots.earlier,
200
+ { loading: loadingEarlier, onPress: onLoadEarlier, label: earlierLabel, testID: `${testID}-earlier` },
201
+ slotProps.earlier,
202
+ )
203
+ : null}
204
+ <View testID={`${testID}-messages`} accessibilityRole="list" style={{ flexGrow: 1, justifyContent: "flex-end", paddingHorizontal: 12, paddingVertical: 8, gap: 6 }}>
205
+ {messages.length === 0
206
+ ? renderSlot(
207
+ DefaultEmpty,
208
+ slots.empty,
209
+ { title: emptyTitle ?? "No messages yet", body: emptyBody ?? "Write the first one below.", testID: `${testID}-empty` },
210
+ slotProps.empty,
211
+ )
212
+ : messages.map((message) => (
213
+ <View key={message.id}>
214
+ {renderSlot(
215
+ DefaultMessage,
216
+ slots.message,
217
+ {
218
+ ...message,
219
+ testID: `${testID}-message-${message.id}`,
220
+ timeLabel: formatTime(toDate(message.timestamp)),
221
+ showReadReceipt: message.id === receiptFor,
222
+ labels,
223
+ },
224
+ slotProps.message,
225
+ )}
226
+ {message.attachments?.length ? (
227
+ <View style={{ flexDirection: "row", flexWrap: "wrap", gap: 6, justifyContent: message.mine ? "flex-end" : "flex-start", marginTop: 4 }}>
228
+ {message.attachments.map((attachment) => (
229
+ <View key={attachment.id}>
230
+ {renderSlot(
231
+ DefaultAttachment,
232
+ slots.attachment,
233
+ { ...attachment, mine: message.mine, testID: `${testID}-attachment-${attachment.id}` },
234
+ slotProps.attachment,
235
+ )}
236
+ </View>
237
+ ))}
238
+ </View>
239
+ ) : null}
240
+ {message.id === receiptFor
241
+ ? renderSlot(DefaultReadReceipt, slots.readReceipt, { label: readLabel, testID: `${testID}-read-receipt` }, slotProps.readReceipt)
242
+ : null}
243
+ </View>
244
+ ))}
245
+ </View>
246
+ </View>
247
+ );
248
+
249
+ const footer = composer ? (
250
+ renderSlot(
251
+ DefaultComposer,
252
+ slots.composer,
253
+ {
254
+ ...composer,
255
+ testID: `${testID}-composer`,
256
+ accessory: renderSlot(Nothing, slots.composerAccessory, { testID: `${testID}-composer-accessory` }, slotProps.composerAccessory),
257
+ },
258
+ slotProps.composer,
259
+ )
260
+ ) : closedNotice ? (
261
+ <NativeText testID={`${testID}-closed`} style={{ textAlign: "center", padding: 16, color: colors.secondaryLabel, fontSize: 13, lineHeight: 18 }}>
262
+ {closedNotice}
263
+ </NativeText>
264
+ ) : null;
265
+
266
+ const page = { flex: 1, backgroundColor: colors.groupedBackground };
267
+ const onContentSizeChange = () => scrollRef.current?.scrollToEnd?.({ animated: false });
268
+
269
+ if (KeyboardScroll) {
270
+ // The composer scrolls with the messages, so the keyboard-aware view keeps it (the focused input) above the keyboard.
271
+ return (
272
+ <SafeAreaView testID={testID} edges={["left", "right", "bottom"]} style={page}>
273
+ {createElement(
274
+ KeyboardScroll as never,
275
+ {
276
+ ref: scrollRef,
277
+ testID: `${testID}-keyboard`,
278
+ keyboardShouldPersistTaps: "handled",
279
+ contentInsetAdjustmentBehavior: "automatic",
280
+ contentContainerStyle: { flexGrow: 1 },
281
+ bottomOffset: 8,
282
+ onContentSizeChange,
283
+ } as never,
284
+ body,
285
+ footer,
286
+ )}
287
+ </SafeAreaView>
288
+ );
289
+ }
290
+ return (
291
+ <SafeAreaView testID={testID} edges={["left", "right", "bottom"]} style={page}>
292
+ <KeyboardAvoidingView testID={`${testID}-kav`} style={{ flex: 1 }} behavior={Platform.OS === "ios" ? "padding" : undefined} keyboardVerticalOffset={Platform.OS === "ios" ? 100 : 0}>
293
+ <ScrollView
294
+ ref={scrollRef as never}
295
+ testID={`${testID}-scroll`}
296
+ keyboardShouldPersistTaps="handled"
297
+ contentInsetAdjustmentBehavior="automatic"
298
+ contentContainerStyle={{ flexGrow: 1 }}
299
+ onContentSizeChange={onContentSizeChange}
300
+ >
301
+ {body}
302
+ </ScrollView>
303
+ {footer}
304
+ </KeyboardAvoidingView>
305
+ </SafeAreaView>
306
+ );
307
+ }
308
+
309
+ function Nothing(_props: { testID: string }) {
310
+ return null;
311
+ }
312
+
313
+ function DefaultEarlier({ loading, onPress, label, testID }: ThreadPageSlotMap["earlier"]) {
314
+ return (
315
+ <View style={{ alignItems: "center", paddingTop: 8 }}>
316
+ <NativeButton variant="ghost" size="sm" onPress={onPress} loading={loading} testID={testID}>
317
+ {label}
318
+ </NativeButton>
319
+ </View>
320
+ );
321
+ }
322
+
323
+ function DefaultEmpty({ title, body, testID }: ThreadPageSlotMap["empty"]) {
324
+ return <NativeEmptyState variant="first-run" title={title} body={body} testID={testID} />;
325
+ }
326
+
327
+ // No `color` key on mine: an undefined color in the style would override the class's.
328
+ const MINE_TEXT = { fontSize: 17, lineHeight: 22 } as const;
329
+
330
+ function DefaultMessage(message: ThreadPageSlotMap["message"]) {
331
+ const colors = useThemeRoles();
332
+ const failed = message.status === "failed";
333
+ const { labels } = message;
334
+ const label = [message.mine ? labels.you : (message.authorName ?? ""), message.body, message.timeLabel, failed ? labels.notSent : message.status === "sending" ? labels.sending : null]
335
+ .filter(Boolean)
336
+ .join(", ");
337
+ return (
338
+ <View style={{ alignItems: message.mine ? "flex-end" : "flex-start" }}>
339
+ {!message.mine && message.authorName ? (
340
+ <NativeText style={{ marginLeft: 12, marginBottom: 2, color: colors.secondaryLabel, fontSize: 12, lineHeight: 16 }}>{message.authorName}</NativeText>
341
+ ) : null}
342
+ <Pressable
343
+ testID={message.testID}
344
+ accessible
345
+ accessibilityLabel={label}
346
+ accessibilityHint={failed && message.onRetry ? labels.retryHint : undefined}
347
+ onPress={failed ? message.onRetry : undefined}
348
+ style={{
349
+ maxWidth: "80%",
350
+ paddingHorizontal: 14,
351
+ paddingVertical: 8,
352
+ borderRadius: 18,
353
+ backgroundColor: message.mine ? colors.tint : colors.surface,
354
+ opacity: message.status === "sending" ? 0.6 : 1,
355
+ }}
356
+ >
357
+ <NativeText className={message.mine ? "text-primary-foreground" : undefined} style={message.mine ? MINE_TEXT : { ...MINE_TEXT, color: colors.label }}>
358
+ {message.body}
359
+ </NativeText>
360
+ </Pressable>
361
+ <NativeText
362
+ testID={`${message.testID}-time`}
363
+ style={{ marginTop: 2, marginHorizontal: 12, color: failed ? colors.destructive : colors.tertiaryLabel, fontSize: 11, lineHeight: 14 }}
364
+ >
365
+ {failed ? labels.notSent : message.timeLabel}
366
+ </NativeText>
367
+ </View>
368
+ );
369
+ }
370
+
371
+ function DefaultAttachment({ uri, width, height, accessibilityLabel, onPress, testID }: ThreadPageSlotMap["attachment"]) {
372
+ const ratio = width && height ? width / height : 0.6;
373
+ const w = 140;
374
+ return (
375
+ <Pressable testID={testID} accessibilityRole="image" accessibilityLabel={accessibilityLabel ?? "Attachment"} onPress={onPress} disabled={!onPress}>
376
+ <Image source={{ uri }} style={{ width: w, height: Math.round(w / ratio), borderRadius: 12 }} resizeMode="cover" />
377
+ </Pressable>
378
+ );
379
+ }
380
+
381
+ function DefaultReadReceipt({ label, testID }: ThreadPageSlotMap["readReceipt"]) {
382
+ const colors = useThemeRoles();
383
+ return (
384
+ <NativeText testID={testID} style={{ alignSelf: "flex-end", marginHorizontal: 12, color: colors.secondaryLabel, fontSize: 11, lineHeight: 14 }}>
385
+ {label}
386
+ </NativeText>
387
+ );
388
+ }
389
+
390
+ function DefaultComposer({
391
+ value,
392
+ onChangeText,
393
+ onSend,
394
+ sending = false,
395
+ placeholder = "Message",
396
+ sendLabel = "Send",
397
+ disabled = false,
398
+ maxLength,
399
+ testID,
400
+ accessory,
401
+ }: ThreadPageSlotMap["composer"]) {
402
+ const colors = useThemeRoles();
403
+ const blank = !value.trim();
404
+ return (
405
+ <View
406
+ testID={testID}
407
+ style={{ flexDirection: "row", alignItems: "flex-end", gap: 8, paddingHorizontal: 12, paddingTop: 8, paddingBottom: 8, backgroundColor: colors.groupedBackground }}
408
+ >
409
+ {accessory}
410
+ <TextInput
411
+ testID={`${testID}-input`}
412
+ value={value}
413
+ onChangeText={onChangeText}
414
+ placeholder={placeholder}
415
+ placeholderTextColor={colors.tertiaryLabel as string}
416
+ accessibilityLabel={placeholder}
417
+ multiline
418
+ maxLength={maxLength}
419
+ editable={!sending}
420
+ style={{
421
+ flex: 1,
422
+ minHeight: 36,
423
+ maxHeight: 120,
424
+ paddingHorizontal: 14,
425
+ paddingTop: 8,
426
+ paddingBottom: 8,
427
+ borderRadius: 18,
428
+ fontSize: 17,
429
+ color: colors.label as string,
430
+ backgroundColor: colors.surface,
431
+ }}
432
+ />
433
+ {sending ? (
434
+ <View style={{ height: 36, justifyContent: "center", paddingHorizontal: 8 }}>
435
+ <ActivityIndicator testID={`${testID}-sending`} accessibilityLabel="Sending" />
436
+ </View>
437
+ ) : (
438
+ <NativeButton size="sm" onPress={onSend} disabled={disabled || blank} testID={`${testID}-send`}>
439
+ {sendLabel}
440
+ </NativeButton>
441
+ )}
442
+ </View>
443
+ );
444
+ }
@@ -0,0 +1,186 @@
1
+ /**
2
+ * GenesisModulesProvider — the native modules an app opts in to, passed in
3
+ * once near the root. Genesis never `require()`s these itself: an app that
4
+ * has a module installed imports it and hands it over, and every component
5
+ * that could use it falls back to plain React Native when it isn't here.
6
+ *
7
+ * import { FlashList } from "@shopify/flash-list";
8
+ * import { Image } from "expo-image";
9
+ * import * as Reanimated from "react-native-reanimated";
10
+ * import * as GlassEffect from "expo-glass-effect";
11
+ * import { SymbolView } from "expo-symbols";
12
+ * import DateTimePicker from "@expo/ui/community/datetime-picker";
13
+ * import { lucideIcons } from "@marktiderman/genesis-ui-native/icons/lucide";
14
+ *
15
+ * // At module scope, not inline:
16
+ * const modules = { list: FlashList, image: Image, reanimated: Reanimated, glass: GlassEffect,
17
+ * symbol: SymbolView, icons: lucideIcons, datePicker: DateTimePicker };
18
+ * <GenesisModulesProvider modules={modules}>…</GenesisModulesProvider>
19
+ *
20
+ * (`GenesisNativeApp` from `@marktiderman/genesis-native` takes the same
21
+ * object as its `modules` prop and mounts this for you.)
22
+ *
23
+ * | Module | Used by | Without it |
24
+ * | ------------------------------ | ---------------------------------------- | ----------------------------- |
25
+ * | `list` (FlashList v2) | NativeResourcePage, NotificationsPage | FlatList / SectionList |
26
+ * | `image` (expo-image) | NativeAvatar, NativeImage | React Native `Image` |
27
+ * | `reanimated` (Reanimated 4) | Toast, Drawer, Skeleton | React Native `Animated` |
28
+ * | `glass` (expo-glass-effect) | Toast, NativeGlassSurface, update banner | the solid surface |
29
+ * | `symbol` (expo-symbols) | NativeIcon on iOS | `icons` (lucide) |
30
+ * | `icons` (a lucide icon set) | NativeIcon on Android, web, and as the SF Symbol fallback | a blank space of the icon's size |
31
+ * | `datePicker` (@expo/ui) | NativeDatePicker, NativeTimePicker | @react-native-community/datetimepicker |
32
+ *
33
+ * The props below are written structurally (no import of the optional
34
+ * packages), so this package builds and type-checks without any of them.
35
+ *
36
+ * @stability Beta
37
+ */
38
+ import { createContext, createElement, useContext, useMemo, type ComponentType, type ReactNode } from "react";
39
+ import type { ColorValue } from "react-native";
40
+ import type { NativeIconName } from "./icon-names";
41
+
42
+ /** The FlatList props Genesis lists pass; FlashList v2 takes the same ones. */
43
+ export interface GenesisListProps<T> {
44
+ data: readonly T[];
45
+ renderItem: (info: { item: T; index: number }) => ReactNode;
46
+ keyExtractor?: (item: T, index: number) => string;
47
+ getItemType?: (item: T, index: number) => string | number | undefined;
48
+ stickyHeaderIndices?: number[];
49
+ /** FlashList v2's: `offset` moves sticky headers down from the list's top (under a native header). */
50
+ stickyHeaderConfig?: { offset?: number };
51
+ ListHeaderComponent?: ReactNode | ComponentType<unknown> | null;
52
+ ListEmptyComponent?: ReactNode | ComponentType<unknown> | null;
53
+ contentContainerStyle?: Record<string, unknown>;
54
+ refreshing?: boolean;
55
+ onRefresh?: () => void;
56
+ refreshControl?: ReactNode;
57
+ testID?: string;
58
+ }
59
+
60
+ /** `FlashList` from `@shopify/flash-list` v2 (New Architecture only; no `estimatedItemSize`). */
61
+ export type GenesisListComponent = ComponentType<GenesisListProps<any>>;
62
+
63
+ /** The expo-image `Image` props Genesis passes. */
64
+ export interface GenesisImageProps {
65
+ source: { uri: string } | number | null;
66
+ style?: unknown;
67
+ contentFit?: "cover" | "contain" | "fill" | "none" | "scale-down";
68
+ cachePolicy?: "none" | "disk" | "memory" | "memory-disk";
69
+ placeholder?: unknown;
70
+ placeholderContentFit?: "cover" | "contain" | "fill" | "none" | "scale-down";
71
+ transition?: number | null;
72
+ recyclingKey?: string | null;
73
+ priority?: "low" | "normal" | "high" | null;
74
+ onError?: (event: unknown) => void;
75
+ onLoad?: (event: unknown) => void;
76
+ accessible?: boolean;
77
+ accessibilityLabel?: string;
78
+ testID?: string;
79
+ }
80
+
81
+ /** `Image` from `expo-image`. */
82
+ export type GenesisImageComponent = ComponentType<GenesisImageProps>;
83
+
84
+ /** `import * as Reanimated from "react-native-reanimated"` (v4). Only what Genesis calls is listed. */
85
+ export interface GenesisReanimatedModule {
86
+ default: { View: ComponentType<any> };
87
+ useSharedValue: <V>(initial: V) => { value: V };
88
+ useAnimatedStyle: (updater: () => Record<string, unknown>, deps?: unknown[]) => Record<string, unknown>;
89
+ withTiming: (toValue: number, config?: { duration?: number; easing?: unknown; reduceMotion?: unknown }, callback?: (finished?: boolean) => void) => number;
90
+ withRepeat: (animation: number, numberOfReps?: number, reverse?: boolean, callback?: unknown, reduceMotion?: unknown) => number;
91
+ cancelAnimation: (value: { value: unknown }) => void;
92
+ Easing: { inOut: (easing: unknown) => unknown; ease: unknown; out: (easing: unknown) => unknown; cubic: unknown };
93
+ ReduceMotion?: { System: unknown; Always: unknown; Never: unknown };
94
+ }
95
+
96
+ /** `import * as GlassEffect from "expo-glass-effect"`. */
97
+ export interface GenesisGlassModule {
98
+ GlassView: ComponentType<{
99
+ style?: unknown;
100
+ glassEffectStyle?: "regular" | "clear" | "none";
101
+ tintColor?: string;
102
+ isInteractive?: boolean;
103
+ colorScheme?: "auto" | "light" | "dark";
104
+ children?: ReactNode;
105
+ testID?: string;
106
+ pointerEvents?: "box-none" | "none" | "box-only" | "auto";
107
+ }>;
108
+ isLiquidGlassAvailable: () => boolean;
109
+ isGlassEffectAPIAvailable: () => boolean;
110
+ }
111
+
112
+ /** The expo-symbols `SymbolView` props Genesis passes. */
113
+ export interface GenesisSymbolProps {
114
+ name: string;
115
+ size?: number;
116
+ tintColor?: ColorValue;
117
+ type?: "monochrome" | "hierarchical" | "palette" | "multicolor";
118
+ weight?: string;
119
+ fallback?: ReactNode;
120
+ style?: unknown;
121
+ accessible?: boolean;
122
+ accessibilityLabel?: string;
123
+ testID?: string;
124
+ }
125
+
126
+ /** `SymbolView` from `expo-symbols`. */
127
+ export type GenesisSymbolComponent = ComponentType<GenesisSymbolProps>;
128
+
129
+ /** A lucide-style icon component: `size`, `color`, `strokeWidth`. */
130
+ export type GenesisIconComponent = ComponentType<{ size?: number; color?: ColorValue; strokeWidth?: number; testID?: string }>;
131
+
132
+ /** Icon components by semantic name (`lucideIcons` from `/icons/lucide` is one). Missing names draw nothing. */
133
+ export type GenesisIconSet = Partial<Record<NativeIconName, GenesisIconComponent>>;
134
+
135
+ /** The `@expo/ui/community/datetime-picker` props Genesis passes (a drop-in for the community picker). */
136
+ export interface GenesisDatePickerProps {
137
+ value: Date;
138
+ mode: "date" | "time";
139
+ display?: "default" | "compact" | "spinner" | "inline";
140
+ presentation?: "inline" | "dialog";
141
+ disabled?: boolean;
142
+ onValueChange?: (event: unknown, date: Date) => void;
143
+ onDismiss?: () => void;
144
+ style?: unknown;
145
+ testID?: string;
146
+ }
147
+
148
+ /** The default export of `@expo/ui/community/datetime-picker`. */
149
+ export type GenesisDatePickerComponent = ComponentType<GenesisDatePickerProps>;
150
+
151
+ /** Every optional native module Genesis components can use. Each is optional on its own. */
152
+ export interface GenesisModules {
153
+ list?: GenesisListComponent;
154
+ image?: GenesisImageComponent;
155
+ reanimated?: GenesisReanimatedModule;
156
+ glass?: GenesisGlassModule;
157
+ symbol?: GenesisSymbolComponent;
158
+ icons?: GenesisIconSet;
159
+ datePicker?: GenesisDatePickerComponent;
160
+ }
161
+
162
+ const EMPTY: GenesisModules = Object.freeze({});
163
+ const GenesisModulesContext = createContext<GenesisModules>(EMPTY);
164
+
165
+ export interface GenesisModulesProviderProps {
166
+ modules: GenesisModules;
167
+ children: ReactNode;
168
+ }
169
+
170
+ /**
171
+ * Pass the optional native modules the app has installed. Nested providers
172
+ * merge: an inner one adds to or replaces what an outer one gave. Define the
173
+ * `modules` object once at module scope (as the starter's
174
+ * `src/lib/native-modules.ts` does): a new inline object on every render
175
+ * re-renders every component that reads it.
176
+ */
177
+ export function GenesisModulesProvider({ modules, children }: GenesisModulesProviderProps) {
178
+ const outer = useContext(GenesisModulesContext);
179
+ const value = useMemo(() => (outer === EMPTY ? modules : { ...outer, ...modules }), [outer, modules]);
180
+ return createElement(GenesisModulesContext.Provider, { value }, children);
181
+ }
182
+
183
+ /** The modules given to the nearest `GenesisModulesProvider`; `{}` without one. */
184
+ export function useGenesisModules(): GenesisModules {
185
+ return useContext(GenesisModulesContext);
186
+ }