@marktiderman/genesis-ui-native 3.2.1 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marktiderman/genesis-ui-native",
3
- "version": "3.2.1",
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
85
  "@hookform/resolvers": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0",
85
- "@marktiderman/genesis-core": "^2.2.1",
86
- "@marktiderman/genesis-design-system": "^1.5.1",
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",
@@ -160,6 +161,10 @@
160
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
  {
@@ -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
- /** The screen's own sections, by id. */
283
- slots?: Partial<Record<string, ReactNode>>;
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
- if (active?.kind === "list") {
391
- body = (
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
- {...lists?.[active.id]}
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
- body = (
403
- <ScrollView contentContainerStyle={{ padding: 16 }} keyboardShouldPersistTaps="handled">
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
- </ScrollView>
447
+ </View>,
418
448
  );
419
- } else if (active) {
420
- body = slots?.[active.id] ?? null;
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
- {top}
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) });