@ornikar/kitt-universal 31.1.0 → 31.1.2-canary.31eec21cbe0c2b92255fb1fa14d83757a05ea8b0.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.
@@ -1,4 +1,4 @@
1
- import React, { useContext, createContext, forwardRef, useMemo, cloneElement, useRef, useEffect, useState, Children, useReducer, Fragment as Fragment$1, useCallback } from 'react';
1
+ import React, { useContext, createContext, forwardRef, useMemo, cloneElement, useState, useRef, useCallback, useLayoutEffect, useEffect, Children, useReducer, Fragment as Fragment$1 } from 'react';
2
2
  import { View as View$1, ScrollView as ScrollView$1, Pressable as Pressable$1, Image as Image$1, FlatList as FlatList$1, SectionList as SectionList$1, Stack as Stack$1, VStack as VStack$1, HStack as HStack$1, Center as Center$1, useBreakpointValue as useBreakpointValue$1, useSx, Text, Input, NativeBaseProvider, extendTheme, useMediaQuery } from 'native-base';
3
3
  export { useClipboard, useContrastText, useMediaQuery, useSx, useToken } from 'native-base';
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
@@ -3633,6 +3633,79 @@ function ButtonContent({
3633
3633
  });
3634
3634
  }
3635
3635
 
3636
+ function ButtonGauge({
3637
+ duration,
3638
+ running,
3639
+ onEnded
3640
+ }) {
3641
+ const [translate, setTranslate] = useState(100);
3642
+ const startTimeRef = useRef(0);
3643
+ const pauseTimeRef = useRef(0);
3644
+ const rafRef = useRef(undefined);
3645
+ const distance = 100;
3646
+ const draw = useCallback(timestamp => {
3647
+ const timeElapsedSinceStart = timestamp - startTimeRef.current;
3648
+ // Since the time between frame is not reliable and regular, we have to
3649
+ // limit the progress to prevent overflows
3650
+ const safeProgress = Math.min(distance * timeElapsedSinceStart / duration, distance);
3651
+ setTranslate(safeProgress);
3652
+ if (safeProgress < distance) {
3653
+ if (!rafRef) return;
3654
+ rafRef.current = requestAnimationFrame(draw);
3655
+ return;
3656
+ }
3657
+ onEnded();
3658
+ if (rafRef.current) {
3659
+ cancelAnimationFrame(rafRef.current);
3660
+ }
3661
+ },
3662
+ // eslint-disable-next-line react-hooks/exhaustive-deps
3663
+ []);
3664
+ useLayoutEffect(() => {
3665
+ if (running) {
3666
+ // Resuming from pause
3667
+ if (pauseTimeRef.current > 0) {
3668
+ startTimeRef.current += global.performance.now() - pauseTimeRef.current;
3669
+ draw(global.performance.now());
3670
+ return;
3671
+ }
3672
+
3673
+ // First launch
3674
+ startTimeRef.current = global.performance.now();
3675
+ draw(startTimeRef.current);
3676
+ }
3677
+
3678
+ // On pause
3679
+ if (!running && rafRef.current) {
3680
+ pauseTimeRef.current = global.performance.now();
3681
+ cancelAnimationFrame(rafRef.current);
3682
+ }
3683
+ // eslint-disable-next-line react-hooks/exhaustive-deps
3684
+ }, [running]);
3685
+ useEffect(() => {
3686
+ return () => {
3687
+ if (rafRef.current) {
3688
+ cancelAnimationFrame(rafRef.current);
3689
+ }
3690
+ };
3691
+ }, []);
3692
+ return /*#__PURE__*/jsx(View, {
3693
+ position: "absolute",
3694
+ left: 0,
3695
+ right: 0,
3696
+ top: 0,
3697
+ bottom: 0,
3698
+ overflow: "hidden",
3699
+ alignItems: "flex-end",
3700
+ borderRadius: "kitt.button.borderRadius",
3701
+ children: /*#__PURE__*/jsx(View, {
3702
+ width: `${translate}%`,
3703
+ height: "100%",
3704
+ backgroundColor: "kitt.palettes.deepPurple['white-alpha.20']"
3705
+ })
3706
+ });
3707
+ }
3708
+
3636
3709
  function ButtonPadding({
3637
3710
  children,
3638
3711
  size,
@@ -3723,6 +3796,7 @@ const Button = /*#__PURE__*/forwardRef(({
3723
3796
  hrefAttrs,
3724
3797
  withBadge,
3725
3798
  badgeCount,
3799
+ timerAttrs,
3726
3800
  accessibilityRole = 'button',
3727
3801
  innerSpacing = 'center',
3728
3802
  isHoveredInternal,
@@ -3770,7 +3844,7 @@ const Button = /*#__PURE__*/forwardRef(({
3770
3844
  isHovered,
3771
3845
  isPressed,
3772
3846
  isFocused
3773
- }) => /*#__PURE__*/jsx(AnimatedContainer$2, {
3847
+ }) => /*#__PURE__*/jsxs(AnimatedContainer$2, {
3774
3848
  animatedStyles: animatedStyles,
3775
3849
  type: type,
3776
3850
  isHovered: isHovered || isHoveredInternal,
@@ -3780,7 +3854,9 @@ const Button = /*#__PURE__*/forwardRef(({
3780
3854
  size: size,
3781
3855
  isIconOnly: isIconOnly,
3782
3856
  isStretch: stretch,
3783
- children: /*#__PURE__*/jsxs(ButtonPadding, {
3857
+ children: [timerAttrs ? /*#__PURE__*/jsx(ButtonGauge, {
3858
+ ...timerAttrs
3859
+ }) : null, /*#__PURE__*/jsxs(ButtonPadding, {
3784
3860
  size: size,
3785
3861
  isIconOnly: isIconOnly,
3786
3862
  children: [/*#__PURE__*/jsx(ButtonContent, {
@@ -3802,7 +3878,7 @@ const Button = /*#__PURE__*/forwardRef(({
3802
3878
  isHovered: isHovered,
3803
3879
  isPressed: isPressed
3804
3880
  })]
3805
- })
3881
+ })]
3806
3882
  })
3807
3883
  });
3808
3884
  });
@@ -11686,7 +11762,7 @@ function NavigationBottomSheet({
11686
11762
  snapPoints,
11687
11763
  maxDynamicContentSize,
11688
11764
  isVisible,
11689
- isExpanded,
11765
+ isExpanded = false,
11690
11766
  onClose
11691
11767
  }) {
11692
11768
  const bottomSheetRef = useBottomSheet();
@@ -11698,7 +11774,8 @@ function NavigationBottomSheet({
11698
11774
  }
11699
11775
  }, [bottomSheetRef, isVisible]);
11700
11776
  useEffect(() => {
11701
- if (isVisible && isExpanded) {
11777
+ if (!isVisible) return;
11778
+ if (isExpanded) {
11702
11779
  bottomSheetRef.current?.expand();
11703
11780
  } else {
11704
11781
  bottomSheetRef.current?.collapse();