@delacour/react-native-ui 0.6.0-alpha.20261103145119 → 0.6.0-alpha.20261103150158
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/calendar.date.test.ts +21 -0
- package/src/components/calendar/calendar.date.ts +16 -2
- package/src/components/calendar/calendar.tsx +15 -6
- package/src/components/calendar/calendar.variants.test.ts +13 -0
- package/src/components/calendar/calendar.variants.ts +16 -0
- package/src/components/date-picker/AGENTS.md +3 -1
- package/src/components/date-picker/date-picker-trigger.tsx +9 -5
- package/src/components/overlay/AGENTS.md +8 -2
- package/src/components/overlay/overlay-registry.test.ts +24 -0
- package/src/components/overlay/overlay-registry.ts +12 -0
- package/src/components/overlay/overlay.tsx +15 -2
- package/src/components/overlay/use-overlay-presence.ts +14 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@delacour/react-native-ui",
|
|
3
|
-
"version": "0.6.0-alpha.
|
|
3
|
+
"version": "0.6.0-alpha.20261103150158",
|
|
4
4
|
"description": "React Native UI components — Uniwind, Reanimated, Gesture Handler",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -181,8 +181,8 @@
|
|
|
181
181
|
"expo-blur": ">=15",
|
|
182
182
|
"@maplibre/maplibre-react-native": "^11.5.0",
|
|
183
183
|
"@central-icons-react-native/round-outlined-radius-1-stroke-1.5": "^1.1",
|
|
184
|
-
"@delacour/react-native-bottom-sheet": "0.6.0-alpha.
|
|
185
|
-
"@delacour/react-native-charts": "0.6.0-alpha.
|
|
184
|
+
"@delacour/react-native-bottom-sheet": "0.6.0-alpha.20261103150158",
|
|
185
|
+
"@delacour/react-native-charts": "0.6.0-alpha.20261103150158",
|
|
186
186
|
"@legendapp/list": ">=3.3",
|
|
187
187
|
"react-native-skia": ">=3.9.0",
|
|
188
188
|
"expo-linear-gradient": ">=15",
|
|
@@ -354,6 +354,27 @@ describe("week start", () => {
|
|
|
354
354
|
expect(resolveWeekStart("not a locale!!")).toBe(1);
|
|
355
355
|
});
|
|
356
356
|
|
|
357
|
+
test("reads the device locale when the engine has no Intl.Locale and none is passed", () => {
|
|
358
|
+
// A plain stub, not a runner's spy: a copied suite runs under Bun, Jest and Vitest alike.
|
|
359
|
+
const intl: { Locale?: typeof Intl.Locale } = Intl;
|
|
360
|
+
const original = intl.Locale;
|
|
361
|
+
const proto = Intl.DateTimeFormat.prototype;
|
|
362
|
+
const resolvedOptions = proto.resolvedOptions;
|
|
363
|
+
const real = new Intl.DateTimeFormat().resolvedOptions();
|
|
364
|
+
let device = "en-US";
|
|
365
|
+
proto.resolvedOptions = () => ({ ...real, locale: device });
|
|
366
|
+
intl.Locale = undefined;
|
|
367
|
+
try {
|
|
368
|
+
expect(resolveWeekStart(undefined)).toBe(0);
|
|
369
|
+
device = "ar-EG";
|
|
370
|
+
expect(resolveWeekStart(undefined)).toBe(6);
|
|
371
|
+
expect(resolveWeekStart("en-NZ")).toBe(1);
|
|
372
|
+
} finally {
|
|
373
|
+
intl.Locale = original;
|
|
374
|
+
proto.resolvedOptions = resolvedOptions;
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
|
|
357
378
|
test("the region table stands in where Intl has no week info", () => {
|
|
358
379
|
expect(weekStartFromRegion("US")).toBe(0);
|
|
359
380
|
expect(weekStartFromRegion("NZ")).toBe(1);
|
|
@@ -433,6 +433,15 @@ type LocaleWithWeekInfo = Intl.Locale & {
|
|
|
433
433
|
weekInfo?: { firstDay: number };
|
|
434
434
|
};
|
|
435
435
|
|
|
436
|
+
/** The device's locale as `Intl.DateTimeFormat` resolves it, or `undefined` when it cannot. */
|
|
437
|
+
function deviceLocale(): string | undefined {
|
|
438
|
+
try {
|
|
439
|
+
return new Intl.DateTimeFormat().resolvedOptions().locale;
|
|
440
|
+
} catch {
|
|
441
|
+
return undefined;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
436
445
|
/**
|
|
437
446
|
* The first day of the week in a locale.
|
|
438
447
|
*
|
|
@@ -442,14 +451,19 @@ type LocaleWithWeekInfo = Intl.Locale & {
|
|
|
442
451
|
* A tag nothing can read is Monday.
|
|
443
452
|
*/
|
|
444
453
|
export function resolveWeekStart(locale: string | undefined): Weekday {
|
|
454
|
+
// The tag is resolved once, before `Intl.Locale` is touched, so the fallback below reads the
|
|
455
|
+
// device locale too. Without that, an en-US phone on an engine with no `Intl.Locale` started
|
|
456
|
+
// the week on Monday.
|
|
457
|
+
const raw = locale ?? deviceLocale();
|
|
458
|
+
if (!raw) return DEFAULT_WEEK_START;
|
|
445
459
|
try {
|
|
446
|
-
const tag = new Intl.Locale(
|
|
460
|
+
const tag = new Intl.Locale(raw) as LocaleWithWeekInfo;
|
|
447
461
|
const info = typeof tag.getWeekInfo === "function" ? tag.getWeekInfo() : tag.weekInfo;
|
|
448
462
|
if (info && Number.isInteger(info.firstDay)) return (info.firstDay % 7) as Weekday;
|
|
449
463
|
const region = tag.region ?? (typeof tag.maximize === "function" ? tag.maximize().region : undefined);
|
|
450
464
|
return weekStartFromRegion(region ?? LIKELY_REGION[tag.language]);
|
|
451
465
|
} catch {
|
|
452
|
-
const match =
|
|
466
|
+
const match = raw.match(/^([a-z]{2,3})(?:[-_][A-Za-z]{4})?(?:[-_]([A-Za-z]{2}))?(?:[-_]|$)/);
|
|
453
467
|
if (!match) return DEFAULT_WEEK_START;
|
|
454
468
|
return weekStartFromRegion(match[2] ?? LIKELY_REGION[match[1] ?? ""]);
|
|
455
469
|
}
|
|
@@ -22,12 +22,15 @@ import {
|
|
|
22
22
|
} from "./calendar.date";
|
|
23
23
|
import type { CalendarProps, CalendarSelection } from "./calendar.types";
|
|
24
24
|
import {
|
|
25
|
+
CALENDAR_NO_PAGING,
|
|
26
|
+
type CalendarPaging,
|
|
25
27
|
type CalendarView,
|
|
26
28
|
calendarVariants,
|
|
27
29
|
isDateSelected,
|
|
28
30
|
isMonthInBounds,
|
|
29
31
|
reconcileVisibleMonth,
|
|
30
32
|
resolveCalendarAxes,
|
|
33
|
+
resolveCommittedPageDirection,
|
|
31
34
|
resolveMonthBounds,
|
|
32
35
|
resolveRangeRole,
|
|
33
36
|
resolveSelectionPage,
|
|
@@ -166,14 +169,19 @@ function CalendarRoot(props: CalendarProps): ReactElement {
|
|
|
166
169
|
const visibleMonth = useMemo(() => startOfMonth(visibleMonthRaw), [visibleMonthRaw]);
|
|
167
170
|
|
|
168
171
|
const [view, setView] = useState<CalendarView>("days");
|
|
169
|
-
|
|
172
|
+
// The direction counts only for the month the calendar paged to. When `month` changes from
|
|
173
|
+
// outside, the stale page is dropped during render, so the new month never slides in from the
|
|
174
|
+
// side of an earlier page.
|
|
175
|
+
const [paging, setPaging] = useState<CalendarPaging>(CALENDAR_NO_PAGING);
|
|
176
|
+
if (paging.month && !isSameMonth(paging.month, visibleMonth)) setPaging(CALENDAR_NO_PAGING);
|
|
177
|
+
const pageDirection = resolveCommittedPageDirection(paging, visibleMonth);
|
|
170
178
|
|
|
171
179
|
// New bounds can leave the visible month outside them. Move it to the nearest bound and report
|
|
172
180
|
// the change, so the arrows and the swipe always have somewhere to go.
|
|
173
181
|
useEffect(() => {
|
|
174
182
|
const held = reconcileVisibleMonth(visibleMonth, monthBounds);
|
|
175
183
|
if (!held) return;
|
|
176
|
-
|
|
184
|
+
setPaging(CALENDAR_NO_PAGING);
|
|
177
185
|
setVisibleMonth(held);
|
|
178
186
|
}, [monthBounds, setVisibleMonth, visibleMonth]);
|
|
179
187
|
|
|
@@ -181,7 +189,7 @@ function CalendarRoot(props: CalendarProps): ReactElement {
|
|
|
181
189
|
(date: CalendarDate) => {
|
|
182
190
|
const target = startOfMonth(clampDate(startOfMonth(date), monthBounds.first, monthBounds.last));
|
|
183
191
|
if (isSameMonth(target, visibleMonth)) return;
|
|
184
|
-
|
|
192
|
+
setPaging(CALENDAR_NO_PAGING);
|
|
185
193
|
setVisibleMonth(target);
|
|
186
194
|
},
|
|
187
195
|
[monthBounds.first, monthBounds.last, setVisibleMonth, visibleMonth]
|
|
@@ -204,7 +212,7 @@ function CalendarRoot(props: CalendarProps): ReactElement {
|
|
|
204
212
|
const target = addMonths(visibleMonth, direction * step);
|
|
205
213
|
const held = startOfMonth(clampDate(target, monthBounds.first, monthBounds.last));
|
|
206
214
|
if (compareMonths(held, visibleMonth) === 0) return;
|
|
207
|
-
|
|
215
|
+
setPaging({ direction: view === "days" ? direction : 0, month: held });
|
|
208
216
|
setVisibleMonth(held);
|
|
209
217
|
},
|
|
210
218
|
[monthBounds.first, monthBounds.last, setVisibleMonth, step, view, visibleMonth]
|
|
@@ -223,8 +231,9 @@ function CalendarRoot(props: CalendarProps): ReactElement {
|
|
|
223
231
|
setSelection(nextSelection(selection, date, isDateDisabled));
|
|
224
232
|
const direction = resolveSelectionPage(date, visibleMonth, monthBounds);
|
|
225
233
|
if (direction === 0) return;
|
|
226
|
-
|
|
227
|
-
|
|
234
|
+
const target = startOfMonth(date);
|
|
235
|
+
setPaging({ direction, month: target });
|
|
236
|
+
setVisibleMonth(target);
|
|
228
237
|
},
|
|
229
238
|
[
|
|
230
239
|
axes.isDisabled,
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
reconcileVisibleMonth,
|
|
15
15
|
resolveCalendarAxes,
|
|
16
16
|
resolveCaptionPage,
|
|
17
|
+
resolveCommittedPageDirection,
|
|
17
18
|
resolveDayState,
|
|
18
19
|
resolveDayTone,
|
|
19
20
|
resolveMonthBounds,
|
|
@@ -410,6 +411,18 @@ describe("resolvePageDirection", () => {
|
|
|
410
411
|
});
|
|
411
412
|
});
|
|
412
413
|
|
|
414
|
+
describe("resolveCommittedPageDirection", () => {
|
|
415
|
+
test("slides the month the calendar paged to in from the side it paged", () => {
|
|
416
|
+
expect(resolveCommittedPageDirection({ direction: 1, month: d(2026, 11, 1) }, d(2026, 11, 1))).toBe(1);
|
|
417
|
+
expect(resolveCommittedPageDirection({ direction: -1, month: d(2026, 9, 1) }, d(2026, 9, 1))).toBe(-1);
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
test("does not slide a month the parent set", () => {
|
|
421
|
+
expect(resolveCommittedPageDirection({ direction: 1, month: d(2026, 11, 1) }, d(2026, 3, 1))).toBe(0);
|
|
422
|
+
expect(resolveCommittedPageDirection({ direction: 0, month: null }, d(2026, 3, 1))).toBe(0);
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
|
|
413
426
|
describe("resolveCaptionPage", () => {
|
|
414
427
|
const open = { canGoNext: true, canGoPrev: true, isDisabled: false, view: "days" } as const;
|
|
415
428
|
|
|
@@ -406,6 +406,22 @@ export function resolveCaptionPage({
|
|
|
406
406
|
return 0;
|
|
407
407
|
}
|
|
408
408
|
|
|
409
|
+
/** A page the calendar asked for: the month it moved to, and the side that month enters from. */
|
|
410
|
+
export type CalendarPaging = { direction: -1 | 0 | 1; month: CalendarDate | null };
|
|
411
|
+
|
|
412
|
+
/** No page in flight: the next month change, wherever it comes from, does not slide. */
|
|
413
|
+
export const CALENDAR_NO_PAGING: CalendarPaging = { direction: 0, month: null };
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Which way the grid slides the visible month in. It uses the paging direction only while the
|
|
417
|
+
* calendar itself moved to that month. A month that the parent sets through a controlled `month`
|
|
418
|
+
* gets `0`. Without this check, reopening a picker on an earlier month after "next" would slide
|
|
419
|
+
* that month in from the right.
|
|
420
|
+
*/
|
|
421
|
+
export function resolveCommittedPageDirection(paging: CalendarPaging, visibleMonth: CalendarDate): -1 | 0 | 1 {
|
|
422
|
+
return paging.month && isSameMonth(paging.month, visibleMonth) ? paging.direction : 0;
|
|
423
|
+
}
|
|
424
|
+
|
|
409
425
|
/**
|
|
410
426
|
* Which way a released swipe pages: `1` forward, `-1` back, `0` settle where it was.
|
|
411
427
|
*
|
|
@@ -74,7 +74,9 @@ The subpath imports `BottomSheet`, so an app using it installs the optional
|
|
|
74
74
|
- **Open is focus.** `resolveTriggerState` maps `isOpen` onto the box's `isFocused`, so the ring
|
|
75
75
|
shows while the sheet is up. A disabled trigger is never focused.
|
|
76
76
|
- **Disabled and read-only never open**, from the trigger, a `Field.Label` tap or `open()`. Read-only
|
|
77
|
-
shows the value at full strength; disabled fades it.
|
|
77
|
+
shows the value at full strength; disabled fades it. Only disabled sets `accessibilityState.disabled`,
|
|
78
|
+
so a screen reader does not read a read-only value as dimmed. A trigger that cannot open drops the
|
|
79
|
+
"Opens calendar" hint, its press handler and its press feedback.
|
|
78
80
|
- **`Field` cascade, nearest wins.** `isInvalid ?? field.isInvalid`, `isDisabled ??
|
|
79
81
|
field.isDisabled` — `??`, so `isInvalid={false}` opts out. The accessible name is
|
|
80
82
|
`accessibilityLabel ?? field.label ?? "Date"`, and the root registers `open` with the field's
|
|
@@ -15,6 +15,10 @@ export type DatePickerTriggerProps = Omit<PressableProps, "asChild" | "busy" | "
|
|
|
15
15
|
* lines up with a text field beside it at every size and variant. Open is its focus state, and
|
|
16
16
|
* invalid outranks it the way it does on a field. Disabled and read-only never open.
|
|
17
17
|
*
|
|
18
|
+
* Only disabled reads as disabled. Read-only shows its value at full strength, so a screen reader
|
|
19
|
+
* reads it as enabled — but it gets no press feedback, no press handler and no "Opens calendar"
|
|
20
|
+
* hint, because it cannot open.
|
|
21
|
+
*
|
|
18
22
|
* Omitted children are `DatePicker.Value` then `DatePicker.Icon`.
|
|
19
23
|
*/
|
|
20
24
|
export function DatePickerTrigger({
|
|
@@ -32,10 +36,10 @@ export function DatePickerTrigger({
|
|
|
32
36
|
|
|
33
37
|
return (
|
|
34
38
|
<Pressable
|
|
35
|
-
accessibilityHint={accessibilityHint}
|
|
39
|
+
accessibilityHint={state.canOpen ? accessibilityHint : undefined}
|
|
36
40
|
accessibilityLabel={picker.accessibilityLabel}
|
|
37
41
|
accessibilityRole="button"
|
|
38
|
-
accessibilityState={{ disabled:
|
|
42
|
+
accessibilityState={{ disabled: state.isDisabled, expanded: picker.isOpen }}
|
|
39
43
|
accessibilityValue={{ text: picker.accessibilityValue }}
|
|
40
44
|
className={resolveDatePickerTriggerClass({
|
|
41
45
|
className,
|
|
@@ -45,9 +49,9 @@ export function DatePickerTrigger({
|
|
|
45
49
|
size: picker.size,
|
|
46
50
|
variant: picker.variant,
|
|
47
51
|
})}
|
|
48
|
-
disabled={
|
|
49
|
-
feedback={feedback}
|
|
50
|
-
onPress={picker.open}
|
|
52
|
+
disabled={state.isDisabled}
|
|
53
|
+
feedback={state.canOpen ? feedback : "none"}
|
|
54
|
+
onPress={state.canOpen ? picker.open : undefined}
|
|
51
55
|
testID={testID ?? resolvePartTestID(picker.testID, "trigger")}
|
|
52
56
|
{...props}
|
|
53
57
|
>
|
|
@@ -19,8 +19,8 @@ imports an overlay never resolves it. The consequence is the same one thing to d
|
|
|
19
19
|
| `overlay-portal.tsx` | `Overlay.Portal` — registers while mounted, teleports to `"root"` in a `box-none` absolute fill carrying the registry's `zIndex`; inline without a provider |
|
|
20
20
|
| `overlay-scrim.tsx` | `Overlay.Scrim` — `bg-overlay`, opacity follows presence, hidden from assistive technology |
|
|
21
21
|
| `overlay.context.tsx` | **Leaf.** `OverlayContext`, `TeleportProvidedContext` and their hooks. `bottom-sheet/` imports it |
|
|
22
|
-
| `overlay-registry.ts` | **Pure.** The z-order reducer, `zIndexOfOverlay`, `topOverlay`, `isTopOverlay`, `OVERLAY_LAYER_BASE` |
|
|
23
|
-
| `overlay-presence.ts` | **Pure.** `reducePresence` — `closed → entering → open → exiting → closed` |
|
|
22
|
+
| `overlay-registry.ts` | **Pure.** The z-order reducer, `zIndexOfOverlay`, `topOverlay`, `isTopOverlay`, `hasModalOverlay`, `OVERLAY_LAYER_BASE` |
|
|
23
|
+
| `overlay-presence.ts` | **Pure.** `reducePresence` — `closed → entering → open → exiting → closed`; `isCurrentFinish` |
|
|
24
24
|
| `overlay.variants.ts` | `overlayVariants` (`scrim`), `OVERLAY_MOTION`, `OVERLAY_SCRIM_TOKEN` |
|
|
25
25
|
| `use-overlay-presence.ts` | `useOverlayPresence` — keeps an overlay mounted through its exit, drives `progress` 0 → 1 |
|
|
26
26
|
| `use-overlay-back-handler.ts` | `useOverlayBackHandler` — Android back, only while the overlay is the top |
|
|
@@ -68,6 +68,12 @@ imports an overlay never resolves it. The consequence is the same one thing to d
|
|
|
68
68
|
It always takes the touch, even with no `onDismiss`, because the app under a non-dismissible
|
|
69
69
|
dialog must not be pressable. It is hidden from assistive technology; a screen reader user
|
|
70
70
|
dismisses through the panel's `onAccessibilityEscape` or the back button.
|
|
71
|
+
- **A modal overlay hides the app from screen readers.** Teleport's `"root"` host is a sibling of
|
|
72
|
+
the provider's content `View`, so a panel's `accessibilityViewIsModal` hides only its siblings in
|
|
73
|
+
the host, and VoiceOver or TalkBack could still reach the app behind a dialog. While
|
|
74
|
+
`hasModalOverlay` is true the provider sets `accessibilityElementsHidden` and
|
|
75
|
+
`importantForAccessibility="no-hide-descendants"` on that `View`. Overlays and sheets draw in the
|
|
76
|
+
host, outside it, and stay reachable.
|
|
71
77
|
- **The portal's wrapper is `box-none`.** An overlay with no scrim — a toast, a tooltip — leaves
|
|
72
78
|
the app under it interactive.
|
|
73
79
|
- **The provider hears every touch that starts beneath it, and claims none.** Its children sit in a
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
2
|
import {
|
|
3
|
+
hasModalOverlay,
|
|
3
4
|
INITIAL_OVERLAY_REGISTRY,
|
|
4
5
|
isTopOverlay,
|
|
5
6
|
OVERLAY_LAYER_BASE,
|
|
@@ -94,3 +95,26 @@ describe("topOverlay / isTopOverlay", () => {
|
|
|
94
95
|
expect(isTopOverlay(state, "a")).toBe(true);
|
|
95
96
|
});
|
|
96
97
|
});
|
|
98
|
+
|
|
99
|
+
describe("hasModalOverlay", () => {
|
|
100
|
+
test("is false when nothing is presented", () => {
|
|
101
|
+
expect(hasModalOverlay(INITIAL_OVERLAY_REGISTRY)).toBe(false);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("is true while a modal overlay is presented", () => {
|
|
105
|
+
const state = reduceOverlayRegistry(INITIAL_OVERLAY_REGISTRY, { type: "open", id: "dialog", layer: "modal" });
|
|
106
|
+
expect(hasModalOverlay(state)).toBe(true);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("ignores anchored overlays and toasts", () => {
|
|
110
|
+
let state = reduceOverlayRegistry(INITIAL_OVERLAY_REGISTRY, { type: "open", id: "popover", layer: "anchored" });
|
|
111
|
+
state = reduceOverlayRegistry(state, { type: "open", id: "toast", layer: "toast" });
|
|
112
|
+
expect(hasModalOverlay(state)).toBe(false);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("is false again once the last modal overlay closes", () => {
|
|
116
|
+
let state = reduceOverlayRegistry(INITIAL_OVERLAY_REGISTRY, { type: "open", id: "dialog", layer: "modal" });
|
|
117
|
+
state = reduceOverlayRegistry(state, { type: "close", id: "dialog" });
|
|
118
|
+
expect(hasModalOverlay(state)).toBe(false);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -97,3 +97,15 @@ export function topOverlay(state: OverlayRegistryState): string | null {
|
|
|
97
97
|
export function isTopOverlay(state: OverlayRegistryState, id: string): boolean {
|
|
98
98
|
return topOverlay(state) === id;
|
|
99
99
|
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Whether a modal overlay is presented — open, or animating closed.
|
|
103
|
+
*
|
|
104
|
+
* Every overlay teleports into the `"root"` host, which sits beside the app
|
|
105
|
+
* content, not above it in the view tree. A panel's `accessibilityViewIsModal`
|
|
106
|
+
* hides only its own siblings in that host, so `OverlayProvider` uses this to
|
|
107
|
+
* hide the app content from screen readers while a dialog or drawer is up.
|
|
108
|
+
*/
|
|
109
|
+
export function hasModalOverlay(state: OverlayRegistryState): boolean {
|
|
110
|
+
return state.open.some((entry) => entry.layer === "modal");
|
|
111
|
+
}
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from "./overlay.context";
|
|
10
10
|
import { OverlayPortal } from "./overlay-portal";
|
|
11
11
|
import {
|
|
12
|
+
hasModalOverlay,
|
|
12
13
|
INITIAL_OVERLAY_REGISTRY,
|
|
13
14
|
type OverlayLayer,
|
|
14
15
|
type OverlayRegistryState,
|
|
@@ -57,9 +58,19 @@ function OverlayRoot({ children }: OverlayProviderProps): ReactElement {
|
|
|
57
58
|
// for a touch on any descendant in the React tree — teleported overlays
|
|
58
59
|
// included, since teleport leaves the fiber where it was — and never stops
|
|
59
60
|
// the touch reaching its target or a gesture handler.
|
|
61
|
+
//
|
|
62
|
+
// While a modal overlay is presented, the app content is hidden from
|
|
63
|
+
// VoiceOver and TalkBack. The overlays draw in teleport's host, outside
|
|
64
|
+
// this view in the native tree, so they stay reachable.
|
|
65
|
+
const isAppHidden = hasModalOverlay(state);
|
|
60
66
|
const registry = (
|
|
61
67
|
<OverlayContext.Provider value={value}>
|
|
62
|
-
<View
|
|
68
|
+
<View
|
|
69
|
+
accessibilityElementsHidden={isAppHidden}
|
|
70
|
+
importantForAccessibility={isAppHidden ? "no-hide-descendants" : "auto"}
|
|
71
|
+
onTouchStart={onTouchStart}
|
|
72
|
+
style={styles.fill}
|
|
73
|
+
>
|
|
63
74
|
{children}
|
|
64
75
|
</View>
|
|
65
76
|
</OverlayContext.Provider>
|
|
@@ -85,7 +96,9 @@ const styles = StyleSheet.create({ fill: { flex: 1 } });
|
|
|
85
96
|
* skipped when a provider above already mounted one, because two would mean
|
|
86
97
|
* two native hosts with one name. And the overlay registry, which gives every
|
|
87
98
|
* presented overlay a `zIndex` in its layer's band and tells each one whether it
|
|
88
|
-
* is the top, the one Android's back button closes.
|
|
99
|
+
* is the top, the one Android's back button closes. While a modal overlay is
|
|
100
|
+
* presented it hides the app content from screen readers, so focus cannot move
|
|
101
|
+
* behind a dialog. It also hears every touch
|
|
89
102
|
* that starts beneath it, without claiming one, so a tooltip can close on an
|
|
90
103
|
* outside tap that still lands where it was aimed.
|
|
91
104
|
*
|
|
@@ -56,6 +56,9 @@ const EXIT_EASING = Easing.in(Easing.cubic);
|
|
|
56
56
|
* `isCurrentFinish` drops one that no longer matches the latest transition
|
|
57
57
|
* and request, before it moves the phase or reaches `onEntered`/`onExited`.
|
|
58
58
|
*
|
|
59
|
+
* `onEntered` and `onExited` are read through refs, so an owner that passes
|
|
60
|
+
* new inline callbacks on every render does not restart the timing.
|
|
61
|
+
*
|
|
59
62
|
* Under reduce motion the fade still runs — an opacity change is not motion —
|
|
60
63
|
* so both timings set `ReduceMotion.Never`, and `isReduced` tells the
|
|
61
64
|
* component to drop its transforms.
|
|
@@ -72,6 +75,13 @@ export function useOverlayPresence({
|
|
|
72
75
|
const isReduced = useReducedMotion();
|
|
73
76
|
const generation = useRef(0);
|
|
74
77
|
const isOpenRequested = useRef(isOpen);
|
|
78
|
+
const onEnteredRef = useRef(onEntered);
|
|
79
|
+
const onExitedRef = useRef(onExited);
|
|
80
|
+
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
onEnteredRef.current = onEntered;
|
|
83
|
+
onExitedRef.current = onExited;
|
|
84
|
+
}, [onEntered, onExited]);
|
|
75
85
|
|
|
76
86
|
const send = useCallback((event: PresenceEvent) => {
|
|
77
87
|
setPhase((current) => reducePresence(current, event));
|
|
@@ -90,18 +100,18 @@ export function useOverlayPresence({
|
|
|
90
100
|
(finishGeneration: number) => {
|
|
91
101
|
if (!isCurrent("entered", finishGeneration)) return;
|
|
92
102
|
send({ type: "entered" });
|
|
93
|
-
|
|
103
|
+
onEnteredRef.current?.();
|
|
94
104
|
},
|
|
95
|
-
[isCurrent, send
|
|
105
|
+
[isCurrent, send]
|
|
96
106
|
);
|
|
97
107
|
|
|
98
108
|
const finishExit = useCallback(
|
|
99
109
|
(finishGeneration: number) => {
|
|
100
110
|
if (!isCurrent("exited", finishGeneration)) return;
|
|
101
111
|
send({ type: "exited" });
|
|
102
|
-
|
|
112
|
+
onExitedRef.current?.();
|
|
103
113
|
},
|
|
104
|
-
[isCurrent, send
|
|
114
|
+
[isCurrent, send]
|
|
105
115
|
);
|
|
106
116
|
|
|
107
117
|
useEffect(() => {
|