@vvedantb/native-ui 0.24.1 → 0.24.2

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.
@@ -1,13 +1,15 @@
1
1
  import { c as _c } from "react/compiler-runtime";
2
2
  import * as Slot from "@rn-primitives/slot";
3
- import { createContext, useContext, useRef, useState } from "react";
3
+ import { createContext, useContext, useEffect, useRef, useState } from "react";
4
4
  import { Modal, Pressable, ScrollView, StyleSheet, Text, View, useWindowDimensions } from "react-native";
5
+ import Animated, { runOnJS, useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated";
5
6
  import { useSafeAreaInsets } from "react-native-safe-area-context";
6
7
  import { IconCheck } from "@tabler/icons-react-native";
7
8
  import { FloatingSurface } from "./FloatingSurface";
8
9
  import { cn } from "./cn";
9
10
  import { sizeStyle, typeStyle } from "./controlStyles";
10
11
  import { selectionHaptic } from "./haptics";
12
+ import { PANEL_SCALE_FROM, POPOVER_ENTER, POPOVER_EXIT } from "./motion";
11
13
  import { palette } from "./palette";
12
14
  import { useLargerText } from "./theme";
13
15
  import { tokens } from "./tokens";
@@ -247,10 +249,12 @@ export function dropdownMenuPosition({
247
249
  * `Dialog` and `Sheet` (`FloatingSurface` without blur, with the floating
248
250
  * shadow) at radius 16, at least 192 wide, `p-1.5`, scrolling when taller than
249
251
  * the room. A tap outside, Android back and the VoiceOver escape gesture close
250
- * it. With Reduce Motion on, the fade is off.
252
+ * it. The panel (not the backdrop) fades in and scales from 0.96 over 150 ms
253
+ * once it is measured, from the corner nearest the trigger, and fades out in
254
+ * 100 ms. With Reduce Motion on, it appears and leaves at once.
251
255
  */
252
256
  export function DropdownMenuContent(t0) {
253
- const $ = _c(49);
257
+ const $ = _c(74);
254
258
  let children;
255
259
  let className;
256
260
  let props;
@@ -291,155 +295,280 @@ export function DropdownMenuContent(t0) {
291
295
  const insets = useSafeAreaInsets();
292
296
  const reduceMotion = useReduceMotion();
293
297
  const [contentHeight, setContentHeight] = useState(null);
298
+ const [shown, setShown] = useState(open);
299
+ if (open && !shown) {
300
+ setShown(true);
301
+ }
302
+ if (!open && shown && reduceMotion) {
303
+ setShown(false);
304
+ }
305
+ const openRef = useRef(open);
294
306
  let t2;
295
- if ($[7] !== setOpen) {
296
- t2 = () => setOpen(false);
297
- $[7] = setOpen;
307
+ let t3;
308
+ if ($[7] !== open) {
309
+ t2 = () => {
310
+ openRef.current = open;
311
+ };
312
+ t3 = [open];
313
+ $[7] = open;
298
314
  $[8] = t2;
315
+ $[9] = t3;
299
316
  } else {
300
317
  t2 = $[8];
318
+ t3 = $[9];
301
319
  }
302
- const close = t2;
303
- const t3 = contentHeight ?? 0;
320
+ useEffect(t2, t3);
321
+ const opacity = useSharedValue(reduceMotion ? 1 : 0);
322
+ const scale = useSharedValue(reduceMotion ? 1 : PANEL_SCALE_FROM);
323
+ const measured = contentHeight !== null;
304
324
  let t4;
305
- if ($[9] !== align || $[10] !== insets || $[11] !== sideOffset || $[12] !== t3 || $[13] !== trigger || $[14] !== window) {
306
- t4 = dropdownMenuPosition({
325
+ if ($[10] !== scale) {
326
+ t4 = () => {
327
+ if (openRef.current) {
328
+ return;
329
+ }
330
+ setShown(false);
331
+ setContentHeight(null);
332
+ scale.set(PANEL_SCALE_FROM);
333
+ };
334
+ $[10] = scale;
335
+ $[11] = t4;
336
+ } else {
337
+ t4 = $[11];
338
+ }
339
+ const hide = t4;
340
+ let t5;
341
+ if ($[12] !== hide || $[13] !== measured || $[14] !== opacity || $[15] !== open || $[16] !== reduceMotion || $[17] !== scale || $[18] !== shown) {
342
+ t5 = () => {
343
+ if (reduceMotion) {
344
+ opacity.set(1);
345
+ scale.set(1);
346
+ return;
347
+ }
348
+ if (open) {
349
+ if (!measured) {
350
+ return;
351
+ }
352
+ opacity.set(withTiming(1, POPOVER_ENTER));
353
+ scale.set(withTiming(1, POPOVER_ENTER));
354
+ } else {
355
+ if (shown) {
356
+ opacity.set(withTiming(0, POPOVER_EXIT, finished => {
357
+ "worklet";
358
+
359
+ if (finished) {
360
+ runOnJS(hide)();
361
+ }
362
+ }));
363
+ }
364
+ }
365
+ };
366
+ $[12] = hide;
367
+ $[13] = measured;
368
+ $[14] = opacity;
369
+ $[15] = open;
370
+ $[16] = reduceMotion;
371
+ $[17] = scale;
372
+ $[18] = shown;
373
+ $[19] = t5;
374
+ } else {
375
+ t5 = $[19];
376
+ }
377
+ let t6;
378
+ if ($[20] !== measured || $[21] !== open || $[22] !== reduceMotion) {
379
+ t6 = [open, measured, reduceMotion];
380
+ $[20] = measured;
381
+ $[21] = open;
382
+ $[22] = reduceMotion;
383
+ $[23] = t6;
384
+ } else {
385
+ t6 = $[23];
386
+ }
387
+ useEffect(t5, t6);
388
+ const panelStyle = useAnimatedStyle(() => ({
389
+ opacity: opacity.get(),
390
+ transform: [{
391
+ scale: scale.get()
392
+ }]
393
+ }));
394
+ let t7;
395
+ if ($[24] !== setOpen) {
396
+ t7 = () => setOpen(false);
397
+ $[24] = setOpen;
398
+ $[25] = t7;
399
+ } else {
400
+ t7 = $[25];
401
+ }
402
+ const close = t7;
403
+ const t8 = contentHeight ?? 0;
404
+ let t9;
405
+ if ($[26] !== align || $[27] !== insets || $[28] !== sideOffset || $[29] !== t8 || $[30] !== trigger || $[31] !== window) {
406
+ t9 = dropdownMenuPosition({
307
407
  trigger,
308
408
  window,
309
409
  insets,
310
410
  align,
311
411
  sideOffset,
312
- contentHeight: t3
412
+ contentHeight: t8
313
413
  });
314
- $[9] = align;
315
- $[10] = insets;
316
- $[11] = sideOffset;
317
- $[12] = t3;
318
- $[13] = trigger;
319
- $[14] = window;
320
- $[15] = t4;
414
+ $[26] = align;
415
+ $[27] = insets;
416
+ $[28] = sideOffset;
417
+ $[29] = t8;
418
+ $[30] = trigger;
419
+ $[31] = window;
420
+ $[32] = t9;
321
421
  } else {
322
- t4 = $[15];
422
+ t9 = $[32];
323
423
  }
324
- const position = t4;
325
- const t5 = reduceMotion ? "none" : "fade";
326
- let t6;
327
- if ($[16] === Symbol.for("react.memo_cache_sentinel")) {
328
- t6 = {
424
+ const position = t9;
425
+ const transformOrigin = `${align === "end" ? 100 : 0}% ${position.bottom === undefined ? 0 : 100}%`;
426
+ let t10;
427
+ if ($[33] === Symbol.for("react.memo_cache_sentinel")) {
428
+ t10 = {
329
429
  flex: 1
330
430
  };
331
- $[16] = t6;
431
+ $[33] = t10;
332
432
  } else {
333
- t6 = $[16];
433
+ t10 = $[33];
334
434
  }
335
- let t7;
336
- if ($[17] !== close) {
337
- t7 = <Pressable testID="DropdownMenu-backdrop" accessibilityRole="button" accessibilityLabel="Close menu" onPress={close} style={StyleSheet.absoluteFill} />;
338
- $[17] = close;
339
- $[18] = t7;
435
+ let t11;
436
+ if ($[34] !== close) {
437
+ t11 = <Pressable testID="DropdownMenu-backdrop" accessibilityRole="button" accessibilityLabel="Close menu" onPress={close} style={StyleSheet.absoluteFill} />;
438
+ $[34] = close;
439
+ $[35] = t11;
340
440
  } else {
341
- t7 = $[18];
441
+ t11 = $[35];
342
442
  }
343
- const t8 = window.width - insets.left - insets.right - 2 * DROPDOWN_MENU.edge;
344
- const t9 = contentHeight === null ? 0 : 1;
345
- let t10;
346
- if ($[19] !== position || $[20] !== t8 || $[21] !== t9) {
347
- t10 = {
443
+ const t12 = open ? "auto" : "none";
444
+ const t13 = window.width - insets.left - insets.right - 2 * DROPDOWN_MENU.edge;
445
+ const t14 = contentHeight === null ? 0 : 1;
446
+ let t15;
447
+ if ($[36] !== position || $[37] !== t13 || $[38] !== t14) {
448
+ t15 = {
348
449
  position: "absolute",
349
450
  ...position,
350
451
  minWidth: DROPDOWN_MENU.minWidth,
351
- maxWidth: t8,
352
- opacity: t9
353
- };
354
- $[19] = position;
355
- $[20] = t8;
356
- $[21] = t9;
357
- $[22] = t10;
358
- } else {
359
- t10 = $[22];
360
- }
361
- let t11;
362
- if ($[23] !== position.maxHeight) {
363
- t11 = {
364
- maxHeight: position.maxHeight
452
+ maxWidth: t13,
453
+ opacity: t14
365
454
  };
366
- $[23] = position.maxHeight;
367
- $[24] = t11;
368
- } else {
369
- t11 = $[24];
370
- }
371
- let t12;
372
- let t13;
373
- if ($[25] === Symbol.for("react.memo_cache_sentinel")) {
374
- t12 = (_width, height) => setContentHeight(height);
375
- t13 = {
376
- padding: DROPDOWN_MENU.padding
377
- };
378
- $[25] = t12;
379
- $[26] = t13;
380
- } else {
381
- t12 = $[25];
382
- t13 = $[26];
383
- }
384
- let t14;
385
- if ($[27] !== className) {
386
- t14 = cn(className);
387
- $[27] = className;
388
- $[28] = t14;
389
- } else {
390
- t14 = $[28];
391
- }
392
- let t15;
393
- if ($[29] !== children || $[30] !== props || $[31] !== style || $[32] !== t14) {
394
- t15 = <ScrollView bounces={false} showsVerticalScrollIndicator={false} onContentSizeChange={t12} contentContainerStyle={t13}><View className={t14} style={style} {...props}>{children}</View></ScrollView>;
395
- $[29] = children;
396
- $[30] = props;
397
- $[31] = style;
398
- $[32] = t14;
399
- $[33] = t15;
455
+ $[36] = position;
456
+ $[37] = t13;
457
+ $[38] = t14;
458
+ $[39] = t15;
400
459
  } else {
401
- t15 = $[33];
460
+ t15 = $[39];
402
461
  }
403
462
  let t16;
404
- if ($[34] !== t11 || $[35] !== t15) {
405
- t16 = <FloatingSurface blur={false} radius={DROPDOWN_MENU.radius} style={t11}>{t15}</FloatingSurface>;
406
- $[34] = t11;
407
- $[35] = t15;
408
- $[36] = t16;
463
+ if ($[40] !== transformOrigin) {
464
+ t16 = {
465
+ transformOrigin
466
+ };
467
+ $[40] = transformOrigin;
468
+ $[41] = t16;
409
469
  } else {
410
- t16 = $[36];
470
+ t16 = $[41];
411
471
  }
412
472
  let t17;
413
- if ($[37] !== close || $[38] !== t10 || $[39] !== t16) {
414
- t17 = <View accessibilityRole="menu" accessibilityViewIsModal={true} onAccessibilityEscape={close} style={t10}>{t16}</View>;
415
- $[37] = close;
416
- $[38] = t10;
417
- $[39] = t16;
418
- $[40] = t17;
473
+ if ($[42] !== panelStyle || $[43] !== t16) {
474
+ t17 = [t16, panelStyle];
475
+ $[42] = panelStyle;
476
+ $[43] = t16;
477
+ $[44] = t17;
419
478
  } else {
420
- t17 = $[40];
479
+ t17 = $[44];
421
480
  }
422
481
  let t18;
423
- if ($[41] !== t17 || $[42] !== t7) {
424
- t18 = <View style={t6} pointerEvents="box-none">{t7}{t17}</View>;
425
- $[41] = t17;
426
- $[42] = t7;
427
- $[43] = t18;
428
- } else {
429
- t18 = $[43];
430
- }
431
- let t19;
432
- if ($[44] !== close || $[45] !== open || $[46] !== t18 || $[47] !== t5) {
433
- t19 = <Modal visible={open} transparent={true} animationType={t5} statusBarTranslucent={true} onRequestClose={close}>{t18}</Modal>;
434
- $[44] = close;
435
- $[45] = open;
482
+ if ($[45] !== position.maxHeight) {
483
+ t18 = {
484
+ maxHeight: position.maxHeight
485
+ };
486
+ $[45] = position.maxHeight;
436
487
  $[46] = t18;
437
- $[47] = t5;
438
- $[48] = t19;
439
488
  } else {
440
- t19 = $[48];
489
+ t18 = $[46];
441
490
  }
442
- return t19;
491
+ let t19;
492
+ let t20;
493
+ if ($[47] === Symbol.for("react.memo_cache_sentinel")) {
494
+ t19 = (_width, height) => setContentHeight(height);
495
+ t20 = {
496
+ padding: DROPDOWN_MENU.padding
497
+ };
498
+ $[47] = t19;
499
+ $[48] = t20;
500
+ } else {
501
+ t19 = $[47];
502
+ t20 = $[48];
503
+ }
504
+ let t21;
505
+ if ($[49] !== className) {
506
+ t21 = cn(className);
507
+ $[49] = className;
508
+ $[50] = t21;
509
+ } else {
510
+ t21 = $[50];
511
+ }
512
+ let t22;
513
+ if ($[51] !== children || $[52] !== props || $[53] !== style || $[54] !== t21) {
514
+ t22 = <ScrollView bounces={false} showsVerticalScrollIndicator={false} onContentSizeChange={t19} contentContainerStyle={t20}><View className={t21} style={style} {...props}>{children}</View></ScrollView>;
515
+ $[51] = children;
516
+ $[52] = props;
517
+ $[53] = style;
518
+ $[54] = t21;
519
+ $[55] = t22;
520
+ } else {
521
+ t22 = $[55];
522
+ }
523
+ let t23;
524
+ if ($[56] !== t18 || $[57] !== t22) {
525
+ t23 = <FloatingSurface blur={false} radius={DROPDOWN_MENU.radius} style={t18}>{t22}</FloatingSurface>;
526
+ $[56] = t18;
527
+ $[57] = t22;
528
+ $[58] = t23;
529
+ } else {
530
+ t23 = $[58];
531
+ }
532
+ let t24;
533
+ if ($[59] !== t17 || $[60] !== t23) {
534
+ t24 = <Animated.View style={t17}>{t23}</Animated.View>;
535
+ $[59] = t17;
536
+ $[60] = t23;
537
+ $[61] = t24;
538
+ } else {
539
+ t24 = $[61];
540
+ }
541
+ let t25;
542
+ if ($[62] !== close || $[63] !== t12 || $[64] !== t15 || $[65] !== t24) {
543
+ t25 = <View accessibilityRole="menu" accessibilityViewIsModal={true} onAccessibilityEscape={close} pointerEvents={t12} style={t15}>{t24}</View>;
544
+ $[62] = close;
545
+ $[63] = t12;
546
+ $[64] = t15;
547
+ $[65] = t24;
548
+ $[66] = t25;
549
+ } else {
550
+ t25 = $[66];
551
+ }
552
+ let t26;
553
+ if ($[67] !== t11 || $[68] !== t25) {
554
+ t26 = <View style={t10} pointerEvents="box-none">{t11}{t25}</View>;
555
+ $[67] = t11;
556
+ $[68] = t25;
557
+ $[69] = t26;
558
+ } else {
559
+ t26 = $[69];
560
+ }
561
+ let t27;
562
+ if ($[70] !== close || $[71] !== shown || $[72] !== t26) {
563
+ t27 = <Modal visible={shown} transparent={true} animationType="none" statusBarTranslucent={true} onRequestClose={close}>{t26}</Modal>;
564
+ $[70] = close;
565
+ $[71] = shown;
566
+ $[72] = t26;
567
+ $[73] = t27;
568
+ } else {
569
+ t27 = $[73];
570
+ }
571
+ return t27;
443
572
  }
444
573
 
445
574
  /** 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. */