@marktiderman/genesis-ui-native 3.7.0 → 3.9.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 (87) hide show
  1. package/README.md +4 -1
  2. package/dist/{chunk-KH2RVAI5.js → chunk-DHONOH6K.js} +24 -210
  3. package/dist/chunk-DHONOH6K.js.map +1 -0
  4. package/dist/{chunk-O4BMDV7I.js → chunk-FGIIBON3.js} +333 -21
  5. package/dist/chunk-FGIIBON3.js.map +1 -0
  6. package/dist/{chunk-YWDDDYDI.js → chunk-FOJJB6AB.js} +2 -2
  7. package/dist/{chunk-YWDDDYDI.js.map → chunk-FOJJB6AB.js.map} +1 -1
  8. package/dist/{chunk-IXC3LO2K.js → chunk-JZ7RAGDQ.js} +44 -36
  9. package/dist/chunk-JZ7RAGDQ.js.map +1 -0
  10. package/dist/{chunk-RTYO24SC.js → chunk-PWS2HLDE.js} +63 -31
  11. package/dist/chunk-PWS2HLDE.js.map +1 -0
  12. package/dist/{chunk-3KFUS7O6.js → chunk-PWYMRUAK.js} +43 -30
  13. package/dist/chunk-PWYMRUAK.js.map +1 -0
  14. package/dist/{chunk-GBNIBHSU.js → chunk-T7FEVT62.js} +53 -12
  15. package/dist/chunk-T7FEVT62.js.map +1 -0
  16. package/dist/{chunk-7NDKIIOT.js → chunk-UZCJDMGE.js} +353 -19
  17. package/dist/chunk-UZCJDMGE.js.map +1 -0
  18. package/dist/components/index.d.ts +229 -23
  19. package/dist/components/index.js +5 -6
  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 +7 -3
  24. package/dist/hooks/index.js +2 -3
  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 -9
  31. package/dist/layouts/index.d.ts +12 -3
  32. package/dist/layouts/index.js +5 -6
  33. package/dist/{native-modules-DEJJQhDx.d.ts → native-modules-CeAaO2Dh.d.ts} +26 -2
  34. package/package.json +51 -3
  35. package/src/__tests__/native-modules-lists.test.tsx +1 -0
  36. package/src/components/__tests__/bulk-bar.test.tsx +36 -0
  37. package/src/components/__tests__/button-haptic.test.tsx +22 -0
  38. package/src/components/__tests__/composer-bar.test.tsx +116 -1
  39. package/src/components/__tests__/gallery-grid.test.tsx +2 -2
  40. package/src/components/__tests__/library-round-5.test.tsx +121 -0
  41. package/src/components/__tests__/share-sheet.test.tsx +47 -0
  42. package/src/components/__tests__/swipe-row-context-menu.test.tsx +215 -0
  43. package/src/components/__tests__/tab-bar.test.tsx +43 -0
  44. package/src/components/__tests__/thread-list.test.tsx +137 -0
  45. package/src/components/__tests__/tier-badge.test.tsx +57 -0
  46. package/src/components/__tests__/whats-new-sheet.test.tsx +29 -0
  47. package/src/components/bulk-bar.tsx +91 -0
  48. package/src/components/button.tsx +74 -35
  49. package/src/components/choice-card.tsx +104 -0
  50. package/src/components/composer-bar.tsx +20 -19
  51. package/src/components/context-menu.tsx +101 -0
  52. package/src/components/gallery-grid.tsx +10 -4
  53. package/src/components/index.ts +18 -1
  54. package/src/components/inline-alert.tsx +36 -1
  55. package/src/components/input.tsx +3 -0
  56. package/src/components/progress.tsx +24 -2
  57. package/src/components/rating.tsx +35 -16
  58. package/src/components/share-sheet.tsx +127 -0
  59. package/src/components/sheet.tsx +9 -1
  60. package/src/components/swipe-row.tsx +74 -0
  61. package/src/components/tab-bar.tsx +133 -0
  62. package/src/components/tabs.tsx +2 -0
  63. package/src/components/text.tsx +3 -0
  64. package/src/components/textarea.tsx +3 -0
  65. package/src/components/thread-list.tsx +48 -23
  66. package/src/components/tier-badge.tsx +74 -0
  67. package/src/components/whats-new-sheet.tsx +89 -0
  68. package/src/data/resource-view/NativeRecordView.tsx +3 -8
  69. package/src/data/resource-view/use-native-resource-view.ts +2 -2
  70. package/src/hooks/index.ts +1 -1
  71. package/src/hooks/use-theme-roles.ts +3 -0
  72. package/src/icon-names.ts +12 -2
  73. package/src/icons/lucide.ts +27 -7
  74. package/src/layouts/__tests__/inbox-page.test.tsx +26 -7
  75. package/src/layouts/__tests__/thread-page.test.tsx +89 -2
  76. package/src/layouts/inbox-page.tsx +28 -12
  77. package/src/layouts/thread-page.tsx +69 -8
  78. package/src/native-modules.tsx +16 -0
  79. package/dist/chunk-3KFUS7O6.js.map +0 -1
  80. package/dist/chunk-7NDKIIOT.js.map +0 -1
  81. package/dist/chunk-CAI7LGN6.js +0 -39
  82. package/dist/chunk-CAI7LGN6.js.map +0 -1
  83. package/dist/chunk-GBNIBHSU.js.map +0 -1
  84. package/dist/chunk-IXC3LO2K.js.map +0 -1
  85. package/dist/chunk-KH2RVAI5.js.map +0 -1
  86. package/dist/chunk-O4BMDV7I.js.map +0 -1
  87. package/dist/chunk-RTYO24SC.js.map +0 -1
@@ -0,0 +1,127 @@
1
+ /**
2
+ * ShareSheet — sharing one published page (a form, a course, a worksheet) from the phone: its
3
+ * link with Copy and the system share sheet, and a QR code to show someone across the desk.
4
+ * The twin of genesis-ui's `ShareDialog`: the host passes the link and how to draw a QR code
5
+ * (`renderQr`, the same approach as the web; Genesis bundles no QR library), so nothing native
6
+ * is added. Copy goes through `onCopy` (pass expo-clipboard's `setStringAsync`); without it,
7
+ * Copy opens the system share sheet, which has Copy.
8
+ *
9
+ * @stability Beta
10
+ */
11
+ import { useEffect, useState, type ReactNode } from "react";
12
+ import { Platform, Share, Text, View } from "react-native";
13
+ import { NativeButton, buttonTextVariants } from "./button";
14
+ import { NativeIcon } from "./icon";
15
+ import { NativeSheet } from "./sheet";
16
+ import { NativeText } from "./text";
17
+
18
+ export interface NativeShareSheetProps {
19
+ open: boolean;
20
+ onOpenChange: (open: boolean) => void;
21
+ /** What it is, in the default title and buttons: "page" (default), "form", "course". */
22
+ noun?: string;
23
+ /** Default "Share your {noun}". */
24
+ title?: string;
25
+ /** Default "Anyone with the link can open it." */
26
+ description?: ReactNode;
27
+ /** The public link; null while it is still loading. */
28
+ url: string | null;
29
+ /** Its name, sent with the link to the system share sheet. */
30
+ name?: string;
31
+ /** Draws a QR code for a link. None hides the QR code. */
32
+ renderQr?: (url: string) => ReactNode;
33
+ /** Copies text (expo-clipboard's `setStringAsync`). Default: the system share sheet. */
34
+ onCopy?: (text: string) => void | Promise<void>;
35
+ testID?: string;
36
+ }
37
+
38
+ function IconButton({ icon, label, onPress, variant, testID }: { icon: "copy" | "share"; label: string; onPress: () => void; variant: "default" | "outline"; testID: string }) {
39
+ return (
40
+ <NativeButton variant={variant} onPress={onPress} testID={testID} accessibilityLabel={label} className="flex-1">
41
+ <NativeIcon name={icon} size={16} />
42
+ <Text className={buttonTextVariants({ variant, size: "md" })}>{label}</Text>
43
+ </NativeButton>
44
+ );
45
+ }
46
+
47
+ export function NativeShareSheet({
48
+ open,
49
+ onOpenChange,
50
+ noun = "page",
51
+ title = `Share your ${noun}`,
52
+ description = "Anyone with the link can open it.",
53
+ url,
54
+ name,
55
+ renderQr,
56
+ onCopy,
57
+ testID = "native-share-sheet",
58
+ }: NativeShareSheetProps) {
59
+ const [copied, setCopied] = useState(false);
60
+ // A new link hasn't been copied yet.
61
+ useEffect(() => setCopied(false), [url]);
62
+ // iOS sends `message` and `url` both (Messages and Mail would show the link twice) and
63
+ // Android reads only `message`: send the link once, in the field each platform uses.
64
+ const share = (link: string) => {
65
+ const content = Platform.OS === "ios" ? { url: link } : { message: link };
66
+ void Share.share(name ? { ...content, title: name } : content).catch(() => undefined);
67
+ };
68
+ const copy = (link: string) => {
69
+ if (!onCopy) return share(link);
70
+ // onCopy runs inside the executor, so a synchronous throw also falls back to the share sheet.
71
+ void new Promise<void>((resolve) => resolve(onCopy(link))).then(
72
+ () => setCopied(true),
73
+ () => share(link),
74
+ );
75
+ };
76
+ return (
77
+ <NativeSheet
78
+ open={open}
79
+ onOpenChange={(next) => {
80
+ if (!next) setCopied(false);
81
+ onOpenChange(next);
82
+ }}
83
+ fitContent
84
+ testID={testID}
85
+ >
86
+ <View className="gap-4 p-6">
87
+ <View className="gap-1">
88
+ <NativeText preset="h3" accessibilityRole="header">
89
+ {title}
90
+ </NativeText>
91
+ {typeof description === "string" ? (
92
+ <NativeText preset="body-sm" className="text-muted-foreground">
93
+ {description}
94
+ </NativeText>
95
+ ) : (
96
+ description
97
+ )}
98
+ </View>
99
+ {!url ? (
100
+ <NativeText preset="body-sm" className="text-muted-foreground" testID={`${testID}-loading`}>
101
+ Loading the link…
102
+ </NativeText>
103
+ ) : (
104
+ <>
105
+ {renderQr ? (
106
+ <View className="items-center gap-2" testID={`${testID}-qr`}>
107
+ <View className="w-56 max-w-full">{renderQr(url)}</View>
108
+ <NativeText preset="caption" className="text-center text-muted-foreground">
109
+ Scan with a phone's camera to open the {noun}.
110
+ </NativeText>
111
+ </View>
112
+ ) : null}
113
+ <View className="rounded-md border border-border bg-muted px-3 py-2">
114
+ <Text selectable numberOfLines={2} className="text-sm text-foreground" testID={`${testID}-url`}>
115
+ {url}
116
+ </Text>
117
+ </View>
118
+ <View className="flex-row gap-2">
119
+ <IconButton icon="copy" label={copied ? "Copied" : "Copy link"} onPress={() => copy(url)} variant="outline" testID={`${testID}-copy`} />
120
+ <IconButton icon="share" label="Share" onPress={() => share(url)} variant="default" testID={`${testID}-share`} />
121
+ </View>
122
+ </>
123
+ )}
124
+ </View>
125
+ </NativeSheet>
126
+ );
127
+ }
@@ -61,6 +61,8 @@ export interface NativeSheetProps {
61
61
  * `snapPoints` is ignored. Default false.
62
62
  */
63
63
  fitContent?: boolean;
64
+ /** The sheet has finished going, where the platform says so (iOS's modal, the library): another modal can present now. */
65
+ onDismissed?: () => void;
64
66
  children: ReactNode;
65
67
  testID?: string;
66
68
  }
@@ -167,6 +169,7 @@ function LibrarySheet({
167
169
  initialSnapIndex = 0,
168
170
  disableBackdropDismiss = false,
169
171
  fitContent = false,
172
+ onDismissed,
170
173
  testID,
171
174
  children,
172
175
  }: NativeSheetProps & { library: NativeSheetLibrary }) {
@@ -176,6 +179,8 @@ function LibrarySheet({
176
179
  const wanted = useRef(open);
177
180
  const onOpenChangeRef = useRef(onOpenChange);
178
181
  onOpenChangeRef.current = onOpenChange;
182
+ const onDismissedRef = useRef(onDismissed);
183
+ onDismissedRef.current = onDismissed;
179
184
 
180
185
  // Child refs are attached before this runs, so the first render presents too.
181
186
  useEffect(() => {
@@ -193,6 +198,7 @@ function LibrarySheet({
193
198
  wanted.current = false;
194
199
  onOpenChangeRef.current(false);
195
200
  }
201
+ onDismissedRef.current?.();
196
202
  }, []);
197
203
  const backdrop = useCallback(
198
204
  (p: Record<string, unknown>) => (
@@ -255,7 +261,7 @@ function useReduceMotionAnswer(): boolean | null {
255
261
  * and a panel at the bottom, drawn under the system bars. `fitContent` on iOS: the same bottom
256
262
  * panel, kept above the keyboard.
257
263
  */
258
- function ModalSheet({ open, onOpenChange, disableBackdropDismiss = false, fitContent = false, testID, children }: NativeSheetProps) {
264
+ function ModalSheet({ open, onOpenChange, disableBackdropDismiss = false, fitContent = false, onDismissed, testID, children }: NativeSheetProps) {
259
265
  const reducedMotion = useReduceMotionAnswer();
260
266
  const roles = useThemeRoles();
261
267
  const requestClose = () => {
@@ -275,6 +281,7 @@ function ModalSheet({ open, onOpenChange, disableBackdropDismiss = false, fitCon
275
281
  allowSwipeDismissal={!disableBackdropDismiss}
276
282
  backdropColor={roles.background}
277
283
  onRequestClose={requestClose}
284
+ onDismiss={onDismissed}
278
285
  >
279
286
  <SafeAreaProvider>
280
287
  <SheetBody
@@ -297,6 +304,7 @@ function ModalSheet({ open, onOpenChange, disableBackdropDismiss = false, fitCon
297
304
  statusBarTranslucent
298
305
  navigationBarTranslucent
299
306
  onRequestClose={requestClose}
307
+ onDismiss={onDismissed}
300
308
  >
301
309
  <SafeAreaProvider>
302
310
  <KeyboardPanel ios={ios}>
@@ -0,0 +1,74 @@
1
+ /**
2
+ * NativeSwipeRow — a row with actions behind a swipe: Archive to one side,
3
+ * Delete to the other (each action's `side`, trailing by default).
4
+ *
5
+ * The gesture is the app's `GenesisModules.swipeable` (react-native-gesture-
6
+ * handler's `ReanimatedSwipeable`, an optional peer). Without it, the row draws
7
+ * as it is, so an action must always be reachable another way too: `InboxPage`
8
+ * puts them in the accessibility actions and on long press. The buttons behind
9
+ * the row are hidden from VoiceOver for that reason (a screen reader doesn't
10
+ * swipe), and a swipe that opens taps `medium` through `useHaptics`.
11
+ *
12
+ * @stability Beta
13
+ */
14
+ import { useRef, type ReactNode } from "react";
15
+ import { Pressable, View } from "react-native";
16
+ import type { InboxSwipeAction } from "@marktiderman/genesis-core/conversation";
17
+ import { useHaptics } from "../hooks/use-haptics";
18
+ import { useThemeRoles } from "../hooks/use-theme-roles";
19
+ import { useGenesisModules } from "../native-modules";
20
+ import { NativeText } from "./text";
21
+
22
+ export interface NativeSwipeRowProps {
23
+ actions: readonly InboxSwipeAction[];
24
+ children?: ReactNode;
25
+ testID?: string;
26
+ }
27
+
28
+ /** A button's width behind the row: room for a short label. */
29
+ const ACTION_WIDTH = 80;
30
+
31
+ export function NativeSwipeRow({ actions, children, testID = "swipe-row" }: NativeSwipeRowProps) {
32
+ const { swipeable: Swipeable } = useGenesisModules();
33
+ const colors = useThemeRoles();
34
+ const play = useHaptics();
35
+ const swipe = useRef<{ close?: () => void } | null>(null);
36
+ if (!Swipeable || actions.length === 0) return <>{children}</>;
37
+
38
+ const leading = actions.filter((a) => a.side === "leading");
39
+ const trailing = actions.filter((a) => a.side !== "leading");
40
+ const group = (list: readonly InboxSwipeAction[]) => () => (
41
+ <View accessibilityElementsHidden importantForAccessibility="no-hide-descendants" style={{ flexDirection: "row" }}>
42
+ {list.map((action) => (
43
+ <Pressable
44
+ key={action.id}
45
+ testID={`${testID}-action-${action.id}`}
46
+ onPress={() => {
47
+ swipe.current?.close?.();
48
+ action.onPress();
49
+ }}
50
+ style={{ width: ACTION_WIDTH, alignItems: "center", justifyContent: "center", backgroundColor: action.destructive ? colors.destructive : colors.tint }}
51
+ >
52
+ <NativeText className={action.destructive ? "text-destructive-foreground" : "text-primary-foreground"} preset="label">
53
+ {action.label}
54
+ </NativeText>
55
+ </Pressable>
56
+ ))}
57
+ </View>
58
+ );
59
+
60
+ return (
61
+ <Swipeable
62
+ ref={swipe}
63
+ testID={testID}
64
+ friction={2}
65
+ overshootLeft={false}
66
+ overshootRight={false}
67
+ onSwipeableWillOpen={() => play("medium")}
68
+ renderLeftActions={leading.length ? group(leading) : undefined}
69
+ renderRightActions={trailing.length ? group(trailing) : undefined}
70
+ >
71
+ {children}
72
+ </Swipeable>
73
+ );
74
+ }
@@ -0,0 +1,133 @@
1
+ /**
2
+ * TabBar — a bottom tab bar with any number of tabs.
3
+ *
4
+ * Built on NativeTabs (each slot is a NativeTabsTrigger). Up to `max` (5) tabs show; past that,
5
+ * the first four show and the fifth slot is "More", which opens a NativeSheet with the rest.
6
+ * The twin of genesis-ui's `TabBar` (the same props, and the same split as AppShell's phone
7
+ * bottom nav). For an Expo Router app's own tabs, the router's tab bar comes first; this is for
8
+ * a bar the screen owns (tabs that aren't routes) or a router `tabBar` render.
9
+ *
10
+ * @stability Beta
11
+ */
12
+ import { useState, type ReactNode } from "react";
13
+ import { Pressable, Text, View } from "react-native";
14
+ import { splitTabBarItems, TAB_BAR_MAX } from "@marktiderman/genesis-core/navigation";
15
+ import { cn } from "../utils";
16
+ import { NativeBadge } from "./badge";
17
+ import { NativeIcon } from "./icon";
18
+ import { NativeSheet } from "./sheet";
19
+ import { NativeTabs, NativeTabsTrigger } from "./tabs";
20
+ import { NativeText } from "./text";
21
+
22
+ /** One tab in a `NativeTabBar`. */
23
+ export interface NativeTabBarItem {
24
+ key: string;
25
+ label: string;
26
+ /** Usually `<NativeIcon name="…" />`. */
27
+ icon: ReactNode;
28
+ /** A count or a short word beside the icon. */
29
+ badge?: ReactNode;
30
+ }
31
+
32
+ export interface NativeTabBarProps {
33
+ items: readonly NativeTabBarItem[];
34
+ /** The current tab's key. */
35
+ value: string;
36
+ onChange: (key: string) => void;
37
+ /** Slots before "More" takes the last. Default 5. */
38
+ max?: number;
39
+ /** "More" (the last slot's label and the sheet's title). */
40
+ moreLabel?: string;
41
+ className?: string;
42
+ testID?: string;
43
+ }
44
+
45
+ function Slot({ item, active }: { item: Pick<NativeTabBarItem, "label" | "icon" | "badge">; active: boolean }) {
46
+ return (
47
+ <View className="items-center gap-1">
48
+ <View>
49
+ {item.icon}
50
+ {item.badge != null ? (
51
+ <View className="absolute -right-3 -top-1.5 min-w-4 items-center rounded-full bg-primary px-1">
52
+ <Text className="text-[10px] font-semibold text-primary-foreground">{item.badge}</Text>
53
+ </View>
54
+ ) : null}
55
+ </View>
56
+ <Text numberOfLines={1} className={cn("text-xs font-medium", active ? "text-primary" : "text-muted-foreground")}>
57
+ {item.label}
58
+ </Text>
59
+ </View>
60
+ );
61
+ }
62
+
63
+ export function NativeTabBar({
64
+ items,
65
+ value,
66
+ onChange,
67
+ max = TAB_BAR_MAX,
68
+ moreLabel = "More",
69
+ className,
70
+ testID = "native-tab-bar",
71
+ }: NativeTabBarProps) {
72
+ const [moreOpen, setMoreOpen] = useState(false);
73
+ const { shown, more } = splitTabBarItems(items, max);
74
+ const moreActive = more.some((item) => item.key === value);
75
+ return (
76
+ <NativeTabs defaultValue={value} value={value} onValueChange={onChange} testID={testID}>
77
+ <View accessibilityRole="tablist" className={cn("flex-row border-t border-border bg-background pt-1", className)}>
78
+ {shown.map((item) => (
79
+ <NativeTabsTrigger
80
+ key={item.key}
81
+ value={item.key}
82
+ testID={`${testID}-${item.key}`}
83
+ accessibilityLabel={typeof item.badge === "string" || typeof item.badge === "number" ? `${item.label} (${item.badge})` : item.label}
84
+ className="min-h-[49px] rounded-none bg-transparent px-1 py-1 shadow-none"
85
+ >
86
+ <Slot item={item} active={item.key === value} />
87
+ </NativeTabsTrigger>
88
+ ))}
89
+ {more.length > 0 ? (
90
+ <Pressable
91
+ accessibilityRole="button"
92
+ accessibilityLabel={moreActive ? `${moreLabel}, current tab inside` : moreLabel}
93
+ accessibilityState={{ expanded: moreOpen, selected: moreActive }}
94
+ onPress={() => setMoreOpen(true)}
95
+ testID={`${testID}-more`}
96
+ className="min-h-[49px] flex-1 items-center justify-center px-1 py-1"
97
+ >
98
+ <Slot item={{ label: moreLabel, icon: <NativeIcon name="more" /> }} active={moreActive} />
99
+ </Pressable>
100
+ ) : null}
101
+ </View>
102
+ {more.length > 0 ? (
103
+ <NativeSheet open={moreOpen} onOpenChange={setMoreOpen} fitContent testID={`${testID}-more-sheet`}>
104
+ <View className="gap-1 p-4">
105
+ <NativeText preset="h4" accessibilityRole="header" className="mb-2">
106
+ {moreLabel}
107
+ </NativeText>
108
+ {more.map((item) => {
109
+ const active = item.key === value;
110
+ return (
111
+ <Pressable
112
+ key={item.key}
113
+ accessibilityRole="button"
114
+ accessibilityState={{ selected: active }}
115
+ onPress={() => {
116
+ setMoreOpen(false);
117
+ onChange(item.key);
118
+ }}
119
+ testID={`${testID}-${item.key}`}
120
+ className={cn("min-h-[44px] flex-row items-center gap-3 rounded-lg px-3", active && "bg-accent")}
121
+ >
122
+ {item.icon}
123
+ <Text className={cn("flex-1 text-base font-medium", active ? "text-primary" : "text-foreground")}>{item.label}</Text>
124
+ {item.badge != null ? <NativeBadge variant="secondary">{item.badge}</NativeBadge> : null}
125
+ </Pressable>
126
+ );
127
+ })}
128
+ </View>
129
+ </NativeSheet>
130
+ ) : null}
131
+ </NativeTabs>
132
+ );
133
+ }
@@ -75,6 +75,8 @@ export interface NativeTabsTriggerProps {
75
75
  value: string;
76
76
  children: React.ReactNode;
77
77
  disabled?: boolean;
78
+ /** Its accessible name, when its children don't say it all (a badge's count, say). */
79
+ accessibilityLabel?: string;
78
80
  testID?: string;
79
81
  }
80
82
 
@@ -4,6 +4,7 @@
4
4
  * @stability Stable
5
5
  */
6
6
  import { type VariantProps, cva } from "class-variance-authority";
7
+ import type { ComponentRef, Ref } from "react";
7
8
  import { Text as RNText, type TextProps } from "react-native";
8
9
  import { cn } from "../utils";
9
10
 
@@ -35,6 +36,8 @@ export interface NativeTextProps
35
36
  VariantProps<typeof textVariants> {
36
37
  /** NativeWind utility class string applied to the underlying Text. */
37
38
  className?: string;
39
+ /** The underlying Text (React 19 passes `ref` as a prop). */
40
+ ref?: Ref<ComponentRef<typeof RNText>> | undefined;
38
41
  }
39
42
 
40
43
  /**
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * @stability Stable
5
5
  */
6
+ import type { ComponentRef, Ref } from "react";
6
7
  import { Text, TextInput, type TextInputProps, View } from "react-native";
7
8
  import { nativeColors } from "@marktiderman/genesis-design-system/tokens/native";
8
9
  import { cn } from "../utils";
@@ -12,6 +13,8 @@ export interface NativeTextareaProps extends TextInputProps {
12
13
  inputClassName?: string;
13
14
  label?: string;
14
15
  error?: string;
16
+ /** The underlying TextInput (React 19 passes `ref` as a prop). */
17
+ ref?: Ref<ComponentRef<typeof TextInput>> | undefined;
15
18
  /** How many lines tall the field is, on both platforms (passed as `numberOfLines`). Default 4. */
16
19
  rows?: number;
17
20
  }
@@ -22,7 +22,12 @@
22
22
  * rendered. Going to a row waits for `loading`, loads until it's held,
23
23
  * scrolls to it (again after FlashList's own placement on open), highlights
24
24
  * it for two seconds and announces it. Reduce Motion scrolls without
25
- * animating.
25
+ * animating. The reader's touch wins: a drag during a jump ends the list's own
26
+ * scrolling and drops the jump, even one still loading, so nothing snaps back.
27
+ *
28
+ * A row is gone when, once `onLoadUntil` has settled, no row answers to its
29
+ * id. The list knows only its rows: a row that's drawn (a deleted message's
30
+ * tombstone) is there, and whatever isn't drawn isn't, whatever a cache holds.
26
31
  *
27
32
  * Promoted from genesis-chat's thread and its `useJumpToMessage` (G4); chat
28
33
  * moves onto it later.
@@ -123,7 +128,7 @@ export interface NativeThreadListProps<T> {
123
128
  onLoadUntil?: (id: string) => Promise<boolean>;
124
129
  /** What VoiceOver says on arriving at `jumpTo`. */
125
130
  jumpAnnouncement?: (row: T) => string;
126
- /** The row couldn't be found (deleted, out of reach). The list goes back to the newest row first. */
131
+ /** No row answers to this id once `onLoadUntil` has settled, or it failed. The list goes back to the newest row first. */
127
132
  onJumpFailed?: (id: string) => void;
128
133
  /** Whether the reader is at the bottom, as it changes (to show a "new messages" pill, say). */
129
134
  onAtBottomChange?: (atBottom: boolean) => void;
@@ -211,6 +216,8 @@ function NativeThreadListInner<T>(props: NativeThreadListProps<T>, ref: React.Fo
211
216
  const placed = useRef(!mode.followsByHand);
212
217
  // While the list scrolls itself, its own scroll events don't move "at the bottom".
213
218
  const settlingUntil = useRef(0);
219
+ // Bumped by each move the list starts and by the reader's touch: a queued try from an older move doesn't run.
220
+ const moveId = useRef(0);
214
221
  const timers = useRef(new Set<ReturnType<typeof setTimeout>>());
215
222
  const later = useCallback((fn: () => void, ms: number) => {
216
223
  const t = setTimeout(() => {
@@ -238,13 +245,14 @@ function NativeThreadListInner<T>(props: NativeThreadListProps<T>, ref: React.Fo
238
245
  const toBottom = useCallback(
239
246
  (animated: boolean) => {
240
247
  settlingUntil.current = Date.now() + SETTLING_MS;
248
+ const move = ++moveId.current;
241
249
  const go = (a: boolean) => listRef.current?.scrollToEnd?.({ animated: a && !reducedMotion });
242
250
  requestAnimationFrame(() => {
243
251
  go(animated);
244
252
  placed.current = true;
245
253
  });
246
254
  // Once more after a new row has its size (FlashList measures it after the first pass).
247
- if (animated) later(() => go(true), 180);
255
+ if (animated) later(() => move === moveId.current && go(true), 180);
248
256
  },
249
257
  [later, reducedMotion],
250
258
  );
@@ -264,7 +272,9 @@ function NativeThreadListInner<T>(props: NativeThreadListProps<T>, ref: React.Fo
264
272
  const jumpTries = useRef<{ id: string; tries: number } | null>(null);
265
273
  const scrollToRow = useCallback(
266
274
  (id: string) => {
275
+ const move = ++moveId.current;
267
276
  const scroll = () => {
277
+ if (move !== moveId.current) return;
268
278
  const at = indexOf(id);
269
279
  if (at < 0) return;
270
280
  // Each try moves the list again: its events don't count until this one settles.
@@ -280,10 +290,25 @@ function NativeThreadListInner<T>(props: NativeThreadListProps<T>, ref: React.Fo
280
290
  },
281
291
  [indexOf, later, reducedMotion],
282
292
  );
293
+ // A jump to a row already in view moves nothing, so no scroll event says where the list is: look
294
+ // once its own scrolling has settled (a second try extends that; mid-way it can still read as the
295
+ // bottom). No scroll event yet means the list hasn't moved from where it opens, the bottom.
296
+ const lookForBottom = useCallback(() => {
297
+ if (recheck.current) clearTimeout(recheck.current);
298
+ const look = () => {
299
+ const wait = settlingUntil.current - Date.now();
300
+ if (wait > 0) {
301
+ recheck.current = setTimeout(look, wait + 50);
302
+ return;
303
+ }
304
+ if (!metrics.current || threadNearBottom(metrics.current)) setAtBottom(true);
305
+ };
306
+ recheck.current = setTimeout(look, SETTLING_MS + 50);
307
+ }, [setAtBottom]);
283
308
  const has = useCallback((id: string) => indexOf(id) >= 0, [indexOf]);
284
309
  // `has` must change when the rows do, so the jump looks again.
285
310
  const hasNow = useMemo(() => (id: string) => has(id), [has, data]); // eslint-disable-line react-hooks/exhaustive-deps
286
- const { highlightedId, jumping } = useThreadJump({
311
+ const { highlightedId, jumping, cancel: cancelJump } = useThreadJump({
287
312
  target: jumpTo,
288
313
  has: hasNow,
289
314
  loading,
@@ -294,18 +319,7 @@ function NativeThreadListInner<T>(props: NativeThreadListProps<T>, ref: React.Fo
294
319
  placed.current = true;
295
320
  },
296
321
  onLanded: (id) => {
297
- // A jump to a row already at the bottom moves nothing, so no scroll event says so: look once it settles.
298
- // Not before the list's own scrolling has settled (a second try extends it): mid-way, it can still read as the bottom.
299
- if (recheck.current) clearTimeout(recheck.current);
300
- const look = () => {
301
- const wait = settlingUntil.current - Date.now();
302
- if (wait > 0) {
303
- recheck.current = setTimeout(look, wait + 50);
304
- return;
305
- }
306
- if (metrics.current && threadNearBottom(metrics.current)) setAtBottom(true);
307
- };
308
- recheck.current = setTimeout(look, SETTLING_MS + 50);
322
+ lookForBottom();
309
323
  const at = indexOf(id);
310
324
  const said = at >= 0 ? latest.current.jumpAnnouncement?.(latest.current.data[at]!) : undefined;
311
325
  if (said) announce(said);
@@ -350,25 +364,36 @@ function NativeThreadListInner<T>(props: NativeThreadListProps<T>, ref: React.Fo
350
364
  },
351
365
  [setAtBottom],
352
366
  );
353
- // The reader's touch ends the list's own scroll: from here their scrolling counts, even mid-jump.
354
- const onScrollBeginDrag = useCallback(() => {
367
+ // The reader's touch ends the list's own scroll: from here their scrolling counts, even mid-jump,
368
+ // the tries still queued don't snap them back, and a jump still loading doesn't land. Only a drag:
369
+ // a fling follows one, and onMomentumScrollBegin isn't promised to be the reader's alone (Android
370
+ // may report a programmatic smooth scroll), which would cancel the list's own retry. VoiceOver's
371
+ // three-finger scroll and a wheel send no drag, so those count once the settling window (400ms) ends.
372
+ const readerTookOver = useCallback(() => {
355
373
  settlingUntil.current = 0;
356
- }, []);
374
+ moveId.current += 1;
375
+ jumpTries.current = null;
376
+ cancelJump();
377
+ }, [cancelJump]);
357
378
  const onScrollToIndexFailed = useCallback(
358
379
  ({ index, averageItemLength }: { index: number; averageItemLength: number }) => {
380
+ const target = jumpTries.current;
381
+ // The reader took over.
382
+ if (!target) return;
359
383
  // FlatList hasn't measured that far up yet: get near it, then try again by id (three times at most).
360
384
  listRef.current?.scrollToOffset?.({ offset: Math.max(0, index * averageItemLength - 200), animated: false });
361
- const target = jumpTries.current;
362
- if (!target || target.tries >= 3) return;
385
+ if (target.tries >= 3) return;
363
386
  target.tries += 1;
364
387
  later(() => {
388
+ if (jumpTries.current !== target) return;
365
389
  const at = indexOf(target.id);
366
390
  if (at < 0) return;
367
391
  settlingUntil.current = Date.now() + SETTLING_MS;
368
392
  listRef.current?.scrollToIndex?.({ index: at, animated: !reducedMotion, viewPosition: 0.5 });
393
+ lookForBottom();
369
394
  }, 250);
370
395
  },
371
- [indexOf, later, reducedMotion],
396
+ [indexOf, later, lookForBottom, reducedMotion],
372
397
  );
373
398
  const follow = useCallback(() => {
374
399
  if (atBottom.current && !jumping) toBottom(false);
@@ -410,7 +435,7 @@ function NativeThreadListInner<T>(props: NativeThreadListProps<T>, ref: React.Fo
410
435
  maintainVisibleContentPosition={mode.maintainVisibleContentPosition}
411
436
  scrollEventThrottle={32}
412
437
  onScroll={onScroll}
413
- onScrollBeginDrag={onScrollBeginDrag}
438
+ onScrollBeginDrag={readerTookOver}
414
439
  onScrollToIndexFailed={onScrollToIndexFailed}
415
440
  {...(mode.followsByHand ? { onContentSizeChange: follow, onLayout: follow } : {})}
416
441
  ListHeaderComponent={listHeader}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * NativeTierBadge — a rank or tier label ("Gold", "Level 3"), with an optional
3
+ * leading icon and a tone from the brand's `accents`.
4
+ *
5
+ * `tone` names a brand accent, read from the nearest `GenesisThemeProvider`
6
+ * (`theme.tokens.accents`): the accent is the border and a 15% tint behind
7
+ * the text, and the text stays the foreground colour, so it reads at AA
8
+ * whatever the accent. Without a tone, a provider or such an accent, it is
9
+ * the secondary chip.
10
+ *
11
+ * @stability Beta
12
+ */
13
+ import { Text, View } from "react-native";
14
+ import { useOptionalTheme } from "@marktiderman/genesis-design-system";
15
+ import { cn } from "../utils";
16
+ import type { NativeIconName } from "../icon-names";
17
+ import { NativeIcon } from "./icon";
18
+
19
+ export interface NativeTierBadgeProps {
20
+ /** The rank or tier, as shown ("Gold"). */
21
+ label: string;
22
+ /** A key of the brand's `accents` (`"gold"`). Unset: neutral. */
23
+ tone?: string;
24
+ /** Leading icon, by Genesis icon name. */
25
+ icon?: NativeIconName;
26
+ /** `sm` for a list row, `md` (default) for a header. */
27
+ size?: "sm" | "md";
28
+ className?: string;
29
+ textClassName?: string;
30
+ /** What a screen reader says. Default: the label. */
31
+ accessibilityLabel?: string;
32
+ testID?: string;
33
+ }
34
+
35
+ /** `#rrggbb` + alpha (0–1) → `#rrggbbaa`; anything else is returned as is. */
36
+ function withAlpha(colour: string, alpha: number): string {
37
+ const full = /^#([0-9a-f]{3})$/i.test(colour) ? `#${[...colour.slice(1)].map((c) => c + c).join("")}` : colour;
38
+ // A colour that can't take an alpha here (rgb(), hsl(), a name) gets no tint, so the text stays readable.
39
+ if (!/^#[0-9a-f]{6}$/i.test(full)) return "transparent";
40
+ return `${full}${Math.round(alpha * 255).toString(16).padStart(2, "0")}`;
41
+ }
42
+
43
+ function NativeTierBadge({ label, tone, icon, size = "md", className, textClassName, accessibilityLabel, testID }: NativeTierBadgeProps) {
44
+ const accents = useOptionalTheme()?.tokens.accents;
45
+ const accent = tone ? accents?.[tone] : undefined;
46
+ return (
47
+ <View
48
+ className={cn(
49
+ "flex-row items-center self-start rounded-full border",
50
+ size === "sm" ? "gap-1 px-2 py-0.5" : "gap-1.5 px-2.5 py-1",
51
+ !accent && "border-transparent bg-secondary",
52
+ className
53
+ )}
54
+ style={accent ? { borderColor: accent, backgroundColor: withAlpha(accent, 0.15) } : undefined}
55
+ accessibilityRole="text"
56
+ accessibilityLabel={accessibilityLabel ?? label}
57
+ testID={testID}
58
+ >
59
+ {icon ? <NativeIcon name={icon} size={size === "sm" ? 12 : 14} {...(accent ? { color: accent } : {})} /> : null}
60
+ <Text
61
+ className={cn(
62
+ "font-semibold",
63
+ size === "sm" ? "text-xs" : "text-sm",
64
+ accent ? "text-foreground" : "text-secondary-foreground",
65
+ textClassName
66
+ )}
67
+ >
68
+ {label}
69
+ </Text>
70
+ </View>
71
+ );
72
+ }
73
+
74
+ export { NativeTierBadge };