@marktiderman/genesis-ui-native 3.2.0 → 3.2.2
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/dist/data/index.d.ts +7 -2
- package/dist/data/index.js +53 -28
- package/dist/data/index.js.map +1 -1
- package/package.json +12 -7
- package/src/__tests__/fake-modules.tsx +10 -3
- package/src/data/resource-view/NativeRecordView.tsx +68 -27
- package/src/data/resource-view/__tests__/native-record-view.test.tsx +42 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marktiderman/genesis-ui-native",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -76,14 +76,15 @@
|
|
|
76
76
|
"react-native": "./src/icons/lucide.ts",
|
|
77
77
|
"import": "./dist/icons/lucide.js",
|
|
78
78
|
"default": "./dist/icons/lucide.js"
|
|
79
|
-
}
|
|
79
|
+
},
|
|
80
|
+
"./package.json": "./package.json"
|
|
80
81
|
},
|
|
81
82
|
"peerDependencies": {
|
|
82
83
|
"@expo/ui": ">=58.0.0",
|
|
83
84
|
"@gorhom/bottom-sheet": ">=5.0.0",
|
|
84
|
-
"@hookform/resolvers": "^3.0.0 || ^4.0.0 || ^5.0.0",
|
|
85
|
-
"@marktiderman/genesis-core": "^2.
|
|
86
|
-
"@marktiderman/genesis-design-system": "^1.
|
|
85
|
+
"@hookform/resolvers": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0",
|
|
86
|
+
"@marktiderman/genesis-core": "^2.4.0",
|
|
87
|
+
"@marktiderman/genesis-design-system": "^1.6.0",
|
|
87
88
|
"@react-native-community/datetimepicker": ">=8.0.0",
|
|
88
89
|
"@shopify/flash-list": ">=2.0.0",
|
|
89
90
|
"@tanstack/react-query": "^5.0.0",
|
|
@@ -151,15 +152,19 @@
|
|
|
151
152
|
"devDependencies": {
|
|
152
153
|
"@testing-library/react": "^16.3.2",
|
|
153
154
|
"@types/react": "^19.2.14",
|
|
154
|
-
"@vitest/coverage-v8": "^
|
|
155
|
+
"@vitest/coverage-v8": "^5.0.5",
|
|
155
156
|
"happy-dom": "^21.0.4",
|
|
156
157
|
"react": "^19.2.5",
|
|
157
158
|
"react-dom": "^19.2.5",
|
|
158
159
|
"tsup": "^8.3.0",
|
|
159
160
|
"typescript": "~6.0.3",
|
|
160
|
-
"vitest": "^
|
|
161
|
+
"vitest": "^5.0.5"
|
|
161
162
|
},
|
|
162
163
|
"genesis": {
|
|
164
|
+
"layer": "foundation",
|
|
165
|
+
"group": "core",
|
|
166
|
+
"owner": "@marktiderman",
|
|
167
|
+
"essential": true,
|
|
163
168
|
"doctor": {
|
|
164
169
|
"prefer": [
|
|
165
170
|
{
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// GenesisModulesProvider. Each records how Genesis called it, so a test can
|
|
3
3
|
// assert the opt-in path, and renders plain DOM so the tree stays testable.
|
|
4
4
|
import * as React from "react";
|
|
5
|
-
import { vi } from "vitest";
|
|
5
|
+
import { type Mock, vi } from "vitest";
|
|
6
6
|
import type {
|
|
7
7
|
GenesisDatePickerProps,
|
|
8
8
|
GenesisGlassModule,
|
|
@@ -14,7 +14,14 @@ import type {
|
|
|
14
14
|
|
|
15
15
|
type AnyProps = Record<string, unknown> & { children?: React.ReactNode; testID?: string };
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
type FakeReanimated = Omit<GenesisReanimatedModule, "useAnimatedStyle" | "withTiming" | "withRepeat" | "cancelAnimation"> & {
|
|
18
|
+
useAnimatedStyle: Mock<(updater: () => Record<string, unknown>) => Record<string, unknown>>;
|
|
19
|
+
withTiming: Mock<(toValue: number) => number>;
|
|
20
|
+
withRepeat: Mock<(animation: number) => number>;
|
|
21
|
+
cancelAnimation: Mock<() => void>;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export function fakeReanimated(): FakeReanimated {
|
|
18
25
|
const AnimatedView = React.forwardRef<HTMLDivElement, AnyProps>(function AnimatedView({ children, testID, style, className, accessibilityLabel, accessibilityRole }, ref) {
|
|
19
26
|
return (
|
|
20
27
|
<div
|
|
@@ -40,7 +47,7 @@ export function fakeReanimated() {
|
|
|
40
47
|
Easing: { inOut: (e: unknown) => e, ease: "ease", out: (e: unknown) => e, cubic: "cubic" },
|
|
41
48
|
ReduceMotion: { System: "system", Always: "always", Never: "never" },
|
|
42
49
|
};
|
|
43
|
-
return mod satisfies GenesisReanimatedModule;
|
|
50
|
+
return mod satisfies GenesisReanimatedModule as FakeReanimated;
|
|
44
51
|
}
|
|
45
52
|
|
|
46
53
|
export function fakeGlass({ liquid = true, api = true, throws = false } = {}) {
|
|
@@ -279,8 +279,13 @@ export interface NativeRecordViewProps<T extends Row = Row> {
|
|
|
279
279
|
onSaved?: (row: T) => void;
|
|
280
280
|
/** Above the sections: a switcher between records. */
|
|
281
281
|
switcher?: ReactNode;
|
|
282
|
-
/**
|
|
283
|
-
|
|
282
|
+
/**
|
|
283
|
+
* The screen's own sections, by id. A node is laid out in the screen's scroll view. A section
|
|
284
|
+
* that scrolls itself (a long FlatList) passes a function instead: it gets the screen's top
|
|
285
|
+
* (switcher, readiness, sections) to render as its list's header, and owns the scroll view, so
|
|
286
|
+
* set `contentInsetAdjustmentBehavior="automatic"` on it.
|
|
287
|
+
*/
|
|
288
|
+
slots?: Partial<Record<string, ReactNode | ((top: ReactNode) => ReactNode)>>;
|
|
284
289
|
/** More props for a list section's NativeResourceView, by section id. */
|
|
285
290
|
lists?: Partial<Record<string, Partial<Omit<NativeResourceViewProps, "view" | "filter">>>>;
|
|
286
291
|
messages?: Partial<NativeRecordViewMessages>;
|
|
@@ -356,20 +361,6 @@ export function NativeRecordView<T extends Row = Row>(props: NativeRecordViewPro
|
|
|
356
361
|
</View>
|
|
357
362
|
);
|
|
358
363
|
|
|
359
|
-
let body: ReactNode = null;
|
|
360
|
-
if (many && !active) {
|
|
361
|
-
body = (
|
|
362
|
-
<ScrollView contentContainerStyle={{ padding: 16 }}>
|
|
363
|
-
<Group testID={`${testID}-sections`}>
|
|
364
|
-
{sections.map((s, i) => (
|
|
365
|
-
<Cell key={s.id} last={i === sections.length - 1}>
|
|
366
|
-
<NativeListItem testID={`${testID}-section-${s.id}`} title={s.label} showChevron onPress={() => choose(s.id)} className="bg-transparent" />
|
|
367
|
-
</Cell>
|
|
368
|
-
))}
|
|
369
|
-
</Group>
|
|
370
|
-
</ScrollView>
|
|
371
|
-
);
|
|
372
|
-
}
|
|
373
364
|
// A section opened in place from the list of sections: a row back to the list.
|
|
374
365
|
const back =
|
|
375
366
|
many && local !== undefined && section === undefined ? (
|
|
@@ -387,20 +378,59 @@ export function NativeRecordView<T extends Row = Row>(props: NativeRecordViewPro
|
|
|
387
378
|
</Group>
|
|
388
379
|
</View>
|
|
389
380
|
) : null;
|
|
390
|
-
|
|
391
|
-
|
|
381
|
+
|
|
382
|
+
// One scroll view holds the whole screen, so iOS insets it below the navigation bar
|
|
383
|
+
// (`contentInsetAdjustmentBehavior`): the header is translucent and the first rows would sit
|
|
384
|
+
// behind it otherwise. A list section is its own scroll view, with the top as its header.
|
|
385
|
+
const scroll = (content: ReactNode) => (
|
|
386
|
+
<ScrollView
|
|
387
|
+
testID={`${testID}-scroll`}
|
|
388
|
+
contentInsetAdjustmentBehavior="automatic"
|
|
389
|
+
// A field and its button in one section: the first tap presses the button.
|
|
390
|
+
keyboardShouldPersistTaps="handled"
|
|
391
|
+
contentContainerStyle={{ flexGrow: 1, paddingBottom: 16 }}
|
|
392
|
+
>
|
|
393
|
+
{top}
|
|
394
|
+
{back}
|
|
395
|
+
{content}
|
|
396
|
+
</ScrollView>
|
|
397
|
+
);
|
|
398
|
+
|
|
399
|
+
let screen: ReactNode;
|
|
400
|
+
if (many && !active) {
|
|
401
|
+
screen = scroll(
|
|
402
|
+
<View style={{ padding: 16 }}>
|
|
403
|
+
<Group testID={`${testID}-sections`}>
|
|
404
|
+
{sections.map((s, i) => (
|
|
405
|
+
<Cell key={s.id} last={i === sections.length - 1}>
|
|
406
|
+
<NativeListItem testID={`${testID}-section-${s.id}`} title={s.label} showChevron onPress={() => choose(s.id)} className="bg-transparent" />
|
|
407
|
+
</Cell>
|
|
408
|
+
))}
|
|
409
|
+
</Group>
|
|
410
|
+
</View>,
|
|
411
|
+
);
|
|
412
|
+
} else if (active?.kind === "list") {
|
|
413
|
+
const more = lists?.[active.id];
|
|
414
|
+
screen = (
|
|
392
415
|
<NativeResourceView
|
|
393
416
|
key={active.id}
|
|
394
417
|
view={active.view}
|
|
395
418
|
testID={`${testID}-list`}
|
|
396
|
-
{...
|
|
419
|
+
{...more}
|
|
420
|
+
header={
|
|
421
|
+
<>
|
|
422
|
+
{top}
|
|
423
|
+
{back}
|
|
424
|
+
{more?.header}
|
|
425
|
+
</>
|
|
426
|
+
}
|
|
397
427
|
title={false}
|
|
398
428
|
filter={recordView.listFilter(active.id, record)}
|
|
399
429
|
/>
|
|
400
430
|
);
|
|
401
431
|
} else if (active?.kind === "settings") {
|
|
402
|
-
|
|
403
|
-
<
|
|
432
|
+
screen = scroll(
|
|
433
|
+
<View style={{ padding: 16 }}>
|
|
404
434
|
<SettingsGroup
|
|
405
435
|
// A fresh draft per record and section.
|
|
406
436
|
key={`${String(recordView.recordId(record))}:${active.id}`}
|
|
@@ -414,17 +444,28 @@ export function NativeRecordView<T extends Row = Row>(props: NativeRecordViewPro
|
|
|
414
444
|
}}
|
|
415
445
|
testID={`${testID}-settings`}
|
|
416
446
|
/>
|
|
417
|
-
</
|
|
447
|
+
</View>,
|
|
418
448
|
);
|
|
419
|
-
} else
|
|
420
|
-
|
|
449
|
+
} else {
|
|
450
|
+
// The screen's own section: in the screen's scroll view, or its own (a function slot) with the
|
|
451
|
+
// top as its header.
|
|
452
|
+
const slot = active ? slots?.[active.id] : undefined;
|
|
453
|
+
screen =
|
|
454
|
+
typeof slot === "function" ? (
|
|
455
|
+
slot(
|
|
456
|
+
<>
|
|
457
|
+
{top}
|
|
458
|
+
{back}
|
|
459
|
+
</>,
|
|
460
|
+
)
|
|
461
|
+
) : (
|
|
462
|
+
scroll(slot ?? null)
|
|
463
|
+
);
|
|
421
464
|
}
|
|
422
465
|
|
|
423
466
|
return (
|
|
424
467
|
<View testID={testID} style={{ flex: 1, backgroundColor: colors.groupedBackground }}>
|
|
425
|
-
{
|
|
426
|
-
{back}
|
|
427
|
-
<View style={{ flex: 1 }}>{body}</View>
|
|
468
|
+
{screen}
|
|
428
469
|
</View>
|
|
429
470
|
);
|
|
430
471
|
}
|
|
@@ -240,6 +240,48 @@ describe("NativeRecordView", () => {
|
|
|
240
240
|
await waitFor(() => expect(onSaved).toHaveBeenCalled());
|
|
241
241
|
});
|
|
242
242
|
|
|
243
|
+
it("keeps the whole screen, the top included, in a scroll view iOS insets below the navigation bar", async () => {
|
|
244
|
+
const { unmount } = render(<NativeRecordView view={page} row={brand} section="settings" />, { wrapper: wrap(provider()) });
|
|
245
|
+
const scroll = screen.getByTestId("native-resource-workspace-scroll");
|
|
246
|
+
expect(scroll.getAttribute("contentInsetAdjustmentBehavior")).toBe("automatic");
|
|
247
|
+
expect(within(scroll).getByTestId("native-resource-workspace-sections")).toBeTruthy();
|
|
248
|
+
expect(within(scroll).getByTestId("native-resource-workspace-settings-website-input")).toBeTruthy();
|
|
249
|
+
unmount();
|
|
250
|
+
|
|
251
|
+
// A list section is its own (inset) list, with the top as its header.
|
|
252
|
+
render(<NativeRecordView view={page} row={brand} lists={{ products: { header: <span data-testid="extra-header" /> } }} />, {
|
|
253
|
+
wrapper: wrap(provider()),
|
|
254
|
+
});
|
|
255
|
+
expect(await screen.findByText("Kettle")).toBeTruthy();
|
|
256
|
+
expect(screen.queryByTestId("native-resource-workspace-scroll")).toBeNull();
|
|
257
|
+
const list = screen.getByTestId("native-resource-workspace-list");
|
|
258
|
+
expect(within(list).getByTestId("native-resource-workspace-sections")).toBeTruthy();
|
|
259
|
+
expect(within(list).getByTestId("extra-header")).toBeTruthy();
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it("lets taps through to a section's buttons while the keyboard is up, and lets a slot own its scroll view", () => {
|
|
263
|
+
const { unmount } = render(<NativeRecordView view={page} row={brand} section="activity" slots={{ activity: <span data-testid="feed" /> }} />, {
|
|
264
|
+
wrapper: wrap(provider()),
|
|
265
|
+
});
|
|
266
|
+
const scroll = screen.getByTestId("native-resource-workspace-scroll");
|
|
267
|
+
expect(scroll.getAttribute("keyboardShouldPersistTaps")).toBe("handled");
|
|
268
|
+
expect(within(scroll).getByTestId("feed")).toBeTruthy();
|
|
269
|
+
unmount();
|
|
270
|
+
|
|
271
|
+
// A function slot gets the top for its own list's header; no outer scroll view to nest it in.
|
|
272
|
+
render(
|
|
273
|
+
<NativeRecordView
|
|
274
|
+
view={page}
|
|
275
|
+
row={brand}
|
|
276
|
+
section="activity"
|
|
277
|
+
slots={{ activity: (top) => <div data-testid="own-list">{top}</div> }}
|
|
278
|
+
/>,
|
|
279
|
+
{ wrapper: wrap(provider()) },
|
|
280
|
+
);
|
|
281
|
+
expect(screen.queryByTestId("native-resource-workspace-scroll")).toBeNull();
|
|
282
|
+
expect(within(screen.getByTestId("own-list")).getByTestId("native-resource-workspace-sections")).toBeTruthy();
|
|
283
|
+
});
|
|
284
|
+
|
|
243
285
|
it("shows a zero-row save as a refusal, inline", async () => {
|
|
244
286
|
const p = provider({ update: vi.fn(async () => ({ data: null })) as unknown as DataProvider["update"] });
|
|
245
287
|
render(<NativeRecordView view={page} row={brand} section="settings" />, { wrapper: wrap(p) });
|