@marktiderman/genesis-ui-native 2.2.0 → 2.3.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 (77) hide show
  1. package/README.md +82 -0
  2. package/dist/chunk-7PCWEY6R.js +27 -0
  3. package/dist/chunk-7PCWEY6R.js.map +1 -0
  4. package/dist/chunk-D5RKSPMH.js +24 -0
  5. package/dist/chunk-D5RKSPMH.js.map +1 -0
  6. package/dist/{chunk-5HRGIA6F.js → chunk-EFXCJ5AN.js} +76 -3
  7. package/dist/chunk-EFXCJ5AN.js.map +1 -0
  8. package/dist/{chunk-ULS7I6ZS.js → chunk-ERHGCWTY.js} +81 -12
  9. package/dist/chunk-ERHGCWTY.js.map +1 -0
  10. package/dist/{chunk-2WCXMJL6.js → chunk-FIITITXO.js} +67 -108
  11. package/dist/chunk-FIITITXO.js.map +1 -0
  12. package/dist/chunk-FZY2IXOX.js +1559 -0
  13. package/dist/chunk-FZY2IXOX.js.map +1 -0
  14. package/dist/{chunk-TXJT55JC.js → chunk-W7BK3ARU.js} +715 -293
  15. package/dist/chunk-W7BK3ARU.js.map +1 -0
  16. package/dist/components/index.d.ts +142 -17
  17. package/dist/components/index.js +6 -4
  18. package/dist/data/index.d.ts +7 -1
  19. package/dist/data/index.js +31 -6
  20. package/dist/data/index.js.map +1 -1
  21. package/dist/hooks/index.js +2 -1
  22. package/dist/icons/lucide.d.ts +7 -0
  23. package/dist/icons/lucide.js +47 -0
  24. package/dist/icons/lucide.js.map +1 -0
  25. package/dist/index.d.ts +3 -2
  26. package/dist/index.js +7 -6
  27. package/dist/layouts/index.d.ts +320 -4
  28. package/dist/layouts/index.js +3 -3
  29. package/dist/native-modules-BSVaEb3D.d.ts +206 -0
  30. package/package.json +34 -5
  31. package/src/__tests__/fake-modules.tsx +134 -0
  32. package/src/__tests__/native-modules-lists.test.tsx +70 -0
  33. package/src/__tests__/native-modules.test.tsx +631 -0
  34. package/src/components/__tests__/sheet.test.tsx +193 -0
  35. package/src/components/__tests__/toast.test.tsx +15 -0
  36. package/src/components/avatar.tsx +69 -16
  37. package/src/components/date-time-picker.tsx +128 -10
  38. package/src/components/drawer.tsx +158 -68
  39. package/src/components/dropdown-menu.tsx +7 -6
  40. package/src/components/glass-surface.tsx +150 -0
  41. package/src/components/icon.tsx +66 -0
  42. package/src/components/image.tsx +89 -0
  43. package/src/components/index.ts +33 -2
  44. package/src/components/list-item.tsx +29 -9
  45. package/src/components/popover.tsx +12 -9
  46. package/src/components/segmented-control.tsx +7 -1
  47. package/src/components/sheet.tsx +276 -133
  48. package/src/components/skeleton.tsx +75 -53
  49. package/src/components/toast.tsx +185 -87
  50. package/src/data/NativeResourcePage.tsx +48 -3
  51. package/src/data/__tests__/resource-page-offline.test.tsx +47 -0
  52. package/src/hooks/use-reduced-motion.ts +24 -10
  53. package/src/icon-names.ts +49 -0
  54. package/src/icons/lucide.ts +88 -0
  55. package/src/layouts/__tests__/google-sign-in.test.tsx +26 -0
  56. package/src/layouts/__tests__/inbox-page.test.tsx +155 -0
  57. package/src/layouts/__tests__/keyboard-scroll.test.tsx +42 -1
  58. package/src/layouts/__tests__/settings-page-native-look.test.tsx +142 -0
  59. package/src/layouts/__tests__/thread-page.test.tsx +128 -0
  60. package/src/layouts/auth-screen.tsx +6 -3
  61. package/src/layouts/google-sign-in.tsx +42 -0
  62. package/src/layouts/inbox-page.tsx +408 -0
  63. package/src/layouts/index.ts +37 -2
  64. package/src/layouts/keyboard.tsx +61 -9
  65. package/src/layouts/notifications-page.tsx +133 -16
  66. package/src/layouts/settings-page.tsx +117 -14
  67. package/src/layouts/settings-sub-page.tsx +9 -3
  68. package/src/layouts/thread-page.tsx +444 -0
  69. package/src/native-modules.tsx +186 -0
  70. package/dist/chunk-2WCXMJL6.js.map +0 -1
  71. package/dist/chunk-5HRGIA6F.js.map +0 -1
  72. package/dist/chunk-F2TGDKOO.js +0 -43
  73. package/dist/chunk-F2TGDKOO.js.map +0 -1
  74. package/dist/chunk-FZTUSM56.js +0 -935
  75. package/dist/chunk-FZTUSM56.js.map +0 -1
  76. package/dist/chunk-TXJT55JC.js.map +0 -1
  77. package/dist/chunk-ULS7I6ZS.js.map +0 -1
@@ -0,0 +1,193 @@
1
+ /**
2
+ * NativeSheet: the native Modal unless the app opts into @gorhom/bottom-sheet
3
+ * through NativeSheetProvider. Being installed is never enough: the library
4
+ * throws on open without its BottomSheetModalProvider.
5
+ */
6
+ /// <reference types="vite/client" />
7
+ import sheetSource from "../sheet.tsx?raw";
8
+ import { act, fireEvent, render, screen } from "@testing-library/react";
9
+ import { forwardRef, useImperativeHandle, type ReactNode } from "react";
10
+ import { afterEach, describe, expect, it, vi } from "vitest";
11
+ import { AccessibilityInfo, Platform } from "react-native";
12
+ import { NativeSheet, NativeSheetProvider, NativeSheetScrollView } from "../sheet";
13
+
14
+ const originalOS = Platform.OS;
15
+ afterEach(() => {
16
+ Platform.OS = originalOS;
17
+ vi.restoreAllMocks();
18
+ });
19
+
20
+ function fakeLibrary() {
21
+ const present = vi.fn();
22
+ const dismiss = vi.fn();
23
+ const providerMounted = vi.fn();
24
+ const modalProps = vi.fn();
25
+ const library = {
26
+ BottomSheetModalProvider: ({ children }: { children: ReactNode }) => {
27
+ providerMounted();
28
+ return <div data-testid="gorhom-provider">{children}</div>;
29
+ },
30
+ BottomSheetModal: forwardRef<unknown, { children: ReactNode; onDismiss: () => void }>(function Modal(props, ref) {
31
+ useImperativeHandle(ref, () => ({ present, dismiss }), []);
32
+ modalProps(props);
33
+ return (
34
+ <div data-testid="gorhom-modal" onClick={props.onDismiss}>
35
+ {props.children}
36
+ </div>
37
+ );
38
+ }),
39
+ BottomSheetView: ({ children, testID }: { children: ReactNode; testID?: string }) => <div data-testid={testID}>{children}</div>,
40
+ BottomSheetBackdrop: () => null,
41
+ BottomSheetScrollView: ({ children }: { children: ReactNode }) => <div data-testid="gorhom-scroll">{children}</div>,
42
+ };
43
+ return { library, present, dismiss, providerMounted, modalProps };
44
+ }
45
+
46
+ const sheet = (props: Partial<Parameters<typeof NativeSheet>[0]> = {}) => (
47
+ <NativeSheet open onOpenChange={() => {}} {...props}>
48
+ <span>body</span>
49
+ </NativeSheet>
50
+ );
51
+
52
+ describe("NativeSheet without a provider", () => {
53
+ it("never loads @gorhom/bottom-sheet itself", () => {
54
+ const source = sheetSource;
55
+ // Statements only: the docs and the error message name the module for the app to import.
56
+ expect(source).not.toMatch(/^\s*import\b[^\n]*["']@gorhom\/bottom-sheet["']|\b(require|import)\(\s*["']@gorhom\/bottom-sheet/m);
57
+ });
58
+
59
+ it("is the iOS page sheet that follows a swipe down", async () => {
60
+ Platform.OS = "ios";
61
+ render(sheet());
62
+ const modal = await screen.findByRole("dialog");
63
+ expect(modal.getAttribute("data-presentation-style")).toBe("pageSheet");
64
+ expect(modal.getAttribute("data-allow-swipe-dismissal")).toBe("true");
65
+ expect(modal.getAttribute("data-animation-type")).toBe("slide");
66
+ expect(modal.getAttribute("data-transparent")).toBeNull();
67
+ expect(screen.getByTestId("native-sheet").textContent).toBe("body");
68
+ });
69
+
70
+ it("closes when iOS asks (onRequestClose), and stays up with dismissal disabled", async () => {
71
+ Platform.OS = "ios";
72
+ const onOpenChange = vi.fn();
73
+ const { rerender } = render(sheet({ onOpenChange }));
74
+ fireEvent.keyDown(await screen.findByRole("dialog"), { key: "Escape" });
75
+ expect(onOpenChange).toHaveBeenCalledWith(false);
76
+
77
+ onOpenChange.mockClear();
78
+ rerender(sheet({ onOpenChange, disableBackdropDismiss: true }));
79
+ const modal = screen.getByRole("dialog");
80
+ expect(modal.getAttribute("data-allow-swipe-dismissal")).toBeNull();
81
+ fireEvent.keyDown(modal, { key: "Escape" });
82
+ expect(onOpenChange).not.toHaveBeenCalled();
83
+ });
84
+
85
+ it("waits for Reduce Motion before presenting, and then doesn't slide", async () => {
86
+ Platform.OS = "ios";
87
+ let answer!: (value: boolean) => void;
88
+ vi.spyOn(AccessibilityInfo, "isReduceMotionEnabled").mockReturnValue(new Promise<boolean>((resolve) => (answer = resolve)));
89
+ render(sheet());
90
+ expect(screen.queryByRole("dialog")).toBeNull();
91
+ await act(async () => answer(true));
92
+ expect(screen.getByRole("dialog").getAttribute("data-animation-type")).toBe("none");
93
+ });
94
+
95
+ it("is a transparent bottom panel with a scrim on Android, under the system bars", async () => {
96
+ Platform.OS = "android";
97
+ const onOpenChange = vi.fn();
98
+ render(sheet({ onOpenChange, testID: "s" }));
99
+ const modal = await screen.findByRole("dialog");
100
+ expect(modal.getAttribute("data-presentation-style")).toBeNull();
101
+ expect(modal.getAttribute("data-transparent")).toBe("true");
102
+ expect(modal.getAttribute("data-status-bar-translucent")).toBe("true");
103
+ expect(modal.getAttribute("data-navigation-bar-translucent")).toBe("true");
104
+ fireEvent.click(screen.getByTestId("s-backdrop"));
105
+ expect(onOpenChange).toHaveBeenCalledWith(false);
106
+ onOpenChange.mockClear();
107
+ fireEvent.keyDown(modal, { key: "Escape" }); // the back button
108
+ expect(onOpenChange).toHaveBeenCalledWith(false);
109
+ });
110
+
111
+ it("keeps the Android sheet up when dismissal is disabled", async () => {
112
+ Platform.OS = "android";
113
+ const onOpenChange = vi.fn();
114
+ render(sheet({ onOpenChange, testID: "s", disableBackdropDismiss: true }));
115
+ const modal = await screen.findByRole("dialog");
116
+ fireEvent.click(screen.getByTestId("s-backdrop"));
117
+ fireEvent.keyDown(modal, { key: "Escape" });
118
+ expect(onOpenChange).not.toHaveBeenCalled();
119
+ });
120
+
121
+ it("renders nothing while closed", async () => {
122
+ render(sheet({ open: false }));
123
+ await act(async () => {});
124
+ expect(screen.queryByRole("dialog")).toBeNull();
125
+ });
126
+ });
127
+
128
+ describe("NativeSheet under NativeSheetProvider", () => {
129
+ it("uses the library the app passed in, inside its BottomSheetModalProvider", () => {
130
+ const { library, present, dismiss, providerMounted, modalProps } = fakeLibrary();
131
+ const onOpenChange = vi.fn();
132
+ const tree = (open: boolean) => (
133
+ <NativeSheetProvider bottomSheet={library}>
134
+ <NativeSheet open={open} onOpenChange={onOpenChange} snapPoints={["25%"]}>
135
+ <NativeSheetScrollView>
136
+ <span>body</span>
137
+ </NativeSheetScrollView>
138
+ </NativeSheet>
139
+ </NativeSheetProvider>
140
+ );
141
+ const { rerender } = render(tree(true));
142
+ expect(providerMounted).toHaveBeenCalled();
143
+ expect(screen.queryByRole("dialog")).toBeNull();
144
+ expect(screen.getByTestId("gorhom-provider").contains(screen.getByTestId("gorhom-modal"))).toBe(true);
145
+ expect(screen.getByTestId("gorhom-scroll").textContent).toBe("body");
146
+ expect(present).toHaveBeenCalledTimes(1);
147
+ // The given snap points are the sheet's only ones (v5 would add a content-height one).
148
+ expect(modalProps).toHaveBeenLastCalledWith(expect.objectContaining({ snapPoints: ["25%"], enableDynamicSizing: false }));
149
+
150
+ // The user closing it reports; the app closing it doesn't report back.
151
+ fireEvent.click(screen.getByTestId("gorhom-modal"));
152
+ expect(onOpenChange).toHaveBeenCalledWith(false);
153
+ onOpenChange.mockClear();
154
+ rerender(tree(false));
155
+ expect(dismiss).toHaveBeenCalledTimes(1);
156
+ fireEvent.click(screen.getByTestId("gorhom-modal"));
157
+ expect(onOpenChange).not.toHaveBeenCalled();
158
+ });
159
+
160
+ it("doesn't report a dismiss that finishes after the app reopened the sheet", () => {
161
+ const { library } = fakeLibrary();
162
+ const onOpenChange = vi.fn();
163
+ const tree = (open: boolean) => (
164
+ <NativeSheetProvider bottomSheet={library}>
165
+ <NativeSheet open={open} onOpenChange={onOpenChange}>
166
+ <span>body</span>
167
+ </NativeSheet>
168
+ </NativeSheetProvider>
169
+ );
170
+ const { rerender } = render(tree(true));
171
+ rerender(tree(false));
172
+ // The dismiss animation finishes after the app has closed the sheet: not the user.
173
+ fireEvent.click(screen.getByTestId("gorhom-modal"));
174
+ expect(onOpenChange).not.toHaveBeenCalled();
175
+ rerender(tree(true));
176
+ fireEvent.click(screen.getByTestId("gorhom-modal"));
177
+ expect(onOpenChange).toHaveBeenCalledTimes(1);
178
+ });
179
+
180
+ it("reports an incomplete module and falls back to the native modal", async () => {
181
+ Platform.OS = "ios";
182
+ const error = vi.spyOn(console, "error").mockImplementation(() => {});
183
+ const { library } = fakeLibrary();
184
+ const broken = { ...library, BottomSheetModalProvider: undefined } as unknown as typeof library;
185
+ render(
186
+ <NativeSheetProvider bottomSheet={broken}>
187
+ {sheet()}
188
+ </NativeSheetProvider>,
189
+ );
190
+ expect((await screen.findByRole("dialog")).getAttribute("data-presentation-style")).toBe("pageSheet");
191
+ expect(error).toHaveBeenCalledWith(expect.stringContaining("missing BottomSheetModalProvider"));
192
+ });
193
+ });
@@ -1,5 +1,7 @@
1
1
  import { fireEvent, render, screen } from "@testing-library/react";
2
2
  import { describe, expect, it, vi } from "vitest";
3
+ import { StyleSheet } from "react-native";
4
+ import { SafeAreaInsetsContext } from "react-native-safe-area-context";
3
5
  import { NativeToastProvider, useToast } from "../toast";
4
6
 
5
7
  function TestHarness() {
@@ -18,6 +20,19 @@ function TestHarness() {
18
20
  }
19
21
 
20
22
  describe("NativeToast", () => {
23
+ it("puts a top toast below the safe area's top (the status bar, the Dynamic Island)", () => {
24
+ render(
25
+ <SafeAreaInsetsContext.Provider value={{ top: 62, bottom: 34, left: 0, right: 0 }}>
26
+ <NativeToastProvider position="top" disableAnimation>
27
+ <TestHarness />
28
+ </NativeToastProvider>
29
+ </SafeAreaInsetsContext.Provider>,
30
+ );
31
+ fireEvent.click(screen.getByTestId("trigger"));
32
+ const region = screen.getByLabelText("Saved. All good.");
33
+ expect(StyleSheet.flatten(JSON.parse(region.dataset.style ?? "null"))).toMatchObject({ top: 70 });
34
+ });
35
+
21
36
  it("queues + renders a toast on show()", () => {
22
37
  render(
23
38
  <NativeToastProvider disableAnimation>
@@ -1,11 +1,22 @@
1
1
  /**
2
2
  * Avatar — user/entity image with fallback initials.
3
3
  *
4
+ * Draws with expo-image when the app passes it (`modules.image` on
5
+ * `GenesisModulesProvider`): cached in memory and on disk, a cross-fade that
6
+ * Reduce Motion turns off, an optional blurhash/thumbhash `placeholder`, and
7
+ * a `recyclingKey` (the image URL by default) so a recycled list row never
8
+ * shows the previous person's picture. Without it, React Native's `Image`.
9
+ * The initials show until the picture loads, and again if it fails.
10
+ *
4
11
  * @stability Stable
5
12
  */
6
- import { useEffect, useState } from "react";
13
+ import { useState } from "react";
7
14
  import { Image, Text, View } from "react-native";
8
15
  import { cn } from "../utils";
16
+ import { useReducedMotion } from "../hooks/use-reduced-motion";
17
+ import { useGenesisModules } from "../native-modules";
18
+
19
+ const FILL = { position: "absolute" as const, top: 0, right: 0, bottom: 0, left: 0 };
9
20
 
10
21
  export interface NativeAvatarProps {
11
22
  className?: string;
@@ -17,6 +28,16 @@ export interface NativeAvatarProps {
17
28
  fallback?: string;
18
29
  /** Size in pixels. Defaults to 40. Use className for NativeWind sizing. */
19
30
  size?: number;
31
+ /**
32
+ * expo-image only: a blurhash or thumbhash shown while the picture loads,
33
+ * as expo-image's `placeholder` takes it (`{ blurhash }`, `{ thumbhash }`).
34
+ */
35
+ placeholder?: { blurhash: string } | { thumbhash: string };
36
+ /**
37
+ * expo-image only: resets the view when it changes, for rows a recycling
38
+ * list (FlashList) reuses. Default the image URL.
39
+ */
40
+ recyclingKey?: string;
20
41
  testID?: string;
21
42
  }
22
43
 
@@ -26,11 +47,23 @@ function NativeAvatar({
26
47
  alt,
27
48
  fallback,
28
49
  size = 40,
29
- ...props
50
+ placeholder,
51
+ recyclingKey,
52
+ testID,
30
53
  }: NativeAvatarProps) {
31
- const [hasError, setHasError] = useState(false);
32
- useEffect(() => { setHasError(false); }, [src]);
33
- const showImage = src && !hasError;
54
+ const { image: ExpoImage } = useGenesisModules();
55
+ const reducedMotion = useReducedMotion();
56
+ // Which URL loaded or failed, not a flag: a row FlashList recycles for
57
+ // someone else gets the right state on its first frame, with no reset.
58
+ const [failedSrc, setFailedSrc] = useState<string | null>(null);
59
+ const [loadedSrc, setLoadedSrc] = useState<string | null>(null);
60
+ const showImage = !!src && failedSrc !== src;
61
+ const loaded = !!src && loadedSrc === src;
62
+ const imageProps = {
63
+ accessible: false,
64
+ onError: () => setFailedSrc(src ?? null),
65
+ onLoad: () => setLoadedSrc(src ?? null),
66
+ };
34
67
 
35
68
  return (
36
69
  <View
@@ -39,20 +72,16 @@ function NativeAvatar({
39
72
  className
40
73
  )}
41
74
  style={[{ width: size, height: size }]}
75
+ accessible
76
+ accessibilityRole="image"
42
77
  accessibilityLabel={alt || fallback || "Avatar"}
43
- {...props}
78
+ testID={testID}
44
79
  >
45
- {showImage ? (
46
- <Image
47
- source={{ uri: src }}
48
- className="h-full w-full"
49
- resizeMode="cover"
50
- onError={() => setHasError(true)}
51
- accessibilityLabel={alt}
52
- />
53
- ) : (
80
+ {!showImage || !loaded ? (
54
81
  <Text
55
82
  className="text-sm font-medium text-muted-foreground"
83
+ accessibilityElementsHidden
84
+ importantForAccessibility="no"
56
85
  style={{
57
86
  fontSize: Math.round(size * 0.4),
58
87
  lineHeight: Math.round(size * 0.5),
@@ -60,7 +89,31 @@ function NativeAvatar({
60
89
  >
61
90
  {fallback || "?"}
62
91
  </Text>
63
- )}
92
+ ) : null}
93
+ {showImage ? (
94
+ ExpoImage ? (
95
+ <ExpoImage
96
+ {...imageProps}
97
+ testID={testID ? `${testID}-image` : undefined}
98
+ source={{ uri: src }}
99
+ style={FILL}
100
+ contentFit="cover"
101
+ cachePolicy="memory-disk"
102
+ placeholder={placeholder}
103
+ placeholderContentFit="cover"
104
+ transition={reducedMotion ? null : 150}
105
+ recyclingKey={recyclingKey ?? src}
106
+ />
107
+ ) : (
108
+ <Image
109
+ {...imageProps}
110
+ testID={testID ? `${testID}-image` : undefined}
111
+ source={{ uri: src }}
112
+ style={FILL}
113
+ resizeMode="cover"
114
+ />
115
+ )
116
+ ) : null}
64
117
  </View>
65
118
  );
66
119
  }
@@ -11,17 +11,25 @@
11
11
  * back to a read-only Text label so screens still render — useful for
12
12
  * sample/demo apps without native module setup.
13
13
  *
14
+ * Optional backend: pass `@expo/ui`'s drop-in picker as `modules.datePicker`
15
+ * (`import DateTimePicker from "@expo/ui/community/datetime-picker"`) on
16
+ * `GenesisModulesProvider` to draw SwiftUI / Jetpack Compose pickers instead.
17
+ * Same props and behavior; the community picker stays the fallback.
18
+ *
14
19
  * @stability Beta
15
20
  */
16
21
  import { useMemo, useState } from "react";
17
22
  import { Platform, Pressable, Text } from "react-native";
18
23
  import { cn } from "../utils";
24
+ import { useGenesisModules, type GenesisDatePickerComponent } from "../native-modules";
19
25
 
20
26
  function resolveDateTimePicker(): React.ComponentType<{
21
27
  value: Date;
22
28
  mode: "date" | "time";
23
29
  display?: string;
24
30
  onChange: (e: unknown, d?: Date) => void;
31
+ disabled?: boolean;
32
+ style?: object;
25
33
  testID?: string;
26
34
  }> | null {
27
35
  try {
@@ -55,7 +63,8 @@ function PickerButton({
55
63
  className,
56
64
  testID,
57
65
  }: BasePickerProps & { mode: "date" | "time" }) {
58
- const Picker = resolveDateTimePicker();
66
+ const { datePicker: ExpoUiPicker } = useGenesisModules();
67
+ const Picker = ExpoUiPicker ? null : resolveDateTimePicker();
59
68
  const [showAndroid, setShowAndroid] = useState(false);
60
69
  const isIOS = Platform.OS === "ios";
61
70
 
@@ -65,6 +74,21 @@ function PickerButton({
65
74
  return value.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
66
75
  }, [formatLabel, mode, value]);
67
76
 
77
+ if (ExpoUiPicker) {
78
+ return (
79
+ <ExpoUiPickerButton
80
+ Picker={ExpoUiPicker}
81
+ value={value}
82
+ onChange={onChange}
83
+ mode={mode}
84
+ label={label}
85
+ disabled={disabled}
86
+ className={className}
87
+ testID={testID}
88
+ />
89
+ );
90
+ }
91
+
68
92
  if (!Picker) {
69
93
  return (
70
94
  <Text
@@ -79,9 +103,26 @@ function PickerButton({
79
103
  );
80
104
  }
81
105
 
82
- // iOS: render the inline picker directly when consumer wants it that
83
- // way; default exposes a button that toggles a sheet-like dialog. For
84
- // simplicity in this primitive we render the button + the picker inline.
106
+ // iOS: the compact picker is itself the button (it shows the value and
107
+ // opens the wheel), so it renders alone; a button beside it showed the
108
+ // value twice.
109
+ if (isIOS) {
110
+ return (
111
+ <Picker
112
+ testID={testID ?? `native-${mode}-picker`}
113
+ value={value}
114
+ mode={mode}
115
+ display="compact"
116
+ disabled={disabled}
117
+ style={disabled ? { opacity: 0.5 } : undefined}
118
+ onChange={(_e, d) => {
119
+ if (d && !disabled) onChange(d);
120
+ }}
121
+ />
122
+ );
123
+ }
124
+
125
+ // Android: a button that opens the platform dialog.
85
126
  return (
86
127
  <>
87
128
  <Pressable
@@ -91,9 +132,7 @@ function PickerButton({
91
132
  accessibilityValue={{ text: label }}
92
133
  accessibilityState={{ disabled }}
93
134
  disabled={disabled}
94
- onPress={() => {
95
- if (!isIOS) setShowAndroid(true);
96
- }}
135
+ onPress={() => setShowAndroid(true)}
97
136
  className={cn(
98
137
  "min-h-[44px] flex-row items-center rounded-md border border-input bg-background px-3",
99
138
  disabled && "opacity-50",
@@ -102,16 +141,95 @@ function PickerButton({
102
141
  >
103
142
  <Text className="flex-1 text-base text-foreground">{label}</Text>
104
143
  </Pressable>
105
- {(isIOS || showAndroid) ? (
144
+ {showAndroid ? (
106
145
  <Picker
107
146
  testID={testID ? `${testID}-picker` : undefined}
108
147
  value={value}
109
148
  mode={mode}
110
- display={isIOS ? "compact" : "default"}
149
+ display="default"
111
150
  onChange={(_e, d) => {
112
- if (!isIOS) setShowAndroid(false);
151
+ setShowAndroid(false);
152
+ if (d) onChange(d);
153
+ }}
154
+ />
155
+ ) : null}
156
+ </>
157
+ );
158
+ }
159
+
160
+ /**
161
+ * The @expo/ui backend (`@expo/ui/community/datetime-picker`, SwiftUI on iOS
162
+ * and Jetpack Compose on Android), a drop-in for the community picker. iOS:
163
+ * the compact picker is the button, as above. Android: a button that mounts
164
+ * the picker as a dialog; it fires `onValueChange` on confirm and
165
+ * `onDismiss` on cancel, and is unmounted on either.
166
+ */
167
+ function ExpoUiPickerButton({
168
+ Picker,
169
+ value,
170
+ onChange,
171
+ mode,
172
+ label,
173
+ disabled,
174
+ className,
175
+ testID,
176
+ }: {
177
+ Picker: GenesisDatePickerComponent;
178
+ value: Date;
179
+ onChange: (next: Date) => void;
180
+ mode: "date" | "time";
181
+ label: string;
182
+ disabled?: boolean;
183
+ className?: string;
184
+ testID?: string;
185
+ }) {
186
+ const [showAndroid, setShowAndroid] = useState(false);
187
+ if (Platform.OS === "ios") {
188
+ // As with the community picker: the native compact picker draws and
189
+ // announces its own value, so `className` and the button label don't apply.
190
+ return (
191
+ <Picker
192
+ testID={testID ?? `native-${mode}-picker`}
193
+ value={value}
194
+ mode={mode}
195
+ display="compact"
196
+ disabled={disabled}
197
+ style={disabled ? { opacity: 0.5 } : undefined}
198
+ onValueChange={(_e, d) => {
199
+ if (d && !disabled) onChange(d);
200
+ }}
201
+ />
202
+ );
203
+ }
204
+ return (
205
+ <>
206
+ <Pressable
207
+ testID={testID ?? `native-${mode}-picker`}
208
+ accessibilityRole="button"
209
+ accessibilityLabel={`Pick a ${mode}`}
210
+ accessibilityValue={{ text: label }}
211
+ accessibilityState={{ disabled }}
212
+ disabled={disabled}
213
+ onPress={() => setShowAndroid(true)}
214
+ className={cn(
215
+ "min-h-[44px] flex-row items-center rounded-md border border-input bg-background px-3",
216
+ disabled && "opacity-50",
217
+ className
218
+ )}
219
+ >
220
+ <Text className="flex-1 text-base text-foreground">{label}</Text>
221
+ </Pressable>
222
+ {showAndroid ? (
223
+ <Picker
224
+ testID={testID ? `${testID}-picker` : undefined}
225
+ value={value}
226
+ mode={mode}
227
+ presentation="dialog"
228
+ onValueChange={(_e, d) => {
229
+ setShowAndroid(false);
113
230
  if (d) onChange(d);
114
231
  }}
232
+ onDismiss={() => setShowAndroid(false)}
115
233
  />
116
234
  ) : null}
117
235
  </>