@delacour/react-native-ui 0.7.0-alpha.20261104124454 → 0.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delacour/react-native-ui",
3
- "version": "0.7.0-alpha.20261104124454",
3
+ "version": "0.7.0",
4
4
  "description": "React Native UI components — Uniwind, Reanimated, Gesture Handler",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -182,8 +182,8 @@
182
182
  "expo-blur": ">=15",
183
183
  "@maplibre/maplibre-react-native": "^11.5.0",
184
184
  "@central-icons-react-native/round-outlined-radius-1-stroke-1.5": "^1.1",
185
- "@delacour/react-native-bottom-sheet": "0.7.0-alpha.20261104124454",
186
- "@delacour/react-native-charts": "0.7.0-alpha.20261104124454",
185
+ "@delacour/react-native-bottom-sheet": ">=0.7.0",
186
+ "@delacour/react-native-charts": ">=0.7.0",
187
187
  "@legendapp/list": ">=3.3",
188
188
  "react-native-skia": ">=3.9.0",
189
189
  "expo-linear-gradient": ">=15",
@@ -9,7 +9,9 @@ logic suites.
9
9
 
10
10
  | File | What it is |
11
11
  | --- | --- |
12
- | `setup.ts` | Jest `setupFiles` entry: a stand-in for every native module the components reach |
12
+ | `setup.ts` | Jest `setupFiles` entry: a stand-in for every native module every app with the kit has |
13
+ | `mocks/*.ts` | One `setupFiles` entry per native module only some components bring — Skia, Pulsar, MapLibre, `expo-linear-gradient`, `expo-blur` |
14
+ | `mock-stub.ts` | `mockDeepStub`, the value the mocks answer with where a result feeds native code |
13
15
  | `render.tsx` | `renderWithProviders` — `render` inside `DelacourProvider` — and RNTL re-exported |
14
16
 
15
17
  Jest needs three settings to run them, all in the package's Jest config: `preset: "jest-expo"`,
@@ -96,10 +98,17 @@ spring values, or test a native module's behaviour through its mock.
96
98
 
97
99
  `setup.ts` mocks a module only when the module ships no Jest mock of its own. The ones it uses
98
100
  from the libraries themselves: Reanimated's `setUpTests()`, Gesture Handler's `jestSetup`, Safe Area
99
- Context's `jest/mock`, Keyboard Controller's `jest` entry and Teleport's `jest` entry. Skia, Pulsar,
100
- Uniwind, Maplibre, `expo-linear-gradient` and `expo-blur` are stubbed by hand — drawing primitives
101
- render nothing, and `useCSSVariable` returns `undefined`, so a component must already tolerate a
102
- token that has not resolved.
101
+ Context's `jest/mock`, Keyboard Controller's `jest` entry and Teleport's `jest` entry. Uniwind,
102
+ Skia, Pulsar, Maplibre, `expo-linear-gradient` and `expo-blur` are stubbed by hand — drawing
103
+ primitives render nothing, and `useCSSVariable` returns `undefined`, so a component must already
104
+ tolerate a token that has not resolved.
105
+
106
+ **A module only some components bring is mocked in `mocks/`, never in `setup.ts`.** The kit is
107
+ copied into apps that hold a few components, and a `jest.mock` of a module that is not installed
108
+ fails every suite at load ("Cannot find module 'react-native-skia'"). So each such mock is a file of
109
+ its own, `mocks/<name>.ts`, and ships as its own registry item: it lands in a project only beside a
110
+ component that installs its module, and is then added to Jest's `setupFiles`. This package's Jest
111
+ config lists every one.
103
112
 
104
113
  Teleport's mock draws a portal where it is written, not in the `"root"` host beside the app. So
105
114
  `setup.ts` also sets the global `delacour.overlay.teleportInline` symbol, and `OverlayProvider`
@@ -108,9 +117,10 @@ feedback panel would sit inside a view hidden from accessibility, and RNTL would
108
117
  [Overlay](../components/overlay/AGENTS.md).
109
118
 
110
119
  A suite needing a module that is not mocked fails at import with the module's own native error
111
- ("`TurboModuleRegistry.getEnforcing(...)` … could not be found"). Add the mock to `setup.ts`, inside
112
- the `jest.mock` factory; a helper the factory calls must be named `mock…`, or Jest's hoisting guard
113
- refuses it.
120
+ ("`TurboModuleRegistry.getEnforcing(...)` … could not be found"). Add the mock inside a `jest.mock`
121
+ factory — in `setup.ts` when every app with the kit has the module, else in a new `mocks/<name>.ts`
122
+ listed in this package's Jest config and mapped to its module in the registry config; a helper the
123
+ factory calls must be named `mock…`, or Jest's hoisting guard refuses it.
114
124
 
115
125
  <!-- registry:omit -->
116
126
  The reference suites are `button/button.render.test.tsx` (press, disabled, busy, group),
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Shared by the native mocks under `mocks/`: each module whose results feed native code a test
3
+ * never reaches answers with this.
4
+ */
5
+ /**
6
+ * A value every property read and call of which returns another such value:
7
+ * enough for a module whose results feed native code a test never reaches
8
+ * (`Presets.System.selection()`, `Skia.Path.Make().addCircle(...)`).
9
+ */
10
+ export function mockDeepStub(): unknown {
11
+ const target = () => undefined;
12
+ const handler: ProxyHandler<() => undefined> = {
13
+ get: (_target, key) => (key === "then" ? undefined : mockDeepStub()),
14
+ apply: () => mockDeepStub(),
15
+ };
16
+ return new Proxy(target, handler);
17
+ }
@@ -0,0 +1,4 @@
1
+ /** `expo-blur` as a plain `View`. A setup file, beside `setup.ts`. */
2
+ import { jest } from "@jest/globals";
3
+
4
+ jest.mock("expo-blur", () => ({ BlurView: require("react-native").View }));
@@ -0,0 +1,4 @@
1
+ /** `expo-linear-gradient` as a plain `View`. A setup file, beside `setup.ts`. */
2
+ import { jest } from "@jest/globals";
3
+
4
+ jest.mock("expo-linear-gradient", () => ({ LinearGradient: require("react-native").View }));
@@ -0,0 +1,29 @@
1
+ /** MapLibre's hosts as `View`s with a stub ref. A setup file, beside `setup.ts`. */
2
+ import { jest } from "@jest/globals";
3
+ import { mockDeepStub } from "../mock-stub";
4
+
5
+ jest.mock("@maplibre/maplibre-react-native", () => {
6
+ const { createElement, forwardRef, useImperativeHandle } = require("react");
7
+ const { View } = require("react-native");
8
+ const mockHost = (name: string) => {
9
+ const Host = forwardRef((props: Record<string, unknown>, ref: unknown) => {
10
+ useImperativeHandle(ref, () => mockDeepStub());
11
+ return createElement(View, { ...props, testID: props.testID ?? `maplibre-${name}` });
12
+ });
13
+ Host.displayName = `MapLibre.${name}`;
14
+ return Host;
15
+ };
16
+ return {
17
+ Map: mockHost("Map"),
18
+ Camera: mockHost("Camera"),
19
+ Marker: mockHost("Marker"),
20
+ GeoJSONSource: mockHost("GeoJSONSource"),
21
+ Layer: mockHost("Layer"),
22
+ LocationManager: {
23
+ requestPermissions: async () => true,
24
+ addListener: () => undefined,
25
+ removeListener: () => undefined,
26
+ getCurrentPosition: async () => null,
27
+ },
28
+ };
29
+ });
@@ -0,0 +1,13 @@
1
+ /** Pulsar's haptics, which have no Jest mock of their own. A setup file, beside `setup.ts`. */
2
+ import { jest } from "@jest/globals";
3
+ import { mockDeepStub } from "../mock-stub";
4
+
5
+ jest.mock("react-native-pulsar", () => ({
6
+ Presets: mockDeepStub(),
7
+ Settings: mockDeepStub(),
8
+ useRealtimeComposer: () => mockDeepStub(),
9
+ usePatternComposer: () => mockDeepStub(),
10
+ useAdaptiveHaptics: () => mockDeepStub(),
11
+ HapticSupport: {},
12
+ RealtimeComposerStrategy: {},
13
+ }));
@@ -0,0 +1,48 @@
1
+ /** Skia, drawn as nothing: a `Canvas` is a `View` and every primitive renders null. A setup file, beside `setup.ts`. */
2
+ import { jest } from "@jest/globals";
3
+ import { mockDeepStub } from "../mock-stub";
4
+
5
+ /**
6
+ * A Skia font with real numbers where a layout reads them — line metrics, and
7
+ * a fixed advance per character — so an axis gutter or a label anchor resolves
8
+ * to finite geometry. Anything else falls through to `mockDeepStub`.
9
+ */
10
+ function mockFont(size = 12): unknown {
11
+ const font: Record<string, unknown> = {
12
+ getSize: () => size,
13
+ getMetrics: () => ({ ascent: -size * 0.8, descent: size * 0.2, leading: 0 }),
14
+ getGlyphIDs: (text: string) => Array.from(text, (_char, index) => index),
15
+ getGlyphWidths: (ids: readonly number[]) => ids.map(() => size * 0.6),
16
+ getTextWidth: (text: string) => text.length * size * 0.6,
17
+ measureText: (text: string) => ({ x: 0, y: -size * 0.8, width: text.length * size * 0.6, height: size }),
18
+ };
19
+ return new Proxy(font, { get: (target, key) => (key in target ? target[key as string] : mockDeepStub()) });
20
+ }
21
+
22
+ jest.mock("react-native-skia", () => {
23
+ const { View } = require("react-native");
24
+ const Draw = () => null;
25
+ return {
26
+ Canvas: View,
27
+ Circle: Draw,
28
+ DashPathEffect: Draw,
29
+ Group: Draw,
30
+ Line: Draw,
31
+ LinearGradient: Draw,
32
+ Path: Draw,
33
+ Picture: Draw,
34
+ Rect: Draw,
35
+ RoundedRect: Draw,
36
+ Shader: Draw,
37
+ Text: Draw,
38
+ Skia: mockDeepStub(),
39
+ BlendMode: mockDeepStub(),
40
+ ImageFormat: mockDeepStub(),
41
+ PaintStyle: mockDeepStub(),
42
+ StrokeCap: mockDeepStub(),
43
+ StrokeJoin: mockDeepStub(),
44
+ matchFont: (style?: { fontSize?: number }) => mockFont(style?.fontSize),
45
+ usePathInterpolation: () => mockDeepStub(),
46
+ vec: (x = 0, y = x) => ({ x, y }),
47
+ };
48
+ });
package/src/test/setup.ts CHANGED
@@ -5,41 +5,15 @@
5
5
  * Listed in `setupFiles`. Ships through the registry as `test-setup` and is
6
6
  * added to a consumer's Jest config by `delacour add --tests`. A mock goes here
7
7
  * only when the library ships none of its own; prefer the library's.
8
+ *
9
+ * Only modules every copy of the kit can count on are mocked here. A module only some
10
+ * components bring — Skia, MapLibre, a gradient — has its own file under `mocks/`, its own
11
+ * registry item, and reaches a project only with a component that needs it: a `jest.mock` of a
12
+ * module that is not installed fails every suite at load.
8
13
  */
9
14
  import { jest } from "@jest/globals";
10
15
  import type { ReactNode } from "react";
11
16
 
12
- /**
13
- * A value every property read and call of which returns another such value:
14
- * enough for a module whose results feed native code a test never reaches
15
- * (`Presets.System.selection()`, `Skia.Path.Make().addCircle(...)`).
16
- */
17
- function mockDeepStub(): unknown {
18
- const target = () => undefined;
19
- const handler: ProxyHandler<() => undefined> = {
20
- get: (_target, key) => (key === "then" ? undefined : mockDeepStub()),
21
- apply: () => mockDeepStub(),
22
- };
23
- return new Proxy(target, handler);
24
- }
25
-
26
- /**
27
- * A Skia font with real numbers where a layout reads them — line metrics, and
28
- * a fixed advance per character — so an axis gutter or a label anchor resolves
29
- * to finite geometry. Anything else falls through to `mockDeepStub`.
30
- */
31
- function mockFont(size = 12): unknown {
32
- const font: Record<string, unknown> = {
33
- getSize: () => size,
34
- getMetrics: () => ({ ascent: -size * 0.8, descent: size * 0.2, leading: 0 }),
35
- getGlyphIDs: (text: string) => Array.from(text, (_char, index) => index),
36
- getGlyphWidths: (ids: readonly number[]) => ids.map(() => size * 0.6),
37
- getTextWidth: (text: string) => text.length * size * 0.6,
38
- measureText: (text: string) => ({ x: 0, y: -size * 0.8, width: text.length * size * 0.6, height: size }),
39
- };
40
- return new Proxy(font, { get: (target, key) => (key in target ? target[key as string] : mockDeepStub()) });
41
- }
42
-
43
17
  jest.mock("react-native-worklets", () => ({
44
18
  ...jest.requireActual<Record<string, unknown>>("react-native-worklets"),
45
19
  getUIRuntimeHolder: () => ({}),
@@ -65,16 +39,6 @@ jest.mock("react-native-teleport", () => require("react-native-teleport/jest"));
65
39
  * `TELEPORT_INLINE`.
66
40
  */
67
41
  (globalThis as unknown as Record<symbol, unknown>)[Symbol.for("delacour.overlay.teleportInline")] = true;
68
- jest.mock("react-native-pulsar", () => ({
69
- Presets: mockDeepStub(),
70
- Settings: mockDeepStub(),
71
- useRealtimeComposer: () => mockDeepStub(),
72
- usePatternComposer: () => mockDeepStub(),
73
- useAdaptiveHaptics: () => mockDeepStub(),
74
- HapticSupport: {},
75
- RealtimeComposerStrategy: {},
76
- }));
77
-
78
42
  jest.mock("uniwind", () => ({
79
43
  withUniwind: <T>(component: T): T => component,
80
44
  useResolveClassNames: () => ({}),
@@ -83,60 +47,3 @@ jest.mock("uniwind", () => ({
83
47
  Uniwind: { setTheme: () => undefined, currentTheme: "light", hasAdaptiveThemes: true },
84
48
  LayoutDirection: ({ children }: { children?: ReactNode }) => children,
85
49
  }));
86
-
87
- jest.mock("react-native-skia", () => {
88
- const { View } = require("react-native");
89
- const Draw = () => null;
90
- return {
91
- Canvas: View,
92
- Circle: Draw,
93
- DashPathEffect: Draw,
94
- Group: Draw,
95
- Line: Draw,
96
- LinearGradient: Draw,
97
- Path: Draw,
98
- Picture: Draw,
99
- Rect: Draw,
100
- RoundedRect: Draw,
101
- Shader: Draw,
102
- Text: Draw,
103
- Skia: mockDeepStub(),
104
- BlendMode: mockDeepStub(),
105
- ImageFormat: mockDeepStub(),
106
- PaintStyle: mockDeepStub(),
107
- StrokeCap: mockDeepStub(),
108
- StrokeJoin: mockDeepStub(),
109
- matchFont: (style?: { fontSize?: number }) => mockFont(style?.fontSize),
110
- usePathInterpolation: () => mockDeepStub(),
111
- vec: (x = 0, y = x) => ({ x, y }),
112
- };
113
- });
114
-
115
- jest.mock("expo-linear-gradient", () => ({ LinearGradient: require("react-native").View }));
116
- jest.mock("expo-blur", () => ({ BlurView: require("react-native").View }));
117
-
118
- jest.mock("@maplibre/maplibre-react-native", () => {
119
- const { createElement, forwardRef, useImperativeHandle } = require("react");
120
- const { View } = require("react-native");
121
- const mockHost = (name: string) => {
122
- const Host = forwardRef((props: Record<string, unknown>, ref: unknown) => {
123
- useImperativeHandle(ref, () => mockDeepStub());
124
- return createElement(View, { ...props, testID: props.testID ?? `maplibre-${name}` });
125
- });
126
- Host.displayName = `MapLibre.${name}`;
127
- return Host;
128
- };
129
- return {
130
- Map: mockHost("Map"),
131
- Camera: mockHost("Camera"),
132
- Marker: mockHost("Marker"),
133
- GeoJSONSource: mockHost("GeoJSONSource"),
134
- Layer: mockHost("Layer"),
135
- LocationManager: {
136
- requestPermissions: async () => true,
137
- addListener: () => undefined,
138
- removeListener: () => undefined,
139
- getCurrentPosition: async () => null,
140
- },
141
- };
142
- });