@marktiderman/genesis-ui-native 3.5.0 → 3.6.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 (92) hide show
  1. package/README.md +71 -7
  2. package/dist/{chunk-LBVD7XXL.js → chunk-2Z72MYHB.js} +627 -20
  3. package/dist/chunk-2Z72MYHB.js.map +1 -0
  4. package/dist/chunk-4OQOJ2OC.js +80 -0
  5. package/dist/chunk-4OQOJ2OC.js.map +1 -0
  6. package/dist/{chunk-6KWEAGRD.js → chunk-6PGLX6ET.js} +101 -6
  7. package/dist/chunk-6PGLX6ET.js.map +1 -0
  8. package/dist/{chunk-ONH2PCGH.js → chunk-AGTBABAH.js} +9 -15
  9. package/dist/chunk-AGTBABAH.js.map +1 -0
  10. package/dist/{chunk-ABVSSJNT.js → chunk-FUMSL7VZ.js} +198 -168
  11. package/dist/chunk-FUMSL7VZ.js.map +1 -0
  12. package/dist/{chunk-GHYUNNNU.js → chunk-NDXNSSM6.js} +175 -93
  13. package/dist/chunk-NDXNSSM6.js.map +1 -0
  14. package/dist/chunk-SEJ6RBP7.js +361 -0
  15. package/dist/chunk-SEJ6RBP7.js.map +1 -0
  16. package/dist/{chunk-D5RKSPMH.js → chunk-ZRQAFFTN.js} +4 -3
  17. package/dist/chunk-ZRQAFFTN.js.map +1 -0
  18. package/dist/components/index.d.ts +331 -4
  19. package/dist/components/index.js +5 -5
  20. package/dist/data/index.d.ts +68 -4
  21. package/dist/data/index.js +235 -31
  22. package/dist/data/index.js.map +1 -1
  23. package/dist/hooks/index.d.ts +60 -1
  24. package/dist/hooks/index.js +2 -3
  25. package/dist/icons/lucide.d.ts +1 -1
  26. package/dist/icons/lucide.js +7 -1
  27. package/dist/icons/lucide.js.map +1 -1
  28. package/dist/{inbox-page-BEarNEIP.d.ts → inbox-page-B7_Oi2fS.d.ts} +2 -44
  29. package/dist/index.d.ts +8 -5
  30. package/dist/index.js +8 -8
  31. package/dist/layouts/index.d.ts +40 -51
  32. package/dist/layouts/index.js +5 -4
  33. package/dist/{native-modules-PwnGltOU.d.ts → native-modules-Cl3zw3kh.d.ts} +27 -1
  34. package/package.json +78 -4
  35. package/src/__tests__/doctor-rules.test.ts +60 -0
  36. package/src/__tests__/native-modules-lists.test.tsx +1 -0
  37. package/src/components/__tests__/composer-bar.test.tsx +55 -0
  38. package/src/components/__tests__/gallery-card.test.tsx +59 -0
  39. package/src/components/__tests__/gallery-grid.test.tsx +160 -0
  40. package/src/components/__tests__/lightbox-resnap.test.tsx +50 -0
  41. package/src/components/__tests__/lightbox-zoom.test.ts +33 -0
  42. package/src/components/__tests__/lightbox.test.tsx +141 -0
  43. package/src/components/__tests__/live-indicator.test.tsx +72 -0
  44. package/src/components/__tests__/rating.test.tsx +82 -0
  45. package/src/components/__tests__/thread-list.test.tsx +156 -0
  46. package/src/components/composer-bar.tsx +198 -0
  47. package/src/components/drawer.tsx +15 -9
  48. package/src/components/gallery-card.tsx +109 -0
  49. package/src/components/gallery-grid.tsx +285 -0
  50. package/src/components/gallery-layout.ts +2 -0
  51. package/src/components/gallery-types.ts +2 -0
  52. package/src/components/index.ts +44 -0
  53. package/src/components/lightbox-zoom.tsx +282 -0
  54. package/src/components/lightbox.tsx +342 -0
  55. package/src/components/live-indicator.tsx +139 -0
  56. package/src/components/rating.tsx +128 -0
  57. package/src/components/skeleton.tsx +9 -4
  58. package/src/components/thread-list.tsx +427 -0
  59. package/src/components/toast.tsx +7 -4
  60. package/src/data/NativeConflictSheet.tsx +181 -0
  61. package/src/data/NativeResourceForm.tsx +15 -1
  62. package/src/data/index.ts +2 -0
  63. package/src/data/resource-view/NativeLinkPicker.tsx +1 -1
  64. package/src/data/resource-view/NativeRecordView.tsx +85 -8
  65. package/src/data/resource-view/NativeResourceView.tsx +79 -32
  66. package/src/data/resource-view/__tests__/native-link-picker.test.tsx +16 -0
  67. package/src/data/resource-view/__tests__/native-record-view.test.tsx +95 -1
  68. package/src/data/resource-view/__tests__/native-resource-gallery.test.tsx +125 -0
  69. package/src/data/resource-view/mapping.ts +3 -0
  70. package/src/hooks/__tests__/use-motion.test.tsx +106 -0
  71. package/src/hooks/__tests__/use-thread-jump.test.tsx +88 -0
  72. package/src/hooks/index.ts +3 -0
  73. package/src/hooks/use-motion.ts +128 -0
  74. package/src/hooks/use-thread-jump.ts +110 -0
  75. package/src/icon-names.ts +6 -0
  76. package/src/icons/lucide.ts +12 -0
  77. package/src/layouts/__tests__/inbox-page.test.tsx +6 -0
  78. package/src/layouts/__tests__/thread-page.test.tsx +114 -14
  79. package/src/layouts/inbox-page.tsx +6 -55
  80. package/src/layouts/index.ts +2 -0
  81. package/src/layouts/thread-page.tsx +326 -262
  82. package/src/native-modules.tsx +16 -2
  83. package/dist/chunk-6KWEAGRD.js.map +0 -1
  84. package/dist/chunk-7PCWEY6R.js +0 -27
  85. package/dist/chunk-7PCWEY6R.js.map +0 -1
  86. package/dist/chunk-ABVSSJNT.js.map +0 -1
  87. package/dist/chunk-D5RKSPMH.js.map +0 -1
  88. package/dist/chunk-GHYUNNNU.js.map +0 -1
  89. package/dist/chunk-LBVD7XXL.js.map +0 -1
  90. package/dist/chunk-ONH2PCGH.js.map +0 -1
  91. package/dist/chunk-Z3AQYVUA.js +0 -36
  92. package/dist/chunk-Z3AQYVUA.js.map +0 -1
@@ -0,0 +1,427 @@
1
+ /**
2
+ * NativeThreadList — a conversation's list: oldest first, top to bottom (the
3
+ * order VoiceOver reads), that opens at the newest row, follows new rows only
4
+ * while you're at the bottom, keeps your place while earlier rows load at the
5
+ * top, and can go to one row (a search result, the first unread).
6
+ *
7
+ * The atom under ThreadPage, and the one any app builds its own thread from:
8
+ * it renders the rows it's given and never fetches. Earlier pages come from
9
+ * `onLoadEarlier`, a row out of reach from `onLoadUntil(id)`.
10
+ *
11
+ * FlashList v2 (`GenesisModules.list`) when the app passed it: its chat mode
12
+ * (`startRenderingFromBottom`, `autoscrollToBottomThreshold`, the first
13
+ * visible row held when rows prepend). Without it, FlatList, which keeps its
14
+ * place with `maintainVisibleContentPosition` (anchored past the header) and
15
+ * follows the bottom by hand.
16
+ *
17
+ * Not inverted: in an inverted FlashList a new row at index 0 lands under the
18
+ * composer, and VoiceOver reads each day's heading after its messages.
19
+ *
20
+ * Earlier rows load by themselves near the top, and the explicit "Load
21
+ * earlier" button stays: VoiceOver can't reach rows a virtualized list hasn't
22
+ * rendered. Going to a row waits for `loading`, loads until it's held,
23
+ * scrolls to it (again after FlashList's own placement on open), highlights
24
+ * it for two seconds and announces it. Reduce Motion scrolls without
25
+ * animating.
26
+ *
27
+ * Promoted from genesis-chat's thread and its `useJumpToMessage` (G4); chat
28
+ * moves onto it later.
29
+ *
30
+ * @stability Beta
31
+ */
32
+ import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState, type ComponentType, type ReactElement, type ReactNode } from "react";
33
+ import { AccessibilityInfo, FlatList, Platform, Pressable, View } from "react-native";
34
+ import { useGenesisModules } from "../native-modules";
35
+ import { useReducedMotion } from "../hooks/use-reduced-motion";
36
+ import { useThemeRoles } from "../hooks/use-theme-roles";
37
+ import { useThreadJump } from "@marktiderman/genesis-core/conversation";
38
+ import { NativeSkeleton } from "./skeleton";
39
+ import { NativeText } from "./text";
40
+
41
+ /** The scroll event fields the list reads. */
42
+ interface ScrollMetrics {
43
+ contentOffset: { y: number };
44
+ contentSize: { height: number };
45
+ layoutMeasurement: { height: number };
46
+ }
47
+
48
+ const announce = (text: string) => (AccessibilityInfo as { announceForAccessibility?: (t: string) => void }).announceForAccessibility?.(text);
49
+
50
+ /** Points from the bottom that still count as "at the bottom". */
51
+ export const THREAD_AT_BOTTOM_POINTS = 120;
52
+
53
+ /** After the list scrolls itself (to the newest, to a row), how long its own scroll events don't count. */
54
+ const SETTLING_MS = 400;
55
+
56
+ /** Whether a scroll position is at (or near) the bottom of its content. */
57
+ export function threadNearBottom(m: ScrollMetrics, slack = THREAD_AT_BOTTOM_POINTS): boolean {
58
+ return m.contentOffset.y + m.layoutMeasurement.height >= m.contentSize.height - slack;
59
+ }
60
+
61
+ /**
62
+ * How the list is set up. FlashList follows by itself, within
63
+ * `THREAD_AT_BOTTOM_POINTS` of the bottom (its threshold is a fraction of the
64
+ * viewport: a fifth until the viewport's height is known); FlatList keeps its
65
+ * place on prepend, anchored on the first row past the header (index 1: the
66
+ * header is child 0), and the list follows the bottom by hand.
67
+ */
68
+ export function threadListMode(
69
+ flash: boolean,
70
+ reducedMotion: boolean,
71
+ viewportHeight = 0,
72
+ ): { followsByHand: boolean; maintainVisibleContentPosition: Record<string, unknown> } {
73
+ if (flash) {
74
+ const threshold = viewportHeight > 0 ? Math.min(1, THREAD_AT_BOTTOM_POINTS / viewportHeight) : 0.2;
75
+ return {
76
+ followsByHand: false,
77
+ maintainVisibleContentPosition: { startRenderingFromBottom: true, autoscrollToBottomThreshold: threshold, animateAutoScrollToBottom: !reducedMotion },
78
+ };
79
+ }
80
+ return { followsByHand: true, maintainVisibleContentPosition: { minIndexForVisible: 1 } };
81
+ }
82
+
83
+ export interface NativeThreadListHandle {
84
+ /** Go to the newest row (after a send: what you send is what you look at next). */
85
+ scrollToEnd: (options?: { animated?: boolean }) => void;
86
+ }
87
+
88
+ /** What `renderItem` is told about a row besides the row itself. */
89
+ export interface ThreadRowInfo {
90
+ index: number;
91
+ /** The row a jump just landed on, for two seconds. */
92
+ highlighted: boolean;
93
+ }
94
+
95
+ export interface NativeThreadListProps<T> {
96
+ /** Oldest first. */
97
+ data: readonly T[];
98
+ /** A row's id. It must stay the same across refreshes (from a cache to the server), or rows jump. */
99
+ keyExtractor: (row: T) => string;
100
+ renderItem: (row: T, info: ThreadRowInfo) => ReactElement | null;
101
+ /** Rows of different shapes recycle apart (FlashList): "mine", "theirs", "event". */
102
+ getItemType?: (row: T) => string;
103
+ /** The first page is loading: shows `loadingView` (a skeleton by default), and a jump waits. */
104
+ loading?: boolean;
105
+ loadingView?: ReactNode;
106
+ /** There are earlier rows: loads them near the top, and shows the "Load earlier" button. */
107
+ hasEarlier?: boolean;
108
+ onLoadEarlier?: () => void;
109
+ loadingEarlier?: boolean;
110
+ earlierLabel?: string;
111
+ /** Replaces the default "Load earlier" button. */
112
+ renderEarlier?: (props: { loading: boolean; onPress: () => void; label: string; testID: string }) => ReactNode;
113
+ /** Go to this row, loading earlier pages with `onLoadUntil` until it's here. A new id, or the same one after `null`, goes again. */
114
+ jumpTo?: string | null;
115
+ /** Load earlier pages until the row is held; resolve false when it can't be found. */
116
+ onLoadUntil?: (id: string) => Promise<boolean>;
117
+ /** What VoiceOver says on arriving at `jumpTo`. */
118
+ jumpAnnouncement?: (row: T) => string;
119
+ /** The row couldn't be found (deleted, out of reach). The list goes back to the newest row first. */
120
+ onJumpFailed?: (id: string) => void;
121
+ /** Whether the reader is at the bottom, as it changes (to show a "new messages" pill, say). */
122
+ onAtBottomChange?: (atBottom: boolean) => void;
123
+ /** Above the first row, before the "Load earlier" button: what the thread is about. */
124
+ header?: ReactNode;
125
+ /** Under the last row: who is typing, a "Sending…" line. */
126
+ footer?: ReactNode;
127
+ /** Shown instead of the rows when there are none. */
128
+ empty?: ReactNode;
129
+ testID?: string;
130
+ }
131
+
132
+ /** The FlatList and FlashList v2 props the thread passes. */
133
+ interface ThreadListComponentProps {
134
+ ref?: unknown;
135
+ data: readonly unknown[];
136
+ renderItem: (info: { item: unknown; index: number }) => ReactElement | null;
137
+ keyExtractor: (row: unknown) => string;
138
+ getItemType?: (row: unknown) => string;
139
+ extraData?: unknown;
140
+ onStartReached?: () => void;
141
+ onStartReachedThreshold?: number;
142
+ ListHeaderComponent?: ReactElement | null;
143
+ ListFooterComponent?: ReactElement | null;
144
+ keyboardShouldPersistTaps?: "handled";
145
+ keyboardDismissMode?: "interactive" | "on-drag";
146
+ contentInsetAdjustmentBehavior?: "automatic";
147
+ contentContainerStyle?: Record<string, unknown>;
148
+ maintainVisibleContentPosition?: Record<string, unknown>;
149
+ onScroll?: (e: { nativeEvent: ScrollMetrics }) => void;
150
+ scrollEventThrottle?: number;
151
+ onContentSizeChange?: () => void;
152
+ onLayout?: () => void;
153
+ onScrollToIndexFailed?: (info: { index: number; averageItemLength: number }) => void;
154
+ accessibilityRole?: "list";
155
+ testID?: string;
156
+ }
157
+
158
+ interface ListRef {
159
+ scrollToEnd?: (o?: { animated?: boolean }) => void;
160
+ scrollToIndex?: (o: { index: number; animated?: boolean; viewPosition?: number }) => void;
161
+ scrollToOffset?: (o: { offset: number; animated?: boolean }) => void;
162
+ }
163
+
164
+ function NativeThreadListInner<T>(props: NativeThreadListProps<T>, ref: React.ForwardedRef<NativeThreadListHandle>) {
165
+ const {
166
+ data,
167
+ keyExtractor,
168
+ renderItem,
169
+ getItemType,
170
+ loading = false,
171
+ loadingView,
172
+ hasEarlier = false,
173
+ onLoadEarlier,
174
+ loadingEarlier = false,
175
+ earlierLabel = "Load earlier messages",
176
+ renderEarlier,
177
+ jumpTo,
178
+ onLoadUntil,
179
+ jumpAnnouncement,
180
+ onJumpFailed,
181
+ onAtBottomChange,
182
+ footer,
183
+ header,
184
+ empty,
185
+ testID = "thread-list",
186
+ } = props;
187
+ const genesis = useGenesisModules();
188
+ const reducedMotion = useReducedMotion();
189
+ const List = (genesis.list ?? FlatList) as unknown as ComponentType<ThreadListComponentProps>;
190
+ const [viewport, setViewport] = useState(0);
191
+ const mode = threadListMode(Boolean(genesis.list), reducedMotion, viewport);
192
+ // The last position the list reported, to re-check "at the bottom" after it moves itself.
193
+ const metrics = useRef<ScrollMetrics | null>(null);
194
+ const recheck = useRef<ReturnType<typeof setTimeout> | null>(null);
195
+ useEffect(() => () => {
196
+ if (recheck.current) clearTimeout(recheck.current);
197
+ }, []);
198
+ const listRef = useRef<ListRef | null>(null);
199
+ // At the bottom (or not yet scrolled): new rows and a shorter list keep it there.
200
+ const atBottom = useRef(true);
201
+ // FlatList opens at the top and is moved down a frame later: until then the top isn't "reached".
202
+ const placed = useRef(!mode.followsByHand);
203
+ // While the list scrolls itself, its own scroll events don't move "at the bottom".
204
+ const settlingUntil = useRef(0);
205
+ const timers = useRef(new Set<ReturnType<typeof setTimeout>>());
206
+ const later = useCallback((fn: () => void, ms: number) => {
207
+ const t = setTimeout(() => {
208
+ timers.current.delete(t);
209
+ fn();
210
+ }, ms);
211
+ timers.current.add(t);
212
+ }, []);
213
+ useEffect(() => {
214
+ const pending = timers.current;
215
+ return () => pending.forEach(clearTimeout);
216
+ }, []);
217
+ const latest = useRef({ data, keyExtractor, jumpAnnouncement, onJumpFailed, onAtBottomChange });
218
+ latest.current = { data, keyExtractor, jumpAnnouncement, onJumpFailed, onAtBottomChange };
219
+ const indexOf = useCallback((id: string) => latest.current.data.findIndex((row) => latest.current.keyExtractor(row) === id), []);
220
+
221
+ const setAtBottom = useCallback((v: boolean) => {
222
+ if (atBottom.current === v) return;
223
+ atBottom.current = v;
224
+ latest.current.onAtBottomChange?.(v);
225
+ }, []);
226
+
227
+ const toBottom = useCallback(
228
+ (animated: boolean) => {
229
+ settlingUntil.current = Date.now() + SETTLING_MS;
230
+ const go = (a: boolean) => listRef.current?.scrollToEnd?.({ animated: a && !reducedMotion });
231
+ requestAnimationFrame(() => {
232
+ go(animated);
233
+ placed.current = true;
234
+ });
235
+ // Once more after a new row has its size (FlashList measures it after the first pass).
236
+ if (animated) later(() => go(true), 180);
237
+ },
238
+ [later, reducedMotion],
239
+ );
240
+
241
+ useImperativeHandle(
242
+ ref,
243
+ () => ({
244
+ scrollToEnd: (options) => {
245
+ setAtBottom(true);
246
+ toBottom(options?.animated ?? true);
247
+ },
248
+ }),
249
+ [setAtBottom, toBottom],
250
+ );
251
+
252
+ // Going to a row: by id, so a page loading in between can't send it to the wrong row.
253
+ const jumpTries = useRef<{ id: string; tries: number } | null>(null);
254
+ const scrollToRow = useCallback(
255
+ (id: string) => {
256
+ const scroll = () => {
257
+ const at = indexOf(id);
258
+ if (at >= 0) listRef.current?.scrollToIndex?.({ index: at, animated: !reducedMotion, viewPosition: 0.5 });
259
+ };
260
+ jumpTries.current = { id, tries: 0 };
261
+ settlingUntil.current = Date.now() + SETTLING_MS;
262
+ requestAnimationFrame(scroll);
263
+ // Once more after the first layout: on open, FlashList's start-at-the-bottom placement comes after
264
+ // the first frame and would win, leaving the thread at the bottom.
265
+ later(scroll, 250);
266
+ },
267
+ [indexOf, later, reducedMotion],
268
+ );
269
+ const has = useCallback((id: string) => indexOf(id) >= 0, [indexOf]);
270
+ // `has` must change when the rows do, so the jump looks again.
271
+ const hasNow = useMemo(() => (id: string) => has(id), [has, data]); // eslint-disable-line react-hooks/exhaustive-deps
272
+ const { highlightedId, jumping } = useThreadJump({
273
+ target: jumpTo,
274
+ has: hasNow,
275
+ loading,
276
+ loadUntil: onLoadUntil,
277
+ scrollTo: scrollToRow,
278
+ onStart: () => {
279
+ setAtBottom(false);
280
+ placed.current = true;
281
+ },
282
+ onLanded: (id) => {
283
+ // A jump to a row already at the bottom moves nothing, so no scroll event says so: look once it settles.
284
+ if (recheck.current) clearTimeout(recheck.current);
285
+ recheck.current = setTimeout(() => {
286
+ if (metrics.current && threadNearBottom(metrics.current)) setAtBottom(true);
287
+ }, SETTLING_MS + 50);
288
+ const at = indexOf(id);
289
+ const said = at >= 0 ? latest.current.jumpAnnouncement?.(latest.current.data[at]!) : undefined;
290
+ if (said) announce(said);
291
+ },
292
+ onGone: (id) => {
293
+ // Back to where the thread opens: the newest rows.
294
+ setAtBottom(true);
295
+ toBottom(false);
296
+ latest.current.onJumpFailed?.(id);
297
+ },
298
+ });
299
+
300
+ const loadEarlier = useCallback(() => {
301
+ if (placed.current && !jumping && hasEarlier && !loadingEarlier) onLoadEarlier?.();
302
+ }, [hasEarlier, jumping, loadingEarlier, onLoadEarlier]);
303
+
304
+ const earlierProps = { loading: loadingEarlier, onPress: () => onLoadEarlier?.(), label: earlierLabel, testID: `${testID}-earlier` };
305
+ const listHeader = (
306
+ <View>
307
+ {header}
308
+ {hasEarlier && onLoadEarlier ? (renderEarlier ? renderEarlier(earlierProps) : <DefaultEarlier {...earlierProps} />) : null}
309
+ </View>
310
+ );
311
+
312
+ const renderListItem = useCallback(
313
+ ({ item, index }: { item: unknown; index: number }) => renderItem(item as T, { index, highlighted: highlightedId !== null && keyExtractor(item as T) === highlightedId }),
314
+ [highlightedId, keyExtractor, renderItem],
315
+ );
316
+ const listKey = useCallback((row: unknown) => keyExtractor(row as T), [keyExtractor]);
317
+ const listItemType = useMemo(() => (getItemType ? (row: unknown) => getItemType(row as T) : undefined), [getItemType]);
318
+ const onScroll = useCallback(
319
+ (e: { nativeEvent: ScrollMetrics }) => {
320
+ metrics.current = { contentOffset: { y: e.nativeEvent.contentOffset.y }, contentSize: { height: e.nativeEvent.contentSize.height }, layoutMeasurement: { height: e.nativeEvent.layoutMeasurement.height } };
321
+ const height = e.nativeEvent.layoutMeasurement.height;
322
+ setViewport((v) => (Math.abs(v - height) < 1 ? v : height));
323
+ const near = threadNearBottom(e.nativeEvent);
324
+ // The list's own scroll (to the newest, to a row) passes through "not at the bottom": ignore that.
325
+ if (!near && Date.now() < settlingUntil.current) return;
326
+ setAtBottom(near);
327
+ },
328
+ [setAtBottom],
329
+ );
330
+ const onScrollToIndexFailed = useCallback(
331
+ ({ index, averageItemLength }: { index: number; averageItemLength: number }) => {
332
+ // FlatList hasn't measured that far up yet: get near it, then try again by id (three times at most).
333
+ listRef.current?.scrollToOffset?.({ offset: Math.max(0, index * averageItemLength - 200), animated: false });
334
+ const target = jumpTries.current;
335
+ if (!target || target.tries >= 3) return;
336
+ target.tries += 1;
337
+ later(() => {
338
+ const at = indexOf(target.id);
339
+ if (at >= 0) listRef.current?.scrollToIndex?.({ index: at, animated: !reducedMotion, viewPosition: 0.5 });
340
+ }, 250);
341
+ },
342
+ [indexOf, later, reducedMotion],
343
+ );
344
+ const follow = useCallback(() => {
345
+ if (atBottom.current && !jumping) toBottom(false);
346
+ }, [jumping, toBottom]);
347
+
348
+ if (loading && data.length === 0) {
349
+ return (
350
+ <View testID={`${testID}-loading`} accessible accessibilityLabel="Loading" style={{ flex: 1, justifyContent: "flex-end", padding: 16, gap: 10 }}>
351
+ {loadingView ?? <DefaultLoading />}
352
+ </View>
353
+ );
354
+ }
355
+
356
+ if (data.length === 0 && empty) {
357
+ return (
358
+ <View testID={testID} style={{ flex: 1, justifyContent: "center" }}>
359
+ {listHeader}
360
+ {empty}
361
+ </View>
362
+ );
363
+ }
364
+
365
+ return (
366
+ <List
367
+ ref={listRef}
368
+ testID={testID}
369
+ accessibilityRole="list"
370
+ data={data as readonly unknown[]}
371
+ renderItem={renderListItem}
372
+ keyExtractor={listKey}
373
+ getItemType={listItemType}
374
+ extraData={highlightedId}
375
+ onStartReached={loadEarlier}
376
+ onStartReachedThreshold={0.5}
377
+ keyboardShouldPersistTaps="handled"
378
+ keyboardDismissMode={Platform.select({ ios: "interactive" as const, default: "on-drag" as const })}
379
+ contentInsetAdjustmentBehavior="automatic"
380
+ contentContainerStyle={{ paddingVertical: 8, paddingHorizontal: 12 }}
381
+ maintainVisibleContentPosition={mode.maintainVisibleContentPosition}
382
+ scrollEventThrottle={32}
383
+ onScroll={onScroll}
384
+ onScrollToIndexFailed={onScrollToIndexFailed}
385
+ {...(mode.followsByHand ? { onContentSizeChange: follow, onLayout: follow } : {})}
386
+ ListHeaderComponent={listHeader}
387
+ ListFooterComponent={footer ? <View>{footer}</View> : null}
388
+ />
389
+ );
390
+ }
391
+
392
+ /** A conversation's list. See the module docs. */
393
+ export const NativeThreadList = forwardRef(NativeThreadListInner) as <T>(
394
+ props: NativeThreadListProps<T> & { ref?: React.Ref<NativeThreadListHandle> },
395
+ ) => ReactElement | null;
396
+
397
+ function DefaultEarlier({ loading, label, onPress, testID }: { loading: boolean; label: string; onPress: () => void; testID: string }) {
398
+ const colors = useThemeRoles();
399
+ return (
400
+ <View style={{ alignItems: "center", paddingVertical: 12 }}>
401
+ {loading ? (
402
+ <View testID={`${testID}-loading`} accessible accessibilityLabel={label} accessibilityState={{ busy: true }} style={{ gap: 8, alignItems: "center" }}>
403
+ <NativeSkeleton width={180} height={14} />
404
+ <NativeSkeleton width={120} height={14} />
405
+ </View>
406
+ ) : (
407
+ <Pressable testID={testID} accessibilityRole="button" accessibilityLabel={label} onPress={onPress} style={{ minHeight: 44, justifyContent: "center", paddingHorizontal: 16 }}>
408
+ <NativeText preset="label" style={{ color: colors.tint }}>
409
+ {label}
410
+ </NativeText>
411
+ </Pressable>
412
+ )}
413
+ </View>
414
+ );
415
+ }
416
+
417
+ function DefaultLoading() {
418
+ return (
419
+ <>
420
+ <NativeSkeleton width={200} height={36} className="rounded-2xl" />
421
+ <View style={{ alignItems: "flex-end" }}>
422
+ <NativeSkeleton width={160} height={36} className="rounded-2xl" />
423
+ </View>
424
+ <NativeSkeleton width={240} height={36} className="rounded-2xl" />
425
+ </>
426
+ );
427
+ }
@@ -20,6 +20,7 @@
20
20
  *
21
21
  * @stability Beta
22
22
  */
23
+ import { MOTION_DURATIONS, MOTION_EASINGS } from "@marktiderman/genesis-design-system/tokens/motion";
23
24
  import {
24
25
  createContext,
25
26
  useCallback,
@@ -32,7 +33,7 @@ import {
32
33
  import { Animated, Pressable, Text } from "react-native";
33
34
  import { SafeAreaInsetsContext } from "react-native-safe-area-context";
34
35
  import { cn } from "../utils";
35
- import { useReducedMotion } from "../hooks/use-reduced-motion";
36
+ import { useMotion } from "../hooks/use-motion";
36
37
  import { useThemeMode } from "../hooks/use-theme-mode";
37
38
  import { useGenesisModules, type GenesisReanimatedModule } from "../native-modules";
38
39
  import { useLiquidGlass } from "./glass-surface";
@@ -79,7 +80,7 @@ export function NativeToastProvider({
79
80
  disableAnimation = false,
80
81
  }: NativeToastProviderProps) {
81
82
  const [queue, setQueue] = useState<ToastInstance[]>([]);
82
- const reducedMotion = useReducedMotion();
83
+ const reducedMotion = useMotion().reduced;
83
84
 
84
85
  const dismiss = useCallback((id?: number) => {
85
86
  setQueue((q) => (id == null ? q.slice(1) : q.filter((t) => t.id !== id)));
@@ -125,7 +126,8 @@ interface ToastFrameProps extends ToastViewProps {
125
126
  glass: GlassComponent | null;
126
127
  }
127
128
 
128
- const ENTER_MS = 180;
129
+ // The shared motion tokens: small things appear at `fast`.
130
+ const ENTER_MS = MOTION_DURATIONS.fast;
129
131
 
130
132
  // Reanimated 4 when the app passed it, else React Native's Animated. Two
131
133
  // components rather than one with a branch, so each keeps a fixed hook order.
@@ -195,7 +197,8 @@ function ReanimatedToastView({
195
197
  useAutoDismiss(toast, onDismiss);
196
198
  useEffect(() => {
197
199
  if (!animate) return;
198
- const easing = R.Easing.out(R.Easing.cubic);
200
+ // The `decelerate` token (a cubic ease-out); a module without `bezier` gets the same curve by name.
201
+ const easing = R.Easing.bezier ? R.Easing.bezier(...MOTION_EASINGS.decelerate) : R.Easing.out(R.Easing.cubic);
199
202
  if (fade) opacity.value = R.withTiming(1, { duration: ENTER_MS, easing });
200
203
  offset.value = R.withTiming(0, { duration: ENTER_MS, easing });
201
204
  // Once per toast: each toast mounts under its own key.
@@ -0,0 +1,181 @@
1
+ import { useEffect, useState, type ReactNode } from "react";
2
+ import { AccessibilityInfo, View } from "react-native";
3
+ import { titleCase, type WriteConflict } from "@marktiderman/genesis-core";
4
+ import { NativeButton } from "../components/button";
5
+ import { NativeSheet, NativeSheetScrollView } from "../components/sheet";
6
+ import { NativeText } from "../components/text";
7
+
8
+ /** The words NativeConflictSheet shows. The same keys as genesis-ui's `uiMessages.conflict`. */
9
+ export interface NativeConflictSheetMessages {
10
+ /** `{noun}`: the record's noun ("task"). */
11
+ title: string;
12
+ description: string;
13
+ /** When their change already matches what was tried. */
14
+ same: string;
15
+ theirs: string;
16
+ mine: string;
17
+ /** An empty value in the comparison. */
18
+ empty: string;
19
+ /** Their value for a field their row as read here doesn't carry. */
20
+ unknown: string;
21
+ keepMine: string;
22
+ takeTheirs: string;
23
+ /** When "keep mine" failed for another reason (offline, refused). */
24
+ failed: string;
25
+ yes: string;
26
+ no: string;
27
+ /** The noun when the screen gave none. */
28
+ record: string;
29
+ }
30
+
31
+ const english: NativeConflictSheetMessages = {
32
+ title: "Someone else changed this {noun}",
33
+ description: "They saved a change after you opened it. Theirs is next to yours below: keep yours to save it over theirs, or take theirs and drop your changes.",
34
+ same: "Their change already matches yours, so there's nothing to choose.",
35
+ theirs: "Theirs",
36
+ mine: "Yours",
37
+ empty: "Empty",
38
+ unknown: "Not shown",
39
+ keepMine: "Keep my version",
40
+ takeTheirs: "Take their version",
41
+ failed: "Your version wasn't saved.",
42
+ yes: "Yes",
43
+ no: "No",
44
+ record: "record",
45
+ };
46
+
47
+ /**
48
+ * Props for {@link NativeConflictSheet}.
49
+ *
50
+ * @stability Beta
51
+ */
52
+ export interface NativeConflictSheetProps {
53
+ /** The conflict to show (`writeConflict(error, values)`); null keeps it closed. */
54
+ conflict: WriteConflict | null;
55
+ /** The record's noun ("task"), for the title. */
56
+ noun?: string;
57
+ /** A field's label. Default: the field name, title-cased. */
58
+ label?: (field: string) => string;
59
+ /** A field's value as shown. Default: plain text. */
60
+ format?: (field: string, value: unknown) => ReactNode;
61
+ /** Save these values over theirs, at the version the conflict reported. The sheet waits for it. */
62
+ onKeepMine: () => void | Promise<void>;
63
+ /** Drop these values and show their row. */
64
+ onTakeTheirs: () => void;
65
+ /** Closed without choosing: the changes stay where they are, unsaved. */
66
+ onDismiss: () => void;
67
+ messages?: Partial<NativeConflictSheetMessages>;
68
+ testID?: string;
69
+ }
70
+
71
+ function plain(value: unknown, w: NativeConflictSheetMessages): string {
72
+ if (value === null || value === undefined || value === "") return w.empty;
73
+ if (typeof value === "boolean") return value ? w.yes : w.no;
74
+ if (typeof value === "object") {
75
+ try {
76
+ return JSON.stringify(value);
77
+ } catch {
78
+ return String(value);
79
+ }
80
+ }
81
+ return String(value);
82
+ }
83
+
84
+ /**
85
+ * The phone's ConflictSheet: when a save met someone else's change, a bottom
86
+ * sheet shows their value above the one this person tried to save, for each
87
+ * field where they differ, then "Take theirs" or "Keep mine".
88
+ * NativeRecordView's settings sections open it on a `conflict`.
89
+ *
90
+ * @stability Beta
91
+ */
92
+ export function NativeConflictSheet({
93
+ conflict,
94
+ noun,
95
+ label = titleCase,
96
+ format,
97
+ onKeepMine,
98
+ onTakeTheirs,
99
+ onDismiss,
100
+ messages,
101
+ testID = "native-conflict-sheet",
102
+ }: NativeConflictSheetProps) {
103
+ const w = { ...english, ...messages };
104
+ const [keeping, setKeeping] = useState(false);
105
+ const [failed, setFailed] = useState<string | null>(null);
106
+ const fields = conflict?.fields ?? [];
107
+ const title = w.title.replace("{noun}", noun ?? w.record);
108
+ // "Keep mine" needs the version their row is at; without one it could only conflict again.
109
+ const canKeep = fields.length > 0 && conflict?.currentVersion != null;
110
+ // Said once as it opens, so a screen reader user knows why a sheet came up.
111
+ useEffect(() => {
112
+ setFailed(null);
113
+ if (conflict) AccessibilityInfo.announceForAccessibility?.(title);
114
+ }, [conflict, title]);
115
+ const has = (field: string) => !!conflict && field in conflict.theirs;
116
+ const text = (field: string, value: unknown, known = true) => (known ? plain(value, w) : w.unknown);
117
+ const show = (field: string, value: unknown, known = true): ReactNode =>
118
+ format && known ? format(field, value) : <NativeText preset="body-sm">{text(field, value, known)}</NativeText>;
119
+
120
+ const keep = async () => {
121
+ setKeeping(true);
122
+ setFailed(null);
123
+ try {
124
+ await onKeepMine();
125
+ } catch (error) {
126
+ setFailed(error instanceof Error && error.message ? error.message : w.failed);
127
+ } finally {
128
+ setKeeping(false);
129
+ }
130
+ };
131
+
132
+ return (
133
+ <NativeSheet
134
+ open={conflict !== null}
135
+ onOpenChange={(open) => !open && !keeping && onDismiss()}
136
+ fitContent
137
+ testID={testID}
138
+ >
139
+ <NativeSheetScrollView>
140
+ <View style={{ gap: 12, paddingHorizontal: 16, paddingVertical: 12 }}>
141
+ <NativeText preset="h4" accessibilityRole="header">
142
+ {title}
143
+ </NativeText>
144
+ <NativeText preset="body-sm" className="text-muted-foreground">
145
+ {fields.length > 0 ? w.description : w.same}
146
+ </NativeText>
147
+ {conflict
148
+ ? fields.map((field) => (
149
+ <View key={field} style={{ gap: 4 }} testID={`${testID}-field-${field}`}>
150
+ <NativeText preset="label">{label(field)}</NativeText>
151
+ <View accessible {...(format ? {} : { accessibilityLabel: `${w.theirs}: ${text(field, conflict.theirs[field], has(field))}` })}>
152
+ <NativeText preset="caption" className="text-muted-foreground">{w.theirs}</NativeText>
153
+ {show(field, conflict.theirs[field], has(field))}
154
+ </View>
155
+ <View accessible {...(format ? {} : { accessibilityLabel: `${w.mine}: ${text(field, conflict.mine[field])}` })}>
156
+ <NativeText preset="caption" className="text-muted-foreground">{w.mine}</NativeText>
157
+ {show(field, conflict.mine[field])}
158
+ </View>
159
+ </View>
160
+ ))
161
+ : null}
162
+ {failed ? (
163
+ <NativeText preset="body-sm" className="text-destructive" accessibilityRole="alert" testID={`${testID}-failed`}>
164
+ {failed}
165
+ </NativeText>
166
+ ) : null}
167
+ <View style={{ gap: 8, paddingTop: 4 }}>
168
+ {canKeep ? (
169
+ <NativeButton size="lg" onPress={() => void keep()} loading={keeping} disabled={keeping} testID={`${testID}-keep-mine`}>
170
+ {w.keepMine}
171
+ </NativeButton>
172
+ ) : null}
173
+ <NativeButton size="lg" variant="outline" onPress={onTakeTheirs} disabled={keeping} testID={`${testID}-take-theirs`}>
174
+ {w.takeTheirs}
175
+ </NativeButton>
176
+ </View>
177
+ </View>
178
+ </NativeSheetScrollView>
179
+ </NativeSheet>
180
+ );
181
+ }