@marktiderman/genesis-ui-native 2.2.0 → 2.3.1
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-2WCXMJL6.js → chunk-FIITITXO.js} +67 -108
- package/dist/chunk-FIITITXO.js.map +1 -0
- package/dist/chunk-H4Q7COTI.js +1587 -0
- package/dist/chunk-H4Q7COTI.js.map +1 -0
- package/dist/{chunk-TXJT55JC.js → chunk-Q445I7WO.js} +715 -324
- package/dist/chunk-Q445I7WO.js.map +1 -0
- package/dist/{chunk-ULS7I6ZS.js → chunk-W2UBJ56D.js} +99 -12
- package/dist/chunk-W2UBJ56D.js.map +1 -0
- package/dist/components/index.d.ts +146 -18
- 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 +60 -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 +329 -4
- package/dist/layouts/index.js +3 -3
- package/dist/native-modules-BGO2MnFF.d.ts +219 -0
- package/package.json +34 -5
- package/src/__tests__/fake-modules.tsx +134 -0
- package/src/__tests__/native-modules-lists.test.tsx +71 -0
- package/src/__tests__/native-modules.test.tsx +631 -0
- package/src/components/__tests__/refresh-control.test.tsx +35 -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/refresh-control.tsx +11 -45
- 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 +62 -0
- package/src/icons/lucide.ts +114 -0
- package/src/layouts/__tests__/google-sign-in.test.tsx +26 -0
- package/src/layouts/__tests__/inbox-page.test.tsx +200 -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 +455 -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,134 @@
|
|
|
1
|
+
// Stand-ins for the optional native modules an app passes to
|
|
2
|
+
// GenesisModulesProvider. Each records how Genesis called it, so a test can
|
|
3
|
+
// assert the opt-in path, and renders plain DOM so the tree stays testable.
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { vi } from "vitest";
|
|
6
|
+
import type {
|
|
7
|
+
GenesisDatePickerProps,
|
|
8
|
+
GenesisGlassModule,
|
|
9
|
+
GenesisImageProps,
|
|
10
|
+
GenesisListProps,
|
|
11
|
+
GenesisReanimatedModule,
|
|
12
|
+
GenesisSymbolProps,
|
|
13
|
+
} from "../native-modules";
|
|
14
|
+
|
|
15
|
+
type AnyProps = Record<string, unknown> & { children?: React.ReactNode; testID?: string };
|
|
16
|
+
|
|
17
|
+
export function fakeReanimated() {
|
|
18
|
+
const AnimatedView = React.forwardRef<HTMLDivElement, AnyProps>(function AnimatedView({ children, testID, style, className, accessibilityLabel, accessibilityRole }, ref) {
|
|
19
|
+
return (
|
|
20
|
+
<div
|
|
21
|
+
ref={ref}
|
|
22
|
+
data-reanimated="true"
|
|
23
|
+
data-testid={testID}
|
|
24
|
+
data-style={JSON.stringify(style)}
|
|
25
|
+
className={className as string}
|
|
26
|
+
aria-label={accessibilityLabel as string}
|
|
27
|
+
role={accessibilityRole as string}
|
|
28
|
+
>
|
|
29
|
+
{children as React.ReactNode}
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
const mod = {
|
|
34
|
+
default: { View: AnimatedView },
|
|
35
|
+
useSharedValue: <V,>(initial: V) => React.useRef({ value: initial }).current,
|
|
36
|
+
useAnimatedStyle: vi.fn((updater: () => Record<string, unknown>) => updater()),
|
|
37
|
+
withTiming: vi.fn((toValue: number) => toValue),
|
|
38
|
+
withRepeat: vi.fn((animation: number) => animation),
|
|
39
|
+
cancelAnimation: vi.fn(),
|
|
40
|
+
Easing: { inOut: (e: unknown) => e, ease: "ease", out: (e: unknown) => e, cubic: "cubic" },
|
|
41
|
+
ReduceMotion: { System: "system", Always: "always", Never: "never" },
|
|
42
|
+
};
|
|
43
|
+
return mod satisfies GenesisReanimatedModule;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function fakeGlass({ liquid = true, api = true, throws = false } = {}) {
|
|
47
|
+
const GlassView = vi.fn(({ children, testID }: AnyProps) => (
|
|
48
|
+
<div data-glass="true" data-testid={testID}>
|
|
49
|
+
{children as React.ReactNode}
|
|
50
|
+
</div>
|
|
51
|
+
));
|
|
52
|
+
return {
|
|
53
|
+
GlassView: GlassView as unknown as GenesisGlassModule["GlassView"],
|
|
54
|
+
isLiquidGlassAvailable: () => {
|
|
55
|
+
if (throws) throw new Error("no glass");
|
|
56
|
+
return liquid;
|
|
57
|
+
},
|
|
58
|
+
isGlassEffectAPIAvailable: () => api,
|
|
59
|
+
calls: GlassView,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function fakeImage() {
|
|
64
|
+
return vi.fn((props: GenesisImageProps) => (
|
|
65
|
+
<img
|
|
66
|
+
data-testid={props.testID}
|
|
67
|
+
data-expo-image="true"
|
|
68
|
+
data-recycling-key={props.recyclingKey ?? ""}
|
|
69
|
+
data-cache-policy={props.cachePolicy}
|
|
70
|
+
data-transition={String(props.transition)}
|
|
71
|
+
src={typeof props.source === "object" && props.source ? props.source.uri : undefined}
|
|
72
|
+
onLoad={() => props.onLoad?.({})}
|
|
73
|
+
onError={() => props.onError?.({})}
|
|
74
|
+
alt=""
|
|
75
|
+
/>
|
|
76
|
+
));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function fakeFlashList() {
|
|
80
|
+
return vi.fn(function FlashList(props: GenesisListProps<any>) {
|
|
81
|
+
const header = props.ListHeaderComponent as React.ReactNode;
|
|
82
|
+
const empty = props.ListEmptyComponent as React.ReactNode;
|
|
83
|
+
return (
|
|
84
|
+
<div
|
|
85
|
+
data-testid={props.testID}
|
|
86
|
+
data-flash-list="true"
|
|
87
|
+
data-sticky={JSON.stringify(props.stickyHeaderIndices ?? [])}
|
|
88
|
+
data-sticky-offset={props.stickyHeaderConfig?.offset}
|
|
89
|
+
>
|
|
90
|
+
{header}
|
|
91
|
+
{props.data.length === 0
|
|
92
|
+
? empty
|
|
93
|
+
: props.data.map((item, index) => (
|
|
94
|
+
<div key={props.keyExtractor ? props.keyExtractor(item, index) : index} data-item-type={String(props.getItemType?.(item, index) ?? "")}>
|
|
95
|
+
{props.renderItem({ item, index })}
|
|
96
|
+
</div>
|
|
97
|
+
))}
|
|
98
|
+
</div>
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function fakeSymbolView() {
|
|
104
|
+
return vi.fn((props: GenesisSymbolProps) => (
|
|
105
|
+
<span data-symbol={props.name} data-size={props.size} data-weight={props.weight}>
|
|
106
|
+
{props.fallback}
|
|
107
|
+
</span>
|
|
108
|
+
));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function fakeIcon(name: string) {
|
|
112
|
+
return function Icon({ size, testID }: { size?: number; testID?: string }) {
|
|
113
|
+
return <svg data-lucide={name} data-size={size} data-testid={testID} />;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function fakeDatePicker() {
|
|
118
|
+
return vi.fn((props: GenesisDatePickerProps) => (
|
|
119
|
+
<div
|
|
120
|
+
data-testid={props.testID}
|
|
121
|
+
data-expo-ui-picker="true"
|
|
122
|
+
data-mode={props.mode}
|
|
123
|
+
data-display={props.display ?? ""}
|
|
124
|
+
data-presentation={props.presentation ?? ""}
|
|
125
|
+
>
|
|
126
|
+
<button type="button" data-testid="fake-picker-choose" onClick={() => props.onValueChange?.({}, new Date(2030, 0, 2))}>
|
|
127
|
+
choose
|
|
128
|
+
</button>
|
|
129
|
+
<button type="button" data-testid="fake-picker-cancel" onClick={() => props.onDismiss?.()}>
|
|
130
|
+
cancel
|
|
131
|
+
</button>
|
|
132
|
+
</div>
|
|
133
|
+
));
|
|
134
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// @feat:native-modules
|
|
2
|
+
/**
|
|
3
|
+
* NativeResourcePage on FlashList v2 (the opt-in) and FlatList (the
|
|
4
|
+
* fallback), and the lucide icon set covering every semantic name.
|
|
5
|
+
*/
|
|
6
|
+
import { render, screen } from "@testing-library/react";
|
|
7
|
+
import { describe, expect, it, vi } from "vitest";
|
|
8
|
+
import { GenesisModulesProvider } from "../native-modules";
|
|
9
|
+
import { NATIVE_ICON_NAMES } from "../icon-names";
|
|
10
|
+
import { fakeFlashList } from "./fake-modules";
|
|
11
|
+
|
|
12
|
+
const refetch = vi.fn(() => Promise.resolve());
|
|
13
|
+
vi.mock("@marktiderman/genesis-core/hooks", () => ({
|
|
14
|
+
useResource: () => ({
|
|
15
|
+
list: {
|
|
16
|
+
data: { data: [{ id: 1, name: "Ada" }, { id: 2, name: "Grace" }] },
|
|
17
|
+
isLoading: false,
|
|
18
|
+
isError: false,
|
|
19
|
+
refetch,
|
|
20
|
+
},
|
|
21
|
+
setSearch: () => {},
|
|
22
|
+
setFilters: () => {},
|
|
23
|
+
}),
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
vi.mock("lucide-react-native", () => {
|
|
27
|
+
const icon = (name: string) => () => <svg data-lucide={name} />;
|
|
28
|
+
const names = [
|
|
29
|
+
"ArrowLeft", "Bell", "Calendar", "Check", "ChevronDown", "ChevronLeft", "ChevronRight", "ChevronUp", "CircleCheck",
|
|
30
|
+
"CircleX", "Clock", "Ellipsis", "ExternalLink", "Funnel", "Heart", "House", "Info", "Lock", "LogOut", "Mail", "Menu",
|
|
31
|
+
"Minus", "Pencil", "Plus", "RefreshCw", "Search", "Settings", "Share", "Star", "Trash2", "TriangleAlert", "User", "X",
|
|
32
|
+
"ArrowUp", "Camera", "Copy", "File", "Image", "MessageCircle", "Mic", "Paperclip", "Pause", "Pin", "Play", "Reply", "SquarePen",
|
|
33
|
+
];
|
|
34
|
+
return Object.fromEntries(names.map((n) => [n, icon(n)]));
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const { NativeResourcePage } = await import("../data/NativeResourcePage");
|
|
38
|
+
const { lucideIcons } = await import("../icons/lucide");
|
|
39
|
+
|
|
40
|
+
describe("NativeResourcePage", () => {
|
|
41
|
+
it("renders its rows in FlashList when the app passed it, with pull-to-refresh", () => {
|
|
42
|
+
const FlashList = fakeFlashList();
|
|
43
|
+
render(
|
|
44
|
+
<GenesisModulesProvider modules={{ list: FlashList }}>
|
|
45
|
+
<NativeResourcePage resource="people" title="People" cardFields={["name"]} />
|
|
46
|
+
</GenesisModulesProvider>,
|
|
47
|
+
);
|
|
48
|
+
expect(screen.getByTestId("native-resource-page-list").dataset.flashList).toBe("true");
|
|
49
|
+
expect(screen.getByText("Ada")).toBeTruthy();
|
|
50
|
+
const props = FlashList.mock.calls[0]![0];
|
|
51
|
+
expect(props).not.toHaveProperty("estimatedItemSize");
|
|
52
|
+
// FlashList's content container takes padding only.
|
|
53
|
+
expect(props.contentContainerStyle).toEqual({ paddingBottom: 24 });
|
|
54
|
+
expect(props.keyExtractor!({ id: 2 }, 0)).toBe("2");
|
|
55
|
+
props.onRefresh!();
|
|
56
|
+
expect(refetch).toHaveBeenCalled();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("falls back to FlatList", () => {
|
|
60
|
+
render(<NativeResourcePage resource="people" title="People" cardFields={["name"]} />);
|
|
61
|
+
expect(screen.getByTestId("native-resource-page-list").dataset.flashList).toBeUndefined();
|
|
62
|
+
expect(screen.getByText("Grace")).toBeTruthy();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe("lucideIcons", () => {
|
|
67
|
+
it("has an icon for every semantic name", () => {
|
|
68
|
+
expect(Object.keys(lucideIcons).sort()).toEqual([...NATIVE_ICON_NAMES].sort());
|
|
69
|
+
for (const name of NATIVE_ICON_NAMES) expect(typeof lucideIcons[name]).toBe("function");
|
|
70
|
+
});
|
|
71
|
+
});
|