@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.
- package/README.md +82 -0
- package/dist/chunk-7PCWEY6R.js +27 -0
- package/dist/chunk-7PCWEY6R.js.map +1 -0
- package/dist/chunk-D5RKSPMH.js +24 -0
- package/dist/chunk-D5RKSPMH.js.map +1 -0
- package/dist/{chunk-5HRGIA6F.js → chunk-EFXCJ5AN.js} +76 -3
- package/dist/chunk-EFXCJ5AN.js.map +1 -0
- package/dist/{chunk-ULS7I6ZS.js → chunk-ERHGCWTY.js} +81 -12
- package/dist/chunk-ERHGCWTY.js.map +1 -0
- package/dist/{chunk-2WCXMJL6.js → chunk-FIITITXO.js} +67 -108
- package/dist/chunk-FIITITXO.js.map +1 -0
- package/dist/chunk-FZY2IXOX.js +1559 -0
- package/dist/chunk-FZY2IXOX.js.map +1 -0
- package/dist/{chunk-TXJT55JC.js → chunk-W7BK3ARU.js} +715 -293
- package/dist/chunk-W7BK3ARU.js.map +1 -0
- package/dist/components/index.d.ts +142 -17
- package/dist/components/index.js +6 -4
- package/dist/data/index.d.ts +7 -1
- package/dist/data/index.js +31 -6
- package/dist/data/index.js.map +1 -1
- package/dist/hooks/index.js +2 -1
- package/dist/icons/lucide.d.ts +7 -0
- package/dist/icons/lucide.js +47 -0
- package/dist/icons/lucide.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +7 -6
- package/dist/layouts/index.d.ts +320 -4
- package/dist/layouts/index.js +3 -3
- package/dist/native-modules-BSVaEb3D.d.ts +206 -0
- package/package.json +34 -5
- package/src/__tests__/fake-modules.tsx +134 -0
- package/src/__tests__/native-modules-lists.test.tsx +70 -0
- package/src/__tests__/native-modules.test.tsx +631 -0
- package/src/components/__tests__/sheet.test.tsx +193 -0
- package/src/components/__tests__/toast.test.tsx +15 -0
- package/src/components/avatar.tsx +69 -16
- package/src/components/date-time-picker.tsx +128 -10
- package/src/components/drawer.tsx +158 -68
- package/src/components/dropdown-menu.tsx +7 -6
- package/src/components/glass-surface.tsx +150 -0
- package/src/components/icon.tsx +66 -0
- package/src/components/image.tsx +89 -0
- package/src/components/index.ts +33 -2
- package/src/components/list-item.tsx +29 -9
- package/src/components/popover.tsx +12 -9
- package/src/components/segmented-control.tsx +7 -1
- package/src/components/sheet.tsx +276 -133
- package/src/components/skeleton.tsx +75 -53
- package/src/components/toast.tsx +185 -87
- package/src/data/NativeResourcePage.tsx +48 -3
- package/src/data/__tests__/resource-page-offline.test.tsx +47 -0
- package/src/hooks/use-reduced-motion.ts +24 -10
- package/src/icon-names.ts +49 -0
- package/src/icons/lucide.ts +88 -0
- package/src/layouts/__tests__/google-sign-in.test.tsx +26 -0
- package/src/layouts/__tests__/inbox-page.test.tsx +155 -0
- package/src/layouts/__tests__/keyboard-scroll.test.tsx +42 -1
- package/src/layouts/__tests__/settings-page-native-look.test.tsx +142 -0
- package/src/layouts/__tests__/thread-page.test.tsx +128 -0
- package/src/layouts/auth-screen.tsx +6 -3
- package/src/layouts/google-sign-in.tsx +42 -0
- package/src/layouts/inbox-page.tsx +408 -0
- package/src/layouts/index.ts +37 -2
- package/src/layouts/keyboard.tsx +61 -9
- package/src/layouts/notifications-page.tsx +133 -16
- package/src/layouts/settings-page.tsx +117 -14
- package/src/layouts/settings-sub-page.tsx +9 -3
- package/src/layouts/thread-page.tsx +444 -0
- package/src/native-modules.tsx +186 -0
- package/dist/chunk-2WCXMJL6.js.map +0 -1
- package/dist/chunk-5HRGIA6F.js.map +0 -1
- package/dist/chunk-F2TGDKOO.js +0 -43
- package/dist/chunk-F2TGDKOO.js.map +0 -1
- package/dist/chunk-FZTUSM56.js +0 -935
- package/dist/chunk-FZTUSM56.js.map +0 -1
- package/dist/chunk-TXJT55JC.js.map +0 -1
- package/dist/chunk-ULS7I6ZS.js.map +0 -1
|
@@ -0,0 +1,631 @@
|
|
|
1
|
+
// @feat:native-modules
|
|
2
|
+
/**
|
|
3
|
+
* Every optional native module, both ways: what a component draws when the
|
|
4
|
+
* app passed the module (the opt-in path) and what it falls back to when it
|
|
5
|
+
* didn't (or the device can't use it).
|
|
6
|
+
*/
|
|
7
|
+
import { act, fireEvent, render, screen } from "@testing-library/react";
|
|
8
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
9
|
+
import type { ReactNode } from "react";
|
|
10
|
+
import { AccessibilityInfo, PanResponder, Platform } from "react-native";
|
|
11
|
+
import { GenesisModulesProvider, useGenesisModules, type GenesisModules } from "../native-modules";
|
|
12
|
+
import { NATIVE_ICON_NAMES, SF_SYMBOLS } from "../icon-names";
|
|
13
|
+
import { __resetReducedMotion, useReducedMotion } from "../hooks/use-reduced-motion";
|
|
14
|
+
import { NativeToastProvider, useToast } from "../components/toast";
|
|
15
|
+
import { NativeSkeleton } from "../components/skeleton";
|
|
16
|
+
import { NativeDrawer } from "../components/drawer";
|
|
17
|
+
import { NativeAvatar } from "../components/avatar";
|
|
18
|
+
import { NativeImage } from "../components/image";
|
|
19
|
+
import { NativeIcon } from "../components/icon";
|
|
20
|
+
import { NativeListItem } from "../components/list-item";
|
|
21
|
+
import { NativeDatePicker } from "../components/date-time-picker";
|
|
22
|
+
import { NativeGlassSurface, __resetReduceTransparency } from "../components/glass-surface";
|
|
23
|
+
import { NotificationsPage, __test as notificationsTest, defaultStickyHeaderOffset, iosCompactNavigationBarHeight } from "../layouts/notifications-page";
|
|
24
|
+
import { fakeDatePicker, fakeFlashList, fakeGlass, fakeIcon, fakeImage, fakeReanimated, fakeSymbolView } from "./fake-modules";
|
|
25
|
+
|
|
26
|
+
const originalOS = Platform.OS;
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
Platform.OS = originalOS;
|
|
29
|
+
vi.restoreAllMocks();
|
|
30
|
+
__resetReducedMotion();
|
|
31
|
+
__resetReduceTransparency();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
function withModules(modules: GenesisModules, ui: ReactNode) {
|
|
35
|
+
return render(<GenesisModulesProvider modules={modules}>{ui}</GenesisModulesProvider>);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
describe("GenesisModulesProvider", () => {
|
|
39
|
+
function Probe() {
|
|
40
|
+
return <span data-testid="probe">{Object.keys(useGenesisModules()).sort().join(",")}</span>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
it("gives {} without a provider", () => {
|
|
44
|
+
render(<Probe />);
|
|
45
|
+
expect(screen.getByTestId("probe").textContent).toBe("");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("merges nested providers, the inner one winning", () => {
|
|
49
|
+
const outerImage = fakeImage();
|
|
50
|
+
const innerImage = fakeImage();
|
|
51
|
+
function Which() {
|
|
52
|
+
return <span data-testid="which">{useGenesisModules().image === innerImage ? "inner" : "outer"}</span>;
|
|
53
|
+
}
|
|
54
|
+
render(
|
|
55
|
+
<GenesisModulesProvider modules={{ image: outerImage, list: fakeFlashList() }}>
|
|
56
|
+
<GenesisModulesProvider modules={{ image: innerImage }}>
|
|
57
|
+
<Probe />
|
|
58
|
+
<Which />
|
|
59
|
+
</GenesisModulesProvider>
|
|
60
|
+
</GenesisModulesProvider>,
|
|
61
|
+
);
|
|
62
|
+
expect(screen.getByTestId("probe").textContent).toBe("image,list");
|
|
63
|
+
expect(screen.getByTestId("which").textContent).toBe("inner");
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
function ShowToast({ variant }: { variant?: "default" | "success" | "destructive" }) {
|
|
68
|
+
const toast = useToast();
|
|
69
|
+
return (
|
|
70
|
+
<button type="button" data-testid="trigger" onClick={() => toast.show({ title: "Saved", variant })}>
|
|
71
|
+
show
|
|
72
|
+
</button>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
describe("NativeToast", () => {
|
|
77
|
+
it("falls back to React Native's Animated without reanimated", () => {
|
|
78
|
+
render(
|
|
79
|
+
<NativeToastProvider>
|
|
80
|
+
<ShowToast />
|
|
81
|
+
</NativeToastProvider>,
|
|
82
|
+
);
|
|
83
|
+
fireEvent.click(screen.getByTestId("trigger"));
|
|
84
|
+
expect(screen.getByTestId("native-toast")).toBeTruthy();
|
|
85
|
+
expect(document.querySelector("[data-reanimated]")).toBeNull();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("animates in with Reanimated when it is passed", () => {
|
|
89
|
+
const R = fakeReanimated();
|
|
90
|
+
withModules(
|
|
91
|
+
{ reanimated: R },
|
|
92
|
+
<NativeToastProvider>
|
|
93
|
+
<ShowToast />
|
|
94
|
+
</NativeToastProvider>,
|
|
95
|
+
);
|
|
96
|
+
fireEvent.click(screen.getByTestId("trigger"));
|
|
97
|
+
expect(document.querySelector("[data-reanimated]")).not.toBeNull();
|
|
98
|
+
expect(screen.getByLabelText("Saved")).toBeTruthy();
|
|
99
|
+
expect(R.withTiming).toHaveBeenCalledWith(1, expect.objectContaining({ duration: 180 }));
|
|
100
|
+
expect(R.withTiming).toHaveBeenCalledWith(0, expect.objectContaining({ duration: 180 }));
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("starts in place, with no timing, when animation is off", () => {
|
|
104
|
+
const R = fakeReanimated();
|
|
105
|
+
withModules(
|
|
106
|
+
{ reanimated: R },
|
|
107
|
+
<NativeToastProvider disableAnimation>
|
|
108
|
+
<ShowToast />
|
|
109
|
+
</NativeToastProvider>,
|
|
110
|
+
);
|
|
111
|
+
fireEvent.click(screen.getByTestId("trigger"));
|
|
112
|
+
expect(R.withTiming).not.toHaveBeenCalled();
|
|
113
|
+
const style = JSON.parse((document.querySelector("[data-reanimated]") as HTMLElement).dataset.style!);
|
|
114
|
+
expect(style).toEqual({ opacity: 1, transform: [{ translateY: 0 }] });
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("starts in place under Reduce Motion", async () => {
|
|
118
|
+
vi.spyOn(AccessibilityInfo, "isReduceMotionEnabled").mockResolvedValue(true);
|
|
119
|
+
const R = fakeReanimated();
|
|
120
|
+
withModules(
|
|
121
|
+
{ reanimated: R },
|
|
122
|
+
<NativeToastProvider>
|
|
123
|
+
<ShowToast />
|
|
124
|
+
</NativeToastProvider>,
|
|
125
|
+
);
|
|
126
|
+
await act(async () => {});
|
|
127
|
+
fireEvent.click(screen.getByTestId("trigger"));
|
|
128
|
+
expect(R.withTiming).not.toHaveBeenCalled();
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("is Liquid Glass on iOS when both availability checks pass", () => {
|
|
132
|
+
Platform.OS = "ios";
|
|
133
|
+
const glass = fakeGlass();
|
|
134
|
+
withModules(
|
|
135
|
+
{ glass },
|
|
136
|
+
<NativeToastProvider disableAnimation>
|
|
137
|
+
<ShowToast />
|
|
138
|
+
</NativeToastProvider>,
|
|
139
|
+
);
|
|
140
|
+
fireEvent.click(screen.getByTestId("trigger"));
|
|
141
|
+
expect(screen.getByTestId("native-toast-glass")).toBeTruthy();
|
|
142
|
+
expect(screen.getByText("Saved").className).toContain("text-foreground");
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it.each([
|
|
146
|
+
["the glass API is missing at run time", { api: false }],
|
|
147
|
+
["the build can't draw Liquid Glass", { liquid: false }],
|
|
148
|
+
["the availability check throws", { throws: true }],
|
|
149
|
+
])("stays solid when %s", (_why, options) => {
|
|
150
|
+
Platform.OS = "ios";
|
|
151
|
+
withModules(
|
|
152
|
+
{ glass: fakeGlass(options) },
|
|
153
|
+
<NativeToastProvider disableAnimation>
|
|
154
|
+
<ShowToast />
|
|
155
|
+
</NativeToastProvider>,
|
|
156
|
+
);
|
|
157
|
+
fireEvent.click(screen.getByTestId("trigger"));
|
|
158
|
+
expect(screen.queryByTestId("native-toast-glass")).toBeNull();
|
|
159
|
+
expect(screen.getByTestId("native-toast").className).toContain("bg-foreground");
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("stays solid on Android, and for success and destructive toasts", () => {
|
|
163
|
+
Platform.OS = "android";
|
|
164
|
+
const { unmount } = withModules(
|
|
165
|
+
{ glass: fakeGlass() },
|
|
166
|
+
<NativeToastProvider disableAnimation>
|
|
167
|
+
<ShowToast />
|
|
168
|
+
</NativeToastProvider>,
|
|
169
|
+
);
|
|
170
|
+
fireEvent.click(screen.getByTestId("trigger"));
|
|
171
|
+
expect(screen.queryByTestId("native-toast-glass")).toBeNull();
|
|
172
|
+
unmount();
|
|
173
|
+
Platform.OS = "ios";
|
|
174
|
+
withModules(
|
|
175
|
+
{ glass: fakeGlass() },
|
|
176
|
+
<NativeToastProvider disableAnimation>
|
|
177
|
+
<ShowToast variant="destructive" />
|
|
178
|
+
</NativeToastProvider>,
|
|
179
|
+
);
|
|
180
|
+
fireEvent.click(screen.getByTestId("trigger"));
|
|
181
|
+
expect(screen.queryByTestId("native-toast-glass")).toBeNull();
|
|
182
|
+
expect(screen.getByTestId("native-toast").className).toContain("bg-destructive");
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("stays solid while Reduce Transparency is on", async () => {
|
|
186
|
+
Platform.OS = "ios";
|
|
187
|
+
(AccessibilityInfo as unknown as { isReduceTransparencyEnabled: () => Promise<boolean> }).isReduceTransparencyEnabled = () => Promise.resolve(true);
|
|
188
|
+
try {
|
|
189
|
+
withModules(
|
|
190
|
+
{ glass: fakeGlass() },
|
|
191
|
+
<NativeToastProvider disableAnimation>
|
|
192
|
+
<ShowToast />
|
|
193
|
+
</NativeToastProvider>,
|
|
194
|
+
);
|
|
195
|
+
fireEvent.click(screen.getByTestId("trigger"));
|
|
196
|
+
await act(async () => {});
|
|
197
|
+
expect(screen.queryByTestId("native-toast-glass")).toBeNull();
|
|
198
|
+
} finally {
|
|
199
|
+
delete (AccessibilityInfo as unknown as { isReduceTransparencyEnabled?: unknown }).isReduceTransparencyEnabled;
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
describe("NativeToast on glass", () => {
|
|
205
|
+
it("slides in without fading, since glass doesn't draw under a translucent parent", () => {
|
|
206
|
+
Platform.OS = "ios";
|
|
207
|
+
const R = fakeReanimated();
|
|
208
|
+
withModules(
|
|
209
|
+
{ reanimated: R, glass: fakeGlass() },
|
|
210
|
+
<NativeToastProvider>
|
|
211
|
+
<ShowToast />
|
|
212
|
+
</NativeToastProvider>,
|
|
213
|
+
);
|
|
214
|
+
fireEvent.click(screen.getByTestId("trigger"));
|
|
215
|
+
const style = JSON.parse((document.querySelector("[data-reanimated]") as HTMLElement).dataset.style!);
|
|
216
|
+
expect(style.opacity).toBe(1);
|
|
217
|
+
expect(R.withTiming).toHaveBeenCalledTimes(1);
|
|
218
|
+
expect(R.withTiming).toHaveBeenCalledWith(0, expect.objectContaining({ duration: 180 }));
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("stays solid, and says so in development, when expo-glass-effect lacks a check", () => {
|
|
222
|
+
Platform.OS = "ios";
|
|
223
|
+
(globalThis as { __DEV__?: boolean }).__DEV__ = true;
|
|
224
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
225
|
+
try {
|
|
226
|
+
const glass = { ...fakeGlass(), isGlassEffectAPIAvailable: undefined } as unknown as GenesisModules["glass"];
|
|
227
|
+
withModules(
|
|
228
|
+
{ glass },
|
|
229
|
+
<NativeToastProvider disableAnimation>
|
|
230
|
+
<ShowToast />
|
|
231
|
+
</NativeToastProvider>,
|
|
232
|
+
);
|
|
233
|
+
fireEvent.click(screen.getByTestId("trigger"));
|
|
234
|
+
expect(screen.queryByTestId("native-toast-glass")).toBeNull();
|
|
235
|
+
expect(warn.mock.calls.some(([m]) => String(m).includes("modules.glass"))).toBe(true);
|
|
236
|
+
} finally {
|
|
237
|
+
delete (globalThis as { __DEV__?: boolean }).__DEV__;
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
describe("useReducedMotion", () => {
|
|
243
|
+
it("starts a later component from the last known answer", async () => {
|
|
244
|
+
vi.spyOn(AccessibilityInfo, "isReduceMotionEnabled").mockResolvedValue(true);
|
|
245
|
+
function Probe({ id }: { id: string }) {
|
|
246
|
+
return <span data-testid={id}>{String(useReducedMotion())}</span>;
|
|
247
|
+
}
|
|
248
|
+
const first = render(<Probe id="first" />);
|
|
249
|
+
await act(async () => {});
|
|
250
|
+
expect(screen.getByTestId("first").textContent).toBe("true");
|
|
251
|
+
first.unmount();
|
|
252
|
+
// The second one's first render, before its own query answers.
|
|
253
|
+
vi.spyOn(AccessibilityInfo, "isReduceMotionEnabled").mockReturnValue(new Promise(() => {}));
|
|
254
|
+
render(<Probe id="second" />);
|
|
255
|
+
expect(screen.getByTestId("second").textContent).toBe("true");
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
describe("Reduce Transparency, before it is known", () => {
|
|
260
|
+
it("keeps surfaces solid until the setting answers off, then draws glass", async () => {
|
|
261
|
+
Platform.OS = "ios";
|
|
262
|
+
let answer: (v: boolean) => void = () => {};
|
|
263
|
+
const info = AccessibilityInfo as unknown as { isReduceTransparencyEnabled?: () => Promise<boolean> };
|
|
264
|
+
info.isReduceTransparencyEnabled = () => new Promise((resolve) => (answer = resolve));
|
|
265
|
+
try {
|
|
266
|
+
withModules({ glass: fakeGlass() }, <NativeGlassSurface testID="surface" fallbackClassName="bg-secondary" />);
|
|
267
|
+
expect(screen.getByTestId("surface").dataset.glass).toBeUndefined();
|
|
268
|
+
await act(async () => answer(false));
|
|
269
|
+
expect(screen.getByTestId("surface").dataset.glass).toBe("true");
|
|
270
|
+
} finally {
|
|
271
|
+
delete info.isReduceTransparencyEnabled;
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
describe("NativeGlassSurface", () => {
|
|
277
|
+
it("draws the fallback classes without expo-glass-effect", () => {
|
|
278
|
+
render(<NativeGlassSurface testID="surface" fallbackClassName="bg-secondary" className="p-2" />);
|
|
279
|
+
expect(screen.getByTestId("surface").className).toBe("bg-secondary p-2");
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it("draws GlassView, without the fallback classes, when glass is available", () => {
|
|
283
|
+
Platform.OS = "ios";
|
|
284
|
+
const glass = fakeGlass();
|
|
285
|
+
withModules(
|
|
286
|
+
{ glass },
|
|
287
|
+
<NativeGlassSurface testID="surface" fallbackClassName="bg-secondary" className="p-2" radius={20}>
|
|
288
|
+
<span>inside</span>
|
|
289
|
+
</NativeGlassSurface>,
|
|
290
|
+
);
|
|
291
|
+
const surface = screen.getByTestId("surface");
|
|
292
|
+
expect(surface.dataset.glass).toBe("true");
|
|
293
|
+
expect(surface.textContent).toBe("inside");
|
|
294
|
+
expect(surface.querySelector(".bg-secondary")).toBeNull();
|
|
295
|
+
expect(glass.calls.mock.calls[0]![0]).toMatchObject({ style: { borderRadius: 20, overflow: "hidden" }, glassEffectStyle: "regular" });
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
describe("NativeSkeleton", () => {
|
|
300
|
+
it("pulses with React Native's Animated without reanimated", () => {
|
|
301
|
+
render(<NativeSkeleton testID="sk" className="h-4 w-24" />);
|
|
302
|
+
expect(screen.getByTestId("sk").className).toContain("bg-muted");
|
|
303
|
+
expect(document.querySelector("[data-reanimated]")).toBeNull();
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it("pulses forever with Reanimated, and keeps the className", () => {
|
|
307
|
+
const R = fakeReanimated();
|
|
308
|
+
withModules({ reanimated: R }, <NativeSkeleton testID="sk" className="h-4 w-24" size={10} />);
|
|
309
|
+
const el = screen.getByTestId("sk");
|
|
310
|
+
expect(el.dataset.reanimated).toBe("true");
|
|
311
|
+
expect(el.className).toContain("w-24");
|
|
312
|
+
expect(R.withRepeat).toHaveBeenCalledWith(1, -1, true);
|
|
313
|
+
expect(JSON.parse(el.dataset.style!)).toEqual([{ opacity: 0.3 }, { width: 10 }, { height: 10 }]);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it("holds still with Reanimated under Reduce Motion", async () => {
|
|
317
|
+
vi.spyOn(AccessibilityInfo, "isReduceMotionEnabled").mockResolvedValue(true);
|
|
318
|
+
const R = fakeReanimated();
|
|
319
|
+
withModules({ reanimated: R }, <NativeSkeleton testID="sk" />);
|
|
320
|
+
await act(async () => {});
|
|
321
|
+
expect(R.cancelAnimation).toHaveBeenCalled();
|
|
322
|
+
expect(R.withRepeat).toHaveBeenCalledTimes(1); // the first, pre-preference render only
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
describe("NativeDrawer", () => {
|
|
327
|
+
it("slides its panel with Reanimated when passed", () => {
|
|
328
|
+
const R = fakeReanimated();
|
|
329
|
+
withModules(
|
|
330
|
+
{ reanimated: R },
|
|
331
|
+
<NativeDrawer open onOpenChange={() => {}}>
|
|
332
|
+
<span>menu</span>
|
|
333
|
+
</NativeDrawer>,
|
|
334
|
+
);
|
|
335
|
+
const panel = screen.getByTestId("native-drawer");
|
|
336
|
+
expect(panel.dataset.reanimated).toBe("true");
|
|
337
|
+
expect(R.withTiming).toHaveBeenCalledWith(0, { duration: 220 });
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
it("settles back open when another responder takes the swipe", () => {
|
|
341
|
+
const configs: Array<{ onPanResponderTerminate?: () => void }> = [];
|
|
342
|
+
vi.spyOn(PanResponder, "create").mockImplementation((cfg) => {
|
|
343
|
+
configs.push(cfg as never);
|
|
344
|
+
return { panHandlers: {} } as never;
|
|
345
|
+
});
|
|
346
|
+
const R = fakeReanimated();
|
|
347
|
+
const onOpenChange = vi.fn();
|
|
348
|
+
withModules(
|
|
349
|
+
{ reanimated: R },
|
|
350
|
+
<NativeDrawer open onOpenChange={onOpenChange}>
|
|
351
|
+
<span>menu</span>
|
|
352
|
+
</NativeDrawer>,
|
|
353
|
+
);
|
|
354
|
+
R.withTiming.mockClear();
|
|
355
|
+
configs[configs.length - 1]!.onPanResponderTerminate!();
|
|
356
|
+
expect(R.withTiming).toHaveBeenCalledWith(0, { duration: 180 });
|
|
357
|
+
expect(onOpenChange).not.toHaveBeenCalled();
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
it("closes on a backdrop tap, not on a panel tap", () => {
|
|
361
|
+
const onOpenChange = vi.fn();
|
|
362
|
+
render(
|
|
363
|
+
<NativeDrawer open onOpenChange={onOpenChange}>
|
|
364
|
+
<span>menu</span>
|
|
365
|
+
</NativeDrawer>,
|
|
366
|
+
);
|
|
367
|
+
fireEvent.click(screen.getByText("menu"));
|
|
368
|
+
expect(onOpenChange).not.toHaveBeenCalled();
|
|
369
|
+
fireEvent.click(screen.getByLabelText("Close drawer"));
|
|
370
|
+
expect(onOpenChange).toHaveBeenCalledWith(false);
|
|
371
|
+
// The panel isn't inside the backdrop button.
|
|
372
|
+
expect(screen.getByLabelText("Close drawer").contains(screen.getByText("menu"))).toBe(false);
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it("falls back to React Native's Animated", () => {
|
|
376
|
+
render(
|
|
377
|
+
<NativeDrawer open onOpenChange={() => {}}>
|
|
378
|
+
<span>menu</span>
|
|
379
|
+
</NativeDrawer>,
|
|
380
|
+
);
|
|
381
|
+
expect(screen.getByTestId("native-drawer").dataset.reanimated).toBeUndefined();
|
|
382
|
+
expect(screen.getByText("menu")).toBeTruthy();
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
describe("NativeAvatar and NativeImage", () => {
|
|
387
|
+
it("use expo-image with a memory and disk cache and the URL as the recycling key", () => {
|
|
388
|
+
const Image = fakeImage();
|
|
389
|
+
withModules({ image: Image }, <NativeAvatar testID="av" src="https://example.com/a.png" fallback="AB" alt="Ada" />);
|
|
390
|
+
const img = screen.getByTestId("av-image");
|
|
391
|
+
expect(img.dataset.expoImage).toBe("true");
|
|
392
|
+
expect(img.dataset.cachePolicy).toBe("memory-disk");
|
|
393
|
+
expect(img.dataset.recyclingKey).toBe("https://example.com/a.png");
|
|
394
|
+
expect(img.dataset.transition).toBe("150");
|
|
395
|
+
// The initials show until the picture loads.
|
|
396
|
+
expect(screen.getByText("AB")).toBeTruthy();
|
|
397
|
+
expect(screen.getByTestId("av").getAttribute("aria-label")).toBe("Ada");
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
it("take an explicit recycling key, and drop the cross-fade under Reduce Motion", async () => {
|
|
401
|
+
vi.spyOn(AccessibilityInfo, "isReduceMotionEnabled").mockResolvedValue(true);
|
|
402
|
+
const Image = fakeImage();
|
|
403
|
+
withModules({ image: Image }, <NativeImage testID="img" src="https://example.com/b.png" recyclingKey="row-7" />);
|
|
404
|
+
await act(async () => {});
|
|
405
|
+
expect(screen.getByTestId("img-image").dataset.recyclingKey).toBe("row-7");
|
|
406
|
+
expect(screen.getByTestId("img-image").dataset.transition).toBe("null");
|
|
407
|
+
expect(screen.getByTestId("img").getAttribute("aria-hidden")).toBe("true");
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
it("fall back to React Native's Image", () => {
|
|
411
|
+
render(<NativeAvatar testID="av" src="https://example.com/a.png" fallback="AB" />);
|
|
412
|
+
expect(screen.getByTestId("av-image").dataset.expoImage).toBeUndefined();
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
it("hide the initials once the picture loads, show them again if it fails or the URL changes", () => {
|
|
416
|
+
const Image = fakeImage();
|
|
417
|
+
const ui = (src: string) => (
|
|
418
|
+
<GenesisModulesProvider modules={{ image: Image }}>
|
|
419
|
+
<NativeAvatar testID="av" src={src} fallback="AB" />
|
|
420
|
+
</GenesisModulesProvider>
|
|
421
|
+
);
|
|
422
|
+
const { rerender } = render(ui("https://example.com/a.png"));
|
|
423
|
+
expect(screen.getByText("AB")).toBeTruthy();
|
|
424
|
+
fireEvent.load(screen.getByTestId("av-image"));
|
|
425
|
+
expect(screen.queryByText("AB")).toBeNull();
|
|
426
|
+
rerender(ui("https://example.com/b.png"));
|
|
427
|
+
expect(screen.getByText("AB")).toBeTruthy(); // b.png hasn't loaded yet
|
|
428
|
+
fireEvent.error(screen.getByTestId("av-image"));
|
|
429
|
+
expect(screen.getByText("AB")).toBeTruthy();
|
|
430
|
+
expect(screen.queryByTestId("av-image")).toBeNull();
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
it("give a recycled row the new person's state on its first frame", () => {
|
|
434
|
+
const Image = vi.fn((props: { testID?: string; onError?: () => void }) => (
|
|
435
|
+
<img data-testid={props.testID} alt="" onClick={() => props.onError?.()} />
|
|
436
|
+
));
|
|
437
|
+
const { rerender } = withModules({ image: Image as never }, <NativeAvatar testID="av" src="https://example.com/a.png" fallback="AB" />);
|
|
438
|
+
fireEvent.click(screen.getByTestId("av-image")); // a.png fails
|
|
439
|
+
expect(screen.queryByTestId("av-image")).toBeNull();
|
|
440
|
+
rerender(
|
|
441
|
+
<GenesisModulesProvider modules={{ image: Image as never }}>
|
|
442
|
+
<NativeAvatar testID="av" src="https://example.com/b.png" fallback="CD" />
|
|
443
|
+
</GenesisModulesProvider>,
|
|
444
|
+
);
|
|
445
|
+
// b.png is tried at once, not after an effect resets the failure.
|
|
446
|
+
expect(screen.getByTestId("av-image")).toBeTruthy();
|
|
447
|
+
expect(screen.getByText("CD")).toBeTruthy();
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
it("show the initials when there is no picture", () => {
|
|
451
|
+
withModules({ image: fakeImage() }, <NativeAvatar testID="av" fallback="CD" />);
|
|
452
|
+
expect(screen.queryByTestId("av-image")).toBeNull();
|
|
453
|
+
expect(screen.getByText("CD")).toBeTruthy();
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
describe("NativeIcon", () => {
|
|
458
|
+
it("draws the SF Symbol on iOS, with the icon set as its fallback", () => {
|
|
459
|
+
Platform.OS = "ios";
|
|
460
|
+
const SymbolView = fakeSymbolView();
|
|
461
|
+
withModules({ symbol: SymbolView, icons: { settings: fakeIcon("Settings") } }, <NativeIcon name="settings" size={22} />);
|
|
462
|
+
const symbol = document.querySelector("[data-symbol]") as HTMLElement;
|
|
463
|
+
expect(symbol.dataset.symbol).toBe("gearshape");
|
|
464
|
+
expect(symbol.dataset.size).toBe("22");
|
|
465
|
+
expect(symbol.querySelector("[data-lucide=Settings]")).not.toBeNull();
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
it("draws the icon set on Android, never the SF Symbol", () => {
|
|
469
|
+
Platform.OS = "android";
|
|
470
|
+
withModules({ symbol: fakeSymbolView(), icons: { bell: fakeIcon("Bell") } }, <NativeIcon name="bell" />);
|
|
471
|
+
expect(document.querySelector("[data-symbol]")).toBeNull();
|
|
472
|
+
expect(document.querySelector("[data-lucide=Bell]")).not.toBeNull();
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
it("is decorative unless labelled", () => {
|
|
476
|
+
withModules({ icons: { bell: fakeIcon("Bell") } }, <NativeIcon name="bell" testID="i" />);
|
|
477
|
+
expect(screen.getByTestId("i").getAttribute("aria-hidden")).toBe("true");
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
it("is an image with a label when given one", () => {
|
|
481
|
+
withModules({ icons: { bell: fakeIcon("Bell") } }, <NativeIcon name="bell" label="Notifications" testID="i" />);
|
|
482
|
+
expect(screen.getByTestId("i").getAttribute("role")).toBe("image");
|
|
483
|
+
expect(screen.getByLabelText("Notifications")).toBeTruthy();
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
it("keeps its space and warns once when there is nothing to draw with", () => {
|
|
487
|
+
Platform.OS = "android";
|
|
488
|
+
(globalThis as { __DEV__?: boolean }).__DEV__ = true;
|
|
489
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
490
|
+
try {
|
|
491
|
+
render(
|
|
492
|
+
<>
|
|
493
|
+
<NativeIcon name="trash" testID="i" size={18} />
|
|
494
|
+
<NativeIcon name="trash" />
|
|
495
|
+
</>,
|
|
496
|
+
);
|
|
497
|
+
expect(JSON.parse(screen.getByTestId("i").dataset.style!)).toMatchObject({ width: 18, height: 18 });
|
|
498
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
499
|
+
expect(warn.mock.calls[0]![0]).toContain('NativeIcon "trash"');
|
|
500
|
+
} finally {
|
|
501
|
+
delete (globalThis as { __DEV__?: boolean }).__DEV__;
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
it("maps every semantic name to an SF Symbol", () => {
|
|
506
|
+
for (const name of NATIVE_ICON_NAMES) expect(SF_SYMBOLS[name]).toMatch(/^[a-z0-9.]+$/);
|
|
507
|
+
});
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
describe("NativeListItem chevron", () => {
|
|
511
|
+
it('is a text "›" without icons', () => {
|
|
512
|
+
render(<NativeListItem title="Row" showChevron />);
|
|
513
|
+
expect(screen.getByText("›")).toBeTruthy();
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
it("is the chevron icon when the app gave an icon set", () => {
|
|
517
|
+
Platform.OS = "android";
|
|
518
|
+
withModules({ icons: { "chevron-right": fakeIcon("ChevronRight") } }, <NativeListItem title="Row" showChevron />);
|
|
519
|
+
expect(screen.queryByText("›")).toBeNull();
|
|
520
|
+
expect(document.querySelector("[data-lucide=ChevronRight]")).not.toBeNull();
|
|
521
|
+
});
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
describe("NativeDatePicker with @expo/ui", () => {
|
|
525
|
+
it("is the compact picker on iOS and reports the chosen date", () => {
|
|
526
|
+
Platform.OS = "ios";
|
|
527
|
+
const Picker = fakeDatePicker();
|
|
528
|
+
const onChange = vi.fn();
|
|
529
|
+
withModules({ datePicker: Picker }, <NativeDatePicker value={new Date(2030, 0, 1)} onChange={onChange} testID="dp" />);
|
|
530
|
+
const picker = screen.getByTestId("dp");
|
|
531
|
+
expect(picker.dataset.expoUiPicker).toBe("true");
|
|
532
|
+
expect(picker.dataset.display).toBe("compact");
|
|
533
|
+
fireEvent.click(screen.getByTestId("fake-picker-choose"));
|
|
534
|
+
expect(onChange).toHaveBeenCalledWith(new Date(2030, 0, 2));
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
it("opens as a dialog on Android and closes on cancel without a change", () => {
|
|
538
|
+
Platform.OS = "android";
|
|
539
|
+
const onChange = vi.fn();
|
|
540
|
+
withModules({ datePicker: fakeDatePicker() }, <NativeDatePicker value={new Date(2030, 0, 1)} onChange={onChange} testID="dp" />);
|
|
541
|
+
expect(screen.queryByTestId("dp-picker")).toBeNull();
|
|
542
|
+
fireEvent.click(screen.getByTestId("dp"));
|
|
543
|
+
expect(screen.getByTestId("dp-picker").dataset.presentation).toBe("dialog");
|
|
544
|
+
fireEvent.click(screen.getByTestId("fake-picker-cancel"));
|
|
545
|
+
expect(screen.queryByTestId("dp-picker")).toBeNull();
|
|
546
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
it("falls back to the community picker, or a label without one", () => {
|
|
550
|
+
render(<NativeDatePicker value={new Date(2030, 0, 1)} onChange={() => {}} testID="dp" />);
|
|
551
|
+
expect(screen.getByTestId("dp").textContent).toContain("picker module not installed");
|
|
552
|
+
});
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
describe("NotificationsPage with FlashList", () => {
|
|
556
|
+
const now = new Date();
|
|
557
|
+
const items = [
|
|
558
|
+
{ id: "a", title: "One", timestamp: now },
|
|
559
|
+
{ id: "b", title: "Two", timestamp: now },
|
|
560
|
+
{ id: "c", title: "Old", timestamp: new Date(2000, 0, 1) },
|
|
561
|
+
];
|
|
562
|
+
|
|
563
|
+
it("flattens sections into one list with sticky headers", () => {
|
|
564
|
+
const FlashList = fakeFlashList();
|
|
565
|
+
withModules({ list: FlashList }, <NotificationsPage items={items} />);
|
|
566
|
+
const list = screen.getByTestId("notifications-page-list");
|
|
567
|
+
expect(list.dataset.flashList).toBe("true");
|
|
568
|
+
expect(JSON.parse(list.dataset.sticky!)).toEqual([0, 3]);
|
|
569
|
+
expect(screen.getByText("Today")).toBeTruthy();
|
|
570
|
+
expect(screen.getByTestId("notifications-page-row-c")).toBeTruthy();
|
|
571
|
+
const types = [...list.querySelectorAll("[data-item-type]")].map((el) => (el as HTMLElement).dataset.itemType);
|
|
572
|
+
expect(types).toEqual(["header", "item", "item-last", "header", "item-last"]);
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
it("separates rows inside a section only", () => {
|
|
576
|
+
const flat = notificationsTest.flattenSections(notificationsTest.groupByDate(items, now));
|
|
577
|
+
expect(flat.rows.map((r) => (r.kind === "item" ? `${r.item.id}${r.last ? "!" : ""}` : r.title))).toEqual(["Today", "a", "b!", "Earlier", "c!"]);
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
it("falls back to SectionList", () => {
|
|
581
|
+
render(<NotificationsPage items={items} />);
|
|
582
|
+
expect(screen.getByTestId("notifications-page-list").dataset.flashList).toBeUndefined();
|
|
583
|
+
});
|
|
584
|
+
|
|
585
|
+
it("sticks section headers under the native header on iOS, not under the status bar", () => {
|
|
586
|
+
const version = Platform.Version;
|
|
587
|
+
try {
|
|
588
|
+
Platform.Version = "26.0";
|
|
589
|
+
const FlashList = fakeFlashList();
|
|
590
|
+
const { unmount } = withModules({ list: FlashList }, <NotificationsPage items={items} />);
|
|
591
|
+
// The safe area's top (0 in tests) plus iOS 26's compact navigation bar.
|
|
592
|
+
expect(screen.getByTestId("notifications-page-list").dataset.stickyOffset).toBe("54");
|
|
593
|
+
unmount();
|
|
594
|
+
Platform.Version = "18.4";
|
|
595
|
+
withModules({ list: fakeFlashList() }, <NotificationsPage items={items} />);
|
|
596
|
+
expect(screen.getByTestId("notifications-page-list").dataset.stickyOffset).toBe("44");
|
|
597
|
+
} finally {
|
|
598
|
+
Platform.Version = version;
|
|
599
|
+
}
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
it("takes the app's own offset, and sticks at 0 on Android (the header sits above the list)", () => {
|
|
603
|
+
const { unmount } = withModules({ list: fakeFlashList() }, <NotificationsPage items={items} stickyHeaderOffset={20} />);
|
|
604
|
+
expect(screen.getByTestId("notifications-page-list").dataset.stickyOffset).toBe("20");
|
|
605
|
+
unmount();
|
|
606
|
+
Platform.OS = "android";
|
|
607
|
+
withModules({ list: fakeFlashList() }, <NotificationsPage items={items} />);
|
|
608
|
+
expect(screen.getByTestId("notifications-page-list").dataset.stickyOffset).toBe("0");
|
|
609
|
+
});
|
|
610
|
+
|
|
611
|
+
it("on React Native's SectionList, lets headers scroll rather than stick under the header", () => {
|
|
612
|
+
const { unmount } = render(<NotificationsPage items={items} />);
|
|
613
|
+
expect(screen.getByTestId("notifications-page-list").dataset.stickySectionHeaders).toBe("false");
|
|
614
|
+
unmount();
|
|
615
|
+
render(<NotificationsPage items={items} stickyHeaderOffset={0} />);
|
|
616
|
+
expect(screen.getByTestId("notifications-page-list").dataset.stickySectionHeaders).toBe("true");
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
it("knows iOS's compact bar height by version", () => {
|
|
620
|
+
expect(iosCompactNavigationBarHeight("26.1")).toBe(54);
|
|
621
|
+
expect(iosCompactNavigationBarHeight(27)).toBe(54);
|
|
622
|
+
expect(iosCompactNavigationBarHeight("18.6")).toBe(44);
|
|
623
|
+
expect(iosCompactNavigationBarHeight("unknown")).toBe(44);
|
|
624
|
+
expect(defaultStickyHeaderOffset("ios", "26.0", 62)).toBe(116);
|
|
625
|
+
expect(defaultStickyHeaderOffset("android", 35, 24)).toBe(0);
|
|
626
|
+
});
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
beforeEach(() => {
|
|
630
|
+
Platform.OS = "ios";
|
|
631
|
+
});
|