@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
@@ -1,9 +1,14 @@
1
1
  /**
2
2
  * Progress — determinate horizontal progress indicator.
3
3
  *
4
+ * The fill is `bg-primary` and the track `bg-muted`. `indicatorColor` and
5
+ * `trackColor` take a colour value (a theme role from `useThemeRoles`, a
6
+ * brand's tint) for a package or screen that styles without NativeWind
7
+ * classes; they win over the class props.
8
+ *
4
9
  * @stability Stable
5
10
  */
6
- import { View } from "react-native";
11
+ import { View, type ColorValue, type ViewStyle } from "react-native";
7
12
  import { cn } from "../utils";
8
13
 
9
14
  export interface NativeProgressProps {
@@ -14,6 +19,14 @@ export interface NativeProgressProps {
14
19
  trackClassName?: string;
15
20
  /** Indicator color class. Defaults to bg-primary */
16
21
  indicatorClassName?: string;
22
+ /** The fill's colour as a value (a theme role, a brand tint); wins over `indicatorClassName`. */
23
+ indicatorColor?: ColorValue;
24
+ /** The track's colour as a value; wins over `trackClassName`. */
25
+ trackColor?: ColorValue;
26
+ /** Track style, for colors from a theme object rather than classes. Wins over the classes. */
27
+ style?: ViewStyle;
28
+ /** Indicator style, for colors from a theme object rather than classes. Wins over the classes. */
29
+ indicatorStyle?: ViewStyle;
17
30
  testID?: string;
18
31
  }
19
32
 
@@ -22,6 +35,10 @@ function NativeProgress({
22
35
  value = 0,
23
36
  trackClassName,
24
37
  indicatorClassName,
38
+ indicatorColor,
39
+ trackColor,
40
+ style,
41
+ indicatorStyle,
25
42
  ...props
26
43
  }: NativeProgressProps) {
27
44
  const safeValue = Number.isFinite(value) ? value : 0;
@@ -38,10 +55,15 @@ function NativeProgress({
38
55
  accessibilityLabel={`${clampedValue}% complete`}
39
56
  accessibilityValue={{ min: 0, max: 100, now: clampedValue }}
40
57
  {...props}
58
+ style={trackColor === undefined ? style : { ...style, backgroundColor: trackColor }}
41
59
  >
42
60
  <View
43
61
  className={cn("h-full rounded-full bg-primary", indicatorClassName)}
44
- style={{ width: `${clampedValue}%` }}
62
+ style={{
63
+ ...indicatorStyle,
64
+ width: `${clampedValue}%`,
65
+ ...(indicatorColor === undefined ? {} : { backgroundColor: indicatorColor }),
66
+ }}
45
67
  />
46
68
  </View>
47
69
  );
@@ -5,9 +5,11 @@
5
5
  * Without `onChange` (or with `readOnly`) it is one image for screen readers
6
6
  * ("3 of 5 stars"). With it, each star is a radio in a radiogroup, so
7
7
  * VoiceOver and TalkBack read the chosen one and the rest as options;
8
- * pressing the current value clears the rating (`nextRating`). Filled stars
9
- * draw in the `warning` role (what `text-warning` resolves to), empty ones in
10
- * the muted foreground. Same props as the web `Rating`.
8
+ * pressing the current value clears the rating (`nextRating`) unless
9
+ * `clearable` is false. Filled stars draw in the `warning` role (what
10
+ * `text-warning` resolves to), or the brand's tint with `tone="primary"`;
11
+ * empty ones in the muted foreground. `size="touch"` gives each star a 44pt
12
+ * target, for a form. Same props as the web `Rating`.
11
13
  *
12
14
  * @stability Beta
13
15
  */
@@ -17,7 +19,8 @@ import { cn } from "../utils";
17
19
  import { useGenesisModules } from "../native-modules";
18
20
  import { NativeIcon } from "./icon";
19
21
 
20
- export type NativeRatingSize = "sm" | "md" | "lg";
22
+ export type NativeRatingSize = "sm" | "md" | "lg" | "touch";
23
+ export type NativeRatingTone = "warning" | "primary";
21
24
 
22
25
  export interface NativeRatingProps {
23
26
  /** The score, 0..`max`. Fractions round to the nearest star. */
@@ -28,8 +31,14 @@ export interface NativeRatingProps {
28
31
  onChange?: (value: number) => void;
29
32
  /** Read-only even with `onChange`. */
30
33
  readOnly?: boolean;
31
- /** Default "md". */
34
+ /** Default "md". `touch` is a 44pt target around a large star, for a form. */
32
35
  size?: NativeRatingSize;
36
+ /** The chosen stars' colour: the `warning` role (default) or the brand's tint. */
37
+ tone?: NativeRatingTone;
38
+ /** Pressing the chosen star clears it to 0. Default true; false for a required answer. */
39
+ clearable?: boolean;
40
+ /** The stars can't be pressed, and read as disabled. */
41
+ disabled?: boolean;
33
42
  /** The control's accessible name ("Service rating"): read-only reads "Service rating: 3 of 5 stars". */
34
43
  label?: string;
35
44
  /** The accessibility text for a value, in place of "N of M stars" (read-only label, each radio's label and value). */
@@ -38,7 +47,7 @@ export interface NativeRatingProps {
38
47
  testID?: string;
39
48
  }
40
49
 
41
- const STAR_SIZE: Record<NativeRatingSize, number> = { sm: 14, md: 20, lg: 28 };
50
+ const STAR_SIZE: Record<NativeRatingSize, number> = { sm: 14, md: 20, lg: 28, touch: 28 };
42
51
 
43
52
  /** The value after pressing `star`: that star, or 0 when it is the current value (a press clears). */
44
53
  export function nextRating(value: number, star: number): number {
@@ -50,14 +59,15 @@ export function nextRating(value: number, star: number): number {
50
59
  * filled star is solid (`fill`) and the empty one an outline, so the state
51
60
  * never rests on colour alone.
52
61
  */
53
- function Star({ on, size, testID }: { on: boolean; size: number; testID?: string }) {
62
+ function Star({ on, size, tone, testID }: { on: boolean; size: number; tone: NativeRatingTone; testID?: string }) {
54
63
  const roles = useThemeRoles();
55
64
  const { symbol, icons } = useGenesisModules();
56
- const color = on ? roles.warning : roles.secondaryLabel;
65
+ const onColor = tone === "primary" ? roles.tint : roles.warning;
66
+ const color = on ? onColor : roles.secondaryLabel;
57
67
  const Lucide = icons?.star;
58
68
  if (!(Platform.OS === "ios" && symbol) && Lucide) {
59
69
  return (
60
- <Lucide size={size} color={color} fill={on ? roles.warning : "none"} strokeWidth={on ? 2 : 1.5} testID={testID} />
70
+ <Lucide size={size} color={color} fill={on ? onColor : "none"} strokeWidth={on ? 2 : 1.5} testID={testID} />
61
71
  );
62
72
  }
63
73
  return <NativeIcon name="star" size={size} weight={on ? "bold" : "regular"} color={color} testID={testID} />;
@@ -69,6 +79,9 @@ export function NativeRating({
69
79
  onChange,
70
80
  readOnly = false,
71
81
  size = "md",
82
+ tone = "warning",
83
+ clearable = true,
84
+ disabled = false,
72
85
  label,
73
86
  getLabel,
74
87
  className,
@@ -92,7 +105,7 @@ export function NativeRating({
92
105
  className={cn("flex-row items-center gap-0.5", className)}
93
106
  >
94
107
  {stars.map((n) => (
95
- <Star key={n} on={n <= filled} size={px} testID={`${testID}-star-${n}`} />
108
+ <Star key={n} on={n <= filled} size={px} tone={tone} testID={`${testID}-star-${n}`} />
96
109
  ))}
97
110
  </View>
98
111
  );
@@ -104,7 +117,8 @@ export function NativeRating({
104
117
  accessibilityRole="radiogroup"
105
118
  accessibilityLabel={label ?? "Rating"}
106
119
  accessibilityValue={{ min: 0, max: count, now: filled, text: summary }}
107
- className={cn("flex-row items-center gap-0.5", className)}
120
+ accessibilityState={{ disabled }}
121
+ className={cn("flex-row items-center", size === "touch" ? "flex-wrap gap-1" : "gap-0.5", disabled && "opacity-50", className)}
108
122
  >
109
123
  {stars.map((n) => {
110
124
  const selected = n === filled;
@@ -114,12 +128,17 @@ export function NativeRating({
114
128
  testID={`${testID}-star-${n}`}
115
129
  accessibilityRole="radio"
116
130
  accessibilityLabel={starsText(n)}
117
- accessibilityState={{ selected, checked: selected }}
118
- onPress={() => onChange?.(nextRating(filled, n))}
119
- hitSlop={4}
120
- className="p-0.5"
131
+ accessibilityState={{ selected, checked: selected, disabled }}
132
+ disabled={disabled}
133
+ onPress={() => {
134
+ const next = nextRating(filled, n);
135
+ if (next === 0 && !clearable) return;
136
+ onChange?.(next);
137
+ }}
138
+ hitSlop={size === "touch" ? 0 : 4}
139
+ className={size === "touch" ? "h-11 w-11 items-center justify-center rounded-md" : "p-0.5"}
121
140
  >
122
- <Star on={n <= filled} size={px} />
141
+ <Star on={n <= filled} size={px} tone={tone} />
123
142
  </Pressable>
124
143
  );
125
144
  })}
@@ -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
  }