@vvedantb/native-ui 0.28.0 → 0.29.0
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/README.md +3 -3
- package/dist/DropdownMenu.jsx +26 -12
- package/dist/ai/conversation-context.js +2 -0
- package/dist/ai/conversation.jsx +31 -7
- package/dist/primitives/overlay.jsx +31 -17
- package/dist/primitives/window-layer.jsx +55 -37
- package/package.json +1 -1
- package/src/DropdownMenu.tsx +13 -12
- package/src/ai/conversation-context.ts +3 -0
- package/src/ai/conversation.tsx +21 -0
- package/src/primitives/overlay.tsx +18 -18
- package/src/primitives/window-layer.tsx +33 -7
package/README.md
CHANGED
|
@@ -348,7 +348,7 @@ configureTheme({ font: { regular: "Inter_400Regular", medium: "Inter_500Medium",
|
|
|
348
348
|
| Actions and fields | `Button` (`default`/`primary`, `secondary`, `outline`, `destructive`, `ghost`, `link`, `tinted`; `sm`/`small`, `default`/`medium`, `lg`/`large`, `icon`; `shape` `pill`/`rounded` from 0.6.0), `IconButton` (0.5.0), `CaptureButton` (0.5.0), `Input`, `SearchInput` (0.3.9), `PasswordInput` (0.11.0), `Textarea`, `Label`, `Select`, `Switch`, `Checkbox`, `LabeledSwitchRow`, `ColorSwatches` (0.5.0), `DateTimeField` (date-only, empty and clearable from 0.5.0) |
|
|
349
349
|
| Display | `Card` (+ `CardHeader`, `CardTitle`, `CardDescription`, `CardContent`, `CardFooter`; `onPress` from 0.5.0), `Badge`, `StatusDot` (`info` from 0.5.0), `Avatar` (+ `AvatarImage`, `AvatarFallback`, `initials()`), `Separator`, `Progress`, `Spinner`, `CenteredSpinner`, `Skeleton`, `EmptyState` (+ `EmptyState.Root` and parts), `ListRow` (`leading`, `titleEnd`, `control`, `onLongPress` from 0.5.0), `StatGrid` (0.5.0), `SectionLabel` (0.5.0), `Chip`, `Text` (0.5.0, `/primitives` only) |
|
|
350
350
|
| Navigation | `Tabs` (+ `TabsList`, `TabsTrigger` (`minHeight` from 0.14.0), `TabsContent`), `PillTabs`, `PageIndicator` (0.5.0), `FloatingTabBar`, `FloatingFAB`, `HeaderIconButton`, `ThemeToggle` (0.3.16), `StackPageHeader` (0.5.0) |
|
|
351
|
-
| Overlays | `Dialog`, `AlertDialog`, `ConfirmDialog`, `Sheet` (RN `Modal
|
|
351
|
+
| Overlays | `Dialog`, `AlertDialog`, `ConfirmDialog`, `Sheet` (a `WindowLayer` from 0.29.0: in the app's window under `WindowLayerHost`, else an RN `Modal`; each with the web part names; a `SheetContent` or compact `DialogContent` drags down to close), `SheetRow` (0.5.0), `BottomSheetContainer` (`@swmansion/react-native-bottom-sheet`; optional `detents`), `DropdownMenu` (Unreleased; see below) |
|
|
352
352
|
| Selection | `BulkActionBar` (Unreleased; see below) |
|
|
353
353
|
| Feedback | `toast()` and `<Toaster />` |
|
|
354
354
|
| Brand and upgrade | `APP_ICONS`, `IconVibot` and the other `Icon*`, `AppMark`, `AppWordmark`, `GoogleMark` (0.3.15), `FAMILY_APPS`, `V_PRO_APP_BENEFITS`, `UpgradeToProCard`, `PricingModal` |
|
|
@@ -621,7 +621,7 @@ import {
|
|
|
621
621
|
|
|
622
622
|
## DropdownMenu (Unreleased)
|
|
623
623
|
|
|
624
|
-
A small menu anchored to its trigger, the native counterpart of the web `DropdownMenu`. On `/primitives` and the root. From 0.12.1 the backdrop and menu sit in a full-size `View` inside the
|
|
624
|
+
A small menu anchored to its trigger, the native counterpart of the web `DropdownMenu`. On `/primitives` and the root. From 0.12.1 the backdrop and menu sit in a full-size `View` inside the overlay, so the menu stays above tab bars and glass layers. From 0.29.0 the overlay is a `WindowLayer`: in the app's window under `WindowLayerHost`, so a chat under it keeps its place, else an RN `Modal`.
|
|
625
625
|
|
|
626
626
|
```tsx
|
|
627
627
|
<DropdownMenu>
|
|
@@ -643,7 +643,7 @@ A small menu anchored to its trigger, the native counterpart of the web `Dropdow
|
|
|
643
643
|
| --- | --- |
|
|
644
644
|
| `DropdownMenu` | `open`, `defaultOpen`, `onOpenChange`. Holds the open state; renders no view. |
|
|
645
645
|
| `DropdownMenuTrigger` | `Pressable` props and `asChild`. On press it measures itself (`measureInWindow`) and opens the menu; pressed again it closes it. Reports `expanded`. With `asChild` the child must pass `ref` on to its native view (`Button` and `IconButton` do). |
|
|
646
|
-
| `DropdownMenuContent` | `align` (`"start"`, default, or `"end"`), `sideOffset` (default 4), `View` props. A transparent RN `Modal
|
|
646
|
+
| `DropdownMenuContent` | `align` (`"start"`, default, or `"end"`), `sideOffset` (default 4), `View` props. A `WindowLayer` (a transparent RN `Modal` without `WindowLayerHost`); the menu sits under the trigger and flips above it when it does not fit below. |
|
|
647
647
|
| `DropdownMenuLabel` | `children`. |
|
|
648
648
|
| `DropdownMenuItem` | `children`, `onSelect`, `icon` (a Tabler icon), `destructive`, `disabled`, `closeOnSelect` (default `true`). |
|
|
649
649
|
| `DropdownMenuRadioItem` | The same without `icon` and `destructive`, plus `checked`. |
|
package/dist/DropdownMenu.jsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { c as _c } from "react/compiler-runtime";
|
|
2
2
|
import * as Slot from "@rn-primitives/slot";
|
|
3
3
|
import { createContext, useContext, useEffect, useRef, useState } from "react";
|
|
4
|
-
import {
|
|
4
|
+
import { Pressable, ScrollView, StyleSheet, Text, View, useWindowDimensions } from "react-native";
|
|
5
5
|
import Animated, { runOnJS, useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated";
|
|
6
6
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
7
7
|
import { IconCheck } from "@tabler/icons-react-native";
|
|
@@ -16,6 +16,7 @@ import { tokens } from "./tokens";
|
|
|
16
16
|
import { useReduceMotion } from "./useReduceMotion";
|
|
17
17
|
import { useScheme } from "./useScheme";
|
|
18
18
|
import { useControllableState } from "./primitives/use-controllable-state";
|
|
19
|
+
import { WindowLayer } from "./primitives/window-layer";
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* Sizes from the web menu classes (`_menu-classes.ts`): content `min-w-[12rem]
|
|
@@ -245,7 +246,8 @@ export function dropdownMenuPosition({
|
|
|
245
246
|
};
|
|
246
247
|
}
|
|
247
248
|
/**
|
|
248
|
-
* The menu in a
|
|
249
|
+
* The menu in a `WindowLayer` (in the app's window under `WindowLayerHost`, so
|
|
250
|
+
* a chat under it keeps its place; else a transparent `Modal`): the opaque overlay surface of
|
|
249
251
|
* `Dialog` and `Sheet` (`FloatingSurface` without blur, with the floating
|
|
250
252
|
* shadow) at radius 16, at least 192 wide, `p-1.5`, scrolling when taller than
|
|
251
253
|
* the room. A tap outside, Android back and the VoiceOver escape gesture close
|
|
@@ -254,7 +256,7 @@ export function dropdownMenuPosition({
|
|
|
254
256
|
* 100 ms. With Reduce Motion on, it appears and leaves at once.
|
|
255
257
|
*/
|
|
256
258
|
export function DropdownMenuContent(t0) {
|
|
257
|
-
const $ = _c(
|
|
259
|
+
const $ = _c(76);
|
|
258
260
|
let children;
|
|
259
261
|
let className;
|
|
260
262
|
let props;
|
|
@@ -286,11 +288,12 @@ export function DropdownMenuContent(t0) {
|
|
|
286
288
|
t1 = $[6];
|
|
287
289
|
}
|
|
288
290
|
const align = t1 === undefined ? "start" : t1;
|
|
291
|
+
const menu = useMenu("DropdownMenuContent");
|
|
289
292
|
const {
|
|
290
293
|
open,
|
|
291
294
|
setOpen,
|
|
292
295
|
trigger
|
|
293
|
-
} =
|
|
296
|
+
} = menu;
|
|
294
297
|
const window = useWindowDimensions();
|
|
295
298
|
const insets = useSafeAreaInsets();
|
|
296
299
|
const reduceMotion = useReduceMotion();
|
|
@@ -423,6 +426,9 @@ export function DropdownMenuContent(t0) {
|
|
|
423
426
|
}
|
|
424
427
|
const position = t9;
|
|
425
428
|
const transformOrigin = `${align === "end" ? 100 : 0}% ${position.bottom === undefined ? 0 : 100}%`;
|
|
429
|
+
if (!shown) {
|
|
430
|
+
return null;
|
|
431
|
+
}
|
|
426
432
|
let t10;
|
|
427
433
|
if ($[33] === Symbol.for("react.memo_cache_sentinel")) {
|
|
428
434
|
t10 = {
|
|
@@ -559,16 +565,24 @@ export function DropdownMenuContent(t0) {
|
|
|
559
565
|
t26 = $[69];
|
|
560
566
|
}
|
|
561
567
|
let t27;
|
|
562
|
-
if ($[70] !==
|
|
563
|
-
t27 = <
|
|
564
|
-
$[70] =
|
|
565
|
-
$[71] =
|
|
566
|
-
$[72] =
|
|
567
|
-
|
|
568
|
+
if ($[70] !== menu || $[71] !== t26) {
|
|
569
|
+
t27 = <MenuContext.Provider value={menu}>{t26}</MenuContext.Provider>;
|
|
570
|
+
$[70] = menu;
|
|
571
|
+
$[71] = t26;
|
|
572
|
+
$[72] = t27;
|
|
573
|
+
} else {
|
|
574
|
+
t27 = $[72];
|
|
575
|
+
}
|
|
576
|
+
let t28;
|
|
577
|
+
if ($[73] !== close || $[74] !== t27) {
|
|
578
|
+
t28 = <WindowLayer onRequestClose={close} fade={false}>{t27}</WindowLayer>;
|
|
579
|
+
$[73] = close;
|
|
580
|
+
$[74] = t27;
|
|
581
|
+
$[75] = t28;
|
|
568
582
|
} else {
|
|
569
|
-
|
|
583
|
+
t28 = $[75];
|
|
570
584
|
}
|
|
571
|
-
return
|
|
585
|
+
return t28;
|
|
572
586
|
}
|
|
573
587
|
|
|
574
588
|
/** Item type and icon size: the web `text-sm` with a 16 icon in 48 rows, or `text-lg` with a 22 icon and 56 rows with larger text. */
|
|
@@ -8,6 +8,8 @@ import { createContext, useContext } from "react";
|
|
|
8
8
|
* the `FlatList` of `ConversationList`. `scrollToEnd` goes to the newest
|
|
9
9
|
* message, which is offset 0 in an inverted list. `scrollTo` goes to an
|
|
10
10
|
* offset; only the `ScrollView` has it, so call it as `scrollTo?.(...)`.
|
|
11
|
+
* `scrollToIndex` brings one row of the list's `data` into view (a find in
|
|
12
|
+
* the thread); only the `FlatList` has it. `viewPosition` 0.5 centres it.
|
|
11
13
|
*/
|
|
12
14
|
|
|
13
15
|
export const ConversationContext = createContext(null);
|
package/dist/ai/conversation.jsx
CHANGED
|
@@ -366,6 +366,9 @@ export function ConversationList({
|
|
|
366
366
|
inset: 0,
|
|
367
367
|
keyboardMoving: false
|
|
368
368
|
});
|
|
369
|
+
// The list, and the row `scrollToIndex` last asked for, for its retry when that row was not drawn.
|
|
370
|
+
const listRef = useRef(null);
|
|
371
|
+
const indexTarget = useRef(null);
|
|
369
372
|
// Not inverted: hidden until the first jump to the end (see above). An
|
|
370
373
|
// empty list (a spinner, an empty state) shows at once.
|
|
371
374
|
const hasRows = (props.data?.length ?? 0) > 0;
|
|
@@ -400,7 +403,7 @@ export function ConversationList({
|
|
|
400
403
|
}
|
|
401
404
|
// The newest message's offset: inverted, 0 less the space before it.
|
|
402
405
|
const end = () => inverted ? size.current.inset > 0 ? -size.current.inset : 0 : Math.max(0, size.current.content + size.current.inset - size.current.view);
|
|
403
|
-
const
|
|
406
|
+
const list_1 = <FlatList className={cn("flex-1", className)}
|
|
404
407
|
// Inverted, the column's end is the top: a short thread sits there.
|
|
405
408
|
contentContainerClassName={cn("px-3 py-3", inverted && "grow justify-end", contentContainerClassName)} {...wired} style={[wired.style, !inverted && hasRows && !placed ? styles.hidden : null]}
|
|
406
409
|
// At the bottom, a new message shows at offset 0; scrolled up, it must not move what the reader sees.
|
|
@@ -412,18 +415,39 @@ export function ConversationList({
|
|
|
412
415
|
size.current.keyboardMoving = moving;
|
|
413
416
|
// The closing menu's window hands the focus back with a keyboard event: frozen until it ends.
|
|
414
417
|
if (!moving) conversation.settleOverlay();
|
|
415
|
-
}} /> : props.renderScrollComponent}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
+
}} /> : props.renderScrollComponent}
|
|
419
|
+
// A row the list has not drawn yet (it draws only those near the view):
|
|
420
|
+
// go to its estimated offset, which draws it, then to the row itself.
|
|
421
|
+
onScrollToIndexFailed={props.onScrollToIndexFailed ?? (info => {
|
|
422
|
+
const list = listRef.current;
|
|
423
|
+
const target = indexTarget.current;
|
|
424
|
+
if (!list || !target || target.index !== info.index || target.tries >= 3) return;
|
|
425
|
+
target.tries += 1;
|
|
426
|
+
list.scrollToOffset({
|
|
427
|
+
offset: info.averageItemLength * info.index,
|
|
428
|
+
animated: false
|
|
429
|
+
});
|
|
430
|
+
requestAnimationFrame(() => list.scrollToIndex(target));
|
|
431
|
+
})} ref={list_0 => {
|
|
432
|
+
listRef.current = list_0;
|
|
433
|
+
conversation.scrollRef.current = list_0 && {
|
|
434
|
+
scrollToEnd: options => list_0.scrollToOffset({
|
|
418
435
|
offset: end(),
|
|
419
436
|
animated: options?.animated
|
|
420
|
-
})
|
|
437
|
+
}),
|
|
438
|
+
scrollToIndex: options_0 => {
|
|
439
|
+
indexTarget.current = {
|
|
440
|
+
...options_0,
|
|
441
|
+
tries: 0
|
|
442
|
+
};
|
|
443
|
+
list_0.scrollToIndex(options_0);
|
|
444
|
+
}
|
|
421
445
|
};
|
|
422
446
|
}} />;
|
|
423
|
-
if (!keyboard) return
|
|
447
|
+
if (!keyboard) return list_1;
|
|
424
448
|
// The keyboard follows the finger from the composer's top: the dock less the inset it pads.
|
|
425
449
|
return <keyboard.GestureArea offset={Math.max(0, conversation.dockHeight - insets.bottom)} style={styles.fill}>
|
|
426
|
-
{
|
|
450
|
+
{list_1}
|
|
427
451
|
</keyboard.GestureArea>;
|
|
428
452
|
}
|
|
429
453
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { c as _c } from "react/compiler-runtime";
|
|
2
2
|
import * as Slot from "@rn-primitives/slot";
|
|
3
3
|
import { createContext, Fragment, useContext, useEffect, useState } from "react";
|
|
4
|
-
import {
|
|
4
|
+
import { Pressable, StyleSheet } from "react-native";
|
|
5
5
|
import Animated, { runOnJS, useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated";
|
|
6
6
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
7
7
|
import { palette } from "../palette";
|
|
@@ -11,6 +11,7 @@ import { useReduceMotion } from "../useReduceMotion";
|
|
|
11
11
|
import { useScheme } from "../useScheme";
|
|
12
12
|
import { SheetDragProvider, SheetGestureContext, slideSheetIn, slideSheetOut, useSheetBackdropStyle, useSheetDragState } from "./sheet-drag";
|
|
13
13
|
import { useControllableState } from "./use-controllable-state";
|
|
14
|
+
import { WindowLayer } from "./window-layer";
|
|
14
15
|
const OverlayContext = createContext(null);
|
|
15
16
|
export function useOverlay(part) {
|
|
16
17
|
const context = useContext(OverlayContext);
|
|
@@ -150,25 +151,26 @@ export function OverlayClose(props) {
|
|
|
150
151
|
}
|
|
151
152
|
|
|
152
153
|
/**
|
|
153
|
-
*
|
|
154
|
+
* A `WindowLayer` (in the app's window under `WindowLayerHost`, so a chat
|
|
155
|
+
* under it keeps its place; else a `Modal`) with a tinted backdrop, safe-area padding and keyboard avoidance
|
|
154
156
|
* (`KeyboardAvoidingView`: frame by frame with `KeyboardControllerProvider`).
|
|
155
157
|
* `placement="center"` centres the child (dialogs) inside the insets on every
|
|
156
158
|
* side: the backdrop fades while the panel scales from 0.96 and fades in (200
|
|
157
|
-
* ms on open, 150 ms on close), and the
|
|
159
|
+
* ms on open, 150 ms on close), and the layer stays up until it is out of
|
|
158
160
|
* sight. `"bottom"` pins it to the bottom
|
|
159
161
|
* edge (sheets), which pad their own bottom inset: the sheet slides up on
|
|
160
162
|
* open and back down on close, however it closes, and may be dragged down to
|
|
161
163
|
* close (`SheetDragView`); the backdrop fades with the sheet's position. The
|
|
162
|
-
*
|
|
164
|
+
* layer stays up until the sheet is out of sight. The backdrop closes the
|
|
163
165
|
* overlay only when `dismissible`; Android back and the VoiceOver escape
|
|
164
166
|
* gesture always close it, as Escape does on the web. With Reduce Motion on,
|
|
165
167
|
* overlays appear and leave in place. With the Gesture Handler parts
|
|
166
168
|
* (`GestureHandlerProvider`), the content sits in its own root view: on
|
|
167
169
|
* Android a `Modal` is a separate root, and without one there every gesture
|
|
168
|
-
* in it silently does nothing.
|
|
170
|
+
* in it silently does nothing (the fallback `Modal`).
|
|
169
171
|
*/
|
|
170
172
|
export function OverlayModal(t0) {
|
|
171
|
-
const $ = _c(
|
|
173
|
+
const $ = _c(22);
|
|
172
174
|
const {
|
|
173
175
|
part,
|
|
174
176
|
placement,
|
|
@@ -176,10 +178,11 @@ export function OverlayModal(t0) {
|
|
|
176
178
|
onShow,
|
|
177
179
|
children
|
|
178
180
|
} = t0;
|
|
181
|
+
const overlay = useOverlay(part);
|
|
179
182
|
const {
|
|
180
183
|
open,
|
|
181
184
|
setOpen
|
|
182
|
-
} =
|
|
185
|
+
} = overlay;
|
|
183
186
|
const reduceMotion = useReduceMotion();
|
|
184
187
|
const slides = placement === "bottom" && !reduceMotion;
|
|
185
188
|
const scales = placement === "center" && !reduceMotion;
|
|
@@ -200,6 +203,9 @@ export function OverlayModal(t0) {
|
|
|
200
203
|
}
|
|
201
204
|
const close = t1;
|
|
202
205
|
const ModalRoot = useContext(SheetGestureContext)?.ModalRoot ?? Fragment;
|
|
206
|
+
if (!shown) {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
203
209
|
let t2;
|
|
204
210
|
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
|
|
205
211
|
t2 = () => setShown(false);
|
|
@@ -232,20 +238,28 @@ export function OverlayModal(t0) {
|
|
|
232
238
|
t4 = $[14];
|
|
233
239
|
}
|
|
234
240
|
let t5;
|
|
235
|
-
if ($[15] !==
|
|
236
|
-
t5 = <
|
|
237
|
-
$[15] =
|
|
238
|
-
$[16] =
|
|
239
|
-
$[17] =
|
|
240
|
-
|
|
241
|
-
$[
|
|
241
|
+
if ($[15] !== overlay || $[16] !== t4) {
|
|
242
|
+
t5 = <OverlayContext.Provider value={overlay}>{t4}</OverlayContext.Provider>;
|
|
243
|
+
$[15] = overlay;
|
|
244
|
+
$[16] = t4;
|
|
245
|
+
$[17] = t5;
|
|
246
|
+
} else {
|
|
247
|
+
t5 = $[17];
|
|
248
|
+
}
|
|
249
|
+
let t6;
|
|
250
|
+
if ($[18] !== close || $[19] !== onShow || $[20] !== t5) {
|
|
251
|
+
t6 = <WindowLayer onRequestClose={close} onShow={onShow} fade={false}>{t5}</WindowLayer>;
|
|
252
|
+
$[18] = close;
|
|
253
|
+
$[19] = onShow;
|
|
254
|
+
$[20] = t5;
|
|
255
|
+
$[21] = t6;
|
|
242
256
|
} else {
|
|
243
|
-
|
|
257
|
+
t6 = $[21];
|
|
244
258
|
}
|
|
245
|
-
return
|
|
259
|
+
return t6;
|
|
246
260
|
}
|
|
247
261
|
|
|
248
|
-
/** The
|
|
262
|
+
/** The layer's content: mounted with each opening, so a sheet starts below the screen (or at rest). */
|
|
249
263
|
function OverlayModalBody(t0) {
|
|
250
264
|
const $ = _c(48);
|
|
251
265
|
const {
|
|
@@ -29,7 +29,16 @@ const upsert = layer => {
|
|
|
29
29
|
layers = at === -1 ? [...layers, layer] : layers.map((item, index) => index === at ? layer : item);
|
|
30
30
|
emit();
|
|
31
31
|
};
|
|
32
|
+
|
|
33
|
+
// Layers that have called `onShow` once, as a Modal does once per opening.
|
|
34
|
+
const announced = new Set();
|
|
35
|
+
const showOnce = layer => {
|
|
36
|
+
if (announced.has(layer.id)) return;
|
|
37
|
+
announced.add(layer.id);
|
|
38
|
+
layer.onShow?.();
|
|
39
|
+
};
|
|
32
40
|
const remove = id => {
|
|
41
|
+
announced.delete(id);
|
|
33
42
|
if (!layers.some(item => item.id === id)) return;
|
|
34
43
|
layers = layers.filter(item => item.id !== id);
|
|
35
44
|
emit();
|
|
@@ -99,7 +108,7 @@ export function WindowLayerHost(t0) {
|
|
|
99
108
|
if ($[6] !== shown) {
|
|
100
109
|
let t7;
|
|
101
110
|
if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
|
|
102
|
-
t7 = layer => <Animated.View key={layer.id} entering={enter} exiting={exit} style={StyleSheet.absoluteFill} pointerEvents="box-none">{layer.node}</Animated.View>;
|
|
111
|
+
t7 = layer => <Animated.View key={layer.id} entering={layer.fade ? enter : undefined} exiting={layer.fade ? exit : undefined} onLayout={() => showOnce(layer)} style={StyleSheet.absoluteFill} pointerEvents="box-none">{layer.node}</Animated.View>;
|
|
103
112
|
$[8] = t7;
|
|
104
113
|
} else {
|
|
105
114
|
t7 = $[8];
|
|
@@ -127,7 +136,8 @@ export function WindowLayerHost(t0) {
|
|
|
127
136
|
* `WindowLayerHost` when the app has one, else a transparent `Modal` (with
|
|
128
137
|
* `onDismiss` there). Render it only while the overlay shows. Android back
|
|
129
138
|
* calls `onRequestClose`. Its children keep the providers above the host, not
|
|
130
|
-
* those between the host and this element
|
|
139
|
+
* those between the host and this element: an overlay with its own context
|
|
140
|
+
* (a Dialog's open state, a menu's) provides it again inside.
|
|
131
141
|
*/
|
|
132
142
|
function _temp2() {
|
|
133
143
|
return EMPTY;
|
|
@@ -136,68 +146,76 @@ function _temp() {
|
|
|
136
146
|
return layers;
|
|
137
147
|
}
|
|
138
148
|
export function WindowLayer(t0) {
|
|
139
|
-
const $ = _c(
|
|
149
|
+
const $ = _c(17);
|
|
140
150
|
const {
|
|
141
151
|
onRequestClose,
|
|
142
152
|
onDismiss,
|
|
153
|
+
onShow,
|
|
154
|
+
fade: t1,
|
|
143
155
|
children
|
|
144
156
|
} = t0;
|
|
157
|
+
const fade = t1 === undefined ? true : t1;
|
|
145
158
|
const id = useId();
|
|
146
159
|
const reduceMotion = useReduceMotion();
|
|
147
160
|
const hosted = useSyncExternalStore(subscribe, _temp3, _temp4);
|
|
148
|
-
let t1;
|
|
149
161
|
let t2;
|
|
150
|
-
|
|
151
|
-
|
|
162
|
+
let t3;
|
|
163
|
+
if ($[0] !== children || $[1] !== fade || $[2] !== hosted || $[3] !== id || $[4] !== onRequestClose || $[5] !== onShow) {
|
|
164
|
+
t2 = () => {
|
|
152
165
|
if (hosted) {
|
|
153
166
|
upsert({
|
|
154
167
|
id,
|
|
155
168
|
node: children,
|
|
156
|
-
onRequestClose
|
|
169
|
+
onRequestClose,
|
|
170
|
+
onShow,
|
|
171
|
+
fade
|
|
157
172
|
});
|
|
158
173
|
}
|
|
159
174
|
};
|
|
160
|
-
|
|
175
|
+
t3 = [hosted, id, children, onRequestClose, onShow, fade];
|
|
161
176
|
$[0] = children;
|
|
162
|
-
$[1] =
|
|
163
|
-
$[2] =
|
|
164
|
-
$[3] =
|
|
165
|
-
$[4] =
|
|
166
|
-
$[5] =
|
|
177
|
+
$[1] = fade;
|
|
178
|
+
$[2] = hosted;
|
|
179
|
+
$[3] = id;
|
|
180
|
+
$[4] = onRequestClose;
|
|
181
|
+
$[5] = onShow;
|
|
182
|
+
$[6] = t2;
|
|
183
|
+
$[7] = t3;
|
|
167
184
|
} else {
|
|
168
|
-
|
|
169
|
-
|
|
185
|
+
t2 = $[6];
|
|
186
|
+
t3 = $[7];
|
|
170
187
|
}
|
|
171
|
-
useLayoutEffect(
|
|
172
|
-
let t3;
|
|
188
|
+
useLayoutEffect(t2, t3);
|
|
173
189
|
let t4;
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
t4 =
|
|
177
|
-
|
|
178
|
-
$[
|
|
179
|
-
$[
|
|
190
|
+
let t5;
|
|
191
|
+
if ($[8] !== id) {
|
|
192
|
+
t4 = () => () => remove(id);
|
|
193
|
+
t5 = [id];
|
|
194
|
+
$[8] = id;
|
|
195
|
+
$[9] = t4;
|
|
196
|
+
$[10] = t5;
|
|
180
197
|
} else {
|
|
181
|
-
|
|
182
|
-
|
|
198
|
+
t4 = $[9];
|
|
199
|
+
t5 = $[10];
|
|
183
200
|
}
|
|
184
|
-
useLayoutEffect(
|
|
201
|
+
useLayoutEffect(t4, t5);
|
|
185
202
|
if (hosted) {
|
|
186
203
|
return null;
|
|
187
204
|
}
|
|
188
|
-
const
|
|
189
|
-
let
|
|
190
|
-
if ($[
|
|
191
|
-
|
|
192
|
-
$[
|
|
193
|
-
$[
|
|
194
|
-
$[
|
|
195
|
-
$[
|
|
196
|
-
$[
|
|
205
|
+
const t6 = fade && !reduceMotion ? "fade" : "none";
|
|
206
|
+
let t7;
|
|
207
|
+
if ($[11] !== children || $[12] !== onDismiss || $[13] !== onRequestClose || $[14] !== onShow || $[15] !== t6) {
|
|
208
|
+
t7 = <Modal visible={true} transparent={true} statusBarTranslucent={true} animationType={t6} onRequestClose={onRequestClose} onDismiss={onDismiss} onShow={onShow}>{children}</Modal>;
|
|
209
|
+
$[11] = children;
|
|
210
|
+
$[12] = onDismiss;
|
|
211
|
+
$[13] = onRequestClose;
|
|
212
|
+
$[14] = onShow;
|
|
213
|
+
$[15] = t6;
|
|
214
|
+
$[16] = t7;
|
|
197
215
|
} else {
|
|
198
|
-
|
|
216
|
+
t7 = $[16];
|
|
199
217
|
}
|
|
200
|
-
return
|
|
218
|
+
return t7;
|
|
201
219
|
}
|
|
202
220
|
function _temp4() {
|
|
203
221
|
return false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/native-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Shared React Native / Expo UI primitives. Floating surfaces, forms, overlays, toasts, settings chrome, tab bar, AI chat parts, the family app marks, a NativeWind preset, the Expo web root and Clerk + Convex auth screens.",
|
|
6
6
|
"type": "module",
|
package/src/DropdownMenu.tsx
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as Slot from "@rn-primitives/slot";
|
|
2
2
|
import { createContext, useContext, useEffect, useRef, useState, type ComponentType, type ReactNode } from "react";
|
|
3
3
|
import {
|
|
4
|
-
Modal,
|
|
5
4
|
Pressable,
|
|
6
5
|
ScrollView,
|
|
7
6
|
StyleSheet,
|
|
@@ -26,6 +25,7 @@ import { tokens } from "./tokens";
|
|
|
26
25
|
import { useReduceMotion } from "./useReduceMotion";
|
|
27
26
|
import { useScheme } from "./useScheme";
|
|
28
27
|
import { useControllableState } from "./primitives/use-controllable-state";
|
|
28
|
+
import { WindowLayer } from "./primitives/window-layer";
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Sizes from the web menu classes (`_menu-classes.ts`): content `min-w-[12rem]
|
|
@@ -193,7 +193,8 @@ export type DropdownMenuContentProps = ViewProps & {
|
|
|
193
193
|
};
|
|
194
194
|
|
|
195
195
|
/**
|
|
196
|
-
* The menu in a
|
|
196
|
+
* The menu in a `WindowLayer` (in the app's window under `WindowLayerHost`, so
|
|
197
|
+
* a chat under it keeps its place; else a transparent `Modal`): the opaque overlay surface of
|
|
197
198
|
* `Dialog` and `Sheet` (`FloatingSurface` without blur, with the floating
|
|
198
199
|
* shadow) at radius 16, at least 192 wide, `p-1.5`, scrolling when taller than
|
|
199
200
|
* the room. A tap outside, Android back and the VoiceOver escape gesture close
|
|
@@ -209,7 +210,8 @@ export function DropdownMenuContent({
|
|
|
209
210
|
children,
|
|
210
211
|
...props
|
|
211
212
|
}: DropdownMenuContentProps) {
|
|
212
|
-
const
|
|
213
|
+
const menu = useMenu("DropdownMenuContent");
|
|
214
|
+
const { open, setOpen, trigger } = menu;
|
|
213
215
|
const window = useWindowDimensions();
|
|
214
216
|
const insets = useSafeAreaInsets();
|
|
215
217
|
const reduceMotion = useReduceMotion();
|
|
@@ -265,16 +267,14 @@ export function DropdownMenuContent({
|
|
|
265
267
|
// The scale grows from the corner nearest the trigger: its edge on the
|
|
266
268
|
// trigger's (`align`), and the top, or the bottom when the menu flipped above.
|
|
267
269
|
const transformOrigin = `${align === "end" ? 100 : 0}% ${position.bottom === undefined ? 0 : 100}%`;
|
|
270
|
+
if (!shown) return null;
|
|
268
271
|
return (
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
statusBarTranslucent
|
|
274
|
-
onRequestClose={close}
|
|
275
|
-
>
|
|
272
|
+
// The panel runs its own motion, so no fade; the items need the menu's
|
|
273
|
+
// context, which a layer loses, so it is provided again.
|
|
274
|
+
<WindowLayer onRequestClose={close} fade={false}>
|
|
275
|
+
<MenuContext.Provider value={menu}>
|
|
276
276
|
{/* A full-size host, as `OverlayModal` has: without it the backdrop and the
|
|
277
|
-
menu are bare
|
|
277
|
+
menu are bare layer children with no box to size or hit-test against,
|
|
278
278
|
and the menu can stack under tab bars and glass layers. */}
|
|
279
279
|
<View style={{ flex: 1 }} pointerEvents="box-none">
|
|
280
280
|
<Pressable
|
|
@@ -314,7 +314,8 @@ export function DropdownMenuContent({
|
|
|
314
314
|
</Animated.View>
|
|
315
315
|
</View>
|
|
316
316
|
</View>
|
|
317
|
-
|
|
317
|
+
</MenuContext.Provider>
|
|
318
|
+
</WindowLayer>
|
|
318
319
|
);
|
|
319
320
|
}
|
|
320
321
|
|
|
@@ -9,10 +9,13 @@ import type { NativeScrollEvent } from "react-native";
|
|
|
9
9
|
* the `FlatList` of `ConversationList`. `scrollToEnd` goes to the newest
|
|
10
10
|
* message, which is offset 0 in an inverted list. `scrollTo` goes to an
|
|
11
11
|
* offset; only the `ScrollView` has it, so call it as `scrollTo?.(...)`.
|
|
12
|
+
* `scrollToIndex` brings one row of the list's `data` into view (a find in
|
|
13
|
+
* the thread); only the `FlatList` has it. `viewPosition` 0.5 centres it.
|
|
12
14
|
*/
|
|
13
15
|
export type ConversationScroller = {
|
|
14
16
|
scrollToEnd: (options?: { animated?: boolean }) => void;
|
|
15
17
|
scrollTo?: (options: { y: number; animated?: boolean }) => void;
|
|
18
|
+
scrollToIndex?: (options: { index: number; animated?: boolean; viewPosition?: number }) => void;
|
|
16
19
|
};
|
|
17
20
|
|
|
18
21
|
export type ConversationContextValue = {
|
package/src/ai/conversation.tsx
CHANGED
|
@@ -255,6 +255,9 @@ export function ConversationList<T>({
|
|
|
255
255
|
// when inverted); `keyboardMoving` is true while the keyboard scrolls the
|
|
256
256
|
// list, which is not the reader leaving the bottom.
|
|
257
257
|
const size = useRef({ content: 0, view: 0, inset: 0, keyboardMoving: false });
|
|
258
|
+
// The list, and the row `scrollToIndex` last asked for, for its retry when that row was not drawn.
|
|
259
|
+
const listRef = useRef<FlatList<T> | null>(null);
|
|
260
|
+
const indexTarget = useRef<{ index: number; animated?: boolean; viewPosition?: number; tries: number } | null>(null);
|
|
258
261
|
// Not inverted: hidden until the first jump to the end (see above). An
|
|
259
262
|
// empty list (a spinner, an empty state) shows at once.
|
|
260
263
|
const hasRows = (props.data?.length ?? 0) > 0;
|
|
@@ -328,9 +331,27 @@ export function ConversationList<T>({
|
|
|
328
331
|
)
|
|
329
332
|
: props.renderScrollComponent
|
|
330
333
|
}
|
|
334
|
+
// A row the list has not drawn yet (it draws only those near the view):
|
|
335
|
+
// go to its estimated offset, which draws it, then to the row itself.
|
|
336
|
+
onScrollToIndexFailed={
|
|
337
|
+
props.onScrollToIndexFailed ??
|
|
338
|
+
((info) => {
|
|
339
|
+
const list = listRef.current;
|
|
340
|
+
const target = indexTarget.current;
|
|
341
|
+
if (!list || !target || target.index !== info.index || target.tries >= 3) return;
|
|
342
|
+
target.tries += 1;
|
|
343
|
+
list.scrollToOffset({ offset: info.averageItemLength * info.index, animated: false });
|
|
344
|
+
requestAnimationFrame(() => list.scrollToIndex(target));
|
|
345
|
+
})
|
|
346
|
+
}
|
|
331
347
|
ref={(list: FlatList<T> | null) => {
|
|
348
|
+
listRef.current = list;
|
|
332
349
|
conversation.scrollRef.current = list && {
|
|
333
350
|
scrollToEnd: (options) => list.scrollToOffset({ offset: end(), animated: options?.animated }),
|
|
351
|
+
scrollToIndex: (options) => {
|
|
352
|
+
indexTarget.current = { ...options, tries: 0 };
|
|
353
|
+
list.scrollToIndex(options);
|
|
354
|
+
},
|
|
334
355
|
};
|
|
335
356
|
}}
|
|
336
357
|
/>
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
type ReactNode,
|
|
10
10
|
} from "react";
|
|
11
11
|
import {
|
|
12
|
-
Modal,
|
|
13
12
|
Pressable,
|
|
14
13
|
StyleSheet,
|
|
15
14
|
View,
|
|
@@ -36,6 +35,7 @@ import {
|
|
|
36
35
|
useSheetDragState,
|
|
37
36
|
} from "./sheet-drag";
|
|
38
37
|
import { useControllableState } from "./use-controllable-state";
|
|
38
|
+
import { WindowLayer } from "./window-layer";
|
|
39
39
|
|
|
40
40
|
type OverlayContextValue = {
|
|
41
41
|
open: boolean;
|
|
@@ -116,22 +116,23 @@ export function OverlayClose(props: OverlayPressableProps & { part: string }) {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
/**
|
|
119
|
-
*
|
|
119
|
+
* A `WindowLayer` (in the app's window under `WindowLayerHost`, so a chat
|
|
120
|
+
* under it keeps its place; else a `Modal`) with a tinted backdrop, safe-area padding and keyboard avoidance
|
|
120
121
|
* (`KeyboardAvoidingView`: frame by frame with `KeyboardControllerProvider`).
|
|
121
122
|
* `placement="center"` centres the child (dialogs) inside the insets on every
|
|
122
123
|
* side: the backdrop fades while the panel scales from 0.96 and fades in (200
|
|
123
|
-
* ms on open, 150 ms on close), and the
|
|
124
|
+
* ms on open, 150 ms on close), and the layer stays up until it is out of
|
|
124
125
|
* sight. `"bottom"` pins it to the bottom
|
|
125
126
|
* edge (sheets), which pad their own bottom inset: the sheet slides up on
|
|
126
127
|
* open and back down on close, however it closes, and may be dragged down to
|
|
127
128
|
* close (`SheetDragView`); the backdrop fades with the sheet's position. The
|
|
128
|
-
*
|
|
129
|
+
* layer stays up until the sheet is out of sight. The backdrop closes the
|
|
129
130
|
* overlay only when `dismissible`; Android back and the VoiceOver escape
|
|
130
131
|
* gesture always close it, as Escape does on the web. With Reduce Motion on,
|
|
131
132
|
* overlays appear and leave in place. With the Gesture Handler parts
|
|
132
133
|
* (`GestureHandlerProvider`), the content sits in its own root view: on
|
|
133
134
|
* Android a `Modal` is a separate root, and without one there every gesture
|
|
134
|
-
* in it silently does nothing.
|
|
135
|
+
* in it silently does nothing (the fallback `Modal`).
|
|
135
136
|
*/
|
|
136
137
|
export function OverlayModal({
|
|
137
138
|
part,
|
|
@@ -147,7 +148,8 @@ export function OverlayModal({
|
|
|
147
148
|
onShow?: () => void;
|
|
148
149
|
children: ReactNode;
|
|
149
150
|
}) {
|
|
150
|
-
const
|
|
151
|
+
const overlay = useOverlay(part);
|
|
152
|
+
const { open, setOpen } = overlay;
|
|
151
153
|
const reduceMotion = useReduceMotion();
|
|
152
154
|
const slides = placement === "bottom" && !reduceMotion;
|
|
153
155
|
const scales = placement === "center" && !reduceMotion;
|
|
@@ -158,15 +160,12 @@ export function OverlayModal({
|
|
|
158
160
|
const close = () => setOpen(false);
|
|
159
161
|
const ModalRoot = useContext(SheetGestureContext)?.ModalRoot ?? Fragment;
|
|
160
162
|
|
|
163
|
+
if (!shown) return null;
|
|
161
164
|
return (
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
statusBarTranslucent
|
|
167
|
-
onRequestClose={close}
|
|
168
|
-
onShow={onShow}
|
|
169
|
-
>
|
|
165
|
+
// The layer runs its own motion, so no fade; a layer loses the context
|
|
166
|
+
// between it and the host, so the open state is provided again.
|
|
167
|
+
<WindowLayer onRequestClose={close} onShow={onShow} fade={false}>
|
|
168
|
+
<OverlayContext.Provider value={overlay}>
|
|
170
169
|
<ModalRoot>
|
|
171
170
|
<OverlayModalBody
|
|
172
171
|
placement={placement}
|
|
@@ -181,11 +180,12 @@ export function OverlayModal({
|
|
|
181
180
|
{children}
|
|
182
181
|
</OverlayModalBody>
|
|
183
182
|
</ModalRoot>
|
|
184
|
-
|
|
183
|
+
</OverlayContext.Provider>
|
|
184
|
+
</WindowLayer>
|
|
185
185
|
);
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
/** The
|
|
188
|
+
/** The layer's content: mounted with each opening, so a sheet starts below the screen (or at rest). */
|
|
189
189
|
function OverlayModalBody({
|
|
190
190
|
part,
|
|
191
191
|
placement,
|
|
@@ -232,7 +232,7 @@ function OverlayModalBody({
|
|
|
232
232
|
}, [open, slides]);
|
|
233
233
|
// The same for a centred dialog, from wherever `progress` is. Opened again
|
|
234
234
|
// while it leaves, it turns back at once, and the exit callback reports
|
|
235
|
-
// `finished` false, so the
|
|
235
|
+
// `finished` false, so the layer stays up.
|
|
236
236
|
useEffect(() => {
|
|
237
237
|
if (!scales) return;
|
|
238
238
|
if (open) {
|
|
@@ -254,7 +254,7 @@ function OverlayModalBody({
|
|
|
254
254
|
is the measured overlap, so it drops to 0 where the window does
|
|
255
255
|
resize. Frame by frame with `KeyboardControllerProvider`. */}
|
|
256
256
|
<KeyboardAvoidingView style={styles.fill}>
|
|
257
|
-
{/*
|
|
257
|
+
{/* Over the app, not in the dock it opened from: the dock's lift is not for it. */}
|
|
258
258
|
<KeyboardLiftContext.Provider value={false}>
|
|
259
259
|
<Animated.View
|
|
260
260
|
pointerEvents="box-none"
|
|
@@ -10,7 +10,7 @@ import { useReduceMotion } from "../useReduceMotion";
|
|
|
10
10
|
// the app instead, so the focus never moves. Without a host, `WindowLayer`
|
|
11
11
|
// falls back to a `Modal`, so an app that mounts none keeps working.
|
|
12
12
|
|
|
13
|
-
type Layer = { id: string; node: ReactNode; onRequestClose: () => void };
|
|
13
|
+
type Layer = { id: string; node: ReactNode; onRequestClose: () => void; onShow?: () => void; fade: boolean };
|
|
14
14
|
|
|
15
15
|
const EMPTY: readonly Layer[] = [];
|
|
16
16
|
let layers: readonly Layer[] = EMPTY;
|
|
@@ -34,7 +34,17 @@ const upsert = (layer: Layer) => {
|
|
|
34
34
|
emit();
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
+
// Layers that have called `onShow` once, as a Modal does once per opening.
|
|
38
|
+
const announced = new Set<string>();
|
|
39
|
+
|
|
40
|
+
const showOnce = (layer: Layer) => {
|
|
41
|
+
if (announced.has(layer.id)) return;
|
|
42
|
+
announced.add(layer.id);
|
|
43
|
+
layer.onShow?.();
|
|
44
|
+
};
|
|
45
|
+
|
|
37
46
|
const remove = (id: string) => {
|
|
47
|
+
announced.delete(id);
|
|
38
48
|
if (!layers.some((item) => item.id === id)) return;
|
|
39
49
|
layers = layers.filter((item) => item.id !== id);
|
|
40
50
|
emit();
|
|
@@ -68,7 +78,8 @@ const hostRef = (view: View | null) => {
|
|
|
68
78
|
*/
|
|
69
79
|
export function WindowLayerHost({ children }: { children: ReactNode }) {
|
|
70
80
|
const shown = useSyncExternalStore(subscribe, () => layers, () => EMPTY);
|
|
71
|
-
// The layers fade in and out as a Modal's `fade
|
|
81
|
+
// The layers fade in and out as a Modal's `fade`, unless they move on their
|
|
82
|
+
// own (`fade={false}`); with Reduce Motion they appear at once.
|
|
72
83
|
const enter = FadeIn.duration(200).reduceMotion(ReduceMotion.System);
|
|
73
84
|
const exit = FadeOut.duration(150).reduceMotion(ReduceMotion.System);
|
|
74
85
|
return (
|
|
@@ -81,7 +92,14 @@ export function WindowLayerHost({ children }: { children: ReactNode }) {
|
|
|
81
92
|
{children}
|
|
82
93
|
</View>
|
|
83
94
|
{shown.map((layer) => (
|
|
84
|
-
<Animated.View
|
|
95
|
+
<Animated.View
|
|
96
|
+
key={layer.id}
|
|
97
|
+
entering={layer.fade ? enter : undefined}
|
|
98
|
+
exiting={layer.fade ? exit : undefined}
|
|
99
|
+
onLayout={() => showOnce(layer)}
|
|
100
|
+
style={StyleSheet.absoluteFill}
|
|
101
|
+
pointerEvents="box-none"
|
|
102
|
+
>
|
|
85
103
|
{layer.node}
|
|
86
104
|
</Animated.View>
|
|
87
105
|
))}
|
|
@@ -94,16 +112,23 @@ export function WindowLayerHost({ children }: { children: ReactNode }) {
|
|
|
94
112
|
* `WindowLayerHost` when the app has one, else a transparent `Modal` (with
|
|
95
113
|
* `onDismiss` there). Render it only while the overlay shows. Android back
|
|
96
114
|
* calls `onRequestClose`. Its children keep the providers above the host, not
|
|
97
|
-
* those between the host and this element
|
|
115
|
+
* those between the host and this element: an overlay with its own context
|
|
116
|
+
* (a Dialog's open state, a menu's) provides it again inside.
|
|
98
117
|
*/
|
|
99
118
|
export function WindowLayer({
|
|
100
119
|
onRequestClose,
|
|
101
120
|
onDismiss,
|
|
121
|
+
onShow,
|
|
122
|
+
fade = true,
|
|
102
123
|
children,
|
|
103
124
|
}: {
|
|
104
125
|
onRequestClose: () => void;
|
|
105
126
|
/** The fallback Modal's dismiss (iOS); a layer is gone as it unmounts. */
|
|
106
127
|
onDismiss?: () => void;
|
|
128
|
+
/** Once the layer is on screen, as a Modal's `onShow`. */
|
|
129
|
+
onShow?: () => void;
|
|
130
|
+
/** Fade in and out. `false` for an overlay that runs its own motion. Default `true`. */
|
|
131
|
+
fade?: boolean;
|
|
107
132
|
children: ReactNode;
|
|
108
133
|
}) {
|
|
109
134
|
const id = useId();
|
|
@@ -112,8 +137,8 @@ export function WindowLayer({
|
|
|
112
137
|
// A portal has to hand the host its children after each render: an external
|
|
113
138
|
// store fed from an effect, the one sync React offers for it.
|
|
114
139
|
useLayoutEffect(() => {
|
|
115
|
-
if (hosted) upsert({ id, node: children, onRequestClose });
|
|
116
|
-
}, [hosted, id, children, onRequestClose]);
|
|
140
|
+
if (hosted) upsert({ id, node: children, onRequestClose, onShow, fade });
|
|
141
|
+
}, [hosted, id, children, onRequestClose, onShow, fade]);
|
|
117
142
|
useLayoutEffect(() => () => remove(id), [id]);
|
|
118
143
|
if (hosted) return null;
|
|
119
144
|
return (
|
|
@@ -121,9 +146,10 @@ export function WindowLayer({
|
|
|
121
146
|
visible
|
|
122
147
|
transparent
|
|
123
148
|
statusBarTranslucent
|
|
124
|
-
animationType={reduceMotion ? "
|
|
149
|
+
animationType={fade && !reduceMotion ? "fade" : "none"}
|
|
125
150
|
onRequestClose={onRequestClose}
|
|
126
151
|
onDismiss={onDismiss}
|
|
152
|
+
onShow={onShow}
|
|
127
153
|
>
|
|
128
154
|
{children}
|
|
129
155
|
</Modal>
|