@kanso-labs/react-native-kanso-ui 0.3.0 → 0.4.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.
@@ -0,0 +1,1090 @@
1
+ import { useTheme } from "../../theme/scope.js";
2
+ import { composeStyles, themedStyles } from "../../theme/styles.js";
3
+ import { useTypeRole } from "../../typography/roles.js";
4
+ import { ButtonSlotContext } from "../../button/slots.js";
5
+ import { messagesFor } from "../../i18n/index.js";
6
+ import { usePressFeedback } from "../../press/index.js";
7
+ import { useWindowSizeClass } from "../../hooks/useWindowSizeClass.js";
8
+ import { ModalWindow, NO_INSETS, insetsOf, panelRoleOf, refsOf, useModalState, useModalTrigger } from "../../modal/index.js";
9
+ import { c } from "react/compiler-runtime";
10
+ import { I18nManager, Pressable, ScrollView, StyleSheet, Text, View, useWindowDimensions } from "react-native";
11
+ import { createContext, use, useEffect, useId, useState } from "react";
12
+ import { jsx, jsxs } from "react/jsx-runtime";
13
+ import Animated, { Easing, useAnimatedStyle, useReducedMotion, useSharedValue, withTiming } from "react-native-reanimated";
14
+ import { SafeAreaInsetsContext } from "react-native-safe-area-context";
15
+ import { Gesture, GestureDetector, GestureHandlerRootView } from "react-native-gesture-handler";
16
+ //#region src/components/sheet/index.tsx
17
+ const SIDE_WIDTH = 400;
18
+ const TOP_MARGIN = 72;
19
+ const PARTIAL = .5;
20
+ const DRAG_SLOP = 8;
21
+ const FLING = 500;
22
+ const BAR_WIDTH = 32;
23
+ const BAR_HEIGHT = 4;
24
+ const BAR_SPACE = 22;
25
+ const BAR_SIDE = 8;
26
+ const stylesOf = themedStyles(({ colors, radii, shadows, spacing }) => StyleSheet.create({
27
+ bar: {
28
+ backgroundColor: colors.onSurfaceVariant,
29
+ borderRadius: radii.pill,
30
+ height: BAR_HEIGHT,
31
+ width: BAR_WIDTH
32
+ },
33
+ body: {
34
+ gap: spacing.lg,
35
+ paddingHorizontal: spacing.xl,
36
+ paddingVertical: spacing.lg
37
+ },
38
+ bodyText: { color: colors.onSurfaceVariant },
39
+ container: {
40
+ backgroundColor: colors.surfaceContainerLow,
41
+ boxShadow: shadows.elevation1,
42
+ overflow: "hidden"
43
+ },
44
+ containerBottom: {
45
+ borderTopLeftRadius: radii.xl,
46
+ borderTopRightRadius: radii.xl,
47
+ width: "100%"
48
+ },
49
+ containerSide: {
50
+ borderBottomStartRadius: radii.lg,
51
+ borderTopStartRadius: radii.lg,
52
+ flex: 1
53
+ },
54
+ footer: {
55
+ alignItems: "center",
56
+ borderTopColor: colors.outlineVariant,
57
+ borderTopWidth: 1,
58
+ flexDirection: "row",
59
+ flexShrink: 0,
60
+ flexWrap: "wrap",
61
+ gap: spacing.sm,
62
+ justifyContent: "flex-start",
63
+ minHeight: 72,
64
+ paddingBottom: spacing.xl,
65
+ paddingHorizontal: spacing.xl,
66
+ paddingTop: spacing.lg
67
+ },
68
+ handle: {
69
+ alignItems: "center",
70
+ alignSelf: "center",
71
+ borderRadius: radii.pill,
72
+ flexShrink: 0,
73
+ paddingHorizontal: BAR_SIDE,
74
+ paddingVertical: BAR_SPACE
75
+ },
76
+ header: {
77
+ alignItems: "center",
78
+ borderBottomColor: colors.outlineVariant,
79
+ borderBottomWidth: 1,
80
+ flexDirection: "row",
81
+ flexShrink: 0,
82
+ gap: spacing.md,
83
+ justifyContent: "space-between",
84
+ paddingHorizontal: spacing.xl,
85
+ paddingVertical: spacing.sm
86
+ },
87
+ rootBottom: {
88
+ bottom: 0,
89
+ left: 0,
90
+ position: "absolute",
91
+ right: 0
92
+ },
93
+ rootSide: {
94
+ bottom: 0,
95
+ end: 0,
96
+ maxWidth: "100%",
97
+ position: "absolute",
98
+ top: 0,
99
+ width: SIDE_WIDTH
100
+ },
101
+ title: {
102
+ color: colors.onSurfaceVariant,
103
+ flexShrink: 1,
104
+ minWidth: 0
105
+ }
106
+ }));
107
+ const SheetLayoutContext = createContext(null);
108
+ const SheetTriggerContext = createContext(null);
109
+ function bottomBoundsOf(insets, height) {
110
+ return {
111
+ ...insetsOf(insets),
112
+ maxHeight: height - Math.max(TOP_MARGIN, insets.top),
113
+ paddingTop: 0
114
+ };
115
+ }
116
+ /**
117
+ * Where a bottom sheet let go comes to rest: one height on in the direction of
118
+ * a fling, and the nearest height otherwise. Heights are how far the panel is
119
+ * moved down, highest first, and the highest is always the whole sheet, 0.
120
+ */
121
+ function settleOf(at, velocity, settles) {
122
+ if (velocity > FLING) return settles.find((stop) => stop > at) ?? settles.at(-1) ?? 0;
123
+ if (velocity < -500) return settles.findLast((stop) => stop < at) ?? 0;
124
+ return settles.reduce((nearest, stop) => Math.abs(stop - at) < Math.abs(nearest - at) ? stop : nearest, 0);
125
+ }
126
+ /**
127
+ * A modal sheet along an edge of the screen, the bottom sheets and side sheets
128
+ * spec pages' modal sheets, paired by window size as kanso-ui's are: a bottom
129
+ * sheet in a compact window, dragged between heights and swiped down to go,
130
+ * and a side sheet along the end edge from the medium window up. Pass
131
+ * `isOpen` with `onOpenChange` to hold the open state, or `defaultOpen` to let
132
+ * it keep its own.
133
+ *
134
+ * ```tsx
135
+ * <Sheet>
136
+ * <Button>Open</Button>
137
+ * <Sheet.Content>
138
+ * <Sheet.Handle />
139
+ * <Sheet.Header>
140
+ * <Sheet.Title>Headline</Sheet.Title>
141
+ * </Sheet.Header>
142
+ * <Sheet.Body>Supporting text</Sheet.Body>
143
+ * <Sheet.Footer>
144
+ * <Button slot="close">Done</Button>
145
+ * </Sheet.Footer>
146
+ * </Sheet.Content>
147
+ * </Sheet>
148
+ * ```
149
+ *
150
+ * Composed rather than configured by props, as web's is. A `Button` or
151
+ * `IconButton` inside `Sheet` and outside its content opens it, and one given
152
+ * `slot="close"` anywhere inside the content closes it. A sheet nothing on the
153
+ * screen opens leaves `Sheet` out and passes `isOpen` and `onOpenChange` to
154
+ * `Sheet.Content` instead.
155
+ */
156
+ function Sheet(t0) {
157
+ const $ = c(10);
158
+ const { children, defaultOpen, isOpen, onOpenChange } = t0;
159
+ let t1;
160
+ if ($[0] !== defaultOpen || $[1] !== isOpen || $[2] !== onOpenChange) {
161
+ t1 = {
162
+ defaultOpen,
163
+ isOpen,
164
+ onOpenChange
165
+ };
166
+ $[0] = defaultOpen;
167
+ $[1] = isOpen;
168
+ $[2] = onOpenChange;
169
+ $[3] = t1;
170
+ } else t1 = $[3];
171
+ const { context, slots } = useModalTrigger(t1);
172
+ let t2;
173
+ if ($[4] !== children || $[5] !== slots) {
174
+ t2 = /* @__PURE__ */ jsx(ButtonSlotContext, {
175
+ value: slots,
176
+ children
177
+ });
178
+ $[4] = children;
179
+ $[5] = slots;
180
+ $[6] = t2;
181
+ } else t2 = $[6];
182
+ let t3;
183
+ if ($[7] !== context || $[8] !== t2) {
184
+ t3 = /* @__PURE__ */ jsx(SheetTriggerContext, {
185
+ value: context,
186
+ children: t2
187
+ });
188
+ $[7] = context;
189
+ $[8] = t2;
190
+ $[9] = t3;
191
+ } else t3 = $[9];
192
+ return t3;
193
+ }
194
+ /**
195
+ * What the sheet shows, as a body that scrolls when its content runs past the
196
+ * room it has. A string is drawn in body medium on on-surface variant;
197
+ * anything else draws itself. `style`, `ref` and `testID` land on the
198
+ * `ScrollView`.
199
+ *
200
+ * A body its content runs past takes focus, as web's is a tab stop, so a
201
+ * keyboard can scroll it when nothing inside it takes focus; a call site's
202
+ * own `focusable` still wins. A bottom sheet's body scrolls only once the
203
+ * sheet is at its whole height, and holds the sheet's drag off while it does.
204
+ */
205
+ function SheetBody(t0) {
206
+ const $ = c(28);
207
+ let children;
208
+ let contentContainerStyle;
209
+ let onContentSizeChange;
210
+ let onLayout;
211
+ let props;
212
+ let t1;
213
+ if ($[0] !== t0) {
214
+ ({children, contentContainerStyle, onContentSizeChange, onLayout, scrollEnabled: t1, ...props} = t0);
215
+ $[0] = t0;
216
+ $[1] = children;
217
+ $[2] = contentContainerStyle;
218
+ $[3] = onContentSizeChange;
219
+ $[4] = onLayout;
220
+ $[5] = props;
221
+ $[6] = t1;
222
+ } else {
223
+ children = $[1];
224
+ contentContainerStyle = $[2];
225
+ onContentSizeChange = $[3];
226
+ onLayout = $[4];
227
+ props = $[5];
228
+ t1 = $[6];
229
+ }
230
+ const scrollEnabled = t1 === void 0 ? true : t1;
231
+ const layout = useLayout("Sheet.Body");
232
+ const styles = stylesOf(useTheme());
233
+ const text = useTypeRole("bodyMedium");
234
+ const [content, setContent] = useState(0);
235
+ const [room, setRoom] = useState(0);
236
+ let t2;
237
+ if ($[7] !== onContentSizeChange) {
238
+ t2 = (width, height) => {
239
+ setContent(height);
240
+ onContentSizeChange?.(width, height);
241
+ };
242
+ $[7] = onContentSizeChange;
243
+ $[8] = t2;
244
+ } else t2 = $[8];
245
+ const measureContent = t2;
246
+ let t3;
247
+ if ($[9] !== onLayout) {
248
+ t3 = (event) => {
249
+ setRoom(event.nativeEvent.layout.height);
250
+ onLayout?.(event);
251
+ };
252
+ $[9] = onLayout;
253
+ $[10] = t3;
254
+ } else t3 = $[10];
255
+ const measureRoom = t3;
256
+ const scrolls = scrollEnabled && layout.expanded;
257
+ const overflows = content > room;
258
+ let t4;
259
+ if ($[11] !== layout.pan || $[12] !== overflows || $[13] !== scrolls) {
260
+ t4 = Gesture.Native().enabled(scrolls && overflows).blocksExternalGesture(layout.pan);
261
+ $[11] = layout.pan;
262
+ $[12] = overflows;
263
+ $[13] = scrolls;
264
+ $[14] = t4;
265
+ } else t4 = $[14];
266
+ const native = t4;
267
+ const T0 = GestureDetector;
268
+ const T1 = ScrollView;
269
+ const t5 = scrolls && overflows;
270
+ const t6 = composeStyles(styles.body, contentContainerStyle);
271
+ const t7 = typeof children === "string" ? /* @__PURE__ */ jsx(Text, {
272
+ style: composeStyles(text, styles.bodyText),
273
+ children
274
+ }) : children;
275
+ let t8;
276
+ if ($[15] !== T1 || $[16] !== measureContent || $[17] !== measureRoom || $[18] !== props || $[19] !== scrolls || $[20] !== t5 || $[21] !== t6 || $[22] !== t7) {
277
+ t8 = /* @__PURE__ */ jsx(T1, {
278
+ focusable: t5,
279
+ onContentSizeChange: measureContent,
280
+ onLayout: measureRoom,
281
+ ...props,
282
+ contentContainerStyle: t6,
283
+ scrollEnabled: scrolls,
284
+ children: t7
285
+ });
286
+ $[15] = T1;
287
+ $[16] = measureContent;
288
+ $[17] = measureRoom;
289
+ $[18] = props;
290
+ $[19] = scrolls;
291
+ $[20] = t5;
292
+ $[21] = t6;
293
+ $[22] = t7;
294
+ $[23] = t8;
295
+ } else t8 = $[23];
296
+ let t9;
297
+ if ($[24] !== T0 || $[25] !== native || $[26] !== t8) {
298
+ t9 = /* @__PURE__ */ jsx(T0, {
299
+ gesture: native,
300
+ children: t8
301
+ });
302
+ $[24] = T0;
303
+ $[25] = native;
304
+ $[26] = t8;
305
+ $[27] = t9;
306
+ } else t9 = $[27];
307
+ return t9;
308
+ }
309
+ /**
310
+ * The sheet itself, and the scrim behind it. Everything the sheet shows goes
311
+ * in here; the button that opens it stays outside it.
312
+ *
313
+ * Inside `Sheet`, the open state is the trigger's. On its own it is this
314
+ * part's: `isOpen` with `onOpenChange` holds it, and a `slot="close"` button,
315
+ * the scrim, the swipe and the back gesture all report through
316
+ * `onOpenChange`. `style`, `ref` and `testID` land on the container, and
317
+ * `testID` names the drag `<testID>-drag` for Gesture Handler's test helpers.
318
+ */
319
+ function SheetContent(t0) {
320
+ const $ = c(19);
321
+ let defaultOpen;
322
+ let isOpen;
323
+ let onOpenChange;
324
+ let props;
325
+ let t1;
326
+ let t2;
327
+ if ($[0] !== t0) {
328
+ ({defaultOpen, isDismissable: t1, isKeyboardDismissDisabled: t2, isOpen, onOpenChange, ...props} = t0);
329
+ $[0] = t0;
330
+ $[1] = defaultOpen;
331
+ $[2] = isOpen;
332
+ $[3] = onOpenChange;
333
+ $[4] = props;
334
+ $[5] = t1;
335
+ $[6] = t2;
336
+ } else {
337
+ defaultOpen = $[1];
338
+ isOpen = $[2];
339
+ onOpenChange = $[3];
340
+ props = $[4];
341
+ t1 = $[5];
342
+ t2 = $[6];
343
+ }
344
+ const isDismissable = t1 === void 0 ? true : t1;
345
+ const isKeyboardDismissDisabled = t2 === void 0 ? false : t2;
346
+ const outer = use(SheetTriggerContext);
347
+ let t3;
348
+ if ($[7] !== defaultOpen || $[8] !== isOpen || $[9] !== onOpenChange) {
349
+ t3 = {
350
+ defaultOpen,
351
+ isOpen,
352
+ onOpenChange
353
+ };
354
+ $[7] = defaultOpen;
355
+ $[8] = isOpen;
356
+ $[9] = onOpenChange;
357
+ $[10] = t3;
358
+ } else t3 = $[10];
359
+ const { close, present, setPresent, slots, state } = useModalState(outer, t3);
360
+ if (!present) return null;
361
+ let t4;
362
+ if ($[11] !== close || $[12] !== isDismissable || $[13] !== isKeyboardDismissDisabled || $[14] !== props || $[15] !== setPresent || $[16] !== slots || $[17] !== state.isOpen) {
363
+ t4 = /* @__PURE__ */ jsx(SheetWindow, {
364
+ ...props,
365
+ close,
366
+ isDismissable,
367
+ isKeyboardDismissDisabled,
368
+ isOpen: state.isOpen,
369
+ setPresent,
370
+ slots
371
+ });
372
+ $[11] = close;
373
+ $[12] = isDismissable;
374
+ $[13] = isKeyboardDismissDisabled;
375
+ $[14] = props;
376
+ $[15] = setPresent;
377
+ $[16] = slots;
378
+ $[17] = state.isOpen;
379
+ $[18] = t4;
380
+ } else t4 = $[18];
381
+ return t4;
382
+ }
383
+ /**
384
+ * The sheet's actions, leading and wrapping onto another row when they do not
385
+ * fit on one, over a divider. On a bottom sheet at half height they are below
386
+ * the fold until the sheet is raised. `style`, `ref` and `testID` land on its
387
+ * view.
388
+ */
389
+ function SheetFooter(t0) {
390
+ const $ = c(7);
391
+ let props;
392
+ let style;
393
+ if ($[0] !== t0) {
394
+ ({style, ...props} = t0);
395
+ $[0] = t0;
396
+ $[1] = props;
397
+ $[2] = style;
398
+ } else {
399
+ props = $[1];
400
+ style = $[2];
401
+ }
402
+ useLayout("Sheet.Footer");
403
+ const styles = stylesOf(useTheme());
404
+ const T0 = View;
405
+ const t1 = composeStyles(styles.footer, style);
406
+ let t2;
407
+ if ($[3] !== T0 || $[4] !== props || $[5] !== t1) {
408
+ t2 = /* @__PURE__ */ jsx(T0, {
409
+ ...props,
410
+ style: t1
411
+ });
412
+ $[3] = T0;
413
+ $[4] = props;
414
+ $[5] = t1;
415
+ $[6] = t2;
416
+ } else t2 = $[6];
417
+ return t2;
418
+ }
419
+ /**
420
+ * The bottom sheet's drag handle, a 32 by 4dp bar centred along its top edge.
421
+ * Where the sheet has two heights it is a button moving it to the other one,
422
+ * named "Drag handle" in the device's locale unless `aria-label` says
423
+ * otherwise; elsewhere it is a mark a screen reader skips. A side sheet draws
424
+ * none. `style`, `ref` and `testID` land on its view.
425
+ */
426
+ function SheetHandle(t0) {
427
+ const $ = c(23);
428
+ let label;
429
+ let props;
430
+ let style;
431
+ if ($[0] !== t0) {
432
+ ({"aria-label": label, style, ...props} = t0);
433
+ $[0] = t0;
434
+ $[1] = label;
435
+ $[2] = props;
436
+ $[3] = style;
437
+ } else {
438
+ label = $[1];
439
+ props = $[2];
440
+ style = $[3];
441
+ }
442
+ const layout = useLayout("Sheet.Handle");
443
+ const theme = useTheme();
444
+ const styles = stylesOf(theme);
445
+ const { colors, radii } = theme;
446
+ let t1;
447
+ if ($[4] !== radii.pill) {
448
+ t1 = { borderRadius: radii.pill };
449
+ $[4] = radii.pill;
450
+ $[5] = t1;
451
+ } else t1 = $[5];
452
+ let t2;
453
+ if ($[6] !== colors.onSurfaceVariant || $[7] !== t1) {
454
+ t2 = {
455
+ color: colors.onSurfaceVariant,
456
+ corners: t1
457
+ };
458
+ $[6] = colors.onSurfaceVariant;
459
+ $[7] = t1;
460
+ $[8] = t2;
461
+ } else t2 = $[8];
462
+ const feedback = usePressFeedback(t2);
463
+ const { toggle } = layout;
464
+ if (!layout.bottom) return null;
465
+ if (toggle === void 0) return /* @__PURE__ */ jsx(View, {
466
+ "aria-hidden": true,
467
+ ...props,
468
+ style: composeStyles(styles.handle, style),
469
+ children: /* @__PURE__ */ jsx(View, { style: styles.bar })
470
+ });
471
+ const T0 = Pressable;
472
+ const t3 = layout.expanded;
473
+ let t4;
474
+ if ($[9] !== label) {
475
+ t4 = label ?? messagesFor().dragHandle;
476
+ $[9] = label;
477
+ $[10] = t4;
478
+ } else t4 = $[10];
479
+ const t5 = "button";
480
+ const t6 = feedback.handlers;
481
+ const t7 = composeStyles(styles.handle, feedback.ring, style);
482
+ let t8;
483
+ if ($[11] !== styles.bar) {
484
+ t8 = /* @__PURE__ */ jsx(View, { style: styles.bar });
485
+ $[11] = styles.bar;
486
+ $[12] = t8;
487
+ } else t8 = $[12];
488
+ let t9;
489
+ if ($[13] !== T0 || $[14] !== feedback.handlers || $[15] !== feedback.layer || $[16] !== layout.expanded || $[17] !== props || $[18] !== t4 || $[19] !== t7 || $[20] !== t8 || $[21] !== toggle) {
490
+ t9 = /* @__PURE__ */ jsxs(T0, {
491
+ "aria-expanded": t3,
492
+ "aria-label": t4,
493
+ role: t5,
494
+ ...props,
495
+ ...t6,
496
+ onPress: toggle,
497
+ style: t7,
498
+ children: [feedback.layer, t8]
499
+ });
500
+ $[13] = T0;
501
+ $[14] = feedback.handlers;
502
+ $[15] = feedback.layer;
503
+ $[16] = layout.expanded;
504
+ $[17] = props;
505
+ $[18] = t4;
506
+ $[19] = t7;
507
+ $[20] = t8;
508
+ $[21] = toggle;
509
+ $[22] = t9;
510
+ } else t9 = $[22];
511
+ return t9;
512
+ }
513
+ /**
514
+ * The sheet's header: its `Sheet.Title`, and anything beside it, such as a
515
+ * close button, over a divider. `style`, `ref` and `testID` land on its view.
516
+ */
517
+ function SheetHeader(t0) {
518
+ const $ = c(7);
519
+ let props;
520
+ let style;
521
+ if ($[0] !== t0) {
522
+ ({style, ...props} = t0);
523
+ $[0] = t0;
524
+ $[1] = props;
525
+ $[2] = style;
526
+ } else {
527
+ props = $[1];
528
+ style = $[2];
529
+ }
530
+ useLayout("Sheet.Header");
531
+ const styles = stylesOf(useTheme());
532
+ const T0 = View;
533
+ const t1 = composeStyles(styles.header, style);
534
+ let t2;
535
+ if ($[3] !== T0 || $[4] !== props || $[5] !== t1) {
536
+ t2 = /* @__PURE__ */ jsx(T0, {
537
+ ...props,
538
+ style: t1
539
+ });
540
+ $[3] = T0;
541
+ $[4] = props;
542
+ $[5] = t1;
543
+ $[6] = t2;
544
+ } else t2 = $[6];
545
+ return t2;
546
+ }
547
+ /**
548
+ * Names the sheet: the container is labelled by it, and a screen reader is
549
+ * sent to it once the sheet shows. In title large on on-surface variant.
550
+ * `style`, `ref` and `testID` land on React Native's own Text.
551
+ */
552
+ function SheetTitle(t0) {
553
+ const $ = c(13);
554
+ let props;
555
+ let ref;
556
+ let style;
557
+ if ($[0] !== t0) {
558
+ ({ref, style, ...props} = t0);
559
+ $[0] = t0;
560
+ $[1] = props;
561
+ $[2] = ref;
562
+ $[3] = style;
563
+ } else {
564
+ props = $[1];
565
+ ref = $[2];
566
+ style = $[3];
567
+ }
568
+ const layout = useLayout("Sheet.Title");
569
+ const styles = stylesOf(useTheme());
570
+ const role = useTypeRole("titleLarge");
571
+ const T0 = Text;
572
+ const t1 = layout.titleId;
573
+ let t2;
574
+ if ($[4] !== layout.setTitle || $[5] !== ref) {
575
+ t2 = refsOf(layout.setTitle, ref);
576
+ $[4] = layout.setTitle;
577
+ $[5] = ref;
578
+ $[6] = t2;
579
+ } else t2 = $[6];
580
+ const t3 = "heading";
581
+ const t4 = composeStyles(role, styles.title, style);
582
+ let t5;
583
+ if ($[7] !== T0 || $[8] !== layout.titleId || $[9] !== props || $[10] !== t2 || $[11] !== t4) {
584
+ t5 = /* @__PURE__ */ jsx(T0, {
585
+ ...props,
586
+ nativeID: t1,
587
+ ref: t2,
588
+ role: t3,
589
+ style: t4
590
+ });
591
+ $[7] = T0;
592
+ $[8] = layout.titleId;
593
+ $[9] = props;
594
+ $[10] = t2;
595
+ $[11] = t4;
596
+ $[12] = t5;
597
+ } else t5 = $[12];
598
+ return t5;
599
+ }
600
+ /**
601
+ * The open sheet, mounted from the moment it opens until its exit has run, so
602
+ * each opening starts from its edge and at its first height.
603
+ */
604
+ function SheetWindow(t0) {
605
+ const $ = c(76);
606
+ let children;
607
+ let close;
608
+ let isDismissable;
609
+ let isKeyboardDismissDisabled;
610
+ let isOpen;
611
+ let onLayout;
612
+ let props;
613
+ let setPresent;
614
+ let slots;
615
+ let style;
616
+ let testID;
617
+ if ($[0] !== t0) {
618
+ ({children, close, isDismissable, isKeyboardDismissDisabled, isOpen, onLayout, setPresent, slots, style, testID, ...props} = t0);
619
+ $[0] = t0;
620
+ $[1] = children;
621
+ $[2] = close;
622
+ $[3] = isDismissable;
623
+ $[4] = isKeyboardDismissDisabled;
624
+ $[5] = isOpen;
625
+ $[6] = onLayout;
626
+ $[7] = props;
627
+ $[8] = setPresent;
628
+ $[9] = slots;
629
+ $[10] = style;
630
+ $[11] = testID;
631
+ } else {
632
+ children = $[1];
633
+ close = $[2];
634
+ isDismissable = $[3];
635
+ isKeyboardDismissDisabled = $[4];
636
+ isOpen = $[5];
637
+ onLayout = $[6];
638
+ props = $[7];
639
+ setPresent = $[8];
640
+ slots = $[9];
641
+ style = $[10];
642
+ testID = $[11];
643
+ }
644
+ const styles = stylesOf(useTheme());
645
+ const insets = use(SafeAreaInsetsContext) ?? NO_INSETS;
646
+ const { height } = useWindowDimensions();
647
+ const bottom = useWindowSizeClass() === "compact";
648
+ const titleId = useId();
649
+ const [title, setTitle] = useState(null);
650
+ const [full, setFull] = useState(null);
651
+ const [expanded, setExpanded] = useState(false);
652
+ let t1;
653
+ if ($[12] !== bottom || $[13] !== full || $[14] !== height || $[15] !== isDismissable) {
654
+ t1 = stopsOf(bottom, full, height, isDismissable);
655
+ $[12] = bottom;
656
+ $[13] = full;
657
+ $[14] = height;
658
+ $[15] = isDismissable;
659
+ $[16] = t1;
660
+ } else t1 = $[16];
661
+ const stops = t1;
662
+ const twoHeights = stops.partial !== null;
663
+ const rest = stops.partial !== null && !expanded ? stops.partial : 0;
664
+ let t2;
665
+ if ($[17] !== bottom || $[18] !== full || $[19] !== isOpen || $[20] !== rest || $[21] !== setPresent) {
666
+ t2 = {
667
+ bottom,
668
+ full,
669
+ isOpen,
670
+ rest,
671
+ setPresent
672
+ };
673
+ $[17] = bottom;
674
+ $[18] = full;
675
+ $[19] = isOpen;
676
+ $[20] = rest;
677
+ $[21] = setPresent;
678
+ $[22] = t2;
679
+ } else t2 = $[22];
680
+ const motion = useSheetMotion(t2);
681
+ const t3 = bottom && isOpen && stops.settles.length > 1;
682
+ let t4;
683
+ if ($[23] !== close || $[24] !== expanded || $[25] !== full || $[26] !== isDismissable || $[27] !== motion.offset || $[28] !== rest || $[29] !== stops || $[30] !== t3 || $[31] !== testID) {
684
+ t4 = {
685
+ close,
686
+ enabled: t3,
687
+ expanded,
688
+ full,
689
+ isDismissable,
690
+ offset: motion.offset,
691
+ rest,
692
+ setExpanded,
693
+ stops,
694
+ testID
695
+ };
696
+ $[23] = close;
697
+ $[24] = expanded;
698
+ $[25] = full;
699
+ $[26] = isDismissable;
700
+ $[27] = motion.offset;
701
+ $[28] = rest;
702
+ $[29] = stops;
703
+ $[30] = t3;
704
+ $[31] = testID;
705
+ $[32] = t4;
706
+ } else t4 = $[32];
707
+ const pan = useSheetDrag(t4);
708
+ let t5;
709
+ if ($[33] === Symbol.for("react.memo_cache_sentinel")) {
710
+ t5 = () => {
711
+ setExpanded(_temp);
712
+ };
713
+ $[33] = t5;
714
+ } else t5 = $[33];
715
+ const toggle = t5;
716
+ const t6 = !twoHeights || expanded;
717
+ const t7 = twoHeights ? toggle : void 0;
718
+ let t8;
719
+ if ($[34] !== bottom || $[35] !== pan || $[36] !== t6 || $[37] !== t7 || $[38] !== titleId) {
720
+ t8 = {
721
+ bottom,
722
+ expanded: t6,
723
+ pan,
724
+ setTitle,
725
+ titleId,
726
+ toggle: t7
727
+ };
728
+ $[34] = bottom;
729
+ $[35] = pan;
730
+ $[36] = t6;
731
+ $[37] = t7;
732
+ $[38] = titleId;
733
+ $[39] = t8;
734
+ } else t8 = $[39];
735
+ const layout = t8;
736
+ let t9;
737
+ if ($[40] !== onLayout) {
738
+ t9 = (event) => {
739
+ setFull(event.nativeEvent.layout.height);
740
+ onLayout?.(event);
741
+ };
742
+ $[40] = onLayout;
743
+ $[41] = t9;
744
+ } else t9 = $[41];
745
+ const measure = t9;
746
+ const labelledBy = title === null ? void 0 : titleId;
747
+ const T0 = ModalWindow;
748
+ const t10 = isDismissable && isOpen ? close : void 0;
749
+ const t11 = motion.scrim;
750
+ const T1 = GestureHandlerRootView;
751
+ const t12 = bottom ? styles.rootBottom : styles.rootSide;
752
+ const T2 = GestureDetector;
753
+ const t13 = Animated;
754
+ let t14;
755
+ if ($[42] !== labelledBy) {
756
+ t14 = panelRoleOf("dialog", labelledBy);
757
+ $[42] = labelledBy;
758
+ $[43] = t14;
759
+ } else t14 = $[43];
760
+ const t15 = isKeyboardDismissDisabled ? void 0 : close;
761
+ const t16 = composeStyles(styles.container, bottom ? styles.containerBottom : styles.containerSide, bottom ? bottomBoundsOf(insets, height) : sideInsetsOf(insets), motion.panel, style);
762
+ let t17;
763
+ if ($[44] !== children || $[45] !== slots) {
764
+ t17 = /* @__PURE__ */ jsx(ButtonSlotContext, {
765
+ value: slots,
766
+ children
767
+ });
768
+ $[44] = children;
769
+ $[45] = slots;
770
+ $[46] = t17;
771
+ } else t17 = $[46];
772
+ let t18;
773
+ if ($[47] !== layout || $[48] !== t17) {
774
+ t18 = /* @__PURE__ */ jsx(SheetLayoutContext, {
775
+ value: layout,
776
+ children: t17
777
+ });
778
+ $[47] = layout;
779
+ $[48] = t17;
780
+ $[49] = t18;
781
+ } else t18 = $[49];
782
+ let t19;
783
+ if ($[50] !== measure || $[51] !== props || $[52] !== t13.View || $[53] !== t14 || $[54] !== t15 || $[55] !== t16 || $[56] !== t18 || $[57] !== testID) {
784
+ t19 = /* @__PURE__ */ jsx(t13.View, {
785
+ ...t14,
786
+ onAccessibilityEscape: t15,
787
+ ...props,
788
+ onLayout: measure,
789
+ style: t16,
790
+ testID,
791
+ children: t18
792
+ });
793
+ $[50] = measure;
794
+ $[51] = props;
795
+ $[52] = t13.View;
796
+ $[53] = t14;
797
+ $[54] = t15;
798
+ $[55] = t16;
799
+ $[56] = t18;
800
+ $[57] = testID;
801
+ $[58] = t19;
802
+ } else t19 = $[58];
803
+ let t20;
804
+ if ($[59] !== T2 || $[60] !== pan || $[61] !== t19) {
805
+ t20 = /* @__PURE__ */ jsx(T2, {
806
+ gesture: pan,
807
+ children: t19
808
+ });
809
+ $[59] = T2;
810
+ $[60] = pan;
811
+ $[61] = t19;
812
+ $[62] = t20;
813
+ } else t20 = $[62];
814
+ let t21;
815
+ if ($[63] !== T1 || $[64] !== t12 || $[65] !== t20) {
816
+ t21 = /* @__PURE__ */ jsx(T1, {
817
+ style: t12,
818
+ children: t20
819
+ });
820
+ $[63] = T1;
821
+ $[64] = t12;
822
+ $[65] = t20;
823
+ $[66] = t21;
824
+ } else t21 = $[66];
825
+ let t22;
826
+ if ($[67] !== T0 || $[68] !== close || $[69] !== isKeyboardDismissDisabled || $[70] !== labelledBy || $[71] !== motion.scrim || $[72] !== t10 || $[73] !== t21 || $[74] !== title) {
827
+ t22 = /* @__PURE__ */ jsx(T0, {
828
+ isKeyboardDismissDisabled,
829
+ labelledBy,
830
+ onClose: close,
831
+ onScrimPress: t10,
832
+ scrim: t11,
833
+ title,
834
+ children: t21
835
+ });
836
+ $[67] = T0;
837
+ $[68] = close;
838
+ $[69] = isKeyboardDismissDisabled;
839
+ $[70] = labelledBy;
840
+ $[71] = motion.scrim;
841
+ $[72] = t10;
842
+ $[73] = t21;
843
+ $[74] = title;
844
+ $[75] = t22;
845
+ } else t22 = $[75];
846
+ return t22;
847
+ }
848
+ function _temp(was) {
849
+ return !was;
850
+ }
851
+ function sideInsetsOf(insets) {
852
+ return {
853
+ ...insetsOf(insets),
854
+ paddingStart: 0
855
+ };
856
+ }
857
+ function stopsOf(bottom, full, height, isDismissable) {
858
+ if (!bottom || full === null) return {
859
+ partial: null,
860
+ settles: [0]
861
+ };
862
+ const lower = full - height * PARTIAL;
863
+ const partial = lower > 0 ? lower : null;
864
+ return {
865
+ partial,
866
+ settles: [
867
+ 0,
868
+ ...partial === null ? [] : [partial],
869
+ ...isDismissable ? [full] : []
870
+ ]
871
+ };
872
+ }
873
+ function useLayout(part) {
874
+ const layout = use(SheetLayoutContext);
875
+ if (layout === null) throw new Error(`${part} is drawn inside Sheet.Content.`);
876
+ return layout;
877
+ }
878
+ /**
879
+ * The bottom sheet's drag. The panel follows the finger, no higher than its
880
+ * whole height and no lower than gone, or than its lowest height when it may
881
+ * not be dismissed, and once let go it settles where `settleOf` says: below
882
+ * the lowest height it closes, and at another height it moves the sheet there.
883
+ */
884
+ function useSheetDrag(t0) {
885
+ const $ = c(17);
886
+ const { close, enabled, expanded, full, isDismissable, offset, rest, setExpanded, stops, testID } = t0;
887
+ const { motion } = useTheme();
888
+ const reduceMotion = useReducedMotion();
889
+ const origin = useSharedValue(0);
890
+ let t1;
891
+ if ($[0] !== stops.settles) {
892
+ t1 = stops.settles.at(-1) ?? 0;
893
+ $[0] = stops.settles;
894
+ $[1] = t1;
895
+ } else t1 = $[1];
896
+ const lowest = t1;
897
+ const follow = function follow(translation) {
898
+ offset.set(Math.min(lowest, Math.max(0, origin.get() + translation)));
899
+ };
900
+ let t2;
901
+ if ($[2] !== close || $[3] !== expanded || $[4] !== full || $[5] !== isDismissable || $[6] !== motion || $[7] !== offset || $[8] !== reduceMotion || $[9] !== setExpanded || $[10] !== stops.partial) {
902
+ t2 = function settle(target) {
903
+ if (isDismissable && target === full) {
904
+ close();
905
+ return;
906
+ }
907
+ const higher = target === 0;
908
+ if (stops.partial !== null && higher !== expanded) {
909
+ setExpanded(higher);
910
+ return;
911
+ }
912
+ offset.set(reduceMotion ? target : withTiming(target, {
913
+ duration: motion.durationMedium1,
914
+ easing: Easing.bezier(...motion.easingEmphasizedDecelerate)
915
+ }));
916
+ };
917
+ $[2] = close;
918
+ $[3] = expanded;
919
+ $[4] = full;
920
+ $[5] = isDismissable;
921
+ $[6] = motion;
922
+ $[7] = offset;
923
+ $[8] = reduceMotion;
924
+ $[9] = setExpanded;
925
+ $[10] = stops.partial;
926
+ $[11] = t2;
927
+ } else t2 = $[11];
928
+ const settle = t2;
929
+ let t5;
930
+ if ($[12] !== offset || $[13] !== rest || $[14] !== settle || $[15] !== stops.settles) {
931
+ t5 = (t6, success) => {
932
+ const { velocityY } = t6;
933
+ settle(success ? settleOf(offset.get(), velocityY, stops.settles) : rest);
934
+ };
935
+ $[12] = offset;
936
+ $[13] = rest;
937
+ $[14] = settle;
938
+ $[15] = stops.settles;
939
+ $[16] = t5;
940
+ } else t5 = $[16];
941
+ const pan = Gesture.Pan().activeOffsetY([-8, DRAG_SLOP]).enabled(enabled).runOnJS(true).onStart((t3) => {
942
+ const { translationY } = t3;
943
+ origin.set(offset.get());
944
+ follow(translationY);
945
+ }).onUpdate((t4) => {
946
+ const { translationY: translationY_0 } = t4;
947
+ follow(translationY_0);
948
+ }).onEnd(t5);
949
+ return testID === void 0 ? pan : pan.withTestId(`${testID}-drag`);
950
+ }
951
+ /**
952
+ * The scrim's and the panel's motion, and the timer that unmounts the sheet
953
+ * once its exit has run. The bottom sheet's position is how far its panel is
954
+ * moved down, which the drag sets too; it starts below the window and rises
955
+ * to its height once that is measured. The side sheet's is how far it has
956
+ * come in from its edge, which is the end edge, and so the left one under
957
+ * right-to-left.
958
+ */
959
+ function useSheetMotion(t0) {
960
+ const $ = c(33);
961
+ const { bottom, full, isOpen, rest, setPresent } = t0;
962
+ const { motion } = useTheme();
963
+ const reduceMotion = useReducedMotion();
964
+ const { height } = useWindowDimensions();
965
+ const offset = useSharedValue(height);
966
+ const shown = useSharedValue(0);
967
+ const scrim = useSharedValue(0);
968
+ const direction = I18nManager.isRTL ? -1 : 1;
969
+ let t1;
970
+ if ($[0] !== bottom || $[1] !== full || $[2] !== height || $[3] !== isOpen || $[4] !== motion.durationMedium1 || $[5] !== motion.durationShort2 || $[6] !== motion.durationShort3 || $[7] !== motion.easingEmphasizedAccelerate || $[8] !== motion.easingEmphasizedDecelerate || $[9] !== motion.easingStandard || $[10] !== offset || $[11] !== reduceMotion || $[12] !== rest || $[13] !== scrim || $[14] !== setPresent || $[15] !== shown) {
971
+ t1 = () => {
972
+ const fade = {
973
+ duration: motion.durationShort2,
974
+ easing: Easing.bezier(...motion.easingStandard)
975
+ };
976
+ const enter = {
977
+ duration: motion.durationMedium1,
978
+ easing: Easing.bezier(...motion.easingEmphasizedDecelerate)
979
+ };
980
+ const exit = {
981
+ duration: motion.durationShort3,
982
+ easing: Easing.bezier(...motion.easingEmphasizedAccelerate)
983
+ };
984
+ if (isOpen) {
985
+ scrim.set(withTiming(1, fade));
986
+ if (!bottom) {
987
+ shown.set(reduceMotion ? 1 : withTiming(1, enter));
988
+ return;
989
+ }
990
+ if (full === null) return;
991
+ if (offset.get() > full) offset.set(full);
992
+ offset.set(reduceMotion ? rest : withTiming(rest, enter));
993
+ return;
994
+ }
995
+ scrim.set(withTiming(0, fade));
996
+ if (bottom) {
997
+ const gone = full ?? height;
998
+ offset.set(reduceMotion ? gone : withTiming(gone, exit));
999
+ } else shown.set(reduceMotion ? 0 : withTiming(0, exit));
1000
+ const timer = setTimeout(() => {
1001
+ setPresent(false);
1002
+ }, reduceMotion ? motion.durationShort2 : Math.max(motion.durationShort2, motion.durationShort3));
1003
+ return () => {
1004
+ clearTimeout(timer);
1005
+ };
1006
+ };
1007
+ $[0] = bottom;
1008
+ $[1] = full;
1009
+ $[2] = height;
1010
+ $[3] = isOpen;
1011
+ $[4] = motion.durationMedium1;
1012
+ $[5] = motion.durationShort2;
1013
+ $[6] = motion.durationShort3;
1014
+ $[7] = motion.easingEmphasizedAccelerate;
1015
+ $[8] = motion.easingEmphasizedDecelerate;
1016
+ $[9] = motion.easingStandard;
1017
+ $[10] = offset;
1018
+ $[11] = reduceMotion;
1019
+ $[12] = rest;
1020
+ $[13] = scrim;
1021
+ $[14] = setPresent;
1022
+ $[15] = shown;
1023
+ $[16] = t1;
1024
+ } else t1 = $[16];
1025
+ let t2;
1026
+ if ($[17] !== bottom || $[18] !== full || $[19] !== height || $[20] !== isOpen || $[21] !== motion || $[22] !== offset || $[23] !== reduceMotion || $[24] !== rest || $[25] !== scrim || $[26] !== setPresent || $[27] !== shown) {
1027
+ t2 = [
1028
+ bottom,
1029
+ full,
1030
+ height,
1031
+ isOpen,
1032
+ motion,
1033
+ offset,
1034
+ reduceMotion,
1035
+ rest,
1036
+ scrim,
1037
+ setPresent,
1038
+ shown
1039
+ ];
1040
+ $[17] = bottom;
1041
+ $[18] = full;
1042
+ $[19] = height;
1043
+ $[20] = isOpen;
1044
+ $[21] = motion;
1045
+ $[22] = offset;
1046
+ $[23] = reduceMotion;
1047
+ $[24] = rest;
1048
+ $[25] = scrim;
1049
+ $[26] = setPresent;
1050
+ $[27] = shown;
1051
+ $[28] = t2;
1052
+ } else t2 = $[28];
1053
+ useEffect(t1, t2);
1054
+ const t3 = useAnimatedStyle(() => {
1055
+ "worklet";
1056
+ if (bottom) return { transform: [{ translateY: offset.get() }] };
1057
+ const progress = shown.get();
1058
+ return {
1059
+ opacity: progress,
1060
+ transform: [{ translateX: (1 - progress) * SIDE_WIDTH * direction }]
1061
+ };
1062
+ });
1063
+ const t4 = useAnimatedStyle(() => {
1064
+ "worklet";
1065
+ return { opacity: scrim.get() };
1066
+ });
1067
+ let t5;
1068
+ if ($[29] !== offset || $[30] !== t3 || $[31] !== t4) {
1069
+ t5 = {
1070
+ offset,
1071
+ panel: t3,
1072
+ scrim: t4
1073
+ };
1074
+ $[29] = offset;
1075
+ $[30] = t3;
1076
+ $[31] = t4;
1077
+ $[32] = t5;
1078
+ } else t5 = $[32];
1079
+ return t5;
1080
+ }
1081
+ Sheet.Body = SheetBody;
1082
+ Sheet.Content = SheetContent;
1083
+ Sheet.Footer = SheetFooter;
1084
+ Sheet.Handle = SheetHandle;
1085
+ Sheet.Header = SheetHeader;
1086
+ Sheet.Title = SheetTitle;
1087
+ //#endregion
1088
+ export { Sheet, SheetBody, SheetContent, SheetFooter, SheetHandle, SheetHeader, SheetTitle };
1089
+
1090
+ //# sourceMappingURL=index.js.map