@marktiderman/genesis-ui-native 3.12.1 → 3.13.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 (33) hide show
  1. package/dist/{chunk-TUDJDIGC.js → chunk-DCCOZSGR.js} +4 -2
  2. package/dist/chunk-DCCOZSGR.js.map +1 -0
  3. package/dist/{chunk-47CDRP43.js → chunk-G5M2Q7OU.js} +77 -4
  4. package/dist/chunk-G5M2Q7OU.js.map +1 -0
  5. package/dist/{chunk-C2ARUGT7.js → chunk-SRCGQWE4.js} +3 -3
  6. package/dist/{chunk-C2ARUGT7.js.map → chunk-SRCGQWE4.js.map} +1 -1
  7. package/dist/{chunk-X5CPLUPZ.js → chunk-WTO3LIUS.js} +4 -77
  8. package/dist/chunk-WTO3LIUS.js.map +1 -0
  9. package/dist/components/index.js +2 -2
  10. package/dist/data/index.d.ts +170 -27
  11. package/dist/data/index.js +471 -21
  12. package/dist/data/index.js.map +1 -1
  13. package/dist/{inbox-page-BGqR_cBs.d.ts → inbox-page-DD1cQdF4.d.ts} +6 -1
  14. package/dist/index.d.ts +1 -1
  15. package/dist/index.js +4 -4
  16. package/dist/layouts/index.d.ts +2 -2
  17. package/dist/layouts/index.js +2 -2
  18. package/package.json +3 -3
  19. package/src/data/NativeRecordPeek.tsx +12 -1
  20. package/src/data/__tests__/parity-data.test.tsx +26 -0
  21. package/src/data/resource-view/NativeResourceView.tsx +139 -16
  22. package/src/data/resource-view/__tests__/native-resource-inbox.test.tsx +59 -0
  23. package/src/data/resource-view/__tests__/native-resource-lists.test.tsx +246 -0
  24. package/src/data/resource-view/index.ts +12 -1
  25. package/src/data/resource-view/list-controls.tsx +508 -0
  26. package/src/data/resource-view/mapping.ts +10 -0
  27. package/src/data/resource-view/messages.ts +70 -0
  28. package/src/data/resource-view/use-native-resource-view.ts +13 -3
  29. package/src/layouts/__tests__/inbox-page-start.test.tsx +39 -0
  30. package/src/layouts/inbox-page.tsx +7 -0
  31. package/dist/chunk-47CDRP43.js.map +0 -1
  32. package/dist/chunk-TUDJDIGC.js.map +0 -1
  33. package/dist/chunk-X5CPLUPZ.js.map +0 -1
@@ -130,6 +130,11 @@ interface InboxPageProps extends ScreenHeaderProps {
130
130
  onRefresh?: () => void | Promise<void>;
131
131
  /** Called near the end of the list, to load the next page. */
132
132
  onEndReached?: () => void;
133
+ /**
134
+ * Called near the top, to load back a page the list dropped from the front (a list that keeps a
135
+ * bounded number of pages). The rows on screen keep their place while it's added above.
136
+ */
137
+ onStartReached?: () => void;
133
138
  /** A next page is loading: the default footer shows a spinner. */
134
139
  loadingMore?: boolean;
135
140
  /** Above the group (a filter, a call to action). Prefer `slots.header` for a component. */
@@ -160,7 +165,7 @@ interface InboxPageProps extends ScreenHeaderProps {
160
165
  declare function getInboxPageStackOptions(props: ScreenHeaderProps & {
161
166
  headerTitle?: string;
162
167
  }): Record<string, unknown>;
163
- declare function InboxPage({ items, refreshing, onRefresh, onEndReached, loadingMore, header, sectionTitle, emptyTitle, emptyBody, emptyActionLabel, onEmptyAction, loading, error, errorTitle, errorBody, formatTime, now, slots, slotProps, testID, }: InboxPageProps): react.JSX.Element;
168
+ declare function InboxPage({ items, refreshing, onRefresh, onEndReached, onStartReached, loadingMore, header, sectionTitle, emptyTitle, emptyBody, emptyActionLabel, onEmptyAction, loading, error, errorTitle, errorBody, formatTime, now, slots, slotProps, testID, }: InboxPageProps): react.JSX.Element;
164
169
  /**
165
170
  * Opens a row's actions as the system alert. `InboxPage` now opens `NativeContextMenu`; `NativeResourceView`
166
171
  * still uses this.
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export { G as GenesisDatePickerComponent, a as GenesisDatePickerProps, b as Gene
3
3
  export { DEFAULT_GALLERY_RATIO, GALLERY_DEFAULTS, GalleryItem, GalleryTileAspect, JustifiedRow, JustifiedTile, galleryItemRatio, justifyRows } from '@marktiderman/genesis-core/gallery';
4
4
  export { BrandExtensionsProvider, BrandExtensionsProviderProps, BrandExtensionsValue, MotionHow, MotionSpringConfig, MotionTimingConfig, PressFeedback, PressFeedbackOptions, ThemeMode, ThemeRoleColors, UseMotionOptions, UseThemeRolesOptions, animateMotion, motionSpring, motionTiming, sentBubbleColor, useGenesisExtension, useMotion, usePressFeedback, useReducedMotion, useThemeMode, useThemeRoles } from './hooks/index.js';
5
5
  export { ComposerMode, ComposerTone, InboxItem, InboxSwipeAction, JUMP_SETTLE_MS, MessageTone, ThreadAttachment, ThreadComposer, ThreadLabels, ThreadMessage, ThreadMessageStatus, UseThreadJumpOptions, formatInboxTime, readReceiptFor, useThreadJump } from '@marktiderman/genesis-core/conversation';
6
- export { I as InboxPage, a as InboxPageProps, b as InboxPageSlotMap, S as SafeAreaEdge, c as ScreenContainer, d as ScreenContainerProps, e as ScreenHeaderProps, f as ScrollEdgeBehavior, g as composeHeaderOptions, h as getInboxPageStackOptions, s as showInboxActions } from './inbox-page-BGqR_cBs.js';
6
+ export { I as InboxPage, a as InboxPageProps, b as InboxPageSlotMap, S as SafeAreaEdge, c as ScreenContainer, d as ScreenContainerProps, e as ScreenHeaderProps, f as ScrollEdgeBehavior, g as composeHeaderOptions, h as getInboxPageStackOptions, s as showInboxActions } from './inbox-page-DD1cQdF4.js';
7
7
  export { AppleButtonModuleLike, AppleProviderOptions, AppleSignInButton, AppleSignInButtonProps, AuthBranding, AuthBrandingProps, AuthForm, AuthFormProps, AuthFormValues, AuthScreen, AuthScreenProps, AuthScreenSlotMap, DashboardPage, DashboardPageProps, DetailPage, DetailPageProps, DocumentPage, DocumentPageProps, ForgotPasswordLink, FormPage, FormPageProps, GoogleProviderOptions, KEYBOARD_TOOLBAR_HEIGHT, KeyboardScrollProps, KeyboardScrollProvider, KeyboardStickyProps, KeyboardToolbarProps, NavBarSaveButton, NavBarSaveButtonProps, NavBarSearchBar, NavBarSearchBarProps, NavBarTitle, NavBarTitleProps, NotificationItem, NotificationsPage, NotificationsPageProps, NotificationsPageSlotMap, SettingsPage, SettingsPageDangerousAction, SettingsPageProps, SettingsPageRow, SettingsPageSection, SettingsPageSlotMap, SettingsSubPage, SettingsSubPageProps, SocialAuthProvider, SocialAuthRow, SocialAuthRowProps, ThreadPage, ThreadPageProps, ThreadPageSlotMap, appleProvider, confirmDiscardChanges, defaultStickyHeaderOffset, getNotificationsPageStackOptions, getSettingsPageStackOptions, getSettingsSubPageStackOptions, getThreadPageStackOptions, googleProvider, iosCompactNavigationBarHeight, useKeyboardScroll, useKeyboardSticky, useKeyboardToolbar } from './layouts/index.js';
8
8
  export { cn } from './utils.js';
9
9
  import 'react';
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- export { Box, FULL_SCREEN_DARK, Grid, Inline, LIGHTBOX_DISMISS_DISTANCE, LIGHTBOX_DISMISS_VELOCITY, LIGHTBOX_DOUBLE_TAP_MS, LIGHTBOX_MAX_ZOOM, NativeAccordion, NativeAccordionContent, NativeAccordionItem, NativeAccordionTrigger, NativeBulkBar, NativeButtonGroup, NativeCalendar, NativeCarousel, NativeChartContainer, NativeChip, NativeChipGroup, NativeChoiceCard, NativeCombobox, NativeDialog, NativeDialogContent, NativeDialogDescription, NativeDialogFooter, NativeDialogHeader, NativeDialogTitle, NativeDrawer, NativeDropdownMenu, NativeDropdownMenuContent, NativeDropdownMenuItem, NativeDropdownMenuTrigger, NativeFollowUpList, NativeFullScreenModal, NativeGalleryCard, NativeGlassSurface, NativeHeaderCard, NativeHeadlineNumbers, NativeInputGroup, NativeInputOTP, NativeLightbox, NativeLiveIndicator, NativeNumberInput, NativePagination, NativePasswordToggleField, NativePopover, NativePopoverContent, NativePopoverTrigger, NativeRadioGroup, NativeRadioGroupItem, NativeRangeSlider, NativeRating, NativeReadinessChip, NativeResourceSettingsPage, NativeResponsesToolbar, NativeSettingsRow, NativeShareSheet, NativeSlider, NativeSortableList, NativeStatCard, NativeStatusBadge, NativeStepper, NativeSummaryCard, NativeTabBar, NativeTabs, NativeTabsContent, NativeTabsList, NativeTabsTrigger, NativeTierBadge, NativeToastProvider, NativeToggle, NativeToggleRow, NativeTooltip, NativeTooltipContent, NativeTooltipTrigger, NativeUserAvatar, NativeWhatsNewSheet, NativeWorkspaceSwitcher, NativeZoomablePhoto, Stack, defaultNativeLightboxLabels, lightboxPanLimit, lightboxPinchScale, lightboxShouldDismiss, lightboxTouchDistance, nextRating, spaceScale, spacingClass, toggleVariants, useLiquidGlass, useReduceTransparency, useToast } from './chunk-X5CPLUPZ.js';
2
- export { DEFAULT_GALLERY_RATIO, GALLERY_DEFAULTS, NativeAlert, NativeAlertDescription, NativeAlertTitle, NativeAvatar, NativeCard, NativeCardContent, NativeCardDescription, NativeCardFooter, NativeCardHeader, NativeCardTitle, NativeCheckbox, NativeDatePicker, NativeGalleryGrid, NativeLabel, NativeProgress, NativeSearchBar, NativeSegmentedControl, NativeSelect, NativeSelectContent, NativeSelectItem, NativeSelectTrigger, NativeSeparator, NativeSwitch, NativeTextarea, NativeTimePicker, alertVariants, galleryItemRatio, justifyRows } from './chunk-47CDRP43.js';
1
+ export { Box, FULL_SCREEN_DARK, Grid, Inline, LIGHTBOX_DISMISS_DISTANCE, LIGHTBOX_DISMISS_VELOCITY, LIGHTBOX_DOUBLE_TAP_MS, LIGHTBOX_MAX_ZOOM, NativeAccordion, NativeAccordionContent, NativeAccordionItem, NativeAccordionTrigger, NativeBulkBar, NativeButtonGroup, NativeCalendar, NativeCarousel, NativeChartContainer, NativeChoiceCard, NativeCombobox, NativeDialog, NativeDialogContent, NativeDialogDescription, NativeDialogFooter, NativeDialogHeader, NativeDialogTitle, NativeDrawer, NativeDropdownMenu, NativeDropdownMenuContent, NativeDropdownMenuItem, NativeDropdownMenuTrigger, NativeFollowUpList, NativeFullScreenModal, NativeGalleryCard, NativeGlassSurface, NativeHeaderCard, NativeHeadlineNumbers, NativeInputGroup, NativeInputOTP, NativeLightbox, NativeLiveIndicator, NativeNumberInput, NativePagination, NativePasswordToggleField, NativePopover, NativePopoverContent, NativePopoverTrigger, NativeRadioGroup, NativeRadioGroupItem, NativeRangeSlider, NativeRating, NativeReadinessChip, NativeResourceSettingsPage, NativeResponsesToolbar, NativeSettingsRow, NativeShareSheet, NativeSlider, NativeSortableList, NativeStatCard, NativeStatusBadge, NativeStepper, NativeSummaryCard, NativeTabBar, NativeTabs, NativeTabsContent, NativeTabsList, NativeTabsTrigger, NativeTierBadge, NativeToastProvider, NativeToggle, NativeToggleRow, NativeTooltip, NativeTooltipContent, NativeTooltipTrigger, NativeUserAvatar, NativeWhatsNewSheet, NativeWorkspaceSwitcher, NativeZoomablePhoto, Stack, defaultNativeLightboxLabels, lightboxPanLimit, lightboxPinchScale, lightboxShouldDismiss, lightboxTouchDistance, nextRating, spaceScale, spacingClass, toggleVariants, useLiquidGlass, useReduceTransparency, useToast } from './chunk-WTO3LIUS.js';
2
+ export { DEFAULT_GALLERY_RATIO, GALLERY_DEFAULTS, NativeAlert, NativeAlertDescription, NativeAlertTitle, NativeAvatar, NativeCard, NativeCardContent, NativeCardDescription, NativeCardFooter, NativeCardHeader, NativeCardTitle, NativeCheckbox, NativeChip, NativeChipGroup, NativeDatePicker, NativeGalleryGrid, NativeLabel, NativeProgress, NativeSearchBar, NativeSegmentedControl, NativeSelect, NativeSelectContent, NativeSelectItem, NativeSelectTrigger, NativeSeparator, NativeSwitch, NativeTextarea, NativeTimePicker, alertVariants, galleryItemRatio, justifyRows } from './chunk-G5M2Q7OU.js';
3
3
  export { BrandExtensionsProvider, JUMP_SETTLE_MS, useGenesisExtension, useThreadJump } from './chunk-FOJJB6AB.js';
4
- export { AppleSignInButton, AuthBranding, AuthForm, AuthScreen, DashboardPage, DetailPage, DocumentPage, ForgotPasswordLink, FormPage, KEYBOARD_TOOLBAR_HEIGHT, KeyboardScrollProvider, NotificationsPage, SettingsPage, SettingsSubPage, SocialAuthRow, ThreadPage, appleProvider, confirmDiscardChanges, defaultStickyHeaderOffset, getNotificationsPageStackOptions, getSettingsPageStackOptions, getSettingsSubPageStackOptions, getThreadPageStackOptions, googleProvider, iosCompactNavigationBarHeight, readReceiptFor, useKeyboardScroll, useKeyboardSticky, useKeyboardToolbar } from './chunk-C2ARUGT7.js';
4
+ export { AppleSignInButton, AuthBranding, AuthForm, AuthScreen, DashboardPage, DetailPage, DocumentPage, ForgotPasswordLink, FormPage, KEYBOARD_TOOLBAR_HEIGHT, KeyboardScrollProvider, NotificationsPage, SettingsPage, SettingsSubPage, SocialAuthRow, ThreadPage, appleProvider, confirmDiscardChanges, defaultStickyHeaderOffset, getNotificationsPageStackOptions, getSettingsPageStackOptions, getSettingsSubPageStackOptions, getThreadPageStackOptions, googleProvider, iosCompactNavigationBarHeight, readReceiptFor, useKeyboardScroll, useKeyboardSticky, useKeyboardToolbar } from './chunk-SRCGQWE4.js';
5
5
  export { NativeComposerBar, NativeThreadList, THREAD_AT_BOTTOM_POINTS, threadListMode, threadNearBottom } from './chunk-BQYT6TH2.js';
6
- export { InboxPage, NavBarSaveButton, NavBarSearchBar, NavBarTitle, ScreenContainer, composeHeaderOptions, formatInboxTime, getInboxPageStackOptions, showInboxActions } from './chunk-TUDJDIGC.js';
6
+ export { InboxPage, NavBarSaveButton, NavBarSearchBar, NavBarTitle, ScreenContainer, composeHeaderOptions, formatInboxTime, getInboxPageStackOptions, showInboxActions } from './chunk-DCCOZSGR.js';
7
7
  export { NATIVE_ICON_NAMES, NativeBadge, NativeBanner, NativeButton, NativeContextMenu, NativeEmptyState, NativeIcon, NativeImage, NativeInlineAlert, NativeInput, NativeListItem, NativeListItemDivider, NativeLoadingState, NativeNoFeaturesFound, NativeNoFeedbackFound, NativeNoSearchResults, NativeRefreshControl, NativeSectionListHeader, NativeSheet, NativeSheetProvider, NativeSheetScrollView, NativeSkeleton, NativeSwipeRow, NativeText, SF_SYMBOLS, badgeTextVariants, badgeVariants, buttonTextVariants, buttonVariants, textVariants } from './chunk-D4UU6KIF.js';
8
8
  export { GenesisModulesProvider, animateMotion, motionSpring, motionTiming, playHaptic, sentBubbleColor, useGenesisModules, useHaptics, useMotion, usePressFeedback, useReducedMotion, useThemeMode, useThemeRoles } from './chunk-VHUUOH46.js';
9
9
  export { cn } from './chunk-OHZD7KRO.js';
@@ -1,5 +1,5 @@
1
- import { e as ScreenHeaderProps, d as ScreenContainerProps } from '../inbox-page-BGqR_cBs.js';
2
- export { I as InboxPage, a as InboxPageProps, b as InboxPageSlotMap, S as SafeAreaEdge, c as ScreenContainer, f as ScrollEdgeBehavior, g as composeHeaderOptions, h as getInboxPageStackOptions, s as showInboxActions } from '../inbox-page-BGqR_cBs.js';
1
+ import { e as ScreenHeaderProps, d as ScreenContainerProps } from '../inbox-page-DD1cQdF4.js';
2
+ export { I as InboxPage, a as InboxPageProps, b as InboxPageSlotMap, S as SafeAreaEdge, c as ScreenContainer, f as ScrollEdgeBehavior, g as composeHeaderOptions, h as getInboxPageStackOptions, s as showInboxActions } from '../inbox-page-DD1cQdF4.js';
3
3
  import * as react from 'react';
4
4
  import { ReactNode, ComponentType } from 'react';
5
5
  import { Slots, SlotPropsFor } from '@marktiderman/genesis-core/slots';
@@ -1,6 +1,6 @@
1
- export { AppleSignInButton, AuthBranding, AuthForm, AuthScreen, DashboardPage, DetailPage, DocumentPage, ForgotPasswordLink, FormPage, KEYBOARD_TOOLBAR_HEIGHT, KeyboardScrollProvider, NotificationsPage, SettingsPage, SettingsSubPage, SocialAuthRow, ThreadPage, appleProvider, confirmDiscardChanges, defaultStickyHeaderOffset, getNotificationsPageStackOptions, getSettingsPageStackOptions, getSettingsSubPageStackOptions, getThreadPageStackOptions, googleProvider, iosCompactNavigationBarHeight, readReceiptFor, useKeyboardScroll, useKeyboardSticky, useKeyboardToolbar } from '../chunk-C2ARUGT7.js';
1
+ export { AppleSignInButton, AuthBranding, AuthForm, AuthScreen, DashboardPage, DetailPage, DocumentPage, ForgotPasswordLink, FormPage, KEYBOARD_TOOLBAR_HEIGHT, KeyboardScrollProvider, NotificationsPage, SettingsPage, SettingsSubPage, SocialAuthRow, ThreadPage, appleProvider, confirmDiscardChanges, defaultStickyHeaderOffset, getNotificationsPageStackOptions, getSettingsPageStackOptions, getSettingsSubPageStackOptions, getThreadPageStackOptions, googleProvider, iosCompactNavigationBarHeight, readReceiptFor, useKeyboardScroll, useKeyboardSticky, useKeyboardToolbar } from '../chunk-SRCGQWE4.js';
2
2
  import '../chunk-BQYT6TH2.js';
3
- export { InboxPage, NavBarSaveButton, NavBarSearchBar, NavBarTitle, ScreenContainer, composeHeaderOptions, formatInboxTime, getInboxPageStackOptions, showInboxActions } from '../chunk-TUDJDIGC.js';
3
+ export { InboxPage, NavBarSaveButton, NavBarSearchBar, NavBarTitle, ScreenContainer, composeHeaderOptions, formatInboxTime, getInboxPageStackOptions, showInboxActions } from '../chunk-DCCOZSGR.js';
4
4
  import '../chunk-D4UU6KIF.js';
5
5
  import '../chunk-VHUUOH46.js';
6
6
  import '../chunk-OHZD7KRO.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marktiderman/genesis-ui-native",
3
- "version": "3.12.1",
3
+ "version": "3.13.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -83,8 +83,8 @@
83
83
  "@expo/ui": ">=58.0.0",
84
84
  "@gorhom/bottom-sheet": ">=5.0.0",
85
85
  "@hookform/resolvers": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0",
86
- "@marktiderman/genesis-core": "^2.16.1",
87
- "@marktiderman/genesis-design-system": "^1.12.0",
86
+ "@marktiderman/genesis-core": "^2.17.0",
87
+ "@marktiderman/genesis-design-system": "^1.13.0",
88
88
  "@react-native-community/datetimepicker": ">=8.0.0",
89
89
  "@shopify/flash-list": ">=2.0.0",
90
90
  "@tanstack/react-query": "^5.0.0",
@@ -35,6 +35,12 @@ export interface NativeRecordPeekProps<T extends Row = Row> extends Omit<NativeR
35
35
  * promise: the sheet closes when it resolves, and a rejection is shown in plain words.
36
36
  */
37
37
  onDelete?: (row: T) => unknown;
38
+ /**
39
+ * `false` when `onDelete` confirms on its own (a list's own delete handler): the peek calls it at
40
+ * once instead of asking first. Default `true`, as genesis-ui's RecordPeek, so one `onDelete`
41
+ * means the same on both.
42
+ */
43
+ confirmDelete?: boolean;
38
44
  /** The screen's own rule, as NativeResourceView's `can`: `false` hides Edit or Delete, a sentence refuses it. Only narrows the view's guards. */
39
45
  can?: NativeResourceScreenCan<T>;
40
46
  /** Above the record (a link to its full page). */
@@ -51,6 +57,7 @@ export function NativeRecordPeek<T extends Row = Row>({
51
57
  onClose,
52
58
  onEdit,
53
59
  onDelete,
60
+ confirmDelete: confirmFirst = true,
54
61
  can,
55
62
  header,
56
63
  snapPoints = ["60%", "92%"],
@@ -82,8 +89,12 @@ export function NativeRecordPeek<T extends Row = Row>({
82
89
  setDeleting(false);
83
90
  }
84
91
  };
92
+ // A handler that confirms on its own owns the rest (its confirm, the write, closing the peek), as
93
+ // on the web: the peek hands the call straight through and stays open.
85
94
  const confirmDelete = (r: T) =>
86
- Alert.alert(labels.deleteTitle ?? fill(words.confirmTitle, { name: title }), labels.deleteBody ?? words.confirmBody, [
95
+ !confirmFirst
96
+ ? void onDelete?.(r)
97
+ : Alert.alert(labels.deleteTitle ?? fill(words.confirmTitle, { name: title }), labels.deleteBody ?? words.confirmBody, [
87
98
  { text: labels.cancel ?? messages.common.cancel, style: "cancel" },
88
99
  { text: deleteLabel, style: "destructive", onPress: () => void runDelete(r) },
89
100
  ]);
@@ -290,6 +290,32 @@ describe("NativeRecordPeek", () => {
290
290
  alert.mockRestore();
291
291
  });
292
292
 
293
+ it("with confirmDelete={false}, calls a handler that confirms on its own at once, as the web's RecordPeek", async () => {
294
+ const onDelete = vi.fn();
295
+ const alert = vi.spyOn(Alert, "alert").mockImplementation(() => {});
296
+ render(<NativeRecordPeek view={recordView} row={PEOPLE[0]!} open onClose={() => undefined} onDelete={onDelete} confirmDelete={false} />, { wrapper: wrap() });
297
+ await screen.findByTestId("record-peek-page");
298
+ await act(async () => {
299
+ fireEvent.click(screen.getByTestId("record-peek-delete"));
300
+ });
301
+ expect(alert).not.toHaveBeenCalled();
302
+ expect(onDelete).toHaveBeenCalledWith(PEOPLE[0]);
303
+ alert.mockRestore();
304
+ });
305
+
306
+ it("with confirmDelete={false}, leaves closing to the handler: a cancelled confirm keeps the peek open", async () => {
307
+ // The handler opens its own confirm and returns at once; the person then cancels.
308
+ const onDelete = vi.fn(() => undefined);
309
+ const onClose = vi.fn();
310
+ render(<NativeRecordPeek view={recordView} row={PEOPLE[0]!} open onClose={onClose} onDelete={onDelete} confirmDelete={false} />, { wrapper: wrap() });
311
+ await screen.findByTestId("record-peek-page");
312
+ await act(async () => {
313
+ fireEvent.click(screen.getByTestId("record-peek-delete"));
314
+ });
315
+ expect(onDelete).toHaveBeenCalledWith(PEOPLE[0]);
316
+ expect(onClose).not.toHaveBeenCalled();
317
+ });
318
+
293
319
  it("hides what the screen's can turns off and explains what the view's guard refuses", async () => {
294
320
  const guarded = defineRecordView(
295
321
  defineView(people, { can: { delete: () => "Only owners delete people." } }),
@@ -20,9 +20,11 @@ import { Alert, Platform, Pressable, SectionList, View } from "react-native";
20
20
  import { SafeAreaView } from "react-native-safe-area-context";
21
21
  import type { BaseRecord, DataRow } from "@marktiderman/genesis-core";
22
22
  import { personTimeZone } from "@marktiderman/genesis-core/dates";
23
- import { scopeClock, useOne, useOptionalViewerScope } from "@marktiderman/genesis-core/hooks";
23
+ import { resourceKeys, useDataProvider, useViewer } from "@marktiderman/genesis-core";
24
+ import { scopeClock, useListState, useOne, useOptionalViewerScope } from "@marktiderman/genesis-core/hooks";
25
+ import { useQueryClient } from "@tanstack/react-query";
24
26
  import type { GalleryItem } from "@marktiderman/genesis-core/gallery";
25
- import type { RowPicture, ViewGallery } from "@marktiderman/genesis-core/resource-view";
27
+ import type { RowPicture, SavedViewStore, ViewGallery } from "@marktiderman/genesis-core/resource-view";
26
28
  import { NativeAvatar } from "../../components/avatar";
27
29
  import { NativeBadge } from "../../components/badge";
28
30
  import { NativeImage } from "../../components/image";
@@ -38,7 +40,7 @@ import { NativeSectionListHeader } from "../../components/section-list";
38
40
  import { NativeSheet } from "../../components/sheet";
39
41
  import { NativeText } from "../../components/text";
40
42
  import { useThemeRoles } from "../../hooks/use-theme-roles";
41
- import { showInboxActions, type InboxPageSlotMap } from "../../layouts/inbox-page";
43
+ import { InboxPage, showInboxActions, type InboxPageSlotMap } from "../../layouts/inbox-page";
42
44
  import { NativeDetailPanel } from "../NativeDetailPanel";
43
45
  import {
44
46
  badgeVariant,
@@ -50,6 +52,7 @@ import {
50
52
  import type { AnyResourceView, NativeResourceRowItem, NativeResourceSection, NativeResourceSwipeAction } from "./mapping";
51
53
  import { fill } from "./messages";
52
54
  import { NativeResourceFormSheet } from "./NativeResourceFormSheet";
55
+ import { NativeListControls, NativeResourceBoard, NativeResourceCalendar, nativeSwitchableTypes } from "./list-controls";
53
56
  import {
54
57
  recordKey,
55
58
  useNativeResourceView,
@@ -67,8 +70,8 @@ export type NativeResourceSwipeableProps = Omit<InboxPageSlotMap["swipeable"], "
67
70
  /** How rows show: a list (the default) or cards in columns, as the web's `mode`. */
68
71
  export type NativeResourceViewMode = "list" | "grid";
69
72
 
70
- /** The view types the phone draws: list, grid and gallery (ADR 0021). @stability Beta */
71
- export type NativeResourceViewType = NativeResourceViewMode | "gallery";
73
+ /** The view types the phone draws (ADR 0021). @stability Beta */
74
+ export type NativeResourceViewType = NativeResourceViewMode | "gallery" | "inbox" | "board" | "calendar";
72
75
 
73
76
  /**
74
77
  * Spread onto your card's Pressable: the press (the screen's `onRowPress`, else the peek), the
@@ -126,10 +129,28 @@ export interface NativeResourceViewProps<T extends Row = Row> extends NativeReso
126
129
  mode?: NativeResourceViewMode;
127
130
  /**
128
131
  * The view type (ADR 0021), as the web's `<ResourceView type>`: `"list"` (default), `"grid"`, or
129
- * `"gallery"` (the grid as photos, from the view's `gallery` block). The phone has no board or
130
- * calendar yet. Wins over `mode`.
132
+ * `"gallery"` (the grid as photos, from the view's `gallery` block), or `"inbox"` (InboxPage's
133
+ * rows from the view's `inbox` block: unread in bold, a preview, a time, swipe actions), `"board"`
134
+ * (the view's board block: columns side by side, a long press moves a card) or `"calendar"` (the
135
+ * view's calendar block: an agenda or a month). Wins over `mode`, and fixes the type: the
136
+ * switcher stays off unless `switcher` asks for it.
131
137
  */
132
138
  type?: NativeResourceViewType;
139
+ /**
140
+ * The view-type switcher above the list (ADR 0017 §11): the view's `types` the phone draws, the
141
+ * person's choice kept in `savedViews`. Default on when the view declares `types` (two or more
142
+ * the phone draws) and the screen fixes neither `type` nor `mode`.
143
+ */
144
+ switcher?: boolean;
145
+ /** Where the person's choices (the view type) are kept: the app's saved-view store, the web's contract. */
146
+ savedViews?: SavedViewStore;
147
+ /** The segment the list opens on. Default the view's first. */
148
+ defaultSegment?: string;
149
+ /**
150
+ * Runs one of the view's actions on a row (a swipe or the long-press menu). Default: the
151
+ * provider's `runAction`, after the action's `confirm`.
152
+ */
153
+ onAction?: (name: string, row: T) => void | Promise<void>;
133
154
  /** Columns in grid mode (React Native's FlatList name). Default 2. */
134
155
  numColumns?: number;
135
156
  /**
@@ -482,15 +503,66 @@ function Screen<T extends Row = Row>(props: NativeResourceViewProps<T>) {
482
503
  renderCard,
483
504
  scopeTimeZone: _zone,
484
505
  testID = "native-resource-view",
506
+ switcher,
507
+ savedViews,
508
+ defaultSegment,
509
+ onAction,
485
510
  ...options
486
511
  } = props;
512
+ // The list's state (ADR 0017): core's, the same the web's ResourceView holds. The segment and
513
+ // declared filters narrow the read; the type comes from the switcher when it's on.
514
+ const switchTypes = useMemo(() => nativeSwitchableTypes(view as AnyResourceView<Row>), [view]);
515
+ // On by default only where the view declares its `types` and the screen fixes neither type nor mode.
516
+ const switcherOn = (switcher ?? (type === undefined && props.mode === undefined && !!view.definition.types)) && switchTypes.length >= 2;
517
+ const list = useListState({
518
+ view: view as never,
519
+ store: savedViews,
520
+ types: switchTypes,
521
+ defaultType: type ?? (switcherOn ? switchTypes[0] : undefined) ?? modeProp,
522
+ rememberType: switcherOn,
523
+ defaultSegment,
524
+ });
525
+ const shown = (switcherOn ? (list.type as NativeResourceViewType | undefined) : undefined) ?? type;
487
526
  // `type` is the view type's name (ADR 0021); `mode` its alias. A gallery is the grid as photos.
488
- const mode: NativeResourceViewMode = type === "gallery" ? "grid" : (type ?? modeProp);
489
- if (type === "gallery" && !view.definition.gallery && !screenGallery?.image) {
527
+ // An inbox is the list drawn as InboxPage's rows (from the view's inbox block).
528
+ const inbox = shown === "inbox";
529
+ const board = shown === "board";
530
+ const calendar = shown === "calendar";
531
+ const mode: NativeResourceViewMode = shown === "gallery" ? "grid" : shown === "grid" ? "grid" : shown === undefined ? modeProp : "list";
532
+ if (shown === "gallery" && !view.definition.gallery && !screenGallery?.image) {
490
533
  throw new Error(`NativeResourceView(${view.resource}): type="gallery" needs a gallery block: the view's gallery.image, or gallery={{ image }}`);
491
534
  }
535
+ if (inbox && !view.definition.inbox) {
536
+ throw new Error(`NativeResourceView(${view.resource}): type="inbox" needs the view's inbox block (which field is the title, the time, unread)`);
537
+ }
492
538
  void _zone;
493
- const state = useNativeResourceView<T>(view, options);
539
+ // The board and the calendar read their own rows; the list waits for them, and for the screen.
540
+ const state = useNativeResourceView<T>(view, { ...options, listFilters: list.filters, enabled: options.enabled !== false && !board && !calendar });
541
+ // The view's own actions, run through the provider (or the screen's `onAction`) after their confirm.
542
+ const provider = useDataProvider();
543
+ const queryClient = useQueryClient();
544
+ const viewer = useViewer();
545
+ const runAction = useCallback(
546
+ async (name: string, row: T) => {
547
+ if (onAction) await onAction(name, row);
548
+ else if (provider.runAction) await provider.runAction(view.resource, { id: recordKey(view as AnyResourceView<Row>, row), action: name });
549
+ await queryClient.invalidateQueries({ queryKey: resourceKeys(view.resource).all });
550
+ },
551
+ [onAction, provider, view, queryClient],
552
+ );
553
+ const actionsOn = !!onAction || !!provider.runAction;
554
+ const cancelWord = useNativeResourceViewMessages().common.cancel;
555
+ const confirmAction = useCallback(
556
+ (name: string, row: T) => {
557
+ const action = view.actions().find((a) => a.name === name);
558
+ const run = () => void runAction(name, row).catch((error: unknown) => Alert.alert(action?.label ?? name, error instanceof Error ? error.message : String(error)));
559
+ if (action?.confirm) Alert.alert(action.confirm, undefined, [{ text: cancelWord, style: "cancel" }, { text: action.label, style: action.destructive ? "destructive" : "default", onPress: run }]);
560
+ else run();
561
+ },
562
+ [view, runAction, cancelWord],
563
+ );
564
+ // Opening an unread inbox row runs the view's markRead action, when it declares one and allows it.
565
+ const markRead = view.inboxActions().markRead;
494
566
  const keyExtractor = useCallback((row: T) => recordKey(view as AnyResourceView<Row>, row), [view]);
495
567
  const messages = useNativeResourceViewMessages();
496
568
  const colors = useThemeRoles();
@@ -523,7 +595,10 @@ function Screen<T extends Row = Row>(props: NativeResourceViewProps<T>) {
523
595
  setPeekId(null);
524
596
  setSheet({ mode: "edit", row });
525
597
  }, []);
526
- const handlers = useMemo(() => ({ onEdit: edit, onDelete: confirmDelete, onRefused: refused }), [edit, confirmDelete, refused]);
598
+ const handlers = useMemo(
599
+ () => ({ onEdit: edit, onDelete: confirmDelete, onRefused: refused, ...(actionsOn ? { onAction: confirmAction } : {}) }),
600
+ [edit, confirmDelete, refused, actionsOn, confirmAction],
601
+ );
527
602
 
528
603
  // The screen's handler through a ref, so an inline `onRowPress` doesn't redraw every row.
529
604
  const rowPress = useRef(onRowPress);
@@ -612,7 +687,8 @@ function Screen<T extends Row = Row>(props: NativeResourceViewProps<T>) {
612
687
  else if (typeof state.canCreate === "string") refused(fill(messages.common.create, { noun: view.noun }), state.canCreate);
613
688
  };
614
689
 
615
- const showSearch = searchable ?? !!(options.searchFields?.length || view.labelField);
690
+ // A board and a calendar read the segment and filters, not the search box.
691
+ const showSearch = !board && !calendar && (searchable ?? !!(options.searchFields?.length || view.labelField));
616
692
  const heading = title === false ? null : (title ?? view.title);
617
693
  const hasRows = state.rows.length > 0;
618
694
 
@@ -664,6 +740,7 @@ function Screen<T extends Row = Row>(props: NativeResourceViewProps<T>) {
664
740
  onDismiss={state.dismissRefusal}
665
741
  />
666
742
  ) : null}
743
+ <NativeListControls view={view as AnyResourceView<Row>} state={list} baseFilters={state.baseFilters} types={switcherOn ? switchTypes : []} enabled={options.enabled !== false} testID={testID} />
667
744
  {header}
668
745
  {state.loadingPrevious ? (
669
746
  <NativeLoadingState fullScreen={false} size="small" label={messages.list.loadingMore} testID={`${testID}-previous`} />
@@ -697,9 +774,11 @@ function Screen<T extends Row = Row>(props: NativeResourceViewProps<T>) {
697
774
  )))
698
775
  );
699
776
 
700
- // The peek and the edit sheet read the row by id: the list's select may be narrower.
701
- const peekRow = useOne<T & BaseRecord>(view.resource, peekId ? ((peekId.row as DataRow).id as string) : null);
702
- const editRow = useOne<T & BaseRecord>(view.resource, sheet?.mode === "edit" ? ((sheet.row as DataRow).id as string) : null);
777
+ // The peek and the edit sheet read the row by id: the list's select may be narrower. They read in
778
+ // the list's scope (as the web's inbox and table do): a function source takes its scope there.
779
+ const recordScope = useMemo(() => [...state.baseFilters, ...list.filters], [state.baseFilters, list.filters]);
780
+ const peekRow = useOne<T & BaseRecord>(view.resource, peekId ? ((peekId.row as DataRow).id as string) : null, { scope: recordScope });
781
+ const editRow = useOne<T & BaseRecord>(view.resource, sheet?.mode === "edit" ? ((sheet.row as DataRow).id as string) : null, { scope: recordScope });
703
782
  const peek = peekId ? ((peekRow.data as T | undefined) ?? peekId.row) : null;
704
783
 
705
784
  // Peek: the view's full column list, drawn like the cells (so `when` hides there too), never
@@ -739,7 +818,51 @@ function Screen<T extends Row = Row>(props: NativeResourceViewProps<T>) {
739
818
 
740
819
  return (
741
820
  <SafeAreaView testID={testID} edges={["left", "right", "bottom"]} style={{ flex: 1, backgroundColor: colors.groupedBackground }}>
742
- {photos ? (
821
+ {board ? (
822
+ <NativeResourceBoard
823
+ view={view as AnyResourceView<Row>}
824
+ filters={[...state.baseFilters, ...list.filters]}
825
+ enabled={options.enabled !== false}
826
+ {...(options.can ? { can: options.can as never } : {})}
827
+ onOpen={(row) => press(row as T)}
828
+ header={listHeader}
829
+ testID={testID}
830
+ />
831
+ ) : calendar ? (
832
+ <NativeResourceCalendar view={view as AnyResourceView<Row>} filters={[...state.baseFilters, ...list.filters]} enabled={options.enabled !== false} onOpen={(row) => press(row as T)} header={listHeader} testID={testID} />
833
+ ) : inbox ? (
834
+ <InboxPage
835
+ testID={`${testID}-inbox`}
836
+ items={state.rows.map((row) => {
837
+ const r = view.inboxRow(row as never);
838
+ return {
839
+ id: r.id,
840
+ title: r.title,
841
+ unread: r.unread,
842
+ ...(r.preview ? { preview: r.preview } : {}),
843
+ ...(r.time ? { timestamp: r.time } : {}),
844
+ ...(r.from || r.badge ? { meta: [r.from, r.badge?.label].filter(Boolean).join(" · ") } : {}),
845
+ onPress: () => {
846
+ if (r.unread && markRead && view.canAction(markRead, row as never, viewer) === true) void runAction(markRead, row).catch(() => undefined);
847
+ press(row);
848
+ },
849
+ // The view's swipe actions (edit, delete, its own), as the list's rows have them.
850
+ swipeActions: actionsFor(row, handlers).map((a) => ({ id: a.id, label: a.label, onPress: a.onPress, ...(a.destructive ? { destructive: true } : {}) })),
851
+ };
852
+ })}
853
+ header={listHeader}
854
+ loading={state.loading}
855
+ error={Boolean(state.error)}
856
+ refreshing={state.refreshing}
857
+ onRefresh={() => state.refresh()}
858
+ loadingMore={state.loadingMore}
859
+ {...(state.hasMore ? { onEndReached: state.loadMore } : {})}
860
+ // maxPages drops pages from the front, as in the list: reaching the top loads them back.
861
+ {...(state.hasPrevious ? { onStartReached: state.loadPrevious } : {})}
862
+ {...(view.definition.copy?.empty?.title ? { emptyTitle: view.definition.copy.empty.title } : {})}
863
+ {...(view.definition.copy?.empty?.body ? { emptyBody: view.definition.copy.empty.body } : {})}
864
+ />
865
+ ) : photos ? (
743
866
  <NativeGalleryGrid
744
867
  testID={`${testID}-gallery`}
745
868
  items={photos.items}
@@ -0,0 +1,59 @@
1
+ // @feat:view-inbox @feat:native-components
2
+ /** NativeResourceView `type="inbox"`: the view's rows as InboxPage's, unread first in weight, a press opening the row. */
3
+ import { fireEvent, render, screen } from "@testing-library/react";
4
+ import { QueryClient } from "@tanstack/react-query";
5
+ import type { ReactNode } from "react";
6
+ import { describe, expect, it, vi } from "vitest";
7
+ import { defineResource, GenesisProvider, type DataProvider } from "@marktiderman/genesis-core";
8
+ import { defineView } from "@marktiderman/genesis-core/resource-view";
9
+ import { NativeResourceView } from "..";
10
+
11
+ type Ticket = { id: string; subject: string; body: string; unread: boolean };
12
+
13
+ const tickets = defineResource<Ticket>()({
14
+ name: "tickets",
15
+ key: "id",
16
+ labelField: "subject",
17
+ fields: [
18
+ { name: "id", type: "string", hasDefault: true },
19
+ { name: "subject", type: "string" },
20
+ { name: "body", type: "string" },
21
+ { name: "unread", type: "boolean" },
22
+ ],
23
+ });
24
+
25
+ const ROWS: Ticket[] = [
26
+ { id: "t1", subject: "Can't sign in", body: "The code never arrives.", unread: true },
27
+ { id: "t2", subject: "Invoice copy", body: "Please resend it.", unread: false },
28
+ ];
29
+
30
+ const view = defineView(tickets, { inbox: { preview: "body", unread: "unread" } });
31
+
32
+ function wrap(p: DataProvider) {
33
+ const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false, staleTime: Infinity } } });
34
+ return ({ children }: { children: ReactNode }) => (
35
+ <GenesisProvider provider={p} queryClient={queryClient}>
36
+ {children}
37
+ </GenesisProvider>
38
+ );
39
+ }
40
+
41
+ describe("NativeResourceView inbox", () => {
42
+ it("draws the rows as an inbox, with their preview, and opens one on press", async () => {
43
+ const p = {
44
+ getList: vi.fn(async () => ({ data: ROWS, total: ROWS.length })),
45
+ getOne: vi.fn(async (_r: string, { id }: { id: string }) => ({ data: ROWS.find((r) => r.id === id) })),
46
+ getMany: vi.fn(async () => ({ data: [] })),
47
+ create: vi.fn(),
48
+ update: vi.fn(),
49
+ deleteOne: vi.fn(),
50
+ } as unknown as DataProvider;
51
+ const onRowPress = vi.fn();
52
+ render(<NativeResourceView view={view} type="inbox" onRowPress={onRowPress} />, { wrapper: wrap(p) });
53
+ expect(await screen.findByText("Can't sign in")).toBeTruthy();
54
+ expect(screen.getByText("Please resend it.")).toBeTruthy();
55
+ expect(screen.queryByTestId("native-resource-view-list")).toBeNull();
56
+ fireEvent.click(screen.getByText("Invoice copy"));
57
+ expect(onRowPress).toHaveBeenCalledWith(expect.objectContaining({ id: "t2" }));
58
+ });
59
+ });