@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.
Files changed (89) hide show
  1. package/README.md +71 -7
  2. package/dist/{chunk-LBVD7XXL.js → chunk-2Z72MYHB.js} +627 -20
  3. package/dist/chunk-2Z72MYHB.js.map +1 -0
  4. package/dist/chunk-4OQOJ2OC.js +80 -0
  5. package/dist/chunk-4OQOJ2OC.js.map +1 -0
  6. package/dist/{chunk-6KWEAGRD.js → chunk-6PGLX6ET.js} +101 -6
  7. package/dist/chunk-6PGLX6ET.js.map +1 -0
  8. package/dist/{chunk-ONH2PCGH.js → chunk-AGTBABAH.js} +9 -15
  9. package/dist/chunk-AGTBABAH.js.map +1 -0
  10. package/dist/{chunk-ABVSSJNT.js → chunk-FUMSL7VZ.js} +198 -168
  11. package/dist/chunk-FUMSL7VZ.js.map +1 -0
  12. package/dist/{chunk-GHYUNNNU.js → chunk-NDXNSSM6.js} +175 -93
  13. package/dist/chunk-NDXNSSM6.js.map +1 -0
  14. package/dist/chunk-SEJ6RBP7.js +361 -0
  15. package/dist/chunk-SEJ6RBP7.js.map +1 -0
  16. package/dist/{chunk-D5RKSPMH.js → chunk-ZRQAFFTN.js} +4 -3
  17. package/dist/chunk-ZRQAFFTN.js.map +1 -0
  18. package/dist/components/index.d.ts +331 -4
  19. package/dist/components/index.js +5 -5
  20. package/dist/data/index.d.ts +68 -4
  21. package/dist/data/index.js +231 -30
  22. package/dist/data/index.js.map +1 -1
  23. package/dist/hooks/index.d.ts +60 -1
  24. package/dist/hooks/index.js +2 -3
  25. package/dist/icons/lucide.d.ts +1 -1
  26. package/dist/icons/lucide.js +7 -1
  27. package/dist/icons/lucide.js.map +1 -1
  28. package/dist/{inbox-page-BEarNEIP.d.ts → inbox-page-B7_Oi2fS.d.ts} +2 -44
  29. package/dist/index.d.ts +8 -5
  30. package/dist/index.js +8 -8
  31. package/dist/layouts/index.d.ts +40 -51
  32. package/dist/layouts/index.js +5 -4
  33. package/dist/{native-modules-PwnGltOU.d.ts → native-modules-Cl3zw3kh.d.ts} +27 -1
  34. package/package.json +78 -4
  35. package/src/__tests__/doctor-rules.test.ts +60 -0
  36. package/src/__tests__/native-modules-lists.test.tsx +1 -0
  37. package/src/components/__tests__/composer-bar.test.tsx +55 -0
  38. package/src/components/__tests__/gallery-card.test.tsx +59 -0
  39. package/src/components/__tests__/gallery-grid.test.tsx +160 -0
  40. package/src/components/__tests__/lightbox-resnap.test.tsx +50 -0
  41. package/src/components/__tests__/lightbox-zoom.test.ts +33 -0
  42. package/src/components/__tests__/lightbox.test.tsx +141 -0
  43. package/src/components/__tests__/live-indicator.test.tsx +72 -0
  44. package/src/components/__tests__/rating.test.tsx +82 -0
  45. package/src/components/__tests__/thread-list.test.tsx +156 -0
  46. package/src/components/composer-bar.tsx +198 -0
  47. package/src/components/drawer.tsx +15 -9
  48. package/src/components/gallery-card.tsx +109 -0
  49. package/src/components/gallery-grid.tsx +285 -0
  50. package/src/components/gallery-layout.ts +2 -0
  51. package/src/components/gallery-types.ts +2 -0
  52. package/src/components/index.ts +44 -0
  53. package/src/components/lightbox-zoom.tsx +282 -0
  54. package/src/components/lightbox.tsx +342 -0
  55. package/src/components/live-indicator.tsx +139 -0
  56. package/src/components/rating.tsx +128 -0
  57. package/src/components/skeleton.tsx +9 -4
  58. package/src/components/thread-list.tsx +427 -0
  59. package/src/components/toast.tsx +7 -4
  60. package/src/data/NativeConflictSheet.tsx +181 -0
  61. package/src/data/NativeResourceForm.tsx +15 -1
  62. package/src/data/index.ts +2 -0
  63. package/src/data/resource-view/NativeRecordView.tsx +85 -8
  64. package/src/data/resource-view/NativeResourceView.tsx +79 -32
  65. package/src/data/resource-view/__tests__/native-record-view.test.tsx +95 -1
  66. package/src/data/resource-view/__tests__/native-resource-gallery.test.tsx +125 -0
  67. package/src/hooks/__tests__/use-motion.test.tsx +106 -0
  68. package/src/hooks/__tests__/use-thread-jump.test.tsx +88 -0
  69. package/src/hooks/index.ts +3 -0
  70. package/src/hooks/use-motion.ts +128 -0
  71. package/src/hooks/use-thread-jump.ts +110 -0
  72. package/src/icon-names.ts +6 -0
  73. package/src/icons/lucide.ts +12 -0
  74. package/src/layouts/__tests__/inbox-page.test.tsx +6 -0
  75. package/src/layouts/__tests__/thread-page.test.tsx +114 -14
  76. package/src/layouts/inbox-page.tsx +6 -55
  77. package/src/layouts/index.ts +2 -0
  78. package/src/layouts/thread-page.tsx +326 -262
  79. package/src/native-modules.tsx +16 -2
  80. package/dist/chunk-6KWEAGRD.js.map +0 -1
  81. package/dist/chunk-7PCWEY6R.js +0 -27
  82. package/dist/chunk-7PCWEY6R.js.map +0 -1
  83. package/dist/chunk-ABVSSJNT.js.map +0 -1
  84. package/dist/chunk-D5RKSPMH.js.map +0 -1
  85. package/dist/chunk-GHYUNNNU.js.map +0 -1
  86. package/dist/chunk-LBVD7XXL.js.map +0 -1
  87. package/dist/chunk-ONH2PCGH.js.map +0 -1
  88. package/dist/chunk-Z3AQYVUA.js +0 -36
  89. package/dist/chunk-Z3AQYVUA.js.map +0 -1
@@ -0,0 +1,141 @@
1
+ /** NativeLightbox: a full-screen pager with close, counter, caption and actions. */
2
+ import { fireEvent, render, screen } from "@testing-library/react";
3
+ import { describe, expect, it, vi } from "vitest";
4
+ import type { GalleryItem } from "../gallery-types";
5
+ import { NativeLightbox } from "../lightbox";
6
+
7
+ const items: GalleryItem[] = [
8
+ { id: "a", src: "https://example.test/a.jpg", alt: "First", caption: "Warm-up" },
9
+ { id: "b", src: "https://example.test/b.jpg", alt: "Second", caption: "Lift" },
10
+ { id: "c", src: "https://example.test/c.jpg" },
11
+ ];
12
+
13
+ describe("NativeLightbox", () => {
14
+ it("renders nothing while closed", () => {
15
+ render(<NativeLightbox open={false} onOpenChange={() => undefined} items={items} index={0} onIndexChange={() => undefined} testID="lb" />);
16
+ expect(screen.queryByTestId("lb")).toBeNull();
17
+ });
18
+
19
+ it("shows every page, the counter and the current caption on a dark full-screen modal", () => {
20
+ render(<NativeLightbox open onOpenChange={() => undefined} items={items} index={1} onIndexChange={() => undefined} testID="lb" />);
21
+ expect(screen.getByTestId("lb").getAttribute("data-presentation-style")).toBe("overFullScreen");
22
+ // The backdrop is its own layer, so a pull down can fade it.
23
+ const backdrop = screen.getByTestId("lb-content").firstElementChild as HTMLElement;
24
+ expect(JSON.parse(backdrop.dataset.style!).backgroundColor).toBe("#000000");
25
+ expect(screen.getByTestId("lb-counter").textContent).toBe("2 / 3");
26
+ expect(screen.getByTestId("lb-caption").textContent).toBe("Lift");
27
+ expect(screen.getByTestId("lb-page-a")).toBeTruthy();
28
+ expect(screen.getByTestId("lb-page-c")).toBeTruthy();
29
+ });
30
+
31
+ it("closes from the top-left button", () => {
32
+ const onOpenChange = vi.fn();
33
+ render(<NativeLightbox open onOpenChange={onOpenChange} items={items} index={0} onIndexChange={() => undefined} testID="lb" />);
34
+ const close = screen.getByTestId("lb-close");
35
+ expect(close.getAttribute("aria-label")).toBe("Close");
36
+ fireEvent.click(close);
37
+ expect(onOpenChange).toHaveBeenCalledWith(false);
38
+ });
39
+
40
+ it("renders custom caption and actions for the current item", () => {
41
+ render(
42
+ <NativeLightbox
43
+ open
44
+ onOpenChange={() => undefined}
45
+ items={items}
46
+ index={2}
47
+ onIndexChange={() => undefined}
48
+ renderCaption={(it, i) => <span data-testid="cap">{`${it.id}#${i}`}</span>}
49
+ renderActions={(it) => <span data-testid="act">{it.id}</span>}
50
+ testID="lb"
51
+ />,
52
+ );
53
+ expect(screen.getByTestId("cap").textContent).toBe("c#2");
54
+ expect(screen.getByTestId("lb-actions").contains(screen.getByTestId("act"))).toBe(true);
55
+ expect(screen.getByTestId("lb-counter").textContent).toBe("3 / 3");
56
+ });
57
+
58
+ it("shows no counter for a single picture", () => {
59
+ render(<NativeLightbox open onOpenChange={() => undefined} items={items.slice(0, 1)} index={0} onIndexChange={() => undefined} testID="lb" />);
60
+ expect(screen.queryByTestId("lb-counter")).toBeNull();
61
+ });
62
+
63
+ it("clamps an out-of-range index", () => {
64
+ render(<NativeLightbox open onOpenChange={() => undefined} items={items} index={9} onIndexChange={() => undefined} testID="lb" />);
65
+ expect(screen.getByTestId("lb-counter").textContent).toBe("3 / 3");
66
+ });
67
+ });
68
+
69
+ describe("NativeLightbox additions", () => {
70
+ it("renderMedia replaces each page's picture", () => {
71
+ render(
72
+ <NativeLightbox open onOpenChange={() => undefined} items={items} index={0} onIndexChange={() => undefined} renderMedia={(it, i) => <span data-testid={`m-${it.id}`}>{i}</span>} testID="lb" />,
73
+ );
74
+ expect(screen.getByTestId("lb-page-b").contains(screen.getByTestId("m-b"))).toBe(true);
75
+ expect(screen.getByTestId("m-c").textContent).toBe("2");
76
+ expect(screen.queryByRole("img")).toBeNull();
77
+ });
78
+
79
+ it("shows title and description in the top bar and labels the viewer with the title", () => {
80
+ render(
81
+ <NativeLightbox open onOpenChange={() => undefined} items={items} index={0} onIndexChange={() => undefined} title="Session photos" description="3 March" testID="lb" />,
82
+ );
83
+ expect(screen.getByTestId("lb-title").textContent).toBe("Session photos");
84
+ expect(screen.getByTestId("lb-title").getAttribute("role")).toBe("header");
85
+ expect(screen.getByTestId("lb-description").textContent).toBe("3 March");
86
+ expect(screen.getByTestId("lb-content").getAttribute("aria-label")).toBe("Session photos");
87
+ expect(screen.getByTestId("lb-counter").textContent).toBe("1 / 3");
88
+ });
89
+
90
+ it("gives screen readers an adjustable pager that reads the position and steps through the items", () => {
91
+ const onIndexChange = vi.fn();
92
+ render(<NativeLightbox open onOpenChange={() => undefined} items={items} index={1} onIndexChange={onIndexChange} testID="lb" />);
93
+ const pager = screen.getByTestId("lb-pager-a11y");
94
+ expect(pager.getAttribute("role")).toBe("adjustable");
95
+ expect(pager.getAttribute("aria-label")).toBe("Second");
96
+ expect(pager.getAttribute("aria-valuetext")).toBe("2 of 3");
97
+ fireEvent(pager, new CustomEvent("accessibilityaction", { detail: "increment" }));
98
+ expect(onIndexChange).toHaveBeenLastCalledWith(2);
99
+ fireEvent(pager, new CustomEvent("accessibilityaction", { detail: "decrement" }));
100
+ expect(onIndexChange).toHaveBeenLastCalledWith(0);
101
+ });
102
+
103
+ it("names a picture with no alt by its position, and leaves renderMedia pages to themselves", () => {
104
+ render(
105
+ <NativeLightbox open onOpenChange={() => undefined} items={items} index={2} onIndexChange={() => undefined} renderMedia={(it) => <span>video {it.id}</span>} testID="lb" />,
106
+ );
107
+ expect(screen.getByTestId("lb-pager-a11y").getAttribute("aria-label")).toBe("Photo 3 of 3");
108
+ expect(screen.getByTestId("lb-page-c").textContent).toBe("video c");
109
+ expect(screen.queryByTestId("lb-photo-c")).toBeNull();
110
+ });
111
+
112
+ it("with renderMedia, keeps the pages ungrouped so their own controls stay reachable, and the counter is the pager", () => {
113
+ const onIndexChange = vi.fn();
114
+ render(
115
+ <NativeLightbox
116
+ open
117
+ onOpenChange={() => undefined}
118
+ items={items}
119
+ index={0}
120
+ onIndexChange={onIndexChange}
121
+ renderMedia={(it) => <button data-testid={`play-${it.id}`}>Play</button>}
122
+ testID="lb"
123
+ />,
124
+ );
125
+ const pages = screen.getByTestId("lb-pages");
126
+ expect(pages.getAttribute("role")).toBeNull();
127
+ expect(pages.contains(screen.getByTestId("play-a"))).toBe(true);
128
+ const pager = screen.getByTestId("lb-pager-a11y");
129
+ expect(pager.contains(screen.getByTestId("lb-counter"))).toBe(true);
130
+ expect(pager.getAttribute("role")).toBe("adjustable");
131
+ expect(pager.getAttribute("aria-valuetext")).toBe("1 of 3");
132
+ fireEvent(pager, new CustomEvent("accessibilityaction", { detail: "increment" }));
133
+ expect(onIndexChange).toHaveBeenLastCalledWith(1);
134
+ });
135
+
136
+ it("zooms the built-in photo pages, and lets the words change", () => {
137
+ render(<NativeLightbox open onOpenChange={() => undefined} items={items} index={0} onIndexChange={() => undefined} labels={{ close: "Fermer" }} testID="lb" />);
138
+ expect(screen.getByTestId("lb-photo-a")).toBeTruthy();
139
+ expect(screen.getByTestId("lb-close").getAttribute("aria-label")).toBe("Fermer");
140
+ });
141
+ });
@@ -0,0 +1,72 @@
1
+ /** NativeLiveIndicator: a polite text live region with a red dot when live, grey when not. */
2
+ import { render, screen } from "@testing-library/react";
3
+ import { AccessibilityInfo } from "react-native";
4
+ import { describe, expect, it, vi } from "vitest";
5
+ import { NativeLiveIndicator } from "../live-indicator";
6
+
7
+ describe("NativeLiveIndicator", () => {
8
+ it("is a pill reading 'Live' with a destructive dot by default", () => {
9
+ render(<NativeLiveIndicator testID="li" />);
10
+ const root = screen.getByTestId("li");
11
+ expect(root.getAttribute("role")).toBe("text");
12
+ expect(root.getAttribute("aria-label")).toBe("Live");
13
+ expect(screen.getByTestId("li-label").textContent).toBe("Live");
14
+ expect(screen.getByTestId("li-dot").className).toContain("bg-destructive");
15
+ });
16
+
17
+ it("goes muted and says so when not live", () => {
18
+ render(<NativeLiveIndicator live={false} label="On air" testID="li" />);
19
+ expect(screen.getByTestId("li").getAttribute("aria-label")).toBe("Not on air");
20
+ expect(screen.getByTestId("li-dot").className).toContain("bg-muted-foreground");
21
+ expect(screen.getByTestId("li-label").textContent).toBe("On air");
22
+ });
23
+
24
+ it("dot variant keeps the label for screen readers only", () => {
25
+ render(<NativeLiveIndicator variant="dot" testID="li" />);
26
+ expect(screen.getByTestId("li").getAttribute("aria-label")).toBe("Live");
27
+ expect(screen.queryByTestId("li-label")).toBeNull();
28
+ expect(screen.getByTestId("li-dot")).toBeTruthy();
29
+ });
30
+ });
31
+
32
+ describe("NativeLiveIndicator additions", () => {
33
+ it("state overrides live, offline is a faint dot", () => {
34
+ render(<NativeLiveIndicator live state="offline" testID="li" />);
35
+ expect(screen.getByTestId("li-dot").className).toContain("bg-muted-foreground/50");
36
+ expect(screen.getByTestId("li").getAttribute("aria-label")).toBe("Offline");
37
+ });
38
+
39
+ it("state idle matches live={false}", () => {
40
+ render(<NativeLiveIndicator state="idle" testID="li" />);
41
+ expect(screen.getByTestId("li-dot").className).toContain("bg-muted-foreground");
42
+ expect(screen.getByTestId("li-dot").className).not.toContain("/50");
43
+ expect(screen.getByTestId("li").getAttribute("aria-label")).toBe("Idle");
44
+ });
45
+
46
+ it("shows detail after the label and announces it", () => {
47
+ render(<NativeLiveIndicator detail="12 watching" testID="li" />);
48
+ expect(screen.getByTestId("li-detail").textContent).toBe("12 watching");
49
+ expect(screen.getByTestId("li-detail").className).toContain("text-muted-foreground");
50
+ expect(screen.getByTestId("li").getAttribute("aria-label")).toBe("Live, 12 watching");
51
+ });
52
+ });
53
+
54
+ describe("NativeLiveIndicator label and announcements", () => {
55
+ it("shows the state's own label unless one is given", () => {
56
+ const { rerender } = render(<NativeLiveIndicator state="idle" testID="li" />);
57
+ expect(screen.getByTestId("li-label").textContent).toBe("Idle");
58
+ rerender(<NativeLiveIndicator state="offline" testID="li" />);
59
+ expect(screen.getByTestId("li-label").textContent).toBe("Offline");
60
+ rerender(<NativeLiveIndicator state="offline" label="Stream" testID="li" />);
61
+ expect(screen.getByTestId("li-label").textContent).toBe("Stream");
62
+ });
63
+
64
+ it("announces a state change after mount, not the first render", () => {
65
+ const spy = vi.spyOn(AccessibilityInfo as unknown as Record<string, () => void>, "announceForAccessibilityWithOptions");
66
+ const { rerender } = render(<NativeLiveIndicator testID="li" />);
67
+ expect(spy).not.toHaveBeenCalled();
68
+ rerender(<NativeLiveIndicator state="offline" testID="li" />);
69
+ expect(spy).toHaveBeenCalledWith("Offline", { queue: true });
70
+ spy.mockRestore();
71
+ });
72
+ });
@@ -0,0 +1,82 @@
1
+ /** NativeRating: one image when read-only, radios when tappable. */
2
+ import { fireEvent, render, screen } from "@testing-library/react";
3
+ import type { ReactNode } from "react";
4
+ import { GenesisModulesProvider, type GenesisModules } from "../../native-modules";
5
+ import { describe, expect, it, vi } from "vitest";
6
+ import { NativeRating, nextRating } from "../rating";
7
+
8
+ describe("NativeRating", () => {
9
+ it("is a single image labelled 'N of M stars' when read-only", () => {
10
+ render(<NativeRating value={3} testID="r" />);
11
+ const root = screen.getByTestId("r");
12
+ expect(root.getAttribute("role")).toBe("image");
13
+ expect(root.getAttribute("aria-label")).toBe("3 of 5 stars");
14
+ expect(screen.queryAllByRole("radio")).toHaveLength(0);
15
+ expect(screen.getByTestId("r-star-5")).toBeTruthy();
16
+ });
17
+
18
+ it("honours max and label, and rounds the value", () => {
19
+ render(<NativeRating value={7.6} max={10} label="hearts" testID="r" />);
20
+ expect(screen.getByTestId("r").getAttribute("aria-label")).toBe("hearts: 8 of 10 stars");
21
+ expect(screen.getByTestId("r-star-10")).toBeTruthy();
22
+ expect(screen.queryByTestId("r-star-11")).toBeNull();
23
+ });
24
+
25
+ it("is a radiogroup of selectable stars with onChange", () => {
26
+ const onChange = vi.fn();
27
+ render(<NativeRating value={2} onChange={onChange} testID="r" />);
28
+ expect(screen.getByTestId("r").getAttribute("role")).toBe("radiogroup");
29
+ const radios = screen.getAllByRole("radio");
30
+ expect(radios).toHaveLength(5);
31
+ expect(screen.getByTestId("r-star-2").getAttribute("aria-selected")).toBe("true");
32
+ expect(screen.getByTestId("r-star-3").getAttribute("aria-selected")).toBe("false");
33
+ fireEvent.click(screen.getByTestId("r-star-4"));
34
+ expect(onChange).toHaveBeenCalledWith(4);
35
+ });
36
+ });
37
+
38
+ describe("NativeRating additions", () => {
39
+ it("nextRating clears when the current value is pressed again", () => {
40
+ expect(nextRating(3, 3)).toBe(0);
41
+ expect(nextRating(3, 4)).toBe(4);
42
+ expect(nextRating(0, 1)).toBe(1);
43
+ });
44
+
45
+ it("pressing the current star reports 0", () => {
46
+ const onChange = vi.fn();
47
+ render(<NativeRating value={2} onChange={onChange} testID="r" />);
48
+ fireEvent.click(screen.getByTestId("r-star-2"));
49
+ expect(onChange).toHaveBeenCalledWith(0);
50
+ });
51
+
52
+ it("readOnly wins over onChange, and getLabel writes the label", () => {
53
+ render(<NativeRating value={4} onChange={() => undefined} readOnly getLabel={(v, m) => `Rated ${v}/${m}`} testID="r" />);
54
+ const root = screen.getByTestId("r");
55
+ expect(root.getAttribute("role")).toBe("image");
56
+ expect(root.getAttribute("aria-label")).toBe("Rated 4/5");
57
+ expect(screen.queryAllByRole("radio")).toHaveLength(0);
58
+ });
59
+ });
60
+
61
+ describe("NativeRating accessibility", () => {
62
+ it("names the read-only control by label, then the count", () => {
63
+ render(<NativeRating value={3} label="Service rating" testID="r" />);
64
+ expect(screen.getByTestId("r").getAttribute("aria-label")).toBe("Service rating: 3 of 5 stars");
65
+ });
66
+
67
+ it("applies getLabel to each radio as well as the value", () => {
68
+ render(<NativeRating value={2} onChange={() => undefined} getLabel={(v, m) => `${v}/${m} hearts`} testID="r" />);
69
+ expect(screen.getByTestId("r-star-4").getAttribute("aria-label")).toBe("4/5 hearts");
70
+ expect(screen.getByTestId("r").getAttribute("aria-valuetext")).toBe("2/5 hearts");
71
+ });
72
+
73
+ it("distinguishes filled from empty fallback stars without colour", () => {
74
+ const modules = {
75
+ icons: { star: (p: { fill?: unknown; testID?: string }) => <i data-testid={p.testID} data-fill={String(p.fill)} /> },
76
+ } as unknown as GenesisModules;
77
+ const wrap = (node: ReactNode) => <GenesisModulesProvider modules={modules}>{node}</GenesisModulesProvider>;
78
+ render(wrap(<NativeRating value={1} testID="r" />));
79
+ expect(screen.getByTestId("r-star-1").getAttribute("data-fill")).not.toBe("none");
80
+ expect(screen.getByTestId("r-star-2").getAttribute("data-fill")).toBe("none");
81
+ });
82
+ });
@@ -0,0 +1,156 @@
1
+ // @feat:inbox-thread
2
+ import { forwardRef, useImperativeHandle, createRef } from "react";
3
+ import { act, fireEvent, render, screen, waitFor } from "@testing-library/react";
4
+ import { AccessibilityInfo } from "react-native";
5
+ import { afterEach, describe, expect, it, vi } from "vitest";
6
+ import { GenesisModulesProvider } from "../../native-modules";
7
+ import { NativeThreadList, threadListMode, threadNearBottom, type NativeThreadListHandle } from "../thread-list";
8
+
9
+ type Row = { id: string; text: string };
10
+ const rows: Row[] = [
11
+ { id: "a", text: "first" },
12
+ { id: "b", text: "second" },
13
+ { id: "c", text: "third" },
14
+ ];
15
+
16
+ /** A list module that records its props and the calls made through its ref. */
17
+ function recordingList() {
18
+ const calls = { props: [] as Record<string, unknown>[], scrollToIndex: vi.fn(), scrollToEnd: vi.fn(), scrollToOffset: vi.fn() };
19
+ const List = forwardRef<unknown, Record<string, any>>(function List(props, ref) {
20
+ calls.props.push(props);
21
+ useImperativeHandle(ref, () => ({ scrollToIndex: calls.scrollToIndex, scrollToEnd: calls.scrollToEnd, scrollToOffset: calls.scrollToOffset }));
22
+ return (
23
+ <div data-testid={props.testID} role={props.accessibilityRole}>
24
+ {props.ListHeaderComponent}
25
+ {props.data.map((item: Row, index: number) => (
26
+ <div key={props.keyExtractor(item)}>{props.renderItem({ item, index })}</div>
27
+ ))}
28
+ </div>
29
+ );
30
+ });
31
+ return { List, calls };
32
+ }
33
+
34
+ const renderRow = (r: Row) => <span data-testid={`row-${r.id}`}>{r.text}</span>;
35
+
36
+ afterEach(() => vi.restoreAllMocks());
37
+
38
+ describe("threadListMode", () => {
39
+ it("uses FlashList's chat mode, and FlatList's held position with following by hand", () => {
40
+ expect(threadListMode(true, false)).toEqual({
41
+ followsByHand: false,
42
+ maintainVisibleContentPosition: { startRenderingFromBottom: true, autoscrollToBottomThreshold: 0.2, animateAutoScrollToBottom: true },
43
+ });
44
+ expect(threadListMode(true, true).maintainVisibleContentPosition.animateAutoScrollToBottom).toBe(false);
45
+ // Anchored past the list header (child 0), so loading earlier rows from the very top keeps the place.
46
+ expect(threadListMode(false, false)).toEqual({ followsByHand: true, maintainVisibleContentPosition: { minIndexForVisible: 1 } });
47
+ });
48
+
49
+ it("counts near the bottom as the bottom", () => {
50
+ expect(threadNearBottom({ contentOffset: { y: 900 }, contentSize: { height: 1500 }, layoutMeasurement: { height: 500 } })).toBe(true);
51
+ expect(threadNearBottom({ contentOffset: { y: 100 }, contentSize: { height: 1500 }, layoutMeasurement: { height: 500 } })).toBe(false);
52
+ });
53
+ });
54
+
55
+ describe("NativeThreadList", () => {
56
+ it("renders oldest first as a list, through the app's FlashList in chat mode, not inverted", () => {
57
+ const { List, calls } = recordingList();
58
+ render(
59
+ <GenesisModulesProvider modules={{ list: List as never }}>
60
+ <NativeThreadList testID="l" data={rows} keyExtractor={(r) => r.id} renderItem={renderRow} getItemType={() => "theirs"} />
61
+ </GenesisModulesProvider>,
62
+ );
63
+ expect(screen.getByTestId("l").getAttribute("role")).toBe("list");
64
+ expect([...screen.getByTestId("l").querySelectorAll('[data-testid^="row-"]')].map((e) => e.textContent)).toEqual(["first", "second", "third"]);
65
+ const props = calls.props.at(-1)!;
66
+ expect(props.inverted).toBeUndefined();
67
+ expect(props.maintainVisibleContentPosition).toMatchObject({ startRenderingFromBottom: true });
68
+ expect(props.keyboardDismissMode).toBe("interactive");
69
+ });
70
+
71
+ it("loads earlier rows near the top, and offers the button too", () => {
72
+ const { List, calls } = recordingList();
73
+ const onLoadEarlier = vi.fn();
74
+ render(
75
+ <GenesisModulesProvider modules={{ list: List as never }}>
76
+ <NativeThreadList testID="l" data={rows} keyExtractor={(r) => r.id} renderItem={renderRow} hasEarlier onLoadEarlier={onLoadEarlier} />
77
+ </GenesisModulesProvider>,
78
+ );
79
+ (calls.props.at(-1)!.onStartReached as () => void)();
80
+ expect(onLoadEarlier).toHaveBeenCalledTimes(1);
81
+ fireEvent.click(screen.getByTestId("l-earlier"));
82
+ expect(onLoadEarlier).toHaveBeenCalledTimes(2);
83
+ });
84
+
85
+ it("doesn't load earlier rows while they're already loading", () => {
86
+ const { List, calls } = recordingList();
87
+ const onLoadEarlier = vi.fn();
88
+ render(
89
+ <GenesisModulesProvider modules={{ list: List as never }}>
90
+ <NativeThreadList testID="l" data={rows} keyExtractor={(r) => r.id} renderItem={renderRow} hasEarlier loadingEarlier onLoadEarlier={onLoadEarlier} />
91
+ </GenesisModulesProvider>,
92
+ );
93
+ (calls.props.at(-1)!.onStartReached as () => void)();
94
+ expect(onLoadEarlier).not.toHaveBeenCalled();
95
+ expect(screen.getByTestId("l-earlier-loading")).toBeTruthy();
96
+ });
97
+
98
+ it("reports leaving and coming back to the bottom", () => {
99
+ const { List, calls } = recordingList();
100
+ const onAtBottomChange = vi.fn();
101
+ render(
102
+ <GenesisModulesProvider modules={{ list: List as never }}>
103
+ <NativeThreadList testID="l" data={rows} keyExtractor={(r) => r.id} renderItem={renderRow} onAtBottomChange={onAtBottomChange} />
104
+ </GenesisModulesProvider>,
105
+ );
106
+ const scroll = calls.props.at(-1)!.onScroll as (e: unknown) => void;
107
+ scroll({ nativeEvent: { contentOffset: { y: 0 }, contentSize: { height: 2000 }, layoutMeasurement: { height: 500 } } });
108
+ expect(onAtBottomChange).toHaveBeenLastCalledWith(false);
109
+ scroll({ nativeEvent: { contentOffset: { y: 1500 }, contentSize: { height: 2000 }, layoutMeasurement: { height: 500 } } });
110
+ expect(onAtBottomChange).toHaveBeenLastCalledWith(true);
111
+ expect(onAtBottomChange).toHaveBeenCalledTimes(2);
112
+ });
113
+
114
+ it("goes to a row it holds, centred, and says where it landed", async () => {
115
+ const { List, calls } = recordingList();
116
+ const announce = vi.fn();
117
+ (AccessibilityInfo as { announceForAccessibility?: unknown }).announceForAccessibility = announce;
118
+ render(
119
+ <GenesisModulesProvider modules={{ list: List as never }}>
120
+ <NativeThreadList testID="l" data={rows} keyExtractor={(r) => r.id} renderItem={renderRow} jumpTo="b" jumpAnnouncement={(r) => r.text} />
121
+ </GenesisModulesProvider>,
122
+ );
123
+ await waitFor(() => expect(calls.scrollToIndex).toHaveBeenCalledWith(expect.objectContaining({ index: 1, viewPosition: 0.5 })));
124
+ expect(announce).toHaveBeenCalledWith("second");
125
+ });
126
+
127
+ it("loads until a row it doesn't hold, and says when it can't be found", async () => {
128
+ const { List } = recordingList();
129
+ const onLoadUntil = vi.fn(async () => false);
130
+ const onJumpFailed = vi.fn();
131
+ render(
132
+ <GenesisModulesProvider modules={{ list: List as never }}>
133
+ <NativeThreadList testID="l" data={rows} keyExtractor={(r) => r.id} renderItem={renderRow} jumpTo="gone" onLoadUntil={onLoadUntil} onJumpFailed={onJumpFailed} />
134
+ </GenesisModulesProvider>,
135
+ );
136
+ await waitFor(() => expect(onJumpFailed).toHaveBeenCalledWith("gone"));
137
+ expect(onLoadUntil).toHaveBeenCalledWith("gone");
138
+ });
139
+
140
+ it("goes to the newest row through its handle", async () => {
141
+ const { List, calls } = recordingList();
142
+ const ref = createRef<NativeThreadListHandle>();
143
+ render(
144
+ <GenesisModulesProvider modules={{ list: List as never }}>
145
+ <NativeThreadList ref={ref} testID="l" data={rows} keyExtractor={(r) => r.id} renderItem={renderRow} />
146
+ </GenesisModulesProvider>,
147
+ );
148
+ act(() => ref.current!.scrollToEnd({ animated: false }));
149
+ await waitFor(() => expect(calls.scrollToEnd).toHaveBeenCalled());
150
+ });
151
+
152
+ it("shows the empty state when there are no rows", () => {
153
+ render(<NativeThreadList testID="l" data={[] as Row[]} keyExtractor={(r) => r.id} renderItem={renderRow} empty={<span data-testid="none" />} />);
154
+ expect(screen.getByTestId("none")).toBeTruthy();
155
+ });
156
+ });
@@ -0,0 +1,198 @@
1
+ /**
2
+ * NativeComposerBar — the bar you write a message in: an input that grows
3
+ * with what you type (up to `maxLines`, then scrolls), a send button, and
4
+ * slots beside and above it. ThreadPage's composer; chat, comments and AI
5
+ * prompts build on it too.
6
+ *
7
+ * - **Modes:** `modes` with a `tone` each ("Reply" / "Internal note"). The
8
+ * picker sits above the input, and an `internal` tone edges the bar and
9
+ * the input in the theme's `warning` role, so a staff-only note never
10
+ * reads like a reply (the send button keeps the tint: text on `warning`
11
+ * would fail contrast). The row it sends carries the same tone (ThreadPage).
12
+ * - **Slots:** `leading` (attach), `trailing` (beside send: a mic), `above`
13
+ * (a reply preview, attachments waiting to send).
14
+ * - **Keyboard:** the bar doesn't move itself. Put it under a keyboard-aware
15
+ * container (ThreadPage does, with `GenesisModules.keyboardAvoidingView`);
16
+ * the list above it dismisses the keyboard interactively on a drag.
17
+ * - **Accessibility:** send and the mode picker are 44pt targets, the input
18
+ * is labelled by its placeholder (and says when it writes an internal
19
+ * note), Sending is announced, and the input stays editable while a
20
+ * message sends (the keyboard stays up).
21
+ *
22
+ * @stability Beta
23
+ */
24
+ import { useEffect, type ReactNode } from "react";
25
+ import { AccessibilityInfo, ActivityIndicator, Dimensions, Platform, Pressable, TextInput, View } from "react-native";
26
+ import type { ComposerMode } from "@marktiderman/genesis-core/conversation";
27
+ import { useThemeRoles } from "../hooks/use-theme-roles";
28
+ import { useGenesisModules } from "../native-modules";
29
+ import { NativeIcon } from "./icon";
30
+ import { NativeText } from "./text";
31
+
32
+ export type { ComposerMode, ComposerTone } from "@marktiderman/genesis-core/conversation";
33
+
34
+ export interface NativeComposerBarProps {
35
+ value: string;
36
+ onChangeText: (text: string) => void;
37
+ onSend: () => void;
38
+ /** A send is in flight: the button spins and won't send twice. */
39
+ sending?: boolean;
40
+ /** Turns sending off (besides a blank value). */
41
+ disabled?: boolean;
42
+ placeholder?: string;
43
+ /** Send's label, to VoiceOver. Default "Send". */
44
+ sendLabel?: string;
45
+ sendingLabel?: string;
46
+ maxLength?: number;
47
+ /** The input grows to this many lines, then scrolls. Default 6. */
48
+ maxLines?: number;
49
+ /** Ways to send ("Reply", "Internal note"). Two or more show the picker. */
50
+ modes?: readonly ComposerMode[];
51
+ /** The chosen mode's id. Default the first. */
52
+ mode?: string;
53
+ onModeChange?: (id: string) => void;
54
+ leading?: ReactNode;
55
+ trailing?: ReactNode;
56
+ above?: ReactNode;
57
+ testID?: string;
58
+ }
59
+
60
+ const LINE = 22;
61
+ const PAD_Y = 8;
62
+
63
+ export function NativeComposerBar({
64
+ value,
65
+ onChangeText,
66
+ onSend,
67
+ sending = false,
68
+ disabled = false,
69
+ placeholder = "Message",
70
+ sendLabel = "Send",
71
+ sendingLabel = "Sending",
72
+ maxLength,
73
+ maxLines = 6,
74
+ modes,
75
+ mode,
76
+ onModeChange,
77
+ leading,
78
+ trailing,
79
+ above,
80
+ testID = "composer",
81
+ }: NativeComposerBarProps) {
82
+ const colors = useThemeRoles();
83
+ const { symbol, icons } = useGenesisModules();
84
+ // No icon module: the arrow would draw nothing, so the button says its label.
85
+ const hasIcon = Boolean(symbol || icons?.["arrow-up"]);
86
+ const current = modes?.find((m) => m.id === mode) ?? modes?.[0];
87
+ const internal = current?.tone === "internal";
88
+ const blank = !value.trim();
89
+ const canSend = !blank && !disabled && !sending;
90
+ // A multiline input grows with its text by itself; this caps it, after which it scrolls.
91
+ // Lines grow with the person's text size (Dynamic Type, Android font scale).
92
+ const fontScale = Dimensions.get("window").fontScale || 1;
93
+ const maxHeight = Math.ceil(LINE * fontScale) * maxLines + PAD_Y * 2;
94
+ // Say "Sending" on iOS too (a live region is Android-only).
95
+ useEffect(() => {
96
+ if (sending && Platform.OS === "ios") (AccessibilityInfo as { announceForAccessibility?: (t: string) => void }).announceForAccessibility?.(sendingLabel);
97
+ }, [sending, sendingLabel]);
98
+
99
+ return (
100
+ <View
101
+ testID={testID}
102
+ style={{
103
+ paddingHorizontal: 12,
104
+ paddingTop: 8,
105
+ paddingBottom: 8,
106
+ gap: 6,
107
+ backgroundColor: colors.groupedBackground,
108
+ borderTopWidth: internal ? 2 : 0,
109
+ borderTopColor: colors.warning,
110
+ }}
111
+ >
112
+ {modes && modes.length > 1 ? (
113
+ <View testID={`${testID}-modes`} accessibilityRole="tablist" style={{ flexDirection: "row", gap: 4 }}>
114
+ {modes.map((m) => {
115
+ const on = m.id === current?.id;
116
+ return (
117
+ <Pressable
118
+ key={m.id}
119
+ testID={`${testID}-mode-${m.id}`}
120
+ accessibilityRole="tab"
121
+ accessibilityState={{ selected: on }}
122
+ accessibilityLabel={m.label}
123
+ onPress={() => onModeChange?.(m.id)}
124
+ style={{
125
+ minHeight: 44,
126
+ justifyContent: "center",
127
+ paddingHorizontal: 12,
128
+ borderRadius: 22,
129
+ backgroundColor: on ? colors.fill : "transparent",
130
+ borderWidth: m.tone === "internal" ? 1 : 0,
131
+ borderColor: colors.warning,
132
+ }}
133
+ >
134
+ <NativeText preset="label" style={{ color: on ? colors.label : colors.secondaryLabel }}>
135
+ {m.label}
136
+ </NativeText>
137
+ </Pressable>
138
+ );
139
+ })}
140
+ </View>
141
+ ) : null}
142
+ {above}
143
+ <View style={{ flexDirection: "row", alignItems: "flex-end", gap: 8 }}>
144
+ {leading}
145
+ <TextInput
146
+ testID={`${testID}-input`}
147
+ value={value}
148
+ onChangeText={onChangeText}
149
+ placeholder={internal ? current!.label : placeholder}
150
+ placeholderTextColor={colors.tertiaryLabel as string}
151
+ accessibilityLabel={internal ? current!.label : placeholder}
152
+ multiline
153
+ maxLength={maxLength}
154
+ style={{
155
+ flex: 1,
156
+ minHeight: 44,
157
+ maxHeight,
158
+ textAlignVertical: "center",
159
+ paddingHorizontal: 14,
160
+ paddingTop: PAD_Y,
161
+ paddingBottom: PAD_Y,
162
+ borderRadius: 22,
163
+ fontSize: 17,
164
+ lineHeight: LINE,
165
+ color: colors.label as string,
166
+ backgroundColor: colors.surface,
167
+ borderWidth: internal ? 1 : 0,
168
+ borderColor: colors.warning,
169
+ }}
170
+ />
171
+ {trailing}
172
+ {sending ? (
173
+ <View testID={`${testID}-sending`} accessible accessibilityLabel={sendingLabel} accessibilityLiveRegion="polite" style={{ width: 44, height: 44, alignItems: "center", justifyContent: "center" }}>
174
+ <ActivityIndicator />
175
+ </View>
176
+ ) : (
177
+ <Pressable
178
+ testID={`${testID}-send`}
179
+ accessibilityRole="button"
180
+ accessibilityLabel={sendLabel}
181
+ accessibilityState={{ disabled: !canSend }}
182
+ disabled={!canSend}
183
+ onPress={onSend}
184
+ style={{ minWidth: 44, height: 44, paddingHorizontal: hasIcon ? 0 : 14, borderRadius: 22, alignItems: "center", justifyContent: "center", backgroundColor: canSend ? colors.tint : colors.fill }}
185
+ >
186
+ {hasIcon ? (
187
+ <NativeIcon name="arrow-up" size={20} color={canSend ? colors.background : colors.tertiaryLabel} />
188
+ ) : (
189
+ <NativeText preset="label" className={canSend ? "text-primary-foreground" : undefined} style={canSend ? undefined : { color: colors.tertiaryLabel }}>
190
+ {sendLabel}
191
+ </NativeText>
192
+ )}
193
+ </Pressable>
194
+ )}
195
+ </View>
196
+ </View>
197
+ );
198
+ }