@marktiderman/genesis-ui-native 3.6.0 → 3.8.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 (90) hide show
  1. package/README.md +48 -1
  2. package/dist/{chunk-NDXNSSM6.js → chunk-DHONOH6K.js} +24 -211
  3. package/dist/chunk-DHONOH6K.js.map +1 -0
  4. package/dist/{chunk-6PGLX6ET.js → chunk-FGIIBON3.js} +334 -24
  5. package/dist/chunk-FGIIBON3.js.map +1 -0
  6. package/dist/{chunk-ZRQAFFTN.js → chunk-FOJJB6AB.js} +2 -2
  7. package/dist/{chunk-ZRQAFFTN.js.map → chunk-FOJJB6AB.js.map} +1 -1
  8. package/dist/{chunk-SEJ6RBP7.js → chunk-JZ7RAGDQ.js} +117 -60
  9. package/dist/chunk-JZ7RAGDQ.js.map +1 -0
  10. package/dist/chunk-PWS2HLDE.js +137 -0
  11. package/dist/chunk-PWS2HLDE.js.map +1 -0
  12. package/dist/{chunk-AGTBABAH.js → chunk-PWYMRUAK.js} +43 -30
  13. package/dist/chunk-PWYMRUAK.js.map +1 -0
  14. package/dist/{chunk-FUMSL7VZ.js → chunk-T7FEVT62.js} +53 -12
  15. package/dist/chunk-T7FEVT62.js.map +1 -0
  16. package/dist/{chunk-2Z72MYHB.js → chunk-UZCJDMGE.js} +353 -19
  17. package/dist/chunk-UZCJDMGE.js.map +1 -0
  18. package/dist/components/index.d.ts +275 -24
  19. package/dist/components/index.js +5 -5
  20. package/dist/data/index.d.ts +2 -1
  21. package/dist/data/index.js +7 -12
  22. package/dist/data/index.js.map +1 -1
  23. package/dist/hooks/index.d.ts +36 -3
  24. package/dist/hooks/index.js +2 -2
  25. package/dist/icons/lucide.d.ts +1 -1
  26. package/dist/icons/lucide.js +13 -3
  27. package/dist/icons/lucide.js.map +1 -1
  28. package/dist/{inbox-page-B7_Oi2fS.d.ts → inbox-page-BGqR_cBs.d.ts} +4 -1
  29. package/dist/index.d.ts +4 -4
  30. package/dist/index.js +8 -8
  31. package/dist/layouts/index.d.ts +12 -3
  32. package/dist/layouts/index.js +5 -5
  33. package/dist/{native-modules-Cl3zw3kh.d.ts → native-modules-CeAaO2Dh.d.ts} +55 -3
  34. package/package.json +73 -2
  35. package/src/__tests__/doctor-rules.test.ts +27 -0
  36. package/src/__tests__/native-modules-lists.test.tsx +1 -0
  37. package/src/components/__tests__/bulk-bar.test.tsx +36 -0
  38. package/src/components/__tests__/button-haptic.test.tsx +74 -0
  39. package/src/components/__tests__/composer-bar.test.tsx +140 -1
  40. package/src/components/__tests__/gallery-grid.test.tsx +2 -2
  41. package/src/components/__tests__/library-round-5.test.tsx +121 -0
  42. package/src/components/__tests__/share-sheet.test.tsx +47 -0
  43. package/src/components/__tests__/swipe-row-context-menu.test.tsx +215 -0
  44. package/src/components/__tests__/tab-bar.test.tsx +43 -0
  45. package/src/components/__tests__/thread-list.test.tsx +200 -0
  46. package/src/components/__tests__/tier-badge.test.tsx +57 -0
  47. package/src/components/__tests__/whats-new-sheet.test.tsx +29 -0
  48. package/src/components/bulk-bar.tsx +91 -0
  49. package/src/components/button.tsx +81 -25
  50. package/src/components/choice-card.tsx +104 -0
  51. package/src/components/composer-bar.tsx +104 -25
  52. package/src/components/context-menu.tsx +101 -0
  53. package/src/components/gallery-grid.tsx +10 -4
  54. package/src/components/index.ts +19 -2
  55. package/src/components/inline-alert.tsx +36 -1
  56. package/src/components/input.tsx +3 -0
  57. package/src/components/progress.tsx +24 -2
  58. package/src/components/rating.tsx +35 -16
  59. package/src/components/share-sheet.tsx +127 -0
  60. package/src/components/sheet.tsx +9 -1
  61. package/src/components/swipe-row.tsx +74 -0
  62. package/src/components/tab-bar.tsx +133 -0
  63. package/src/components/tabs.tsx +2 -0
  64. package/src/components/text.tsx +3 -0
  65. package/src/components/textarea.tsx +3 -0
  66. package/src/components/thread-list.tsx +78 -23
  67. package/src/components/tier-badge.tsx +74 -0
  68. package/src/components/whats-new-sheet.tsx +89 -0
  69. package/src/data/resource-view/NativeRecordView.tsx +3 -8
  70. package/src/data/resource-view/use-native-resource-view.ts +2 -2
  71. package/src/hooks/__tests__/use-haptics.test.tsx +146 -0
  72. package/src/hooks/index.ts +3 -1
  73. package/src/hooks/use-haptics.ts +64 -0
  74. package/src/hooks/use-press-feedback.ts +87 -0
  75. package/src/hooks/use-theme-roles.ts +3 -0
  76. package/src/icon-names.ts +12 -2
  77. package/src/icons/lucide.ts +27 -7
  78. package/src/layouts/__tests__/inbox-page.test.tsx +26 -7
  79. package/src/layouts/__tests__/thread-page.test.tsx +89 -2
  80. package/src/layouts/inbox-page.tsx +28 -12
  81. package/src/layouts/thread-page.tsx +69 -8
  82. package/src/native-modules.tsx +20 -0
  83. package/dist/chunk-2Z72MYHB.js.map +0 -1
  84. package/dist/chunk-4OQOJ2OC.js +0 -80
  85. package/dist/chunk-4OQOJ2OC.js.map +0 -1
  86. package/dist/chunk-6PGLX6ET.js.map +0 -1
  87. package/dist/chunk-AGTBABAH.js.map +0 -1
  88. package/dist/chunk-FUMSL7VZ.js.map +0 -1
  89. package/dist/chunk-NDXNSSM6.js.map +0 -1
  90. package/dist/chunk-SEJ6RBP7.js.map +0 -1
@@ -45,12 +45,14 @@
45
45
  */
46
46
  import { memo, useCallback, useEffect, useMemo, useRef, useState, type ComponentType, type ReactNode } from "react";
47
47
  import { renderSlot, type SlotPropsFor, type Slots } from "@marktiderman/genesis-core/slots";
48
- import { AccessibilityInfo, Image, KeyboardAvoidingView, Platform, Pressable, View } from "react-native";
48
+ import { AccessibilityInfo, Image, KeyboardAvoidingView, Linking, Platform, Pressable, View } from "react-native";
49
49
  import { SafeAreaView } from "react-native-safe-area-context";
50
- import { useThemeRoles } from "../hooks/use-theme-roles";
50
+ import { sentBubbleColor, useThemeRoles } from "../hooks/use-theme-roles";
51
51
  import { useGenesisModules } from "../native-modules";
52
52
  import { useKeyboardScroll } from "./keyboard";
53
53
  import { NativeEmptyState } from "../components/empty-state";
54
+ import { NativeButton } from "../components/button";
55
+ import { NativeIcon } from "../components/icon";
54
56
  import { NativeText } from "../components/text";
55
57
  import { NativeComposerBar, type ComposerMode } from "../components/composer-bar";
56
58
  import { NativeThreadList, type NativeThreadListHandle, type ThreadRowInfo } from "../components/thread-list";
@@ -84,7 +86,7 @@ export type ThreadPageSlotMap = {
84
86
  headerRegion: { testID: string };
85
87
  header: { testID: string };
86
88
  earlier: { loading: boolean; onPress: () => void; label: string; testID: string };
87
- empty: { title: string; body: string; testID: string };
89
+ empty: { title: string; body: string; actionLabel?: string | undefined; onAction?: (() => void) | undefined; testID: string };
88
90
  };
89
91
 
90
92
  export interface ThreadPageProps extends ScreenHeaderProps {
@@ -117,6 +119,13 @@ export interface ThreadPageProps extends ScreenHeaderProps {
117
119
  onJumpFailed?: (id: string) => void;
118
120
  /** The first page is loading: a skeleton instead of the empty state, and a jump waits for it. */
119
121
  loading?: boolean;
122
+ /** The read failed and there are no messages: the empty slot shows `errorTitle` / `errorBody` instead. */
123
+ error?: boolean;
124
+ errorTitle?: string;
125
+ errorBody?: string;
126
+ /** A "Try again" button with `error`. */
127
+ onRetry?: () => void;
128
+ retryLabel?: string;
120
129
  /** Fresher rows are on their way (the cache showed first): a quiet "Updating…" line under the header region, announced once. */
121
130
  updating?: boolean;
122
131
  /**
@@ -155,6 +164,7 @@ const toDate = (value: string | Date) => (typeof value === "string" ? new Date(v
155
164
  const NO_SLOTS: Slots<ThreadPageSlotMap> = {};
156
165
  const NO_SLOT_PROPS: SlotPropsFor<ThreadPageSlotMap> = {};
157
166
  const messageKey = (m: ThreadMessage) => m.id;
167
+ const messageJumpId = (m: ThreadMessage) => m.jumpId ?? m.id;
158
168
  const messageType = (m: ThreadMessage) => (m.kind === "event" ? "event" : m.mine ? "mine" : "theirs");
159
169
 
160
170
  declare const __DEV__: boolean | undefined;
@@ -187,6 +197,11 @@ export function ThreadPage({
187
197
  onLoadUntil,
188
198
  onJumpFailed,
189
199
  loading = false,
200
+ error = false,
201
+ errorTitle = "Couldn't load this conversation",
202
+ errorBody = "Check your connection and try again.",
203
+ onRetry,
204
+ retryLabel = "Try again",
190
205
  updating = false,
191
206
  keyboardVerticalOffset,
192
207
  emptyTitle,
@@ -324,6 +339,7 @@ export function ThreadPage({
324
339
  earlierLabel={earlierLabel}
325
340
  renderEarlier={(p) => renderSlot(DefaultEarlierButton, slots.earlier, { ...p, testID: `${testID}-earlier` }, slotProps.earlier)}
326
341
  jumpTo={jumpTo}
342
+ jumpId={messageJumpId}
327
343
  onLoadUntil={onLoadUntil}
328
344
  jumpAnnouncement={(m) => [m.mine ? labels.you : m.authorName, m.body].filter(Boolean).join(", ")}
329
345
  onJumpFailed={onJumpFailed ?? (() => announce(labels.messageGone))}
@@ -332,7 +348,9 @@ export function ThreadPage({
332
348
  empty={renderSlot(
333
349
  DefaultEmpty,
334
350
  slots.empty,
335
- { title: emptyTitle ?? "No messages yet", body: emptyBody ?? "Write the first one below.", testID: `${testID}-empty` },
351
+ error
352
+ ? { title: errorTitle, body: errorBody, actionLabel: onRetry ? retryLabel : undefined, onAction: onRetry, testID: `${testID}-error` }
353
+ : { title: emptyTitle ?? "No messages yet", body: emptyBody ?? "Write the first one below.", testID: `${testID}-empty` },
336
354
  slotProps.empty,
337
355
  )}
338
356
  />
@@ -371,8 +389,22 @@ function DefaultEarlierButton({ loading, onPress, label, testID }: ThreadPageSlo
371
389
  );
372
390
  }
373
391
 
374
- function DefaultEmpty({ title, body, testID }: ThreadPageSlotMap["empty"]) {
375
- return <NativeEmptyState variant="first-run" title={title} body={body} testID={testID} />;
392
+ function DefaultEmpty({ title, body, actionLabel, onAction, testID }: ThreadPageSlotMap["empty"]) {
393
+ return (
394
+ <NativeEmptyState
395
+ variant="first-run"
396
+ title={title}
397
+ body={body}
398
+ testID={testID}
399
+ primaryAction={
400
+ actionLabel && onAction ? (
401
+ <NativeButton onPress={onAction} testID={`${testID}-action`}>
402
+ {actionLabel}
403
+ </NativeButton>
404
+ ) : undefined
405
+ }
406
+ />
407
+ );
376
408
  }
377
409
 
378
410
  function DefaultUnreadDivider({ label, testID }: ThreadPageSlotMap["unreadDivider"]) {
@@ -453,7 +485,7 @@ const DefaultMessage = memo(function DefaultMessage(message: ThreadPageSlotMap["
453
485
  paddingHorizontal: 14,
454
486
  paddingVertical: 8,
455
487
  borderRadius: 18,
456
- backgroundColor: internal ? colors.surface : message.mine ? colors.tint : colors.surface,
488
+ backgroundColor: internal ? colors.surface : message.mine ? sentBubbleColor(colors) : colors.surface,
457
489
  borderWidth: internal || message.highlighted ? 2 : 0,
458
490
  borderColor: internal ? colors.warning : colors.tint,
459
491
  opacity: waiting ? 0.6 : 1,
@@ -477,7 +509,36 @@ const DefaultMessage = memo(function DefaultMessage(message: ThreadPageSlotMap["
477
509
  );
478
510
  });
479
511
 
480
- function DefaultAttachment({ id, uri, width, height, accessibilityLabel, onPress, testID }: ThreadPageSlotMap["attachment"]) {
512
+ /** What a file attachment may open: the web, and a file on this phone only when you sent it. */
513
+ const OPENABLE = /^https?:/i;
514
+ const OPENABLE_IF_MINE = /^(file|content):/i;
515
+
516
+ function FileAttachment({ uri, name, accessibilityLabel, onPress, mine, testID }: ThreadPageSlotMap["attachment"]) {
517
+ const colors = useThemeRoles();
518
+ const label = name ?? accessibilityLabel ?? "Attachment";
519
+ const open = onPress ?? (OPENABLE.test(uri) || (mine && OPENABLE_IF_MINE.test(uri)) ? () => void Linking.openURL(uri).catch(() => undefined) : undefined);
520
+ return (
521
+ <Pressable
522
+ testID={testID}
523
+ accessibilityRole={open ? "link" : undefined}
524
+ accessibilityLabel={accessibilityLabel ?? label}
525
+ onPress={open}
526
+ disabled={!open}
527
+ style={{ flexDirection: "row", alignItems: "center", gap: 8, minHeight: 44, maxWidth: 240, paddingHorizontal: 12, borderRadius: 12, backgroundColor: mine ? colors.fill : colors.surface }}
528
+ >
529
+ <NativeIcon name="file" size={18} color={colors.secondaryLabel} />
530
+ <NativeText numberOfLines={1} style={{ flexShrink: 1, color: colors.label, fontSize: 15, lineHeight: 20 }}>
531
+ {label}
532
+ </NativeText>
533
+ </Pressable>
534
+ );
535
+ }
536
+
537
+ function DefaultAttachment(attachment: ThreadPageSlotMap["attachment"]) {
538
+ return attachment.kind === "file" ? <FileAttachment {...attachment} /> : <ImageAttachment {...attachment} />;
539
+ }
540
+
541
+ function ImageAttachment({ id, uri, width, height, accessibilityLabel, onPress, testID }: ThreadPageSlotMap["attachment"]) {
481
542
  const { image: ExpoImage } = useGenesisModules();
482
543
  const ratio = width && height ? width / height : 0.6;
483
544
  const w = 140;
@@ -32,6 +32,8 @@
32
32
  * | `icons` (a lucide icon set) | NativeIcon on Android, web, and as the SF Symbol fallback | a blank space of the icon's size |
33
33
  * | `datePicker` (@expo/ui) | NativeDatePicker, NativeTimePicker | @react-native-community/datetimepicker |
34
34
  * | `keyboardAvoidingView` (react-native-keyboard-controller's `KeyboardAvoidingView`) | ThreadPage: the composer follows the keyboard frame by frame (`translate-with-padding`) | React Native `KeyboardAvoidingView` |
35
+ * | `haptics` (expo-haptics) | useHaptics, usePressFeedback, NativeComposerBar (send) | no haptics |
36
+ * | `swipeable` (react-native-gesture-handler's `ReanimatedSwipeable`) | NativeSwipeRow, InboxPage: the swipe to a row's actions | the actions on long press and as accessibility actions |
35
37
  * | `navigation` (React Navigation's theming: from `expo-router` in an Expo Router app, which bundles its own copy; `@react-navigation/native` otherwise) | GenesisNativeApp: headers and tab bars in the brand's light and dark colors | React Navigation's default (light) theme |
36
38
  *
37
39
  * The props below are written structurally (no import of the optional
@@ -40,6 +42,7 @@
40
42
  * @stability Beta
41
43
  */
42
44
  import { createContext, createElement, useContext, useMemo, type ComponentType, type ReactNode } from "react";
45
+ import type { GenesisHapticsModule } from "./hooks/use-haptics";
43
46
  import type { ColorValue } from "react-native";
44
47
  import type { NativeIconName } from "./icon-names";
45
48
 
@@ -192,8 +195,25 @@ export interface GenesisModules {
192
195
  navigation?: GenesisNavigationModule;
193
196
  /** react-native-keyboard-controller's `KeyboardAvoidingView` (it takes `behavior: "translate-with-padding"`). */
194
197
  keyboardAvoidingView?: KeyboardAvoidingLike;
198
+ /** expo-haptics (`import * as Haptics from "expo-haptics"`): `useHaptics`, `usePressFeedback`, and the primitives that answer a touch. Without it, no haptics. */
199
+ haptics?: GenesisHapticsModule;
200
+ /** react-native-gesture-handler's `ReanimatedSwipeable`: NativeSwipeRow and InboxPage's rows. Without it, no swipe; the actions stay on long press. */
201
+ swipeable?: GenesisSwipeableComponent;
195
202
  }
196
203
 
204
+ /** The props NativeSwipeRow passes; `ReanimatedSwipeable` takes them, and its ref has `close()`. */
205
+ export type GenesisSwipeableComponent = ComponentType<{
206
+ ref?: unknown;
207
+ testID?: string;
208
+ friction?: number;
209
+ overshootLeft?: boolean;
210
+ overshootRight?: boolean;
211
+ onSwipeableWillOpen?: () => void;
212
+ renderLeftActions?: () => ReactNode;
213
+ renderRightActions?: () => ReactNode;
214
+ children?: ReactNode;
215
+ }>;
216
+
197
217
  const EMPTY: GenesisModules = Object.freeze({});
198
218
  const GenesisModulesContext = createContext<GenesisModules>(EMPTY);
199
219