@marktiderman/genesis-ui-native 3.5.1 → 3.6.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 +71 -7
- package/dist/{chunk-LBVD7XXL.js → chunk-2Z72MYHB.js} +627 -20
- package/dist/chunk-2Z72MYHB.js.map +1 -0
- package/dist/chunk-4OQOJ2OC.js +80 -0
- package/dist/chunk-4OQOJ2OC.js.map +1 -0
- package/dist/{chunk-6KWEAGRD.js → chunk-6PGLX6ET.js} +101 -6
- package/dist/chunk-6PGLX6ET.js.map +1 -0
- package/dist/{chunk-ONH2PCGH.js → chunk-AGTBABAH.js} +9 -15
- package/dist/chunk-AGTBABAH.js.map +1 -0
- package/dist/{chunk-ABVSSJNT.js → chunk-FUMSL7VZ.js} +198 -168
- package/dist/chunk-FUMSL7VZ.js.map +1 -0
- package/dist/{chunk-GHYUNNNU.js → chunk-NDXNSSM6.js} +175 -93
- package/dist/chunk-NDXNSSM6.js.map +1 -0
- package/dist/chunk-SEJ6RBP7.js +361 -0
- package/dist/chunk-SEJ6RBP7.js.map +1 -0
- package/dist/{chunk-D5RKSPMH.js → chunk-ZRQAFFTN.js} +4 -3
- package/dist/chunk-ZRQAFFTN.js.map +1 -0
- package/dist/components/index.d.ts +331 -4
- package/dist/components/index.js +5 -5
- package/dist/data/index.d.ts +68 -4
- package/dist/data/index.js +231 -30
- package/dist/data/index.js.map +1 -1
- package/dist/hooks/index.d.ts +60 -1
- package/dist/hooks/index.js +2 -3
- package/dist/icons/lucide.d.ts +1 -1
- package/dist/icons/lucide.js +7 -1
- package/dist/icons/lucide.js.map +1 -1
- package/dist/{inbox-page-BEarNEIP.d.ts → inbox-page-B7_Oi2fS.d.ts} +2 -44
- package/dist/index.d.ts +8 -5
- package/dist/index.js +8 -8
- package/dist/layouts/index.d.ts +40 -51
- package/dist/layouts/index.js +5 -4
- package/dist/{native-modules-PwnGltOU.d.ts → native-modules-Cl3zw3kh.d.ts} +27 -1
- package/package.json +78 -4
- package/src/__tests__/doctor-rules.test.ts +60 -0
- package/src/__tests__/native-modules-lists.test.tsx +1 -0
- package/src/components/__tests__/composer-bar.test.tsx +55 -0
- package/src/components/__tests__/gallery-card.test.tsx +59 -0
- package/src/components/__tests__/gallery-grid.test.tsx +160 -0
- package/src/components/__tests__/lightbox-resnap.test.tsx +50 -0
- package/src/components/__tests__/lightbox-zoom.test.ts +33 -0
- package/src/components/__tests__/lightbox.test.tsx +141 -0
- package/src/components/__tests__/live-indicator.test.tsx +72 -0
- package/src/components/__tests__/rating.test.tsx +82 -0
- package/src/components/__tests__/thread-list.test.tsx +156 -0
- package/src/components/composer-bar.tsx +198 -0
- package/src/components/drawer.tsx +15 -9
- package/src/components/gallery-card.tsx +109 -0
- package/src/components/gallery-grid.tsx +285 -0
- package/src/components/gallery-layout.ts +2 -0
- package/src/components/gallery-types.ts +2 -0
- package/src/components/index.ts +44 -0
- package/src/components/lightbox-zoom.tsx +282 -0
- package/src/components/lightbox.tsx +342 -0
- package/src/components/live-indicator.tsx +139 -0
- package/src/components/rating.tsx +128 -0
- package/src/components/skeleton.tsx +9 -4
- package/src/components/thread-list.tsx +427 -0
- package/src/components/toast.tsx +7 -4
- package/src/data/NativeConflictSheet.tsx +181 -0
- package/src/data/NativeResourceForm.tsx +15 -1
- package/src/data/index.ts +2 -0
- package/src/data/resource-view/NativeRecordView.tsx +85 -8
- package/src/data/resource-view/NativeResourceView.tsx +79 -32
- package/src/data/resource-view/__tests__/native-record-view.test.tsx +95 -1
- package/src/data/resource-view/__tests__/native-resource-gallery.test.tsx +125 -0
- package/src/hooks/__tests__/use-motion.test.tsx +106 -0
- package/src/hooks/__tests__/use-thread-jump.test.tsx +88 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/use-motion.ts +128 -0
- package/src/hooks/use-thread-jump.ts +110 -0
- package/src/icon-names.ts +6 -0
- package/src/icons/lucide.ts +12 -0
- package/src/layouts/__tests__/inbox-page.test.tsx +6 -0
- package/src/layouts/__tests__/thread-page.test.tsx +114 -14
- package/src/layouts/inbox-page.tsx +6 -55
- package/src/layouts/index.ts +2 -0
- package/src/layouts/thread-page.tsx +326 -262
- package/src/native-modules.tsx +16 -2
- package/dist/chunk-6KWEAGRD.js.map +0 -1
- package/dist/chunk-7PCWEY6R.js +0 -27
- package/dist/chunk-7PCWEY6R.js.map +0 -1
- package/dist/chunk-ABVSSJNT.js.map +0 -1
- package/dist/chunk-D5RKSPMH.js.map +0 -1
- package/dist/chunk-GHYUNNNU.js.map +0 -1
- package/dist/chunk-LBVD7XXL.js.map +0 -1
- package/dist/chunk-ONH2PCGH.js.map +0 -1
- package/dist/chunk-Z3AQYVUA.js +0 -36
- package/dist/chunk-Z3AQYVUA.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marktiderman/genesis-ui-native",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -83,8 +83,8 @@
|
|
|
83
83
|
"@expo/ui": ">=58.0.0",
|
|
84
84
|
"@gorhom/bottom-sheet": ">=5.0.0",
|
|
85
85
|
"@hookform/resolvers": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0",
|
|
86
|
-
"@marktiderman/genesis-core": "^2.
|
|
87
|
-
"@marktiderman/genesis-design-system": "^1.
|
|
86
|
+
"@marktiderman/genesis-core": "^2.11.0",
|
|
87
|
+
"@marktiderman/genesis-design-system": "^1.8.0",
|
|
88
88
|
"@react-native-community/datetimepicker": ">=8.0.0",
|
|
89
89
|
"@shopify/flash-list": ">=2.0.0",
|
|
90
90
|
"@tanstack/react-query": "^5.0.0",
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
"react-hook-form": "^7.0.0",
|
|
100
100
|
"react-native": ">=0.76.0",
|
|
101
101
|
"react-native-gesture-handler": ">=2.0.0",
|
|
102
|
-
"react-native-keyboard-controller": ">=1.
|
|
102
|
+
"react-native-keyboard-controller": ">=1.21.0",
|
|
103
103
|
"react-native-reanimated": ">=3.0.0",
|
|
104
104
|
"react-native-safe-area-context": ">=4.0.0",
|
|
105
105
|
"tailwind-merge": "^3.0.0",
|
|
@@ -150,6 +150,7 @@
|
|
|
150
150
|
"class-variance-authority": "^0.7.1"
|
|
151
151
|
},
|
|
152
152
|
"devDependencies": {
|
|
153
|
+
"@tanstack/react-query": "^5.105.0",
|
|
153
154
|
"@testing-library/react": "^16.3.2",
|
|
154
155
|
"@types/react": "^19.2.14",
|
|
155
156
|
"@vitest/coverage-v8": "^5.0.5",
|
|
@@ -195,6 +196,49 @@
|
|
|
195
196
|
"import": "@marktiderman/genesis-ui-native/data",
|
|
196
197
|
"docs": "https://github.com/marktiderman/genesis/blob/main/docs/RESOURCE-VIEW.md#native",
|
|
197
198
|
"why": "The phone list comes from the same view as the web list: one description, two surfaces, no second set of helpers."
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
"id": "motion-uses-tokens",
|
|
202
|
+
"need": "an animation on the phone",
|
|
203
|
+
"level": "warn",
|
|
204
|
+
"platform": "native",
|
|
205
|
+
"newOnly": true,
|
|
206
|
+
"files": [
|
|
207
|
+
"**/*.tsx",
|
|
208
|
+
"**/*.ts"
|
|
209
|
+
],
|
|
210
|
+
"forbid": {
|
|
211
|
+
"pattern": "(?:\\bwith(?:Timing|Spring)\\(\\s*[^,()]+,\\s*\\{[^}]*\\b(?:duration|damping|stiffness)\\s*:\\s*(?:0?\\.\\d*[1-9]|[1-9])|\\bAnimated\\.(?:timing|spring)\\(\\s*[^,()]+,\\s*\\{[^}]*\\b(?:duration|bounciness|speed|damping|stiffness)\\s*:\\s*(?:0?\\.\\d*[1-9]|[1-9])|\\b(?:FadeIn|FadeOut|Slide|Zoom|Bounce|Flip|Stretch|Roll|Rotate|Pinwheel|LightSpeed|Layout|LinearTransition|SequencedTransition|FadingTransition|JumpingTransition|CurvedTransition|EntryExitTransition)\\w*(?:\\.\\w+\\([^()]*\\))*\\.(?:duration|damping|stiffness)\\(\\s*(?:0?\\.\\d*[1-9]|[1-9]))"
|
|
212
|
+
},
|
|
213
|
+
"use": "useMotion() with animateMotion on the JS thread, or motionSpring / motionTiming inside a worklet: the shared motion tokens",
|
|
214
|
+
"import": "@marktiderman/genesis-ui-native",
|
|
215
|
+
"docs": "https://github.com/marktiderman/genesis/blob/main/packages/ui-native/README.md#motion",
|
|
216
|
+
"why": "Motion is defined once, and Reduce Motion is honoured in one place; a duration or spring written as a number drifts from the rest of the app."
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
"id": "threads-use-thread-list",
|
|
220
|
+
"need": "a conversation's message list on the phone",
|
|
221
|
+
"level": "warn",
|
|
222
|
+
"platform": "native",
|
|
223
|
+
"newOnly": true,
|
|
224
|
+
"files": [
|
|
225
|
+
"**/*.tsx",
|
|
226
|
+
"**/*.jsx"
|
|
227
|
+
],
|
|
228
|
+
"forbid": {
|
|
229
|
+
"pattern": "(?:<(?:FlatList|FlashList)\\b[\\s\\S]{0,400}?\\binverted\\b(?!\\s*=\\s*\\{\\s*false\\s*\\})|\\bstartRenderingFromBottom\\s*:\\s*true)"
|
|
230
|
+
},
|
|
231
|
+
"unless": {
|
|
232
|
+
"renders": [
|
|
233
|
+
"ThreadPage",
|
|
234
|
+
"NativeThreadList",
|
|
235
|
+
"ChatThreadScreen"
|
|
236
|
+
]
|
|
237
|
+
},
|
|
238
|
+
"use": "ThreadPage, or NativeThreadList for a thread of your own (bottom-anchored, holds its place on load, jumps to a message)",
|
|
239
|
+
"import": "@marktiderman/genesis-ui-native",
|
|
240
|
+
"docs": "https://github.com/marktiderman/genesis/blob/main/packages/ui-native/README.md#inbox-and-thread-inboxpage-and-threadpage",
|
|
241
|
+
"why": "A hand-built inverted or bottom-started list recreates what NativeThreadList already does (G5), usually without holding its place, VoiceOver order or the jump."
|
|
198
242
|
}
|
|
199
243
|
],
|
|
200
244
|
"primitives": [
|
|
@@ -209,6 +253,36 @@
|
|
|
209
253
|
"use": "NativeRecordView",
|
|
210
254
|
"import": "@marktiderman/genesis-ui-native/data",
|
|
211
255
|
"docs": "https://github.com/marktiderman/genesis/blob/main/docs/RESOURCE-VIEW.md#recordview"
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
"need": "a conversation on the phone: messages, a composer",
|
|
259
|
+
"use": "ThreadPage (slots, modes, events), or NativeThreadList and NativeComposerBar to build your own",
|
|
260
|
+
"import": "@marktiderman/genesis-ui-native",
|
|
261
|
+
"docs": "https://github.com/marktiderman/genesis/blob/main/packages/ui-native/README.md#inbox-and-thread-inboxpage-and-threadpage"
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
"need": "a photo gallery on the phone",
|
|
265
|
+
"use": "NativeGalleryGrid, with NativeGalleryCard for media-first cards",
|
|
266
|
+
"import": "@marktiderman/genesis-ui-native/components",
|
|
267
|
+
"docs": "https://github.com/marktiderman/genesis/blob/main/packages/ui-native/README.md"
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
"need": "a full-screen photo viewer on the phone (zoom, swipe down to close)",
|
|
271
|
+
"use": "NativeLightbox",
|
|
272
|
+
"import": "@marktiderman/genesis-ui-native/components",
|
|
273
|
+
"docs": "https://github.com/marktiderman/genesis/blob/main/packages/ui-native/README.md"
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
"need": "a star rating on the phone",
|
|
277
|
+
"use": "NativeRating",
|
|
278
|
+
"import": "@marktiderman/genesis-ui-native/components",
|
|
279
|
+
"docs": "https://github.com/marktiderman/genesis/blob/main/packages/ui-native/README.md"
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
"need": "a photo gallery over a list (a photo per record, in justified rows)",
|
|
283
|
+
"use": "the view's gallery block (defineView) rendered by <NativeResourceView mode=\"grid\">; NativeGalleryGrid for photos that aren't records (attachments, uploads)",
|
|
284
|
+
"import": "@marktiderman/genesis-ui-native",
|
|
285
|
+
"docs": "https://github.com/marktiderman/genesis/blob/main/docs/RESOURCE-VIEW.md#gallery"
|
|
212
286
|
}
|
|
213
287
|
]
|
|
214
288
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// The doctor rules ui-native declares (package.json, genesis.doctor): their patterns, held to
|
|
2
|
+
// fixtures so a change that widens or narrows one shows here.
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import pkgJson from "../../package.json";
|
|
5
|
+
|
|
6
|
+
const pkg = pkgJson as unknown as {
|
|
7
|
+
genesis: { doctor: { prefer: { id: string; forbid: { pattern?: string }; unless?: unknown }[] } };
|
|
8
|
+
};
|
|
9
|
+
const rule = (id: string) => {
|
|
10
|
+
const found = pkg.genesis.doctor.prefer.find((r) => r.id === id);
|
|
11
|
+
if (!found?.forbid.pattern) throw new Error(`no pattern for ${id}`);
|
|
12
|
+
return { ...found, re: new RegExp(found.forbid.pattern) };
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
describe("motion-uses-tokens", () => {
|
|
16
|
+
const { re, unless } = rule("motion-uses-tokens");
|
|
17
|
+
|
|
18
|
+
it.each([
|
|
19
|
+
["withTiming(1, { duration: 300 })"],
|
|
20
|
+
["R.withSpring(target, { damping: 20 })"],
|
|
21
|
+
["withSpring(x, {\n damping: 20,\n})"],
|
|
22
|
+
["withTiming(0, {\n easing: Easing.out(Easing.cubic),\n duration: .3,\n})"],
|
|
23
|
+
["withTiming(1, { duration: 0.3 })"],
|
|
24
|
+
["Animated.timing(v, { toValue: 1, duration: 220, useNativeDriver: true })"],
|
|
25
|
+
["Animated.spring(v, { toValue: 0, bounciness: 6 })"],
|
|
26
|
+
["FadeIn.duration(300)"],
|
|
27
|
+
["FadeInDown.springify().damping(15)"],
|
|
28
|
+
["LinearTransition.duration(250)"],
|
|
29
|
+
])("flags %s", (code) => expect(re.test(code)).toBe(true));
|
|
30
|
+
|
|
31
|
+
it.each([
|
|
32
|
+
["withTiming(1, motionTiming(motion, 'fast', Easing))"],
|
|
33
|
+
["withSpring(0, motionSpring(motion, 'snappy', velocity))"],
|
|
34
|
+
["animateMotion(R, motion, 0, { spring: 'snappy' })"],
|
|
35
|
+
["withTiming(1);\ntoast.show({ title: 'Saved', duration: 3000 })"],
|
|
36
|
+
["dayjs.duration(5, 'minutes')"],
|
|
37
|
+
["moment.duration(30)"],
|
|
38
|
+
["withTiming(0, { duration: 0 })"],
|
|
39
|
+
["Animated.timing(v, cfg).start(); const t = { duration: 1000 }"],
|
|
40
|
+
])("leaves %s alone", (code) => expect(re.test(code)).toBe(false));
|
|
41
|
+
|
|
42
|
+
it("checks every file: a token call elsewhere in it doesn't exempt a literal", () => {
|
|
43
|
+
expect(unless).toBeUndefined();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe("threads-use-thread-list", () => {
|
|
48
|
+
const { re } = rule("threads-use-thread-list");
|
|
49
|
+
|
|
50
|
+
it.each([
|
|
51
|
+
["<FlatList inverted data={m} />"],
|
|
52
|
+
["<FlatList renderItem={({ item }) => <Row item={item} />} inverted />"],
|
|
53
|
+
["<FlatList data={m} inverted={true} />"],
|
|
54
|
+
["<FlashList data={m} maintainVisibleContentPosition={{ startRenderingFromBottom: true }} />"],
|
|
55
|
+
])("flags %s", (code) => expect(re.test(code)).toBe(true));
|
|
56
|
+
it.each([["<FlatList data={rows} />"], ["<FlatList data={rows} inverted={false} />"], ["<FlatList data={rows} inverted={ false } />"]])(
|
|
57
|
+
"leaves %s alone",
|
|
58
|
+
(code) => expect(re.test(code)).toBe(false),
|
|
59
|
+
);
|
|
60
|
+
});
|
|
@@ -31,6 +31,7 @@ vi.mock("lucide-react-native", () => {
|
|
|
31
31
|
"Minus", "Pencil", "Plus", "RefreshCw", "Search", "Settings", "Share", "Star", "Trash2", "TriangleAlert", "User", "X",
|
|
32
32
|
"ArrowUp", "Camera", "Copy", "File", "Image", "MessageCircle", "Mic", "Paperclip", "Pause", "Pin", "Play", "Reply", "SquarePen",
|
|
33
33
|
"Download", "Smile", "Maximize2", "Square", "SwitchCamera", "Video", "Volume2", "VolumeX",
|
|
34
|
+
"Aperture", "Clapperboard", "FolderPlus", "Maximize", "Radio", "Settings2",
|
|
34
35
|
];
|
|
35
36
|
return Object.fromEntries(names.map((n) => [n, icon(n)]));
|
|
36
37
|
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// @feat:inbox-thread
|
|
2
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
3
|
+
import { describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { GenesisModulesProvider } from "../../native-modules";
|
|
5
|
+
import { NativeComposerBar } from "../composer-bar";
|
|
6
|
+
import { fakeIcon } from "../../__tests__/fake-modules";
|
|
7
|
+
|
|
8
|
+
const base = { value: "", onChangeText: vi.fn(), onSend: vi.fn() };
|
|
9
|
+
|
|
10
|
+
describe("NativeComposerBar", () => {
|
|
11
|
+
it("won't send a blank message, and sends a written one", () => {
|
|
12
|
+
const onSend = vi.fn();
|
|
13
|
+
const { rerender } = render(<NativeComposerBar {...base} onSend={onSend} value=" " testID="c" />);
|
|
14
|
+
expect(screen.getByTestId("c-send").getAttribute("aria-disabled")).toBe("true");
|
|
15
|
+
rerender(<NativeComposerBar {...base} onSend={onSend} value="Hi" testID="c" />);
|
|
16
|
+
fireEvent.click(screen.getByTestId("c-send"));
|
|
17
|
+
expect(onSend).toHaveBeenCalledTimes(1);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("spins instead of sending twice", () => {
|
|
21
|
+
render(<NativeComposerBar {...base} value="Hi" sending testID="c" />);
|
|
22
|
+
expect(screen.getByTestId("c-sending").getAttribute("aria-label")).toBe("Sending");
|
|
23
|
+
expect(screen.queryByTestId("c-send")).toBeNull();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("draws the arrow with an icon module, and says Send without one", () => {
|
|
27
|
+
const { unmount } = render(<NativeComposerBar {...base} value="Hi" testID="c" />);
|
|
28
|
+
expect(screen.getByTestId("c-send").textContent).toBe("Send");
|
|
29
|
+
unmount();
|
|
30
|
+
render(
|
|
31
|
+
<GenesisModulesProvider modules={{ icons: { "arrow-up": fakeIcon("arrow-up") } }}>
|
|
32
|
+
<NativeComposerBar {...base} value="Hi" testID="c" />
|
|
33
|
+
</GenesisModulesProvider>,
|
|
34
|
+
);
|
|
35
|
+
expect(screen.getByTestId("c-send").querySelector('[data-lucide="arrow-up"]')).toBeTruthy();
|
|
36
|
+
expect(screen.getByTestId("c-send").getAttribute("aria-label")).toBe("Send");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("shows the mode picker only with two or more modes, and switches", () => {
|
|
40
|
+
const onModeChange = vi.fn();
|
|
41
|
+
const { rerender } = render(<NativeComposerBar {...base} modes={[{ id: "reply", label: "Reply" }]} testID="c" />);
|
|
42
|
+
expect(screen.queryByTestId("c-modes")).toBeNull();
|
|
43
|
+
rerender(
|
|
44
|
+
<NativeComposerBar {...base} modes={[{ id: "reply", label: "Reply" }, { id: "note", label: "Internal note", tone: "internal" }]} onModeChange={onModeChange} testID="c" />,
|
|
45
|
+
);
|
|
46
|
+
expect(screen.getByTestId("c-mode-reply").getAttribute("aria-selected")).toBe("true");
|
|
47
|
+
fireEvent.click(screen.getByTestId("c-mode-note"));
|
|
48
|
+
expect(onModeChange).toHaveBeenCalledWith("note");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("fills its slots", () => {
|
|
52
|
+
render(<NativeComposerBar {...base} leading={<i data-testid="attach" />} trailing={<i data-testid="mic" />} above={<i data-testid="reply-to" />} testID="c" />);
|
|
53
|
+
for (const id of ["attach", "mic", "reply-to"]) expect(screen.getByTestId(id)).toBeTruthy();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** NativeGalleryCard: cover at a ratio, overlays, footer, button with onPress. */
|
|
2
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
3
|
+
import { describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { NativeGalleryCard } from "../gallery-card";
|
|
5
|
+
|
|
6
|
+
describe("NativeGalleryCard", () => {
|
|
7
|
+
it("draws the cover at the ratio with title, subtitle, badges and actions", () => {
|
|
8
|
+
render(
|
|
9
|
+
<NativeGalleryCard
|
|
10
|
+
src="https://example.test/cover.jpg"
|
|
11
|
+
alt="A cover"
|
|
12
|
+
title="Morning session"
|
|
13
|
+
subtitle="12 photos"
|
|
14
|
+
ratio={16 / 9}
|
|
15
|
+
badges={<span data-testid="badge">New</span>}
|
|
16
|
+
actions={<span data-testid="action">…</span>}
|
|
17
|
+
testID="c"
|
|
18
|
+
/>,
|
|
19
|
+
);
|
|
20
|
+
expect(screen.getByTestId("c").getAttribute("role")).toBeNull();
|
|
21
|
+
expect(JSON.parse((screen.getByTestId("c-cover") as HTMLElement).dataset.style!).aspectRatio).toBeCloseTo(16 / 9, 5);
|
|
22
|
+
expect(screen.getByTestId("c-title").textContent).toBe("Morning session");
|
|
23
|
+
expect(screen.getByTestId("c-subtitle").textContent).toBe("12 photos");
|
|
24
|
+
expect(screen.getByTestId("c-badges").contains(screen.getByTestId("badge"))).toBe(true);
|
|
25
|
+
expect(screen.getByTestId("c-actions").contains(screen.getByTestId("action"))).toBe(true);
|
|
26
|
+
expect(screen.getByLabelText("A cover")).toBeTruthy();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("defaults to 4:3 and no footer", () => {
|
|
30
|
+
render(<NativeGalleryCard src="https://example.test/cover.jpg" testID="c" />);
|
|
31
|
+
expect(JSON.parse((screen.getByTestId("c-cover") as HTMLElement).dataset.style!).aspectRatio).toBeCloseTo(4 / 3, 5);
|
|
32
|
+
expect(screen.queryByTestId("c-footer")).toBeNull();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("is a button with onPress", () => {
|
|
36
|
+
const onPress = vi.fn();
|
|
37
|
+
render(<NativeGalleryCard src="https://example.test/cover.jpg" title="Tap" onPress={onPress} testID="c" />);
|
|
38
|
+
const card = screen.getByTestId("c");
|
|
39
|
+
expect(card.getAttribute("role")).toBe("button");
|
|
40
|
+
expect(card.getAttribute("aria-label")).toBe("Tap");
|
|
41
|
+
fireEvent.click(card);
|
|
42
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe("NativeGalleryCard additions", () => {
|
|
47
|
+
it("draws a skeleton cover without src", () => {
|
|
48
|
+
render(<NativeGalleryCard title="Pending" testID="c" />);
|
|
49
|
+
expect(screen.getByTestId("c-skeleton")).toBeTruthy();
|
|
50
|
+
expect(screen.queryByRole("img")).toBeNull();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("draws a skeleton cover while loading, and is busy", () => {
|
|
54
|
+
render(<NativeGalleryCard src="https://example.test/cover.jpg" alt="A cover" loading testID="c" />);
|
|
55
|
+
expect(screen.getByTestId("c-skeleton")).toBeTruthy();
|
|
56
|
+
expect(screen.queryByLabelText("A cover")).toBeNull();
|
|
57
|
+
expect(screen.getByTestId("c").getAttribute("aria-busy")).toBe("true");
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/** NativeGalleryGrid: justified rows from the measured width, tappable tiles. */
|
|
2
|
+
import { act, fireEvent, render, screen } from "@testing-library/react";
|
|
3
|
+
import { describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { GALLERY_DEFAULTS, type GalleryItem } from "../gallery-types";
|
|
5
|
+
import { NativeGalleryGrid } from "../gallery-grid";
|
|
6
|
+
|
|
7
|
+
const items: GalleryItem[] = Array.from({ length: 5 }, (_, i) => ({
|
|
8
|
+
id: `p${i}`,
|
|
9
|
+
src: `https://example.test/${i}.jpg`,
|
|
10
|
+
alt: `Photo ${i}`,
|
|
11
|
+
width: 400,
|
|
12
|
+
height: 300,
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
const style = (el: HTMLElement) => JSON.parse(el.dataset.style!) as { width: number; height: number };
|
|
16
|
+
|
|
17
|
+
/** Measure the grid: the shim turns a `layout` DOM event into onLayout. */
|
|
18
|
+
function measure(el: HTMLElement, width: number) {
|
|
19
|
+
act(() => {
|
|
20
|
+
el.dispatchEvent(new CustomEvent("layout", { detail: { width, height: 0 } }));
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
describe("NativeGalleryGrid", () => {
|
|
25
|
+
it("draws nothing until the container is measured, then a tile per item", () => {
|
|
26
|
+
render(<NativeGalleryGrid items={items} testID="g" />);
|
|
27
|
+
expect(screen.queryByTestId("g-item-p0")).toBeNull();
|
|
28
|
+
measure(screen.getByTestId("g"), 600);
|
|
29
|
+
expect(screen.getAllByTestId(/^g-item-/)).toHaveLength(5);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("grid layout: square tiles, `columns` per row", () => {
|
|
33
|
+
render(<NativeGalleryGrid items={items} layout="grid" columns={2} gap={10} testID="g" />);
|
|
34
|
+
measure(screen.getByTestId("g"), 210);
|
|
35
|
+
expect(style(screen.getByTestId("g-item-p0"))).toEqual({ width: 100, height: 100 });
|
|
36
|
+
expect(screen.getAllByTestId(/^g-item-/)).toHaveLength(5);
|
|
37
|
+
expect(screen.queryAllByRole("button")).toHaveLength(0);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("justified layout: rows fill the width and tiles are buttons with onItemPress", () => {
|
|
41
|
+
const onItemPress = vi.fn();
|
|
42
|
+
render(<NativeGalleryGrid items={items} rowHeight={100} gap={4} onItemPress={onItemPress} testID="g" />);
|
|
43
|
+
measure(screen.getByTestId("g"), 600);
|
|
44
|
+
const tiles = screen.getAllByRole("button");
|
|
45
|
+
expect(tiles).toHaveLength(5);
|
|
46
|
+
expect(tiles[0].getAttribute("aria-label")).toBe("Photo 0");
|
|
47
|
+
const first = style(tiles[0]);
|
|
48
|
+
expect(first.height).toBeGreaterThan(0);
|
|
49
|
+
fireEvent.click(screen.getByTestId("g-item-p2"));
|
|
50
|
+
expect(onItemPress).toHaveBeenCalledWith(items[2], 2);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("renderItem replaces the tile's content", () => {
|
|
54
|
+
render(<NativeGalleryGrid items={items.slice(0, 1)} renderItem={(it) => <span data-testid={`custom-${it.id}`}>x</span>} testID="g" />);
|
|
55
|
+
measure(screen.getByTestId("g"), 300);
|
|
56
|
+
expect(screen.getByTestId("custom-p0")).toBeTruthy();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe("NativeGalleryGrid additions", () => {
|
|
61
|
+
it("overlays renderBadges on the default tile", () => {
|
|
62
|
+
render(<NativeGalleryGrid items={items.slice(0, 2)} renderBadges={(it) => <span data-testid={`b-${it.id}`}>new</span>} testID="g" />);
|
|
63
|
+
measure(screen.getByTestId("g"), 600);
|
|
64
|
+
expect(screen.getByTestId("g-badges-p0").contains(screen.getByTestId("b-p0"))).toBe(true);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("a press only selects when onSelectionChange is set, not also onItemPress", () => {
|
|
68
|
+
const onItemPress = vi.fn();
|
|
69
|
+
const onSelectionChange = vi.fn();
|
|
70
|
+
render(<NativeGalleryGrid items={items} onItemPress={onItemPress} onSelectionChange={onSelectionChange} testID="g" />);
|
|
71
|
+
measure(screen.getByTestId("g"), 600);
|
|
72
|
+
fireEvent.click(screen.getByTestId("g-item-p0"));
|
|
73
|
+
expect(onSelectionChange).toHaveBeenCalledTimes(1);
|
|
74
|
+
expect(onItemPress).not.toHaveBeenCalled();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("toggles selection on press, ringing selected tiles", () => {
|
|
78
|
+
const onSelectionChange = vi.fn();
|
|
79
|
+
render(<NativeGalleryGrid items={items} selected={["p1"]} onSelectionChange={onSelectionChange} testID="g" />);
|
|
80
|
+
measure(screen.getByTestId("g"), 600);
|
|
81
|
+
const chosen = screen.getByTestId("g-item-p1");
|
|
82
|
+
expect(chosen.getAttribute("aria-selected")).toBe("true");
|
|
83
|
+
expect(chosen.className).toContain("border-ring");
|
|
84
|
+
expect(screen.getByTestId("g-item-p0").getAttribute("aria-selected")).toBe("false");
|
|
85
|
+
fireEvent.click(screen.getByTestId("g-item-p0"));
|
|
86
|
+
expect(onSelectionChange).toHaveBeenCalledWith(["p1", "p0"], { item: items[0], index: 0 });
|
|
87
|
+
fireEvent.click(chosen);
|
|
88
|
+
expect(onSelectionChange).toHaveBeenLastCalledWith([], { item: items[1], index: 1 });
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("calls loadMore only when scrolling nears the end, not on measure or on new items", () => {
|
|
92
|
+
const loadMore = vi.fn();
|
|
93
|
+
const many = Array.from({ length: 60 }, (_, i) => ({ id: `m${i}`, src: `https://example.test/m${i}.jpg`, width: 400, height: 300 }));
|
|
94
|
+
const { rerender } = render(<NativeGalleryGrid items={many} loadMore={loadMore} testID="g" />);
|
|
95
|
+
measure(screen.getByTestId("g"), 600);
|
|
96
|
+
rerender(<NativeGalleryGrid items={[...many, { id: "x", src: "https://example.test/x.jpg" }]} loadMore={loadMore} testID="g" />);
|
|
97
|
+
expect(loadMore).not.toHaveBeenCalled();
|
|
98
|
+
act(() => {
|
|
99
|
+
screen.getByTestId("g-list").dispatchEvent(new Event("endreached"));
|
|
100
|
+
});
|
|
101
|
+
expect(loadMore).toHaveBeenCalledTimes(1);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("renders the rows through a list with a header and footer, and sizes grid tiles by aspectRatio", () => {
|
|
105
|
+
render(
|
|
106
|
+
<NativeGalleryGrid items={items} layout="grid" columns={2} gap={10} aspectRatio={2} header={<span>Top</span>} footer={<span>More</span>} testID="g" />,
|
|
107
|
+
);
|
|
108
|
+
measure(screen.getByTestId("g"), 210);
|
|
109
|
+
expect(screen.getByTestId("g-list").textContent).toMatch(/^Top.*More$/);
|
|
110
|
+
expect(style(screen.getByTestId("g-item-p0"))).toEqual({ width: 100, height: 50 });
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("still takes the deprecated onNearEnd and getGroup", () => {
|
|
114
|
+
const onNearEnd = vi.fn();
|
|
115
|
+
render(<NativeGalleryGrid items={items} onNearEnd={onNearEnd} getGroup={() => "All"} testID="g" />);
|
|
116
|
+
measure(screen.getByTestId("g"), 600);
|
|
117
|
+
act(() => {
|
|
118
|
+
screen.getByTestId("g-list").dispatchEvent(new Event("endreached"));
|
|
119
|
+
});
|
|
120
|
+
expect(onNearEnd).toHaveBeenCalledTimes(1);
|
|
121
|
+
expect(screen.getByTestId("g-group-All")).toBeTruthy();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("draws an item with no image as a neutral tile with its words, still named and pressable", () => {
|
|
125
|
+
const onItemPress = vi.fn();
|
|
126
|
+
render(<NativeGalleryGrid items={[{ id: "n", src: "", alt: "Untitled", caption: "No photo yet" }]} onItemPress={onItemPress} testID="g" />);
|
|
127
|
+
measure(screen.getByTestId("g"), 300);
|
|
128
|
+
const tile = screen.getByTestId("g-item-n");
|
|
129
|
+
expect(tile.getAttribute("aria-label")).toBe("Untitled");
|
|
130
|
+
expect(tile.querySelector("img")).toBeNull();
|
|
131
|
+
expect(screen.getByTestId("g-placeholder-n").textContent).toBe("UntitledNo photo yet");
|
|
132
|
+
fireEvent.click(tile);
|
|
133
|
+
expect(onItemPress).toHaveBeenCalledWith(expect.objectContaining({ id: "n" }), 0);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("names a plain (not pressable) placeholder tile as an image", () => {
|
|
137
|
+
render(<NativeGalleryGrid items={[{ id: "n", src: "", alt: "Untitled" }]} testID="g" />);
|
|
138
|
+
measure(screen.getByTestId("g"), 300);
|
|
139
|
+
const placeholder = screen.getByTestId("g-placeholder-n");
|
|
140
|
+
expect(placeholder.getAttribute("role")).toBe("image");
|
|
141
|
+
expect(placeholder.getAttribute("aria-label")).toBe("Untitled");
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("shares the web's defaults", () => {
|
|
145
|
+
expect(GALLERY_DEFAULTS).toEqual({ rowHeight: 180, gap: 4, columns: 3 });
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("groups items in order of first appearance under headers", () => {
|
|
149
|
+
const grouped = items.map((it, i) => ({ ...it, caption: i % 2 ? "Odd" : "Even" }));
|
|
150
|
+
const onItemPress = vi.fn();
|
|
151
|
+
render(<NativeGalleryGrid items={grouped} groupBy={(it) => it.caption!} onItemPress={onItemPress} testID="g" />);
|
|
152
|
+
measure(screen.getByTestId("g"), 600);
|
|
153
|
+
const headers = screen.getAllByRole("header").map((h) => h.textContent);
|
|
154
|
+
expect(headers).toEqual(["Even", "Odd"]);
|
|
155
|
+
expect(screen.getByTestId("g-group-Odd").textContent).toBe("Odd");
|
|
156
|
+
expect(screen.getAllByTestId("g-row-Odd").some((row) => row.contains(screen.getByTestId("g-item-p1")))).toBe(true);
|
|
157
|
+
fireEvent.click(screen.getByTestId("g-item-p3"));
|
|
158
|
+
expect(onItemPress).toHaveBeenCalledWith(grouped[3], 3);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** NativeLightbox re-snaps to the current page when the width changes (rotation). */
|
|
2
|
+
import { act, render, screen } from "@testing-library/react";
|
|
3
|
+
import { forwardRef, useImperativeHandle } from "react";
|
|
4
|
+
import { describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { NativeLightbox } from "../lightbox";
|
|
6
|
+
|
|
7
|
+
const scrollToIndex = vi.fn();
|
|
8
|
+
const listProps: { current: Record<string, unknown> } = { current: {} };
|
|
9
|
+
|
|
10
|
+
vi.mock("react-native", async (importOriginal) => {
|
|
11
|
+
const actual = await importOriginal<Record<string, unknown>>();
|
|
12
|
+
const Original = actual.FlatList as React.ComponentType<Record<string, unknown>>;
|
|
13
|
+
const FlatList = forwardRef<{ scrollToIndex: typeof scrollToIndex }, Record<string, unknown>>((props, ref) => {
|
|
14
|
+
useImperativeHandle(ref, () => ({ scrollToIndex }));
|
|
15
|
+
listProps.current = props;
|
|
16
|
+
return <Original {...props} />;
|
|
17
|
+
});
|
|
18
|
+
return { ...actual, FlatList };
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const items = [
|
|
22
|
+
{ id: "a", src: "https://example.test/a.jpg" },
|
|
23
|
+
{ id: "b", src: "https://example.test/b.jpg" },
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
describe("NativeLightbox rotation", () => {
|
|
27
|
+
it("scrolls back to the current page, unanimated, when the width changes", () => {
|
|
28
|
+
render(<NativeLightbox open onOpenChange={() => undefined} items={items} index={1} onIndexChange={() => undefined} testID="lb" />);
|
|
29
|
+
expect(scrollToIndex).toHaveBeenLastCalledWith({ index: 1, animated: true });
|
|
30
|
+
scrollToIndex.mockClear();
|
|
31
|
+
act(() => {
|
|
32
|
+
screen.getByTestId("lb-content").dispatchEvent(new CustomEvent("layout", { detail: { width: 812, height: 375 } }));
|
|
33
|
+
});
|
|
34
|
+
expect(scrollToIndex).toHaveBeenCalledWith({ index: 1, animated: false });
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("scrolls back when a swipe's page isn't taken by the parent", () => {
|
|
38
|
+
vi.useFakeTimers();
|
|
39
|
+
const onIndexChange = vi.fn();
|
|
40
|
+
render(<NativeLightbox open onOpenChange={() => undefined} items={items} index={0} onIndexChange={onIndexChange} testID="lb" />);
|
|
41
|
+
scrollToIndex.mockClear();
|
|
42
|
+
act(() => {
|
|
43
|
+
(listProps.current.onMomentumScrollEnd as (e: unknown) => void)({ nativeEvent: { contentOffset: { x: 9999, y: 0 } } });
|
|
44
|
+
});
|
|
45
|
+
expect(onIndexChange).toHaveBeenCalledWith(1);
|
|
46
|
+
act(() => vi.runAllTimers());
|
|
47
|
+
expect(scrollToIndex).toHaveBeenCalledWith(expect.objectContaining({ index: 0 }));
|
|
48
|
+
vi.useRealTimers();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** The zoom and dismiss rules NativeLightbox's photo pages use (moved from genesis-chat's viewer). */
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
LIGHTBOX_DISMISS_DISTANCE,
|
|
5
|
+
LIGHTBOX_MAX_ZOOM,
|
|
6
|
+
lightboxPanLimit,
|
|
7
|
+
lightboxPinchScale,
|
|
8
|
+
lightboxShouldDismiss,
|
|
9
|
+
lightboxTouchDistance,
|
|
10
|
+
} from "../lightbox-zoom";
|
|
11
|
+
|
|
12
|
+
describe("lightbox zoom rules", () => {
|
|
13
|
+
it("closes on a long pull or a quick flick down, not a nudge", () => {
|
|
14
|
+
expect(lightboxShouldDismiss(LIGHTBOX_DISMISS_DISTANCE + 1, 0)).toBe(true);
|
|
15
|
+
expect(lightboxShouldDismiss(30, 1.5)).toBe(true);
|
|
16
|
+
expect(lightboxShouldDismiss(20, 3)).toBe(false);
|
|
17
|
+
expect(lightboxShouldDismiss(60, 0.2)).toBe(false);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("zooms with the fingers' spread, between 0.8× and the maximum", () => {
|
|
21
|
+
expect(lightboxPinchScale(1, 100, 200)).toBe(2);
|
|
22
|
+
expect(lightboxPinchScale(2, 100, 1000)).toBe(LIGHTBOX_MAX_ZOOM);
|
|
23
|
+
expect(lightboxPinchScale(1, 100, 10)).toBe(0.8);
|
|
24
|
+
expect(lightboxPinchScale(1.5, 0, 50)).toBe(1.5);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("measures two touches, and pans only as far as the zoomed photo reaches", () => {
|
|
28
|
+
expect(lightboxTouchDistance([{ pageX: 0, pageY: 0 }, { pageX: 3, pageY: 4 }])).toBe(5);
|
|
29
|
+
expect(lightboxTouchDistance([{ pageX: 0, pageY: 0 }])).toBe(0);
|
|
30
|
+
expect(lightboxPanLimit(1, 400)).toBe(0);
|
|
31
|
+
expect(lightboxPanLimit(2, 400)).toBe(200);
|
|
32
|
+
});
|
|
33
|
+
});
|