@delacour/react-native-ui 0.9.0 → 0.9.1-alpha.20261120122915

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.9.0",
3
+ "version": "0.9.1-alpha.20261120122915",
4
4
  "description": "React Native UI components — Uniwind, Reanimated, Gesture Handler",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -186,8 +186,8 @@
186
186
  "expo-blur": ">=15",
187
187
  "@maplibre/maplibre-react-native": "^11.5.0",
188
188
  "@central-icons-react-native/round-outlined-radius-1-stroke-1.5": "^1.1",
189
- "@delacour/react-native-bottom-sheet": ">=0.9.0",
190
- "@delacour/react-native-charts": ">=0.9.0",
189
+ "@delacour/react-native-bottom-sheet": "0.9.1-alpha.20261120122915",
190
+ "@delacour/react-native-charts": "0.9.1-alpha.20261120122915",
191
191
  "@legendapp/list": ">=3.3",
192
192
  "react-native-skia": ">=3.9.0",
193
193
  "expo-linear-gradient": ">=15",
@@ -24,8 +24,8 @@ engine. An app that imports no picker still never resolves it.
24
24
  | `select.collect.ts` | `collectOptions` / `findChildOfType` — reads the markers into the `options` shape |
25
25
  | `select.context.tsx` | `SelectProvider`, `useSelect()`, `useSelectContext()`, `useSelectPart()` |
26
26
  | `select.types.ts` | `SelectOption`, `SelectOptionGroup`, `SelectRowOption`, `SelectEntry`, `SelectListRow`, `SelectHighlightRange` |
27
- | `select.variants.ts` | Pure `tv()` slots + every resolver, no RN imports — the sheet cap and the searchable list's floor among them |
28
- | `select.render.test.tsx` | Mounted under Jest inside `BottomSheetProvider` — trigger role, expanded and value, single and multiple picks, controlled and uncontrolled, limit, search, `Field` inheritance, parts outside a root |
27
+ | `select.variants.ts` | Pure `tv()` slots + every resolver, no RN imports — the sheet cap, the searchable list's floor and the list's virtualisation window among them |
28
+ | `select.render.test.tsx` | Mounted under Jest inside `BottomSheetProvider` — trigger role, expanded and value, single and multiple picks, controlled and uncontrolled, limit, search, long-list virtualisation, `Field` inheritance, parts outside a root |
29
29
  | `select.variants.test.ts` | |
30
30
  | `select.collect.test.ts` | |
31
31
 
@@ -109,6 +109,15 @@ engine. An app that imports no picker still never resolves it.
109
109
  short searchable list sits at the top of a full-height sheet, as `Combobox`'s
110
110
  does. Without search the rows cannot change while it is open, so it keeps
111
111
  sizing to them.
112
+ - **A long list mounts the rows near its viewport, not all of them.**
113
+ `resolveSelectListWindow` sizes `BottomSheet.FlatList`'s virtualisation from
114
+ the sheet's cap: the first paint and every later batch are one sheet of rows
115
+ at the row floor (`SELECT_ROW_MIN_HEIGHT`, pinned to the `row` slot's
116
+ `min-h-*` by the test), and `windowSize` is `SELECT_LIST_WINDOW_SIZE` (5)
117
+ viewports. On React Native's defaults — 10 rows first, 10 more every 50ms, a
118
+ window of 21 — a searchable Select with ~250 options mounted 120-odd rows,
119
+ each with an animated indicator, while the sheet was still opening, and the
120
+ open stuttered. On a simulator it now mounts 32.
112
121
  - **Scrolling a searchable list keeps the keyboard up**, as in `Combobox`. The
113
122
  engine puts the keyboard away the moment any pan starts on the sheet
114
123
  (`enableBlurKeyboardOnGesture`), and its lists dismiss interactively, so
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, jest, test } from "@jest/globals";
2
2
  import { type ReactElement, type ReactNode, useState } from "react";
3
- import { fireEvent, renderWithProviders, screen, waitFor } from "../../test/render";
3
+ import { act, fireEvent, renderWithProviders, screen, waitFor } from "../../test/render";
4
4
  import { BottomSheetProvider } from "../bottom-sheet";
5
5
  import { Button } from "../button";
6
6
  import { Field } from "../field";
@@ -23,6 +23,34 @@ const trigger = (name = "Choose") => screen.getByRole("button", { name });
23
23
  const valueText = () => trigger().props.accessibilityValue?.text;
24
24
  const openSheet = async (name?: string) => tap(trigger(name));
25
25
 
26
+ /** `settleList` waits 40 passes of 60ms by design; Jest's 5s default leaves no room on a loaded runner. */
27
+ const SETTLE_TIMEOUT_MS = 20_000;
28
+
29
+ /**
30
+ * Lays the open sheet's list out as a device would, pass by pass: the viewport
31
+ * and content size on the scroll view, then a height on each mounted cell,
32
+ * until the list has had time to mount every batch it wants.
33
+ */
34
+ async function settleList({ rowHeight, viewportHeight }: { rowHeight: number; viewportHeight: number }) {
35
+ let list = screen.getAllByRole("radio")[0]?.parent ?? null;
36
+ while (list && !list.props.onContentSizeChange) list = list.parent;
37
+ if (!list) throw new Error("No list is open.");
38
+ await fireEvent(list, "layout", { nativeEvent: { layout: { height: viewportHeight, width: 400, x: 0, y: 0 } } });
39
+ await fireEvent(list, "contentSizeChange", 400, rowHeight * 250);
40
+ for (let pass = 0; pass < 40; pass++) {
41
+ for (const [index, row] of screen.queryAllByRole("radio").entries()) {
42
+ let cell = row.parent;
43
+ while (cell && cell !== list && !cell.props.onLayout) cell = cell.parent;
44
+ if (!cell || cell === list) continue;
45
+ const layout = { height: rowHeight, width: 400, x: 0, y: index * rowHeight };
46
+ await fireEvent(cell, "layout", { nativeEvent: { layout } });
47
+ }
48
+ await act(async () => {
49
+ await new Promise((resolve) => setTimeout(resolve, 60));
50
+ });
51
+ }
52
+ }
53
+
26
54
  /** Prints the className it receives, so a test can see what a Slot handed it. */
27
55
  function ClassProbe({ className }: { className?: string }): ReactElement {
28
56
  return <Text testID="probe">{className ?? ""}</Text>;
@@ -430,6 +458,20 @@ describe("Select search", () => {
430
458
  expect(screen.queryByLabelText("Search")).not.toBeOnTheScreen();
431
459
  });
432
460
 
461
+ test(
462
+ "a long list mounts the rows near the viewport, not the whole list",
463
+ async () => {
464
+ const many = Array.from({ length: 250 }, (_, index) => ({ label: `Option ${index}`, value: `o${index}` }));
465
+ await renderSelect({ isSearchable: true, options: many });
466
+ await openSheet();
467
+ await settleList({ rowHeight: 64, viewportHeight: 700 });
468
+ const mounted = screen.queryAllByRole("radio").length;
469
+ expect(mounted).toBeGreaterThan(10);
470
+ expect(mounted).toBeLessThanOrEqual(60);
471
+ },
472
+ SETTLE_TIMEOUT_MS
473
+ );
474
+
433
475
  test("the query clears when the sheet closes", async () => {
434
476
  await renderSelect({ isSearchable: true, options: countries });
435
477
  await openSheet();
@@ -21,6 +21,7 @@ import {
21
21
  normalizeOptions,
22
22
  resolveSelectedOptions,
23
23
  resolveSelectListMinHeight,
24
+ resolveSelectListWindow,
24
25
  resolveSelectRowState,
25
26
  resolveSelectSheetMaxHeight,
26
27
  resolveSelectTriggerText,
@@ -243,6 +244,8 @@ function SelectRoot(props: SelectProps): ReactElement {
243
244
  [listMinHeight]
244
245
  );
245
246
 
247
+ const listWindow = resolveSelectListWindow({ maxHeight: sheetMaxHeight, size });
248
+
246
249
  const rows = buildSelectRows(isSearchable ? filterGroups(entries, query) : entries);
247
250
  const slots = selectVariants({ size, variant });
248
251
 
@@ -344,12 +347,15 @@ function SelectRoot(props: SelectProps): ReactElement {
344
347
  contentContainerStyle={listContentStyle}
345
348
  data={rows}
346
349
  extraData={selected}
350
+ initialNumToRender={listWindow.initialNumToRender}
347
351
  keyboardDismissMode={isSearchable ? "none" : undefined}
348
352
  keyboardShouldPersistTaps="handled"
349
353
  keyExtractor={(row) => row.key}
350
354
  ListEmptyComponent={empty}
351
355
  ListHeaderComponent={header}
356
+ maxToRenderPerBatch={listWindow.maxToRenderPerBatch}
352
357
  renderItem={renderRow}
358
+ windowSize={listWindow.windowSize}
353
359
  />
354
360
  {multiple ? (
355
361
  <BottomSheet.Footer sticky>
@@ -12,11 +12,14 @@ import {
12
12
  normalizeSearchText,
13
13
  resolveSelectIconToken,
14
14
  resolveSelectListMinHeight,
15
+ resolveSelectListWindow,
15
16
  resolveSelectRowState,
16
17
  resolveSelectSheetMaxHeight,
17
18
  resolveSelectTriggerClass,
18
19
  resolveSelectTriggerText,
19
20
  SELECT_DEFAULT_MAX_LABELS,
21
+ SELECT_LIST_WINDOW_SIZE,
22
+ SELECT_ROW_MIN_HEIGHT,
20
23
  SELECT_SHEET_MAX_FRACTION,
21
24
  SELECT_SHEET_TOP_GAP,
22
25
  selectVariants,
@@ -575,3 +578,31 @@ describe("resolveSelectListMinHeight", () => {
575
578
  expect(resolveSelectListMinHeight({ isSearchable: true, maxHeight, snapPoints: ["50%"] })).toBeUndefined();
576
579
  });
577
580
  });
581
+
582
+ describe("resolveSelectListWindow", () => {
583
+ const maxHeight = resolveSelectSheetMaxHeight({ topInset: 62, windowHeight: 874 });
584
+
585
+ test.each(INPUT_SIZES)("a %s row floor matches the row slot's min-h class", (size) => {
586
+ expect(selectVariants({ size }).row()).toContain(`min-h-${SELECT_ROW_MIN_HEIGHT[size] / 4}`);
587
+ });
588
+
589
+ test.each(INPUT_SIZES)("the first paint fills a %s sheet at its cap and no more", (size) => {
590
+ const { initialNumToRender } = resolveSelectListWindow({ maxHeight, size });
591
+ expect(initialNumToRender * SELECT_ROW_MIN_HEIGHT[size]).toBeGreaterThanOrEqual(maxHeight);
592
+ expect((initialNumToRender - 1) * SELECT_ROW_MIN_HEIGHT[size]).toBeLessThan(maxHeight);
593
+ });
594
+
595
+ test("each later batch is one sheet of rows", () => {
596
+ const window = resolveSelectListWindow({ maxHeight, size: "lg" });
597
+ expect(window.maxToRenderPerBatch).toBe(window.initialNumToRender);
598
+ });
599
+
600
+ test("keeps a few viewports mounted, not React Native's default of 21", () => {
601
+ expect(resolveSelectListWindow({ maxHeight, size: "md" }).windowSize).toBe(SELECT_LIST_WINDOW_SIZE);
602
+ expect(SELECT_LIST_WINDOW_SIZE).toBeLessThan(21);
603
+ });
604
+
605
+ test("a zero cap still paints one row", () => {
606
+ expect(resolveSelectListWindow({ maxHeight: 0, size: "md" }).initialNumToRender).toBe(1);
607
+ });
608
+ });
@@ -1,6 +1,6 @@
1
1
  import type { VariantProps } from "tailwind-variants";
2
2
  import { tv } from "../../lib/tv";
3
- import { type InputBoxState, resolveInputGroupClass } from "../input/input.variants";
3
+ import { type InputBoxState, type InputSize, resolveInputGroupClass } from "../input/input.variants";
4
4
  import type {
5
5
  SelectEntry,
6
6
  SelectHighlightRange,
@@ -89,6 +89,33 @@ export function resolveSelectListMinHeight({
89
89
  return isSearchable && snapPoints === undefined ? maxHeight : undefined;
90
90
  }
91
91
 
92
+ /** A row's floor in points at each size — the `row` slot's `min-h-12/14/16`. The test pins the pair. */
93
+ export const SELECT_ROW_MIN_HEIGHT: Record<InputSize, number> = { sm: 48, md: 56, lg: 64 };
94
+
95
+ /** How many viewports of rows the list keeps mounted: the visible one and two either side. */
96
+ export const SELECT_LIST_WINDOW_SIZE = 5;
97
+
98
+ /**
99
+ * How the sheet's list virtualises.
100
+ *
101
+ * On React Native's defaults — 10 rows first, 10 more every 50ms, a window of
102
+ * 21 viewports — a list of about 250 options mounted nearly every row, batch by
103
+ * batch, while the sheet was still opening, and every row carries an animated
104
+ * indicator of its own. The JS thread stayed busy for the whole open and the
105
+ * sheet stuttered. The first paint fills the sheet at its cap, each later batch
106
+ * is one more sheet, and the window keeps the rows a quick fling reaches
107
+ * without mounting the rest. A row's floor is the smallest it can measure, so
108
+ * the count never comes up short of the viewport.
109
+ */
110
+ export function resolveSelectListWindow({ maxHeight, size }: { maxHeight: number; size: InputSize }): {
111
+ initialNumToRender: number;
112
+ maxToRenderPerBatch: number;
113
+ windowSize: number;
114
+ } {
115
+ const rows = Math.max(1, Math.ceil(maxHeight / SELECT_ROW_MIN_HEIGHT[size]));
116
+ return { initialNumToRender: rows, maxToRenderPerBatch: rows, windowSize: SELECT_LIST_WINDOW_SIZE };
117
+ }
118
+
92
119
  /**
93
120
  * Styling for every part of a select.
94
121
  *