@delacour/react-native-ui 0.9.0 → 0.10.0-alpha.20261120132923
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 +3 -3
- package/src/components/calendar/AGENTS.md +8 -1
- package/src/components/calendar/calendar.render.test.tsx +38 -0
- package/src/components/calendar/calendar.tsx +3 -1
- package/src/components/calendar/calendar.types.ts +9 -1
- package/src/components/date-picker/AGENTS.md +9 -3
- package/src/components/date-picker/date-picker-calendar.tsx +9 -1
- package/src/components/date-picker/date-picker.context.tsx +8 -1
- package/src/components/date-picker/date-picker.render.test.tsx +56 -0
- package/src/components/date-picker/date-picker.tsx +16 -1
- package/src/components/date-picker/date-picker.types.ts +13 -2
- package/src/components/screen/AGENTS.md +22 -0
- package/src/components/screen/screen-footer.tsx +33 -2
- package/src/components/screen/screen.context.tsx +10 -0
- package/src/components/screen/screen.render.test.tsx +90 -0
- package/src/components/screen/screen.variants.test.ts +6 -0
- package/src/components/screen/screen.variants.ts +8 -3
- package/src/components/screen/use-screen-scroll-insets.ts +26 -1
- package/src/components/select/AGENTS.md +11 -2
- package/src/components/select/select.render.test.tsx +43 -1
- package/src/components/select/select.tsx +6 -0
- package/src/components/select/select.variants.test.ts +31 -0
- package/src/components/select/select.variants.ts +28 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@delacour/react-native-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0-alpha.20261120132923",
|
|
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": "
|
|
190
|
-
"@delacour/react-native-charts": "
|
|
189
|
+
"@delacour/react-native-bottom-sheet": "0.10.0-alpha.20261120132923",
|
|
190
|
+
"@delacour/react-native-charts": "0.10.0-alpha.20261120132923",
|
|
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
|
-
|
|
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
|
-
-
|
|
130
|
-
|
|
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,
|
|
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
|
-
/**
|
|
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;
|
|
@@ -122,6 +122,28 @@ whole-screen states.
|
|
|
122
122
|
open keyboard and excludes the band the sticky shift parks behind it.
|
|
123
123
|
Conflating them is a real bug — the derivation is in the block comment above
|
|
124
124
|
them, and the tests pin both.
|
|
125
|
+
- **`keyboardOffset` stacks a sticky footer on a bar riding the keyboard.** A
|
|
126
|
+
form's previous / next / done toolbar sits on top of the keyboard, and a
|
|
127
|
+
sticky footer that only knew the keyboard's height parked its submit button
|
|
128
|
+
behind that bar. The footer's `offset.opened` becomes `bottom - keyboardOffset`,
|
|
129
|
+
and the footer publishes the value on the screen context
|
|
130
|
+
(`footer.keyboardOffset`) — reset to 0 on unmount — so
|
|
131
|
+
`useScreenFooterKeyboardClearance` adds the same distance and a keyboard-aware
|
|
132
|
+
scroll area keeps the focused field clear of the lifted footer. The value is
|
|
133
|
+
the distance from the keyboard's top edge to the bar's top edge — the bar's
|
|
134
|
+
height plus any gap it floats at (keyboard-controller's `KeyboardToolbar`
|
|
135
|
+
floats 11pt above a keyboard with rounded corners) — built from the bar's own
|
|
136
|
+
constants, never a literal: a literal drifts the day the bar is restyled, and
|
|
137
|
+
the footer then overlaps it or floats a gap above it. A footer that is not
|
|
138
|
+
sticky publishes 0, because it does not lift.
|
|
139
|
+
- **Two scrollables do not read `keyboardOffset` yet.** `resolveScrollBottomInset`
|
|
140
|
+
does not add it, so with the keyboard open and a list scrolled to its very end
|
|
141
|
+
the last `keyboardOffset` points of content sit under the footer. And
|
|
142
|
+
`Screen.ChatList` lifts its content by the keyboard minus its own `offset`
|
|
143
|
+
(the safe-area inset by default) and never reads the footer's, so a sticky
|
|
144
|
+
composer given a `keyboardOffset` covers the newest messages by that much —
|
|
145
|
+
pass the chat list `offset={bottom - keyboardOffset}` until it reads the
|
|
146
|
+
context.
|
|
125
147
|
|
|
126
148
|
## Lists
|
|
127
149
|
|
|
@@ -40,6 +40,19 @@ export type ScreenFooterProps = ScreenPlacementProps & {
|
|
|
40
40
|
* React Navigation both expose `useIsFocused()`.
|
|
41
41
|
*/
|
|
42
42
|
isFocused?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Lift a sticky footer this many points further while the keyboard is open,
|
|
45
|
+
* so it sits on a bar that rides the keyboard — a form's previous / next /
|
|
46
|
+
* done toolbar — instead of hiding under it. A keyboard-aware scroll area
|
|
47
|
+
* clears the same extra distance, through the screen context.
|
|
48
|
+
*
|
|
49
|
+
* The distance from the keyboard's top edge to the bar's top edge: the bar's
|
|
50
|
+
* height plus any gap it floats at. Build it from the bar's own constants,
|
|
51
|
+
* never a literal. Only applies to a `sticky` footer.
|
|
52
|
+
*
|
|
53
|
+
* @default 0
|
|
54
|
+
*/
|
|
55
|
+
keyboardOffset?: number;
|
|
43
56
|
};
|
|
44
57
|
|
|
45
58
|
/**
|
|
@@ -80,12 +93,18 @@ export type ScreenFooterProps = ScreenPlacementProps & {
|
|
|
80
93
|
* <Screen.Footer sticky>
|
|
81
94
|
* <MessageComposer />
|
|
82
95
|
* </Screen.Footer>
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* <Screen.Footer keyboardOffset={TOOLBAR_OFFSET} sticky>
|
|
99
|
+
* <Button onPress={submit}>Submit</Button>
|
|
100
|
+
* </Screen.Footer>
|
|
83
101
|
*/
|
|
84
102
|
export function ScreenFooter({
|
|
85
103
|
placement = "overlay",
|
|
86
104
|
sticky = false,
|
|
87
105
|
fadeBorderOnScroll = false,
|
|
88
106
|
isFocused = true,
|
|
107
|
+
keyboardOffset = 0,
|
|
89
108
|
className,
|
|
90
109
|
children,
|
|
91
110
|
style,
|
|
@@ -132,6 +151,17 @@ export function ScreenFooter({
|
|
|
132
151
|
footer.placement.value = placement;
|
|
133
152
|
}, [placement, footer.placement]);
|
|
134
153
|
|
|
154
|
+
// Published so a keyboard-aware scrollable clears the bar under the footer
|
|
155
|
+
// too, and cleared on unmount so a screen without the bar stops clearing it.
|
|
156
|
+
// A footer that is not sticky never lifts, so it publishes 0: otherwise the
|
|
157
|
+
// scrollable would scroll the focused field past a gap that is not there.
|
|
158
|
+
useEffect(() => {
|
|
159
|
+
footer.keyboardOffset.value = sticky ? keyboardOffset : 0;
|
|
160
|
+
return () => {
|
|
161
|
+
footer.keyboardOffset.value = 0;
|
|
162
|
+
};
|
|
163
|
+
}, [sticky, keyboardOffset, footer.keyboardOffset]);
|
|
164
|
+
|
|
135
165
|
useEffect(() => {
|
|
136
166
|
return () => {
|
|
137
167
|
footer.height.value = 0;
|
|
@@ -147,8 +177,9 @@ export function ScreenFooter({
|
|
|
147
177
|
// Shift by the inset rather than animating the padding away: the
|
|
148
178
|
// footer's safe-area band is meaningless once the keyboard covers it,
|
|
149
179
|
// and animating padding leaves a visible gap between the two
|
|
150
|
-
// mid-transition.
|
|
151
|
-
|
|
180
|
+
// mid-transition. `keyboardOffset` lifts it further, onto a bar that
|
|
181
|
+
// rides the keyboard.
|
|
182
|
+
offset={{ closed: 0, opened: bottom - keyboardOffset }}
|
|
152
183
|
style={{ paddingBottom: SCREEN_FLOATING_BOTTOM_GAP, paddingTop: SCREEN_FOOTER_PADDING }}
|
|
153
184
|
>
|
|
154
185
|
<ScreenFooterBackground fadeOnScroll={fadeBorderOnScroll} placement={placement} />
|
|
@@ -34,6 +34,13 @@ export type ScreenFooterMeasurements = {
|
|
|
34
34
|
* this — whoever drives it owns clearing it.
|
|
35
35
|
*/
|
|
36
36
|
overlayHeight: SharedValue<number>;
|
|
37
|
+
/**
|
|
38
|
+
* How far a sticky footer sits above the open keyboard's top edge — the
|
|
39
|
+
* height of a bar riding the keyboard under it, or 0. A keyboard-aware
|
|
40
|
+
* scrollable adds it to the clearance its focused input needs. The footer
|
|
41
|
+
* writes it from its `keyboardOffset` prop and resets it on unmount.
|
|
42
|
+
*/
|
|
43
|
+
keyboardOffset: SharedValue<number>;
|
|
37
44
|
};
|
|
38
45
|
|
|
39
46
|
/** Everything a screen's parts share, all of it readable from the UI thread. */
|
|
@@ -85,6 +92,7 @@ export function ScreenProvider({ parentContext = null, debug = false, children }
|
|
|
85
92
|
const footerHeight = useSharedValue<number>(0);
|
|
86
93
|
const footerInitialHeight = useSharedValue<number>(0);
|
|
87
94
|
const footerOverlayHeight = useSharedValue<number>(0);
|
|
95
|
+
const footerKeyboardOffset = useSharedValue<number>(0);
|
|
88
96
|
|
|
89
97
|
const scrollY = useSharedValue<number>(0);
|
|
90
98
|
const contentHeight = useSharedValue<number>(0);
|
|
@@ -100,6 +108,7 @@ export function ScreenProvider({ parentContext = null, debug = false, children }
|
|
|
100
108
|
height: footerHeight,
|
|
101
109
|
initialHeight: footerInitialHeight,
|
|
102
110
|
overlayHeight: footerOverlayHeight,
|
|
111
|
+
keyboardOffset: footerKeyboardOffset,
|
|
103
112
|
},
|
|
104
113
|
scrollY,
|
|
105
114
|
contentHeight,
|
|
@@ -114,6 +123,7 @@ export function ScreenProvider({ parentContext = null, debug = false, children }
|
|
|
114
123
|
footerHeight,
|
|
115
124
|
footerInitialHeight,
|
|
116
125
|
footerOverlayHeight,
|
|
126
|
+
footerKeyboardOffset,
|
|
117
127
|
scrollY,
|
|
118
128
|
contentHeight,
|
|
119
129
|
layoutHeight,
|
|
@@ -4,6 +4,7 @@ import { Text } from "react-native";
|
|
|
4
4
|
import { fireEvent, renderWithProviders, screen } from "../../test/render";
|
|
5
5
|
import { Button } from "../button";
|
|
6
6
|
import { Screen } from "./screen";
|
|
7
|
+
import { type ScreenContextValue, useScreen } from "./screen.context";
|
|
7
8
|
|
|
8
9
|
const tap = (name: string) => fireEvent(screen.getByRole("button", { name }), "accessibilityTap");
|
|
9
10
|
|
|
@@ -81,6 +82,95 @@ describe("Screen", () => {
|
|
|
81
82
|
expect(screen.getByText("Footer note")).toBeOnTheScreen();
|
|
82
83
|
});
|
|
83
84
|
|
|
85
|
+
test("a sticky footer's keyboardOffset lifts it that far above the open keyboard", async () => {
|
|
86
|
+
// The keyboard mock renders the sticky view as a plain View, so its offset is a prop on the
|
|
87
|
+
// nearest ancestor of the footer's content that carries one.
|
|
88
|
+
const stickyOffset = () => {
|
|
89
|
+
let node = screen.getByText("Footer note").parent;
|
|
90
|
+
while (node && node.props.offset === undefined) node = node.parent;
|
|
91
|
+
return node?.props.offset;
|
|
92
|
+
};
|
|
93
|
+
const view = await renderWithProviders(
|
|
94
|
+
<Screen>
|
|
95
|
+
<Screen.Footer sticky>
|
|
96
|
+
<Text>Footer note</Text>
|
|
97
|
+
</Screen.Footer>
|
|
98
|
+
</Screen>
|
|
99
|
+
);
|
|
100
|
+
expect(stickyOffset()).toEqual({ closed: 0, opened: 0 });
|
|
101
|
+
|
|
102
|
+
await view.rerender(
|
|
103
|
+
<Screen>
|
|
104
|
+
<Screen.Footer keyboardOffset={44} sticky>
|
|
105
|
+
<Text>Footer note</Text>
|
|
106
|
+
</Screen.Footer>
|
|
107
|
+
</Screen>
|
|
108
|
+
);
|
|
109
|
+
expect(stickyOffset()).toEqual({ closed: 0, opened: -44 });
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("a footer publishes its keyboardOffset on the screen context, and clears it when it unmounts", async () => {
|
|
113
|
+
const captured: { context: ScreenContextValue | null } = { context: null };
|
|
114
|
+
function Probe(): null {
|
|
115
|
+
captured.context = useScreen();
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
const view = await renderWithProviders(
|
|
119
|
+
<Screen>
|
|
120
|
+
<Probe />
|
|
121
|
+
<Screen.Footer keyboardOffset={44} sticky>
|
|
122
|
+
<Text>Footer note</Text>
|
|
123
|
+
</Screen.Footer>
|
|
124
|
+
</Screen>
|
|
125
|
+
);
|
|
126
|
+
expect(captured.context?.footer.keyboardOffset.value).toBe(44);
|
|
127
|
+
|
|
128
|
+
await view.rerender(
|
|
129
|
+
<Screen>
|
|
130
|
+
<Probe />
|
|
131
|
+
</Screen>
|
|
132
|
+
);
|
|
133
|
+
expect(captured.context?.footer.keyboardOffset.value).toBe(0);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("a footer that is not sticky publishes no keyboardOffset, because it does not lift", async () => {
|
|
137
|
+
const captured: { context: ScreenContextValue | null } = { context: null };
|
|
138
|
+
function Probe(): null {
|
|
139
|
+
captured.context = useScreen();
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
await renderWithProviders(
|
|
143
|
+
<Screen>
|
|
144
|
+
<Probe />
|
|
145
|
+
<Screen.Footer keyboardOffset={44}>
|
|
146
|
+
<Text>Footer note</Text>
|
|
147
|
+
</Screen.Footer>
|
|
148
|
+
</Screen>
|
|
149
|
+
);
|
|
150
|
+
expect(captured.context?.footer.keyboardOffset.value).toBe(0);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("a keyboard-aware scroll area clears a footer's keyboardOffset as well as the footer", async () => {
|
|
154
|
+
const clearance = () => screen.getByTestId("form").props.bottomOffset;
|
|
155
|
+
function Form({ keyboardOffset }: { keyboardOffset?: number }): ReactElement {
|
|
156
|
+
return (
|
|
157
|
+
<Screen>
|
|
158
|
+
<Screen.ScrollArea keyboardAware testID="form">
|
|
159
|
+
<Text>Field</Text>
|
|
160
|
+
</Screen.ScrollArea>
|
|
161
|
+
<Screen.Footer keyboardOffset={keyboardOffset} sticky>
|
|
162
|
+
<Text>Footer note</Text>
|
|
163
|
+
</Screen.Footer>
|
|
164
|
+
</Screen>
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
const view = await renderWithProviders(<Form />);
|
|
168
|
+
const base = clearance();
|
|
169
|
+
|
|
170
|
+
await view.rerender(<Form keyboardOffset={44} />);
|
|
171
|
+
expect(clearance()).toBe(base + 44);
|
|
172
|
+
});
|
|
173
|
+
|
|
84
174
|
test("a Screen.View renders its children", async () => {
|
|
85
175
|
await renderWithProviders(
|
|
86
176
|
<Screen>
|
|
@@ -87,6 +87,12 @@ describe("footerAboveKeyboard", () => {
|
|
|
87
87
|
expect(footerAboveKeyboard(58)).toBe(86);
|
|
88
88
|
expect(footerAboveKeyboard(0)).toBe(CHROME);
|
|
89
89
|
});
|
|
90
|
+
|
|
91
|
+
test("a keyboardOffset adds exactly that distance, for a bar riding the keyboard under the footer", () => {
|
|
92
|
+
for (const offset of [0, 42, 56]) {
|
|
93
|
+
expect(footerAboveKeyboard(58, offset) - footerAboveKeyboard(58)).toBe(offset);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
90
96
|
});
|
|
91
97
|
|
|
92
98
|
describe("the layout constants", () => {
|
|
@@ -294,7 +294,9 @@ export function resolveScreenEdgePadding(
|
|
|
294
294
|
* the list's content bottom IS the screen bottom. Reserve = `c + m + b`.
|
|
295
295
|
* - OPEN: `KeyboardStickyView` translates by `-(K - b)` (its `offset.opened` is
|
|
296
296
|
* the inset), so the footer's `b` band ends up BEHIND the keyboard and its top
|
|
297
|
-
* edge is `keyboardTop - (c + m)`.
|
|
297
|
+
* edge is `keyboardTop - (c + m)`. A footer given a `keyboardOffset` `o` — a
|
|
298
|
+
* bar riding the keyboard under it — translates by `-(K - b + o)` instead, and
|
|
299
|
+
* its top edge is `keyboardTop - (c + m + o)`. The list lifts by `(K - b)`, because
|
|
298
300
|
* `KeyboardChatScrollView` scrolls by "distance (`keyboardHeight - offset`)
|
|
299
301
|
* instead of the full keyboard height" and `Screen.ChatList` passes the inset
|
|
300
302
|
* as that offset. Measured from the lifted content bottom, the footer's top is
|
|
@@ -352,10 +354,13 @@ export function footerOccupancy(measuredContentHeight: number, safeAreaBottom: n
|
|
|
352
354
|
*
|
|
353
355
|
* For `KeyboardAwareScrollView`'s `bottomOffset` — clearance between the focused
|
|
354
356
|
* input and the keyboard top, not clearance in content space.
|
|
357
|
+
*
|
|
358
|
+
* @param measuredContentHeight - `footer.initialHeight`, what `Screen.Footer` measures
|
|
359
|
+
* @param keyboardOffset - `footer.keyboardOffset`: how much further a sticky footer is lifted, onto a bar riding the keyboard
|
|
355
360
|
*/
|
|
356
|
-
export function footerAboveKeyboard(measuredContentHeight: number): number {
|
|
361
|
+
export function footerAboveKeyboard(measuredContentHeight: number, keyboardOffset = 0): number {
|
|
357
362
|
"worklet";
|
|
358
|
-
return measuredContentHeight + SCREEN_FOOTER_PADDING + SCREEN_FLOATING_BOTTOM_GAP;
|
|
363
|
+
return measuredContentHeight + SCREEN_FOOTER_PADDING + SCREEN_FLOATING_BOTTOM_GAP + keyboardOffset;
|
|
359
364
|
}
|
|
360
365
|
|
|
361
366
|
/** How a scrollable reserves space at its bottom edge. See {@link resolveScrollBottomInset}. */
|
|
@@ -49,6 +49,26 @@ function useFooterBaselineHeight(estimatedHeight = 0): number {
|
|
|
49
49
|
return measured;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* The sticky footer's `keyboardOffset`, as JS state — mirrored from the UI
|
|
54
|
+
* thread for the same reason as {@link useFooterBaselineHeight}. Unlike the
|
|
55
|
+
* baseline, 0 is a real value here: the footer resets it on unmount.
|
|
56
|
+
*/
|
|
57
|
+
function useFooterKeyboardOffset(): number {
|
|
58
|
+
const { footer } = useScreenPart("a Screen scrollable");
|
|
59
|
+
const [offset, setOffset] = useState(0);
|
|
60
|
+
|
|
61
|
+
useAnimatedReaction(
|
|
62
|
+
() => Math.round(footer.keyboardOffset.value),
|
|
63
|
+
(current, previous) => {
|
|
64
|
+
if (current === previous) return;
|
|
65
|
+
scheduleOnRN(setOffset, current);
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
return offset;
|
|
70
|
+
}
|
|
71
|
+
|
|
52
72
|
/**
|
|
53
73
|
* The shared value a footer's own content drives when it expands VISUALLY above
|
|
54
74
|
* its measured layout box.
|
|
@@ -145,9 +165,14 @@ export function useChatComposerBaseSpacerHeight(estimatedFooterHeight = 0): Chat
|
|
|
145
165
|
* not just the keyboard. Deliberately NOT the full occupancy: the sticky shift
|
|
146
166
|
* parks the footer's safe-area band behind the keyboard, so counting it here
|
|
147
167
|
* would scroll the input further than it needs to go.
|
|
168
|
+
*
|
|
169
|
+
* A footer with a `keyboardOffset` sits that much higher, on a bar riding the
|
|
170
|
+
* keyboard, so the input clears that distance too.
|
|
148
171
|
*/
|
|
149
172
|
export function useScreenFooterKeyboardClearance(): number {
|
|
150
|
-
|
|
173
|
+
const baseline = useFooterBaselineHeight();
|
|
174
|
+
const keyboardOffset = useFooterKeyboardOffset();
|
|
175
|
+
return footerAboveKeyboard(baseline, keyboardOffset) + CHAT_COMPOSER_GAP;
|
|
151
176
|
}
|
|
152
177
|
|
|
153
178
|
/**
|
|
@@ -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
|
|
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
|
*
|