@delacour/react-native-ui 0.9.0 → 0.10.0-alpha.20261120132800

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.10.0-alpha.20261120132800",
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.10.0-alpha.20261120132800",
190
+ "@delacour/react-native-charts": "0.10.0-alpha.20261120132800",
191
191
  "@legendapp/list": ">=3.3",
192
192
  "react-native-skia": ">=3.9.0",
193
193
  "expo-linear-gradient": ">=15",
@@ -15,7 +15,7 @@ sheets.
15
15
  | `calendar.tsx` | Root: selection and month state, bounds, the context value, the `Object.assign` surface |
16
16
  | `calendar-header.tsx` | `Calendar.Header` — prev arrow, caption, next arrow by default |
17
17
  | `calendar-nav.tsx` | `Calendar.Nav` — a ghost `Button` that disables itself at a bound |
18
- | `calendar-caption.tsx` | `Calendar.Caption` — label, or the button that cycles days → months → years |
18
+ | `calendar-caption.tsx` | `Calendar.Caption` — label, or the button that cycles days → months → years. `initialView` picks the view the calendar opens on (picker caption only) |
19
19
  | `calendar-weekdays.tsx` | `Calendar.Weekdays` — short names shown, full names spoken |
20
20
  | `calendar-grid.tsx` | `Calendar.Grid` — six weeks, the paging pan and slide, hosts the picker |
21
21
  | `calendar-day.tsx` | `Calendar.Day` — one cell: band, circle, number or custom content |
@@ -61,6 +61,13 @@ sheets.
61
61
  - **Disabled vs read-only.** `isDisabled` makes everything inert and fades the root. `isReadOnly`
62
62
  ignores day taps and leaves paging working — looking at another month changes nothing.
63
63
 
64
+ ## Opening view
65
+
66
+ - **`initialView` seeds the view once, on mount**, like `defaultMonth`. `years` is for a date of
67
+ birth: a year opens its months, a month its days, so a date decades back is three taps rather
68
+ than dozens of swipes. A `label` caption ignores it and opens on the days, because a jump view
69
+ with no caption button has no way back to them.
70
+
64
71
  ## Layout
65
72
 
66
73
  - **Always six weeks** (`CALENDAR_WEEKS`). A month that fits in four or five rows still draws six,
@@ -356,6 +356,44 @@ describe("Calendar", () => {
356
356
  expect(onMonthChange).toHaveBeenLastCalledWith(day(2026, 3, 1));
357
357
  });
358
358
 
359
+ test('initialView="years" opens on the year list, then walks year, month and day', async () => {
360
+ const onSelect = jest.fn();
361
+ await renderWithProviders(
362
+ <Calendar
363
+ initialView="years"
364
+ locale="en"
365
+ maxDate={day(2008, 11, 20)}
366
+ minDate={day(1926, 11, 20)}
367
+ onSelect={onSelect}
368
+ testID="cal"
369
+ />
370
+ );
371
+ expect(screen.getByRole("button", { name: "1926 – 2008" })).toBeOnTheScreen();
372
+ expect(screen.queryByTestId("cal-day-2008-11-01")).not.toBeOnTheScreen();
373
+
374
+ await fireEvent(screen.getByTestId("cal-year-1990"), "accessibilityTap");
375
+ expect(screen.getByRole("button", { name: "1990" })).toBeOnTheScreen();
376
+
377
+ await fireEvent(screen.getByTestId("cal-month-3"), "accessibilityTap");
378
+ expect(screen.getByRole("button", { name: "March 1990" })).toBeOnTheScreen();
379
+
380
+ await press("1990-03-23");
381
+ expect(onSelect).toHaveBeenLastCalledWith(day(1990, 3, 23));
382
+ });
383
+
384
+ test('initialView="months" opens on the months of the visible year', async () => {
385
+ await renderWithProviders(<Calendar initialView="months" locale="en" testID="cal" />);
386
+ expect(screen.getByRole("button", { name: "2026" })).toBeOnTheScreen();
387
+ expect(screen.getByTestId("cal-month-10")).toBeOnTheScreen();
388
+ });
389
+
390
+ test("initialView is ignored by a label caption, which has no way back to the days", async () => {
391
+ await renderWithProviders(<Calendar captionLayout="label" initialView="years" locale="en" testID="cal" />);
392
+ expect(screen.getByRole("adjustable", { name: "October 2026" })).toBeOnTheScreen();
393
+ expect(screen.queryByTestId("cal-year-2026")).not.toBeOnTheScreen();
394
+ expect(screen.getByTestId("cal-day-2026-10-14")).toBeOnTheScreen();
395
+ });
396
+
359
397
  test('captionLayout="label" is an adjustable text, not a button', async () => {
360
398
  await renderWithProviders(<Calendar captionLayout="label" locale="en" testID="cal" />);
361
399
  expect(screen.getByRole("adjustable", { name: "October 2026" })).toBeOnTheScreen();
@@ -127,6 +127,7 @@ function CalendarRoot(props: CalendarProps): ReactElement {
127
127
  locale,
128
128
  weekStartsOn = "auto",
129
129
  captionLayout = "picker",
130
+ initialView = "days",
130
131
  showOutsideDays = true,
131
132
  selectOutsideDays = false,
132
133
  isBordered = false,
@@ -168,7 +169,8 @@ function CalendarRoot(props: CalendarProps): ReactElement {
168
169
  });
169
170
  const visibleMonth = useMemo(() => startOfMonth(visibleMonthRaw), [visibleMonthRaw]);
170
171
 
171
- const [view, setView] = useState<CalendarView>("days");
172
+ // Read on mount only. A label caption cannot leave a jump view, so it always opens on the days.
173
+ const [view, setView] = useState<CalendarView>(captionLayout === "picker" ? initialView : "days");
172
174
  // The direction counts only for the month the calendar paged to. When `month` changes from
173
175
  // outside, the stale page is dropped during render, so the new month never slides in from the
174
176
  // side of an earlier page.
@@ -1,7 +1,7 @@
1
1
  import type { ReactNode } from "react";
2
2
  import type { ViewProps } from "react-native";
3
3
  import type { CalendarDate, CalendarDateRange, DateMatcher, Weekday } from "./calendar.date";
4
- import type { CalendarSize, CalendarVariant } from "./calendar.variants";
4
+ import type { CalendarSize, CalendarVariant, CalendarView } from "./calendar.variants";
5
5
 
6
6
  /**
7
7
  * What a calendar selects, and the value it reports — one shape per mode.
@@ -71,6 +71,14 @@ export type CalendarProps = Omit<ViewProps, "children"> &
71
71
  weekStartsOn?: Weekday | "auto";
72
72
  /** `picker` makes the caption open the month and year views. */
73
73
  captionLayout?: CalendarCaptionLayout;
74
+ /**
75
+ * The view the calendar opens on. `years` starts a date of birth at the year list: a year
76
+ * opens its months, a month opens its days. Read on mount only, like `defaultMonth`.
77
+ * A `label` caption always opens on the days, since it has no way back to them.
78
+ *
79
+ * @default "days"
80
+ */
81
+ initialView?: CalendarView;
74
82
  /** Draws the neighbouring months' days in the leading and trailing cells. */
75
83
  showOutsideDays?: boolean;
76
84
  /** Lets an outside day be picked, paging to its month. */
@@ -22,7 +22,7 @@ The subpath imports `BottomSheet`, so an app using it installs the optional
22
22
  | `date-picker-value.tsx` | `DatePicker.Value` — the formatted selection or the placeholder; a half range ends on a muted "End" |
23
23
  | `date-picker-icon.tsx` | `DatePicker.Icon` — `IconCalendar1`, muted or destructive |
24
24
  | `date-picker-content.tsx` | `DatePicker.Content` — the sheet (scrim, close, title, calendar, footer), or the calendar in place when inline |
25
- | `date-picker-calendar.tsx` | `DatePicker.Calendar` — `Calendar` bound to the picker, every tap routed through `select` |
25
+ | `date-picker-calendar.tsx` | `DatePicker.Calendar` — `Calendar` bound to the picker, every tap routed through `select`; keyed by `openCount`, so each opening starts on `initialView` (empty) or the value's days |
26
26
  | `date-picker-done.tsx` | `DatePicker.Done` — closes |
27
27
  | `date-picker-clear.tsx` | `DatePicker.Clear` — empties, reports, stays open |
28
28
  | `date-picker.context.tsx` | `DatePickerProvider`, `useDatePicker()`, `useDatePickerContext()`, `useDatePickerPart()` |
@@ -126,13 +126,19 @@ The subpath imports `BottomSheet`, so an app using it installs the optional
126
126
  anatomy can open near a likely date and bound paging and the year list without a custom
127
127
  `DatePicker.Calendar`. Omitted, the calendar derives `startMonth`/`endMonth` from
128
128
  `minDate`/`maxDate`, and opens on the selection's month, else today's.
129
- - **A date of birth sets `maxDate`.** Without it the picker allows future days and the year list
130
- runs a century ahead:
129
+ - **`initialView` and `defaultMonth` apply only while the picker is empty.** With a value, the
130
+ calendar opens on that value's month of days, so an edit starts where the last pick ended rather
131
+ than at the year list or a month chosen for an empty field. The root counts openings
132
+ (`openCount`) and keys the calendar by it, so every opening starts fresh — including a sheet
133
+ reopened before its close settled, or one kept mounted — rather than where the last one was left.
134
+ - **A date of birth sets `maxDate` and opens on the years.** Without `maxDate` the picker allows
135
+ future days and the year list runs a century ahead:
131
136
 
132
137
  ```tsx
133
138
  const now = today();
134
139
  <DatePicker
135
140
  defaultMonth={{ year: now.year - 30, month: 1, day: 1 }}
141
+ initialView="years"
136
142
  maxDate={addYears(now, -18)}
137
143
  minDate={{ year: now.year - 120, month: 1, day: 1 }}
138
144
  onValueChange={field.onChange}
@@ -16,6 +16,7 @@ export type DatePickerCalendarProps = Omit<
16
16
  | "isDisabled"
17
17
  | "isInvalid"
18
18
  | "isReadOnly"
19
+ | "initialView"
19
20
  >;
20
21
 
21
22
  /**
@@ -25,15 +26,19 @@ export type DatePickerCalendarProps = Omit<
25
26
  * included — and hands every tap to the picker's finish rule rather than straight to the caller:
26
27
  * a single day commits and closes, a range commits and closes once both ends exist, several days
27
28
  * commit on every toggle and stay open. Every other `Calendar` prop passes through.
29
+ *
30
+ * Keyed by the picker's `openCount`, so each opening starts on the root's `initialView` (or the
31
+ * picked value's days) even when the sheet engine keeps its content mounted between openings.
28
32
  */
29
33
  export function DatePickerCalendar(props: DatePickerCalendarProps): ReactElement {
30
34
  const picker = useDatePickerPart("DatePicker.Calendar");
31
35
  const { calendar, shown, select } = picker;
32
36
  const common = {
33
37
  captionLayout: calendar.captionLayout,
34
- defaultMonth: calendar.defaultMonth,
38
+ defaultMonth: picker.hasValue ? undefined : calendar.defaultMonth,
35
39
  disabled: calendar.disabled,
36
40
  endMonth: calendar.endMonth,
41
+ initialView: picker.hasValue ? "days" : calendar.initialView,
37
42
  isDisabled: picker.isDisabled,
38
43
  isInvalid: picker.isInvalid,
39
44
  isReadOnly: picker.isReadOnly,
@@ -54,6 +59,7 @@ export function DatePickerCalendar(props: DatePickerCalendarProps): ReactElement
54
59
  return (
55
60
  <Calendar
56
61
  {...common}
62
+ key={picker.openCount}
57
63
  mode="range"
58
64
  onSelect={(value) => select({ mode: "range", value })}
59
65
  selected={shown.value}
@@ -63,6 +69,7 @@ export function DatePickerCalendar(props: DatePickerCalendarProps): ReactElement
63
69
  return (
64
70
  <Calendar
65
71
  {...common}
72
+ key={picker.openCount}
66
73
  mode="multiple"
67
74
  onSelect={(value) => select({ mode: "multiple", value })}
68
75
  selected={shown.value}
@@ -72,6 +79,7 @@ export function DatePickerCalendar(props: DatePickerCalendarProps): ReactElement
72
79
  return (
73
80
  <Calendar
74
81
  {...common}
82
+ key={picker.openCount}
75
83
  mode="single"
76
84
  onSelect={(value) => select({ mode: "single", value })}
77
85
  selected={shown.value}
@@ -1,7 +1,7 @@
1
1
  import { createContext, type ReactElement, type ReactNode, use } from "react";
2
2
  import type { CalendarDate, CalendarSelectionState, DateMatcher, Weekday } from "../calendar/calendar.date";
3
3
  import type { CalendarCaptionLayout } from "../calendar/calendar.types";
4
- import type { CalendarSize } from "../calendar/calendar.variants";
4
+ import type { CalendarSize, CalendarView } from "../calendar/calendar.variants";
5
5
  import type { InputSize, InputVariant } from "../input/input.variants";
6
6
  import type { DatePickerMode, DatePickerPresentation } from "./date-picker.variants";
7
7
 
@@ -48,6 +48,11 @@ export type DatePickerContextValue = {
48
48
  description: string | undefined;
49
49
  doneLabel: string;
50
50
  clearLabel: string;
51
+ /**
52
+ * Counts the sheet's openings. The calendar is keyed by it, so each opening starts on
53
+ * `initialView` and the selection's month, never where the last opening was left.
54
+ */
55
+ openCount: number;
51
56
  calendar: {
52
57
  size: CalendarSize;
53
58
  minDate: CalendarDate | undefined;
@@ -58,6 +63,8 @@ export type DatePickerContextValue = {
58
63
  disabled: readonly DateMatcher[] | undefined;
59
64
  weekStartsOn: Weekday | "auto";
60
65
  captionLayout: CalendarCaptionLayout;
66
+ /** The view an empty picker's calendar opens on. A picked value always opens on its days. */
67
+ initialView: CalendarView;
61
68
  selectOutsideDays: boolean;
62
69
  today: CalendarDate | undefined;
63
70
  };
@@ -430,3 +430,59 @@ describe("DatePicker parts", () => {
430
430
  }
431
431
  });
432
432
  });
433
+
434
+ describe("DatePicker initialView", () => {
435
+ const bounds = { maxDate: { day: 20, month: 11, year: 2008 }, minDate: { day: 20, month: 11, year: 1926 } };
436
+ const year = (y: number) => screen.queryByTestId(`stay-calendar-year-${y}`);
437
+ const caption = () => screen.getByTestId("stay-calendar-caption");
438
+
439
+ test("an empty picker opens on the years, then walks year, month and day to a pick", async () => {
440
+ const onValueChange = jest.fn();
441
+ await renderWithProviders(<Picker defaultOpen initialView="years" onValueChange={onValueChange} {...bounds} />, {
442
+ wrapper: Providers,
443
+ });
444
+ expect(year(1990)).toBeOnTheScreen();
445
+ await tap(screen.getByTestId("stay-calendar-year-1990"));
446
+ await tap(screen.getByTestId("stay-calendar-month-3"));
447
+ await tap(day("1990-03-23"));
448
+ expect(onValueChange).toHaveBeenCalledWith({ day: 23, month: 3, year: 1990 });
449
+ });
450
+
451
+ test("a picked value opens on its month's days, not the years", async () => {
452
+ await renderWithProviders(
453
+ <Picker defaultOpen defaultValue={{ day: 23, month: 3, year: 1990 }} initialView="years" {...bounds} />,
454
+ { wrapper: Providers }
455
+ );
456
+ expect(caption()).toHaveAccessibleName("March 1990");
457
+ expect(year(1990)).not.toBeOnTheScreen();
458
+ });
459
+
460
+ test("reopening after a pick shows the picked month's days, even with a defaultMonth", async () => {
461
+ await renderWithProviders(
462
+ <Picker defaultMonth={{ day: 1, month: 1, year: 1996 }} initialView="years" {...bounds} />,
463
+ { wrapper: Providers }
464
+ );
465
+ await tap(trigger());
466
+ await tap(screen.getByTestId("stay-calendar-year-1990"));
467
+ await tap(screen.getByTestId("stay-calendar-month-3"));
468
+ await tap(day("1990-03-23"));
469
+ await settle();
470
+ expect(trigger()).not.toBeExpanded();
471
+
472
+ await tap(trigger());
473
+ expect(caption()).toHaveAccessibleName("March 1990");
474
+ expect(year(1990)).not.toBeOnTheScreen();
475
+ });
476
+
477
+ test("starts again on the years each time the sheet opens while empty", async () => {
478
+ const { rerender } = await renderWithProviders(<Picker initialView="years" isOpen {...bounds} />, {
479
+ wrapper: Providers,
480
+ });
481
+ await tap(screen.getByTestId("stay-calendar-year-1990"));
482
+ expect(year(1990)).not.toBeOnTheScreen();
483
+
484
+ await rerender(<Picker initialView="years" isOpen={false} {...bounds} />);
485
+ await rerender(<Picker initialView="years" isOpen {...bounds} />);
486
+ expect(year(1990)).toBeOnTheScreen();
487
+ });
488
+ });
@@ -83,6 +83,7 @@ function DatePickerRoot(props: DatePickerProps): ReactElement {
83
83
  locale,
84
84
  weekStartsOn = "auto",
85
85
  captionLayout = "picker",
86
+ initialView = "days",
86
87
  minDate,
87
88
  maxDate,
88
89
  defaultMonth,
@@ -157,6 +158,15 @@ function DatePickerRoot(props: DatePickerProps): ReactElement {
157
158
  setRangeDraft(null);
158
159
  }, [cancelPendingClose, isOpen, presentation]);
159
160
 
161
+ // Counted during render, the way React derives state from a prop: each opening, controlled or
162
+ // not, remounts the calendar on `initialView`.
163
+ const [openCount, setOpenCount] = useState(0);
164
+ const [wasOpen, setWasOpen] = useState(isOpen);
165
+ if (isOpen !== wasOpen) {
166
+ setWasOpen(isOpen);
167
+ if (isOpen) setOpenCount((count) => count + 1);
168
+ }
169
+
160
170
  const trigger = resolveTriggerState({ ...axes, isOpen });
161
171
 
162
172
  const open = useCallback(() => {
@@ -248,6 +258,7 @@ function DatePickerRoot(props: DatePickerProps): ReactElement {
248
258
  defaultMonth,
249
259
  disabled: disabledDates,
250
260
  endMonth,
261
+ initialView,
251
262
  maxDate,
252
263
  minDate,
253
264
  selectOutsideDays,
@@ -272,6 +283,7 @@ function DatePickerRoot(props: DatePickerProps): ReactElement {
272
283
  locale,
273
284
  mode,
274
285
  open,
286
+ openCount,
275
287
  placeholder: placeholder ?? resolveDefaultPlaceholder(mode),
276
288
  presentation,
277
289
  select,
@@ -301,6 +313,7 @@ function DatePickerRoot(props: DatePickerProps): ReactElement {
301
313
  doneLabel,
302
314
  endMonth,
303
315
  field?.label,
316
+ initialView,
304
317
  isClearable,
305
318
  isOpen,
306
319
  locale,
@@ -308,6 +321,7 @@ function DatePickerRoot(props: DatePickerProps): ReactElement {
308
321
  minDate,
309
322
  mode,
310
323
  open,
324
+ openCount,
311
325
  placeholder,
312
326
  presentation,
313
327
  select,
@@ -389,9 +403,10 @@ function DatePickerRoot(props: DatePickerProps): ReactElement {
389
403
  * <DatePicker disabledDates={[{ type: "weekday", days: [0, 6] }]} mode="multiple" />
390
404
  *
391
405
  * @example
392
- * // A date of birth: no future days, opens near a likely year, the year list bounded.
406
+ * // A date of birth: no future days, opens on the year list near a likely year, bounded.
393
407
  * <DatePicker
394
408
  * defaultMonth={{ year: today().year - 30, month: 1, day: 1 }}
409
+ * initialView="years"
395
410
  * maxDate={addYears(today(), -18)}
396
411
  * minDate={{ year: today().year - 120, month: 1, day: 1 }}
397
412
  * onValueChange={setDob}
@@ -2,7 +2,7 @@ import type { ReactNode } from "react";
2
2
  import type { ViewProps } from "react-native";
3
3
  import type { CalendarDate, CalendarDateRange, DateMatcher, Weekday } from "../calendar/calendar.date";
4
4
  import type { CalendarCaptionLayout } from "../calendar/calendar.types";
5
- import type { CalendarSize } from "../calendar/calendar.variants";
5
+ import type { CalendarSize, CalendarView } from "../calendar/calendar.variants";
6
6
  import type { InputSize, InputVariant } from "../input/input.variants";
7
7
  import type { DatePickerFormat, DatePickerFormatRange, DatePickerPresentation } from "./date-picker.variants";
8
8
 
@@ -57,11 +57,22 @@ export type DatePickerProps = Omit<ViewProps, "children"> &
57
57
  weekStartsOn?: Weekday | "auto";
58
58
  /** `picker` makes the calendar's caption open the month and year views. */
59
59
  captionLayout?: CalendarCaptionLayout;
60
+ /**
61
+ * The view the calendar opens on while nothing is picked. `years` starts a date of birth at
62
+ * the year list: a year opens its months, a month its days. With a value, the calendar opens
63
+ * on that value's days, so an edit starts where the last pick ended.
64
+ *
65
+ * @default "days"
66
+ */
67
+ initialView?: CalendarView;
60
68
  /** The earliest day that can be picked, inclusive. */
61
69
  minDate?: CalendarDate;
62
70
  /** The latest day that can be picked, inclusive. */
63
71
  maxDate?: CalendarDate;
64
- /** The month the calendar opens on. Omitted, the selection's month, else today's. */
72
+ /**
73
+ * The month an empty picker's calendar opens on. Omitted, today's. With a value, the calendar
74
+ * opens on the value's month instead.
75
+ */
65
76
  defaultMonth?: CalendarDate;
66
77
  /** The earliest month paging and the year list reach. Omitted, `minDate`'s month. */
67
78
  startMonth?: CalendarDate;
@@ -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
  *