@marktiderman/genesis-ui-native 2.4.1 → 2.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 (47) hide show
  1. package/README.md +30 -0
  2. package/dist/{chunk-BPD5DCFP.js → chunk-3S5XVER4.js} +271 -6
  3. package/dist/chunk-3S5XVER4.js.map +1 -0
  4. package/dist/chunk-56QLEHHV.js +1231 -0
  5. package/dist/chunk-56QLEHHV.js.map +1 -0
  6. package/dist/chunk-6JBNSW4D.js +479 -0
  7. package/dist/chunk-6JBNSW4D.js.map +1 -0
  8. package/dist/{chunk-RARJGZA3.js → chunk-KZEIF4YI.js} +7 -741
  9. package/dist/chunk-KZEIF4YI.js.map +1 -0
  10. package/dist/{chunk-6TLBCRS6.js → chunk-VMSIKSU2.js} +13 -477
  11. package/dist/chunk-VMSIKSU2.js.map +1 -0
  12. package/dist/components/index.d.ts +29 -3
  13. package/dist/components/index.js +3 -4
  14. package/dist/data/index.d.ts +382 -4
  15. package/dist/data/index.js +1067 -19
  16. package/dist/data/index.js.map +1 -1
  17. package/dist/inbox-page-DZUR-PJ1.d.ts +199 -0
  18. package/dist/index.d.ts +3 -2
  19. package/dist/index.js +5 -5
  20. package/dist/layouts/index.d.ts +4 -186
  21. package/dist/layouts/index.js +3 -3
  22. package/package.json +2 -2
  23. package/src/components/__tests__/loading-state.test.tsx +41 -0
  24. package/src/components/image.tsx +5 -0
  25. package/src/components/index.ts +3 -0
  26. package/src/components/loading-state.tsx +92 -0
  27. package/src/data/NativeDetailPanel.tsx +8 -1
  28. package/src/data/index.ts +1 -0
  29. package/src/data/resource-view/NativeResourceFormSheet.tsx +305 -0
  30. package/src/data/resource-view/NativeResourceView.tsx +528 -0
  31. package/src/data/resource-view/__tests__/native-resource-view.test.tsx +870 -0
  32. package/src/data/resource-view/display.tsx +256 -0
  33. package/src/data/resource-view/index.ts +50 -0
  34. package/src/data/resource-view/mapping.ts +326 -0
  35. package/src/data/resource-view/messages.ts +121 -0
  36. package/src/data/resource-view/use-native-resource-view.ts +307 -0
  37. package/src/layouts/__tests__/inbox-page.test.tsx +2 -1
  38. package/src/layouts/__tests__/screen-container.test.tsx +27 -0
  39. package/src/layouts/inbox-page.tsx +4 -7
  40. package/src/layouts/screen-container.tsx +18 -1
  41. package/dist/chunk-6TLBCRS6.js.map +0 -1
  42. package/dist/chunk-BPD5DCFP.js.map +0 -1
  43. package/dist/chunk-EFXCJ5AN.js +0 -234
  44. package/dist/chunk-EFXCJ5AN.js.map +0 -1
  45. package/dist/chunk-FIITITXO.js +0 -492
  46. package/dist/chunk-FIITITXO.js.map +0 -1
  47. package/dist/chunk-RARJGZA3.js.map +0 -1
@@ -0,0 +1,528 @@
1
+ // NativeResourceView: a native list screen from a genesis-core view, in one line
2
+ // (docs/RESOURCE-VIEW.md, "Native"). It reads the same view as the web's ResourceView:
3
+ // - `view.summary(row)` → NativeListItem (title, subtitle, a chip); `view.columns()` → the peek;
4
+ // - `definition.groupBy` → SectionList sections (sorted on the server first), inset grouped on iOS;
5
+ // - `view.can()` → swipe actions (InboxPage's shape: long press and accessibility actions,
6
+ // the `swipeable` slot for the gesture), every refusal with its reason;
7
+ // - `view.form(mode)` + `view.writable(mode)` → the form sheet, over the row fetched by id,
8
+ // sending only the writable fields the person changed.
9
+ // Paging is by cursor on `onEndReached`, search is debounced 300 ms, a delete is optimistic and
10
+ // comes back if the server refuses, and a refusal shows inline in plain words.
11
+ //
12
+ // List performance follows React Native's "Optimizing FlatList configuration" (SectionList is a
13
+ // VirtualizedList and a PureComponent): a memoised row component, a stable `renderItem` and
14
+ // `keyExtractor`, and `extraData` only for what rows read besides their item.
15
+
16
+ import { memo, useCallback, useMemo, useRef, useState, type ComponentType, type ReactNode } from "react";
17
+ import { Alert, Platform, Pressable, SectionList, View } from "react-native";
18
+ import { SafeAreaView } from "react-native-safe-area-context";
19
+ import type { BaseRecord, DataRow } from "@marktiderman/genesis-core";
20
+ import { isTimeZone, personTimeZone } from "@marktiderman/genesis-core/dates";
21
+ import { useOne, useOptionalViewerScope } from "@marktiderman/genesis-core/hooks";
22
+ import type { RowPicture } from "@marktiderman/genesis-core/resource-view";
23
+ import { NativeAvatar } from "../../components/avatar";
24
+ import { NativeBadge } from "../../components/badge";
25
+ import { NativeImage } from "../../components/image";
26
+ import { NativeButton } from "../../components/button";
27
+ import { NativeEmptyState } from "../../components/empty-state";
28
+ import { NativeInlineAlert } from "../../components/inline-alert";
29
+ import { NativeListItem } from "../../components/list-item";
30
+ import { NativeLoadingState } from "../../components/loading-state";
31
+ import { NativeRefreshControl } from "../../components/refresh-control";
32
+ import { NativeSearchBar } from "../../components/search-bar";
33
+ import { NativeSectionListHeader } from "../../components/section-list";
34
+ import { NativeSheet } from "../../components/sheet";
35
+ import { NativeText } from "../../components/text";
36
+ import { useThemeRoles } from "../../hooks/use-theme-roles";
37
+ import { showInboxActions, type InboxPageSlotMap } from "../../layouts/inbox-page";
38
+ import { NativeDetailPanel } from "../NativeDetailPanel";
39
+ import {
40
+ badgeVariant,
41
+ DisplayTimeZonesProvider,
42
+ useDisplayCell,
43
+ useNativeResourceViewMessages,
44
+ type DisplayTimeZones,
45
+ } from "./display";
46
+ import type { AnyResourceView, NativeResourceRowItem, NativeResourceSection, NativeResourceSwipeAction } from "./mapping";
47
+ import { fill } from "./messages";
48
+ import { NativeResourceFormSheet } from "./NativeResourceFormSheet";
49
+ import {
50
+ useNativeResourceView,
51
+ type NativeResourceViewOptions,
52
+ type UseNativeResourceViewReturn,
53
+ } from "./use-native-resource-view";
54
+
55
+ type Row = Record<string, unknown>;
56
+
57
+ /** The gesture wrapper around a row, the same props as InboxPage's `swipeable` slot. */
58
+ export type NativeResourceSwipeableProps = Omit<InboxPageSlotMap["swipeable"], "actions"> & {
59
+ actions: NativeResourceSwipeAction[];
60
+ };
61
+
62
+ export interface NativeResourceViewProps<T extends Row = Row> extends NativeResourceViewOptions<T> {
63
+ view: AnyResourceView<T>;
64
+ /** The heading above the list. Default the view's title; `false` when the navigation bar shows it. */
65
+ title?: string | false;
66
+ subtitle?: string;
67
+ /**
68
+ * A row was pressed: push its detail route (`router.push(\`/brands/${row.id}\`)`), so deep links
69
+ * and notification taps land on the same screen. Without it, a press opens a peek sheet.
70
+ */
71
+ onRowPress?: (row: T) => void;
72
+ /** Wraps each row that has actions in a swipe gesture (e.g. gesture-handler's ReanimatedSwipeable). */
73
+ swipeable?: ComponentType<NativeResourceSwipeableProps>;
74
+ /** Above the list, under the search (a filter, a call to action). */
75
+ header?: ReactNode;
76
+ /** Replaces the empty state. */
77
+ emptyState?: ReactNode;
78
+ /** Hide the search box. Shown by default when the view has something to search. */
79
+ searchable?: boolean;
80
+ /**
81
+ * The practice's IANA zone, for columns with `timeZone: "practice"`. Timestamps otherwise read
82
+ * on the viewer's clock (ViewerScope's zone, else the device's).
83
+ */
84
+ practiceTimeZone?: string;
85
+ testID?: string;
86
+ }
87
+
88
+ /** UIKit's inset grouped margin on a phone, in points (as InboxPage and SettingsPage). */
89
+ const IOS_GROUP_MARGIN = 16;
90
+ /** The group's corner radius: computed once, the OS version doesn't change while the app runs. */
91
+ const GROUP_RADIUS = Number.parseFloat(String(Platform.Version)) >= 26 ? 26 : 10;
92
+ const IOS = Platform.OS === "ios";
93
+
94
+ const keyExtractor = (row: Row) => String((row as DataRow).id);
95
+
96
+ /**
97
+ * A native list screen from a view:
98
+ *
99
+ * ```tsx
100
+ * <NativeResourceView view={brandsView} onRowPress={(b) => router.push(`/brands/${b.id}`)} />
101
+ * ```
102
+ */
103
+ export function NativeResourceView<T extends Row = Row>(props: NativeResourceViewProps<T>) {
104
+ const scope = useOptionalViewerScope();
105
+ const viewer = scope?.timeZone;
106
+ const { practiceTimeZone } = props;
107
+ const zones = useMemo<DisplayTimeZones>(() => {
108
+ const own = personTimeZone({ timeZone: viewer });
109
+ return { viewer: own, practice: practiceTimeZone && isTimeZone(practiceTimeZone) ? practiceTimeZone : own };
110
+ }, [viewer, practiceTimeZone]);
111
+ return (
112
+ <DisplayTimeZonesProvider value={zones}>
113
+ <Screen {...props} />
114
+ </DisplayTimeZonesProvider>
115
+ );
116
+ }
117
+
118
+ interface RowProps<T extends Row> {
119
+ row: T;
120
+ first: boolean;
121
+ last: boolean;
122
+ item: UseNativeResourceViewReturn<T>["item"];
123
+ actions: UseNativeResourceViewReturn<T>["actions"];
124
+ handlers: Parameters<UseNativeResourceViewReturn<T>["actions"]>[1];
125
+ onPress: (row: T) => void;
126
+ chevron: boolean;
127
+ Swipeable: ComponentType<NativeResourceSwipeableProps> | undefined;
128
+ cancelLabel: string;
129
+ surface: string;
130
+ separator: string;
131
+ testID: string;
132
+ }
133
+
134
+ /** A row picture's size, in points (Mail's and Contacts' list avatars). */
135
+ const PICTURE_SIZE = 40;
136
+
137
+ /**
138
+ * NativeListItem's `leading` from `rowPicture(summary)`: the image (decorative unless it has
139
+ * `alt`), with its initials if it fails to load; initials alone; or nothing.
140
+ */
141
+ function RowLeading({ picture, testID }: { picture: RowPicture; testID: string }) {
142
+ // Which src failed, not a flag: a recycled row for another record starts fresh.
143
+ const [failed, setFailed] = useState<string | null>(null);
144
+ if (picture.kind === "image" && failed !== picture.src) {
145
+ return (
146
+ <NativeImage
147
+ testID={`${testID}-image`}
148
+ src={picture.src}
149
+ {...(picture.alt ? { alt: picture.alt } : {})}
150
+ width={PICTURE_SIZE}
151
+ height={PICTURE_SIZE}
152
+ className="rounded-full"
153
+ onError={() => setFailed(picture.src)}
154
+ />
155
+ );
156
+ }
157
+ const initials = picture.kind === "image" ? picture.fallback : picture.text;
158
+ if (!initials) return null;
159
+ return (
160
+ // The row's label already names it; the letters would only be read twice.
161
+ <View accessibilityElementsHidden importantForAccessibility="no-hide-descendants">
162
+ <NativeAvatar testID={`${testID}-initials`} fallback={initials} size={PICTURE_SIZE} />
163
+ </View>
164
+ );
165
+ }
166
+
167
+ /** One row. Memoised: it redraws only when its row or what it reads changes, not per keystroke. */
168
+ const ResourceRow = memo(function ResourceRow<T extends Row>({
169
+ row,
170
+ first,
171
+ last,
172
+ item: itemFor,
173
+ actions: actionsFor,
174
+ handlers,
175
+ onPress,
176
+ chevron,
177
+ Swipeable,
178
+ cancelLabel,
179
+ surface,
180
+ separator,
181
+ testID,
182
+ }: RowProps<T>) {
183
+ const item: NativeResourceRowItem = itemFor(row);
184
+ const actions = actionsFor(row, handlers);
185
+ const chip = item.chips[0];
186
+ const picture = item.picture;
187
+ const rowTestID = `${testID}-row-${item.id}`;
188
+ const content = (
189
+ <View
190
+ testID={`${rowTestID}-cell`}
191
+ style={[
192
+ { backgroundColor: surface },
193
+ IOS
194
+ ? {
195
+ marginHorizontal: IOS_GROUP_MARGIN,
196
+ borderTopLeftRadius: first ? GROUP_RADIUS : 0,
197
+ borderTopRightRadius: first ? GROUP_RADIUS : 0,
198
+ borderBottomLeftRadius: last ? GROUP_RADIUS : 0,
199
+ borderBottomRightRadius: last ? GROUP_RADIUS : 0,
200
+ overflow: "hidden",
201
+ }
202
+ : null,
203
+ ]}
204
+ >
205
+ <Pressable
206
+ testID={rowTestID}
207
+ accessibilityRole="button"
208
+ accessibilityLabel={[picture?.kind === "image" ? picture.alt : null, item.title, item.subtitle, chip?.label].filter(Boolean).join(", ")}
209
+ accessibilityActions={actions.map((a) => ({ name: a.id, label: a.reason ? `${a.label}: ${a.reason}` : a.label }))}
210
+ onAccessibilityAction={(event) => actions.find((a) => a.id === event.nativeEvent.actionName)?.onPress()}
211
+ onPress={() => onPress(row)}
212
+ onLongPress={actions.length ? () => showInboxActions(item.title, actions, cancelLabel) : undefined}
213
+ >
214
+ <NativeListItem
215
+ testID={`${rowTestID}-item`}
216
+ title={item.title}
217
+ subtitle={item.subtitle}
218
+ leading={picture ? <RowLeading picture={picture} testID={rowTestID} /> : undefined}
219
+ className="bg-transparent"
220
+ trailing={
221
+ chip ? (
222
+ <NativeBadge testID={`${rowTestID}-chip`} variant={badgeVariant(chip.tone)}>
223
+ {chip.label}
224
+ </NativeBadge>
225
+ ) : undefined
226
+ }
227
+ showChevron={chevron}
228
+ />
229
+ </Pressable>
230
+ {!last ? <View style={{ height: 0.5, marginLeft: 16, backgroundColor: separator }} /> : null}
231
+ </View>
232
+ );
233
+ return actions.length && Swipeable ? (
234
+ <Swipeable actions={actions} testID={`${rowTestID}-swipe`}>
235
+ {content}
236
+ </Swipeable>
237
+ ) : (
238
+ content
239
+ );
240
+ }) as <T extends Row>(props: RowProps<T>) => ReactNode;
241
+
242
+ function Screen<T extends Row = Row>(props: NativeResourceViewProps<T>) {
243
+ const {
244
+ view,
245
+ title,
246
+ subtitle,
247
+ onRowPress,
248
+ swipeable: Swipeable,
249
+ header,
250
+ emptyState,
251
+ searchable,
252
+ practiceTimeZone: _zone,
253
+ testID = "native-resource-view",
254
+ ...options
255
+ } = props;
256
+ void _zone;
257
+ const state = useNativeResourceView<T>(view, options);
258
+ const messages = useNativeResourceViewMessages();
259
+ const colors = useThemeRoles();
260
+ const cell = useDisplayCell();
261
+
262
+ const [peekId, setPeekId] = useState<{ row: T } | null>(null);
263
+ const [sheet, setSheet] = useState<{ mode: "create" | "edit"; row?: T } | null>(null);
264
+
265
+ const refused = useCallback((label: string, reason: string) => Alert.alert(label, reason), []);
266
+ const { remove, softDelete, item: itemFor, actions: actionsFor } = state;
267
+ const confirmDelete = useCallback(
268
+ (row: T) => {
269
+ const name = itemFor(row).title;
270
+ const words = softDelete ? messages.bin : messages.delete;
271
+ Alert.alert(fill(words.confirmTitle, { name }), words.confirmBody, [
272
+ { text: messages.common.cancel, style: "cancel" },
273
+ {
274
+ text: words.action,
275
+ style: "destructive",
276
+ onPress: () => {
277
+ setPeekId(null);
278
+ remove(row);
279
+ },
280
+ },
281
+ ]);
282
+ },
283
+ [itemFor, softDelete, messages, remove],
284
+ );
285
+ const edit = useCallback((row: T) => {
286
+ setPeekId(null);
287
+ setSheet({ mode: "edit", row });
288
+ }, []);
289
+ const handlers = useMemo(() => ({ onEdit: edit, onDelete: confirmDelete, onRefused: refused }), [edit, confirmDelete, refused]);
290
+
291
+ // The screen's handler through a ref, so an inline `onRowPress` doesn't redraw every row.
292
+ const rowPress = useRef(onRowPress);
293
+ rowPress.current = onRowPress;
294
+ const press = useCallback((row: T) => (rowPress.current ? rowPress.current(row) : setPeekId({ row })), []);
295
+ const chevron = !!onRowPress;
296
+
297
+ const renderItem = useCallback(
298
+ ({ item: row, index, section }: { item: T; index: number; section: NativeResourceSection<T> }) => (
299
+ <ResourceRow<T>
300
+ row={row}
301
+ first={index === 0}
302
+ last={index === section.data.length - 1}
303
+ item={itemFor}
304
+ actions={actionsFor}
305
+ handlers={handlers}
306
+ onPress={press}
307
+ chevron={chevron}
308
+ Swipeable={Swipeable}
309
+ cancelLabel={messages.common.cancel}
310
+ surface={colors.surface as string}
311
+ separator={colors.separator as string}
312
+ testID={testID}
313
+ />
314
+ ),
315
+ [itemFor, actionsFor, handlers, press, chevron, Swipeable, messages, colors.surface, colors.separator, testID],
316
+ );
317
+
318
+ // Rows are counted only as far as they're loaded, so the header shows the title alone.
319
+ const renderSectionHeader = useCallback(
320
+ ({ section }: { section: NativeResourceSection<T> }) =>
321
+ section.title ? (
322
+ <NativeSectionListHeader
323
+ testID={`${testID}-section-${section.key || "none"}`}
324
+ title={section.title}
325
+ className="border-b-0 bg-transparent pt-4"
326
+ />
327
+ ) : null,
328
+ [testID],
329
+ );
330
+
331
+ const create = () => {
332
+ if (state.canCreate === true) setSheet({ mode: "create" });
333
+ else if (typeof state.canCreate === "string") refused(fill(messages.common.create, { noun: view.noun }), state.canCreate);
334
+ };
335
+
336
+ const showSearch = searchable ?? !!(options.searchFields?.length || view.labelField);
337
+ const heading = title === false ? null : (title ?? view.title);
338
+ const hasRows = state.rows.length > 0;
339
+
340
+ const listHeader = (
341
+ <View style={{ paddingHorizontal: 16, paddingTop: 8, paddingBottom: 8, gap: 12 }}>
342
+ {heading || state.canCreate !== false ? (
343
+ <View style={{ flexDirection: "row", alignItems: "center", justifyContent: "space-between" }}>
344
+ <View style={{ flex: 1 }}>
345
+ {heading ? (
346
+ <NativeText preset="h2" accessibilityRole="header">
347
+ {heading}
348
+ </NativeText>
349
+ ) : null}
350
+ {(subtitle ?? view.definition.copy?.subtitle) ? (
351
+ <NativeText preset="body-sm" className="text-muted-foreground mt-0.5">
352
+ {subtitle ?? view.definition.copy?.subtitle}
353
+ </NativeText>
354
+ ) : null}
355
+ </View>
356
+ {state.canCreate !== false ? (
357
+ <NativeButton size="sm" testID={`${testID}-create`} onPress={create}>
358
+ {view.definition.copy?.create ?? fill(messages.common.create, { noun: view.noun })}
359
+ </NativeButton>
360
+ ) : null}
361
+ </View>
362
+ ) : null}
363
+ {showSearch ? (
364
+ <NativeSearchBar
365
+ testID={`${testID}-search`}
366
+ value={state.search}
367
+ onChange={state.setSearch}
368
+ placeholder={fill(messages.common.search, { nounPlural: view.nounPlural })}
369
+ />
370
+ ) : null}
371
+ {state.error && hasRows ? (
372
+ // A refetch or the next page failed: keep the rows, say so above them.
373
+ <View testID={`${testID}-read-error`} style={{ gap: 8 }}>
374
+ <NativeInlineAlert variant="destructive" description={state.error} />
375
+ <NativeButton variant="outline" size="sm" onPress={() => void state.refresh()}>
376
+ {messages.list.retry}
377
+ </NativeButton>
378
+ </View>
379
+ ) : null}
380
+ {state.refusal ? (
381
+ <NativeInlineAlert
382
+ testID={`${testID}-refusal`}
383
+ variant="destructive"
384
+ description={state.refusal}
385
+ onDismiss={state.dismissRefusal}
386
+ />
387
+ ) : null}
388
+ {header}
389
+ {state.loadingPrevious ? (
390
+ <NativeLoadingState fullScreen={false} size="small" label={messages.list.loadingMore} testID={`${testID}-previous`} />
391
+ ) : null}
392
+ </View>
393
+ );
394
+
395
+ const empty = state.loading ? (
396
+ <NativeLoadingState fullScreen={false} testID={`${testID}-loading`} />
397
+ ) : state.error ? (
398
+ <NativeEmptyState
399
+ testID={`${testID}-error`}
400
+ variant="error"
401
+ title={state.error}
402
+ primaryAction={
403
+ <NativeButton variant="outline" size="sm" onPress={() => void state.refresh()}>
404
+ {messages.list.retry}
405
+ </NativeButton>
406
+ }
407
+ />
408
+ ) : (
409
+ (emptyState ??
410
+ (state.search ? (
411
+ <NativeEmptyState testID={`${testID}-empty`} variant="no-results" title={messages.list.noResultsTitle} body={messages.list.noResultsBody} />
412
+ ) : (
413
+ <NativeEmptyState
414
+ testID={`${testID}-empty`}
415
+ title={view.definition.copy?.empty?.title ?? fill(messages.list.emptyTitle, { nounPlural: view.nounPlural })}
416
+ body={view.definition.copy?.empty?.body ?? messages.list.emptyBody}
417
+ />
418
+ )))
419
+ );
420
+
421
+ // The peek and the edit sheet read the row by id: the list's select may be narrower.
422
+ const peekRow = useOne<T & BaseRecord>(view.resource, peekId ? ((peekId.row as DataRow).id as string) : null);
423
+ const editRow = useOne<T & BaseRecord>(view.resource, sheet?.mode === "edit" ? ((sheet.row as DataRow).id as string) : null);
424
+ const peek = peekId ? ((peekRow.data as T | undefined) ?? peekId.row) : null;
425
+
426
+ // Peek: the view's full column list, drawn like the cells (so `when` hides there too), never
427
+ // every key of the row: sensitive values and columns the view leaves out stay out. As the web's.
428
+ const peekFields = useMemo(
429
+ () =>
430
+ view.columns().map((column) => ({
431
+ key: column.key,
432
+ label: column.label,
433
+ render: (_value: unknown, row: Row) => cell(column as never, row),
434
+ })),
435
+ [view, cell],
436
+ );
437
+ const { formFields } = state;
438
+ const createFields = useMemo(() => formFields("create"), [formFields]);
439
+ const editFields = useMemo(() => formFields("edit"), [formFields]);
440
+ const peekActions = peek ? actionsFor(peek, handlers) : [];
441
+ const editLoading = sheet?.mode === "edit" && editRow.data === undefined && !editRow.isError;
442
+
443
+ return (
444
+ <SafeAreaView testID={testID} edges={["left", "right", "bottom"]} style={{ flex: 1, backgroundColor: colors.groupedBackground }}>
445
+ <SectionList<T, NativeResourceSection<T>>
446
+ testID={`${testID}-list`}
447
+ sections={state.sections}
448
+ keyExtractor={keyExtractor}
449
+ renderItem={renderItem}
450
+ renderSectionHeader={renderSectionHeader}
451
+ // Rows read their item and actions besides `sections`; they change only with the view,
452
+ // the bin capability or the words, never per keystroke.
453
+ extraData={actionsFor}
454
+ stickySectionHeadersEnabled={false}
455
+ contentInsetAdjustmentBehavior="automatic"
456
+ keyboardShouldPersistTaps="handled"
457
+ ListHeaderComponent={listHeader}
458
+ ListEmptyComponent={empty}
459
+ ListFooterComponent={
460
+ state.loadingMore ? (
461
+ <NativeLoadingState fullScreen={false} size="small" label={messages.list.loadingMore} testID={`${testID}-more`} />
462
+ ) : null
463
+ }
464
+ contentContainerStyle={{ flexGrow: 1, paddingBottom: 32 }}
465
+ onEndReached={state.hasMore ? state.loadMore : undefined}
466
+ onEndReachedThreshold={0.5}
467
+ // maxPages drops pages from the front; reaching the top loads them back, and the rows on
468
+ // screen keep their place while they're added above (VirtualizedList's onStartReached and
469
+ // ScrollView's maintainVisibleContentPosition, both inherited by SectionList).
470
+ onStartReached={state.hasPrevious ? state.loadPrevious : undefined}
471
+ onStartReachedThreshold={0.5}
472
+ maintainVisibleContentPosition={{ minIndexForVisible: 0 }}
473
+ refreshControl={<NativeRefreshControl testID={`${testID}-refresh`} refreshing={state.refreshing} onRefresh={() => void state.refresh()} />}
474
+ />
475
+
476
+ <NativeSheet open={peek !== null} onOpenChange={(open) => (open ? undefined : setPeekId(null))} testID={`${testID}-peek`}>
477
+ {peek ? (
478
+ <NativeDetailPanel<Row>
479
+ item={peek}
480
+ title={itemFor(peek).title}
481
+ fields={peekFields}
482
+ footer={
483
+ peekActions.length ? (
484
+ <View testID={`${testID}-peek-actions`} style={{ gap: 12 }}>
485
+ {peekActions.map((action) => (
486
+ <View key={action.id} style={{ gap: 4 }}>
487
+ <NativeButton
488
+ testID={`${testID}-peek-${action.id}`}
489
+ variant={action.destructive ? "destructive" : "outline"}
490
+ // A refused action stays, dimmed, and pressing it says why.
491
+ className={action.reason ? "opacity-50" : undefined}
492
+ onPress={action.onPress}
493
+ >
494
+ {action.label}
495
+ </NativeButton>
496
+ {action.reason ? (
497
+ <NativeText testID={`${testID}-peek-${action.id}-reason`} preset="caption" className="text-muted-foreground">
498
+ {action.reason}
499
+ </NativeText>
500
+ ) : null}
501
+ </View>
502
+ ))}
503
+ </View>
504
+ ) : null
505
+ }
506
+ />
507
+ ) : null}
508
+ </NativeSheet>
509
+
510
+ <NativeResourceFormSheet
511
+ open={sheet !== null}
512
+ mode={sheet?.mode ?? "create"}
513
+ title={fill(sheet?.mode === "edit" ? messages.common.editTitle : messages.common.create, { noun: view.noun })}
514
+ fields={sheet?.mode === "edit" ? editFields : createFields}
515
+ initial={sheet?.mode === "edit" ? ((editRow.data as Row | undefined) ?? (editRow.isError ? sheet.row : undefined)) : undefined}
516
+ loading={editLoading}
517
+ recordKey={sheet?.row ? String((sheet.row as DataRow).id) : "new"}
518
+ onCancel={() => setSheet(null)}
519
+ onSave={async (values, dirty) => {
520
+ const result = await state.save(sheet?.mode ?? "create", values, sheet?.row, dirty);
521
+ if (result.ok) setSheet(null);
522
+ return result;
523
+ }}
524
+ testID={`${testID}-form`}
525
+ />
526
+ </SafeAreaView>
527
+ );
528
+ }