react-native-system-ui 0.0.7 → 1.0.1
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 +46 -31
- package/dist/cjs/components/action-sheet/ActionSheet.js +128 -142
- package/dist/cjs/components/action-sheet/tokens.js +16 -27
- package/dist/cjs/components/area/Area.js +57 -70
- package/dist/cjs/components/area/tokens.js +6 -3
- package/dist/cjs/components/avatar/Avatar.js +38 -36
- package/dist/cjs/components/badge/Badge.js +68 -73
- package/dist/cjs/components/badge/tokens.js +6 -8
- package/dist/cjs/components/button/Button.js +135 -176
- package/dist/cjs/components/button/ButtonGroup.js +11 -45
- package/dist/cjs/components/button/tokens.js +1 -8
- package/dist/cjs/components/calendar/Calendar.js +212 -223
- package/dist/cjs/components/calendar/tokens.js +3 -3
- package/dist/cjs/components/cascader/Cascader.js +257 -267
- package/dist/cjs/components/cascader/tokens.js +2 -2
- package/dist/cjs/components/cascader/useCascaderExtend.js +25 -29
- package/dist/cjs/components/cell/Cell.js +94 -104
- package/dist/cjs/components/cell/CellGroup.js +37 -49
- package/dist/cjs/components/checkbox/Checkbox.js +140 -132
- package/dist/cjs/components/checkbox/CheckboxGroup.js +21 -51
- package/dist/cjs/components/checkbox/tokens.js +7 -10
- package/dist/cjs/components/circle/Circle.js +87 -74
- package/dist/cjs/components/collapse/Collapse.js +88 -104
- package/dist/cjs/components/config-provider/ConfigProvider.js +17 -4
- package/dist/cjs/components/config-provider/DirectionContext.js +15 -0
- package/dist/cjs/components/config-provider/index.js +7 -0
- package/dist/cjs/components/config-provider/locale/en-US.js +32 -0
- package/dist/cjs/components/config-provider/locale/zh-CN.js +32 -0
- package/dist/cjs/components/config-provider/useDirection.js +16 -0
- package/dist/cjs/components/count-down/CountDown.js +32 -27
- package/dist/cjs/components/datetime-picker/DatetimePicker.js +80 -104
- package/dist/cjs/components/datetime-picker/tokens.js +14 -3
- package/dist/cjs/components/dialog/Dialog.js +159 -121
- package/dist/cjs/components/dialog/imperative.js +24 -43
- package/dist/cjs/components/dialog/tokens.js +1 -0
- package/dist/cjs/components/divider/Divider.js +57 -62
- package/dist/cjs/components/empty/Empty.js +53 -52
- package/dist/cjs/components/error-boundary/ErrorBoundary.js +74 -0
- package/dist/cjs/components/error-boundary/index.js +19 -0
- package/dist/cjs/components/field/Field.js +109 -106
- package/dist/cjs/components/flex/Flex.js +32 -32
- package/dist/cjs/components/flex/FlexItem.js +27 -27
- package/dist/cjs/components/form/Form.js +178 -196
- package/dist/cjs/components/form/FormItem.js +87 -109
- package/dist/cjs/components/form/FormList.js +57 -45
- package/dist/cjs/components/form/tokens.js +6 -3
- package/dist/cjs/components/form/utils.js +15 -34
- package/dist/cjs/components/grid/Grid.js +44 -43
- package/dist/cjs/components/grid/GridItem.js +92 -86
- package/dist/cjs/components/image/Image.js +76 -79
- package/dist/cjs/components/image/tokens.js +5 -3
- package/dist/cjs/components/image-preview/ImagePreview.js +125 -113
- package/dist/cjs/components/image-preview/imperative.js +4 -13
- package/dist/cjs/components/image-preview/tokens.js +3 -1
- package/dist/cjs/components/index.js +13 -0
- package/dist/cjs/components/input/Input.js +40 -35
- package/dist/cjs/components/loading/Loading.js +32 -33
- package/dist/cjs/components/nav-bar/NavBar.js +88 -100
- package/dist/cjs/components/nav-bar/tokens.js +4 -10
- package/dist/cjs/components/notice-bar/NoticeBar.js +81 -80
- package/dist/cjs/components/notice-bar/tokens.js +3 -1
- package/dist/cjs/components/notify/Notify.js +89 -84
- package/dist/cjs/components/notify/imperative.js +32 -55
- package/dist/cjs/components/notify/tokens.js +2 -11
- package/dist/cjs/components/number-keyboard/NumberKeyboard.js +277 -283
- package/dist/cjs/components/number-keyboard/tokens.js +7 -1
- package/dist/cjs/components/overlay/Overlay.js +37 -52
- package/dist/cjs/components/overlay/tokens.js +5 -3
- package/dist/cjs/components/password-input/PasswordInput.js +114 -95
- package/dist/cjs/components/picker/Picker.js +465 -454
- package/dist/cjs/components/picker/tokens.js +1 -1
- package/dist/cjs/components/popup/Popup.js +269 -299
- package/dist/cjs/components/popup/tokens.js +1 -0
- package/dist/cjs/components/portal/Portal.js +12 -30
- package/dist/cjs/components/portal/PortalHost.js +151 -234
- package/dist/cjs/components/progress/Progress.js +103 -101
- package/dist/cjs/components/progress/tokens.js +1 -0
- package/dist/cjs/components/radio/Radio.js +98 -91
- package/dist/cjs/components/radio/RadioGroup.js +13 -45
- package/dist/cjs/components/radio/tokens.js +7 -10
- package/dist/cjs/components/safe-area-view/SafeAreaView.js +22 -26
- package/dist/cjs/components/search/Search.js +65 -57
- package/dist/cjs/components/selector/Selector.js +21 -27
- package/dist/cjs/components/share-sheet/ShareSheet.js +165 -161
- package/dist/cjs/components/share-sheet/tokens.js +3 -1
- package/dist/cjs/components/sidebar/Sidebar.js +51 -51
- package/dist/cjs/components/sidebar/SidebarContext.js +1 -2
- package/dist/cjs/components/sidebar/SidebarItem.js +19 -21
- package/dist/cjs/components/sidebar/tokens.js +4 -4
- package/dist/cjs/components/skeleton/Skeleton.js +71 -77
- package/dist/cjs/components/skeleton/tokens.js +1 -2
- package/dist/cjs/components/slider/Slider.js +156 -135
- package/dist/cjs/components/space/Space.js +57 -76
- package/dist/cjs/components/space/tokens.js +7 -1
- package/dist/cjs/components/stepper/Stepper.js +182 -158
- package/dist/cjs/components/stepper/tokens.js +1 -0
- package/dist/cjs/components/swiper/Swiper.js +256 -255
- package/dist/cjs/components/swiper/SwiperPagIndicator.js +26 -27
- package/dist/cjs/components/swiper/tokens.js +10 -3
- package/dist/cjs/components/switch/Switch.js +23 -25
- package/dist/cjs/components/tabbar/Tabbar.js +48 -40
- package/dist/cjs/components/tabbar/TabbarContext.js +1 -2
- package/dist/cjs/components/tabbar/TabbarItem.js +65 -68
- package/dist/cjs/components/tabs/Tabs.js +402 -439
- package/dist/cjs/components/tabs/tokens.js +3 -1
- package/dist/cjs/components/tag/Tag.js +68 -59
- package/dist/cjs/components/toast/Toast.js +91 -90
- package/dist/cjs/components/toast/imperative.js +16 -41
- package/dist/cjs/components/toast/tokens.js +1 -0
- package/dist/cjs/components/typography/Typography.js +25 -25
- package/dist/cjs/components/water-mark/WaterMark.js +80 -78
- package/dist/cjs/design-system/Text.js +38 -0
- package/dist/cjs/design-system/ThemeProvider.js +5 -11
- package/dist/cjs/design-system/createComponentTokensHook.js +11 -13
- package/dist/cjs/design-system/index.js +7 -0
- package/dist/cjs/design-system/mergeTokensOverride.js +1 -4
- package/dist/cjs/design-system/presets.js +2 -3
- package/dist/cjs/design-system/tokens.js +2 -11
- package/dist/cjs/hooks/animation/index.js +25 -0
- package/dist/cjs/hooks/animation/useAnimatedTransition.js +72 -0
- package/dist/cjs/hooks/animation/useReducedMotion.js +75 -0
- package/dist/cjs/hooks/aria/useAriaListBox.js +8 -16
- package/dist/cjs/hooks/aria/useAriaOverlay.js +3 -3
- package/dist/cjs/hooks/aria/useAriaPress.js +8 -21
- package/dist/cjs/hooks/aria/useAriaToggle.js +3 -3
- package/dist/cjs/hooks/gesture/useGestureScroll.js +60 -61
- package/dist/cjs/hooks/index.js +12 -0
- package/dist/cjs/hooks/overlay/OverlayStackStore.js +49 -69
- package/dist/cjs/hooks/overlay/useOverlayStack.js +13 -19
- package/dist/cjs/hooks/useControllableValue.js +13 -24
- package/dist/cjs/hooks/useCountDown.js +30 -38
- package/dist/cjs/hooks/useHairline.js +17 -29
- package/dist/cjs/hooks/useSafeAreaPadding.js +1 -4
- package/dist/cjs/index.js +67 -1
- package/dist/cjs/platform/animation.js +10 -2
- package/dist/cjs/platform/measure.js +21 -37
- package/dist/cjs/utils/color.js +20 -39
- package/dist/cjs/utils/compare.js +7 -12
- package/dist/cjs/utils/createPlatformShadow.js +28 -39
- package/dist/cjs/utils/date.js +20 -50
- package/dist/cjs/utils/deepMerge.js +16 -26
- package/dist/cjs/utils/hairline.js +75 -71
- package/dist/cjs/utils/index.js +22 -0
- package/dist/cjs/utils/number.js +21 -29
- package/dist/cjs/utils/render.js +21 -0
- package/dist/cjs/utils/rtl.js +25 -0
- package/dist/cjs/utils/string.js +8 -25
- package/dist/cjs/utils/validate.js +2 -4
- package/dist/es/components/action-sheet/ActionSheet.js +130 -144
- package/dist/es/components/action-sheet/tokens.js +16 -27
- package/dist/es/components/area/Area.js +58 -71
- package/dist/es/components/area/tokens.js +6 -3
- package/dist/es/components/avatar/Avatar.js +38 -36
- package/dist/es/components/avatar/index.js +1 -2
- package/dist/es/components/badge/Badge.js +70 -75
- package/dist/es/components/badge/tokens.js +6 -8
- package/dist/es/components/button/Button.js +136 -177
- package/dist/es/components/button/ButtonGroup.js +12 -46
- package/dist/es/components/button/tokens.js +2 -3
- package/dist/es/components/calendar/Calendar.js +214 -225
- package/dist/es/components/calendar/tokens.js +3 -3
- package/dist/es/components/cascader/Cascader.js +260 -270
- package/dist/es/components/cascader/tokens.js +2 -2
- package/dist/es/components/cascader/useCascaderExtend.js +25 -29
- package/dist/es/components/cell/Cell.js +95 -105
- package/dist/es/components/cell/CellGroup.js +37 -48
- package/dist/es/components/checkbox/Checkbox.js +141 -133
- package/dist/es/components/checkbox/CheckboxGroup.js +22 -52
- package/dist/es/components/checkbox/tokens.js +7 -10
- package/dist/es/components/circle/Circle.js +87 -73
- package/dist/es/components/collapse/Collapse.js +90 -105
- package/dist/es/components/config-provider/ConfigProvider.js +11 -4
- package/dist/es/components/config-provider/DirectionContext.js +2 -0
- package/dist/es/components/config-provider/index.js +1 -0
- package/dist/es/components/config-provider/locale/en-US.js +32 -0
- package/dist/es/components/config-provider/locale/zh-CN.js +32 -0
- package/dist/es/components/config-provider/useDirection.js +3 -0
- package/dist/es/components/count-down/CountDown.js +35 -30
- package/dist/es/components/datetime-picker/DatetimePicker.js +80 -104
- package/dist/es/components/datetime-picker/tokens.js +14 -3
- package/dist/es/components/dialog/Dialog.js +160 -121
- package/dist/es/components/dialog/imperative.js +24 -43
- package/dist/es/components/dialog/tokens.js +1 -0
- package/dist/es/components/divider/Divider.js +59 -63
- package/dist/es/components/empty/Empty.js +54 -52
- package/dist/es/components/error-boundary/ErrorBoundary.js +62 -0
- package/dist/es/components/error-boundary/index.js +1 -0
- package/dist/es/components/field/Field.js +109 -106
- package/dist/es/components/flex/Flex.js +32 -31
- package/dist/es/components/flex/FlexItem.js +28 -27
- package/dist/es/components/form/Form.js +179 -197
- package/dist/es/components/form/FormItem.js +86 -107
- package/dist/es/components/form/FormList.js +57 -45
- package/dist/es/components/form/tokens.js +6 -3
- package/dist/es/components/form/utils.js +15 -34
- package/dist/es/components/grid/Grid.js +44 -42
- package/dist/es/components/grid/GridItem.js +94 -87
- package/dist/es/components/image/Image.js +79 -82
- package/dist/es/components/image/tokens.js +5 -3
- package/dist/es/components/image-preview/ImagePreview.js +125 -113
- package/dist/es/components/image-preview/imperative.js +4 -13
- package/dist/es/components/image-preview/tokens.js +3 -1
- package/dist/es/components/index.js +3 -1
- package/dist/es/components/input/Input.js +41 -36
- package/dist/es/components/loading/Loading.js +34 -34
- package/dist/es/components/nav-bar/NavBar.js +88 -100
- package/dist/es/components/nav-bar/tokens.js +4 -4
- package/dist/es/components/notice-bar/NoticeBar.js +81 -79
- package/dist/es/components/notice-bar/tokens.js +3 -1
- package/dist/es/components/notify/Notify.js +93 -87
- package/dist/es/components/notify/imperative.js +33 -56
- package/dist/es/components/notify/tokens.js +2 -5
- package/dist/es/components/number-keyboard/NumberKeyboard.js +277 -283
- package/dist/es/components/number-keyboard/tokens.js +7 -1
- package/dist/es/components/overlay/Overlay.js +36 -51
- package/dist/es/components/overlay/tokens.js +5 -3
- package/dist/es/components/password-input/PasswordInput.js +114 -95
- package/dist/es/components/picker/Picker.js +465 -454
- package/dist/es/components/picker/tokens.js +1 -1
- package/dist/es/components/popup/Popup.js +269 -298
- package/dist/es/components/popup/tokens.js +1 -0
- package/dist/es/components/portal/Portal.js +13 -30
- package/dist/es/components/portal/PortalHost.js +152 -234
- package/dist/es/components/progress/Progress.js +103 -101
- package/dist/es/components/progress/tokens.js +1 -0
- package/dist/es/components/radio/Radio.js +100 -93
- package/dist/es/components/radio/RadioGroup.js +15 -46
- package/dist/es/components/radio/tokens.js +7 -10
- package/dist/es/components/safe-area-view/SafeAreaView.js +22 -25
- package/dist/es/components/search/Search.js +66 -58
- package/dist/es/components/selector/Selector.js +21 -27
- package/dist/es/components/share-sheet/ShareSheet.js +167 -163
- package/dist/es/components/share-sheet/tokens.js +3 -1
- package/dist/es/components/sidebar/Sidebar.js +53 -53
- package/dist/es/components/sidebar/SidebarContext.js +1 -2
- package/dist/es/components/sidebar/SidebarItem.js +19 -20
- package/dist/es/components/sidebar/tokens.js +4 -4
- package/dist/es/components/skeleton/Skeleton.js +71 -77
- package/dist/es/components/skeleton/tokens.js +1 -2
- package/dist/es/components/slider/Slider.js +156 -134
- package/dist/es/components/space/Space.js +59 -78
- package/dist/es/components/space/tokens.js +7 -1
- package/dist/es/components/stepper/Stepper.js +183 -159
- package/dist/es/components/stepper/tokens.js +1 -0
- package/dist/es/components/swiper/Swiper.js +258 -257
- package/dist/es/components/swiper/SwiperPagIndicator.js +26 -27
- package/dist/es/components/swiper/tokens.js +10 -3
- package/dist/es/components/switch/Switch.js +23 -25
- package/dist/es/components/tabbar/Tabbar.js +49 -41
- package/dist/es/components/tabbar/TabbarContext.js +1 -2
- package/dist/es/components/tabbar/TabbarItem.js +66 -69
- package/dist/es/components/tabs/Tabs.js +403 -440
- package/dist/es/components/tabs/tokens.js +3 -1
- package/dist/es/components/tag/Tag.js +71 -61
- package/dist/es/components/toast/Toast.js +94 -91
- package/dist/es/components/toast/imperative.js +16 -41
- package/dist/es/components/toast/tokens.js +1 -0
- package/dist/es/components/typography/Typography.js +25 -25
- package/dist/es/components/water-mark/WaterMark.js +81 -79
- package/dist/es/design-system/Text.js +19 -0
- package/dist/es/design-system/ThemeProvider.js +5 -11
- package/dist/es/design-system/createComponentTokensHook.js +11 -13
- package/dist/es/design-system/index.js +1 -0
- package/dist/es/design-system/mergeTokensOverride.js +1 -4
- package/dist/es/design-system/presets.js +2 -3
- package/dist/es/design-system/tokens.js +1 -9
- package/dist/es/hooks/animation/index.js +2 -0
- package/dist/es/hooks/animation/useAnimatedTransition.js +53 -0
- package/dist/es/hooks/animation/useReducedMotion.js +54 -0
- package/dist/es/hooks/aria/useAriaListBox.js +8 -16
- package/dist/es/hooks/aria/useAriaOverlay.js +3 -3
- package/dist/es/hooks/aria/useAriaPress.js +8 -21
- package/dist/es/hooks/aria/useAriaToggle.js +3 -3
- package/dist/es/hooks/gesture/useGestureScroll.js +60 -61
- package/dist/es/hooks/index.js +1 -0
- package/dist/es/hooks/overlay/OverlayStackStore.js +49 -69
- package/dist/es/hooks/overlay/useOverlayStack.js +13 -19
- package/dist/es/hooks/useControllableValue.js +13 -24
- package/dist/es/hooks/useCountDown.js +30 -38
- package/dist/es/hooks/useHairline.js +16 -28
- package/dist/es/hooks/useSafeAreaPadding.js +1 -4
- package/dist/es/index.js +8 -1
- package/dist/es/platform/animation.js +9 -1
- package/dist/es/platform/measure.js +21 -37
- package/dist/es/utils/color.js +18 -35
- package/dist/es/utils/compare.js +7 -12
- package/dist/es/utils/createPlatformShadow.js +28 -39
- package/dist/es/utils/date.js +20 -50
- package/dist/es/utils/deepMerge.js +16 -26
- package/dist/es/utils/hairline.js +74 -65
- package/dist/es/utils/index.js +2 -0
- package/dist/es/utils/number.js +21 -29
- package/dist/es/utils/render.js +7 -0
- package/dist/es/utils/rtl.js +17 -0
- package/dist/es/utils/string.js +8 -25
- package/dist/es/utils/validate.js +1 -2
- package/dist/types/components/action-sheet/ActionSheet.d.ts +1 -1
- package/dist/types/components/area/Area.d.ts +1 -1
- package/dist/types/components/area/tokens.d.ts +4 -0
- package/dist/types/components/avatar/Avatar.d.ts +1 -1
- package/dist/types/components/avatar/index.d.ts +1 -2
- package/dist/types/components/badge/Badge.d.ts +1 -1
- package/dist/types/components/button/Button.d.ts +1 -1
- package/dist/types/components/button/index.d.ts +1 -1
- package/dist/types/components/calendar/Calendar.d.ts +1 -1
- package/dist/types/components/cascader/Cascader.d.ts +1 -1
- package/dist/types/components/cell/Cell.d.ts +1 -1
- package/dist/types/components/cell/CellGroup.d.ts +1 -1
- package/dist/types/components/cell/index.d.ts +2 -2
- package/dist/types/components/checkbox/Checkbox.d.ts +1 -1
- package/dist/types/components/circle/Circle.d.ts +1 -1
- package/dist/types/components/collapse/Collapse.d.ts +1 -2
- package/dist/types/components/config-provider/DirectionContext.d.ts +3 -0
- package/dist/types/components/config-provider/index.d.ts +2 -1
- package/dist/types/components/config-provider/locale/en-US.d.ts +32 -0
- package/dist/types/components/config-provider/locale/zh-CN.d.ts +32 -0
- package/dist/types/components/config-provider/useDirection.d.ts +1 -0
- package/dist/types/components/count-down/CountDown.d.ts +1 -1
- package/dist/types/components/datetime-picker/DatetimePicker.d.ts +1 -1
- package/dist/types/components/datetime-picker/tokens.d.ts +12 -0
- package/dist/types/components/dialog/Dialog.d.ts +1 -1
- package/dist/types/components/dialog/tokens.d.ts +1 -0
- package/dist/types/components/divider/Divider.d.ts +1 -1
- package/dist/types/components/empty/Empty.d.ts +1 -1
- package/dist/types/components/error-boundary/ErrorBoundary.d.ts +6 -0
- package/dist/types/components/error-boundary/index.d.ts +2 -0
- package/dist/types/components/field/Field.d.ts +1 -1
- package/dist/types/components/flex/Flex.d.ts +1 -1
- package/dist/types/components/flex/FlexItem.d.ts +1 -1
- package/dist/types/components/flex/index.d.ts +2 -2
- package/dist/types/components/form/Form.d.ts +1 -1
- package/dist/types/components/form/FormItem.d.ts +2 -1
- package/dist/types/components/form/index.d.ts +2 -2
- package/dist/types/components/form/tokens.d.ts +4 -0
- package/dist/types/components/grid/Grid.d.ts +1 -1
- package/dist/types/components/grid/GridItem.d.ts +1 -1
- package/dist/types/components/grid/index.d.ts +2 -2
- package/dist/types/components/image/Image.d.ts +1 -1
- package/dist/types/components/image-preview/ImagePreview.d.ts +1 -1
- package/dist/types/components/image-preview/tokens.d.ts +1 -0
- package/dist/types/components/index.d.ts +4 -1
- package/dist/types/components/input/Input.d.ts +3 -3
- package/dist/types/components/loading/Loading.d.ts +1 -1
- package/dist/types/components/nav-bar/NavBar.d.ts +1 -1
- package/dist/types/components/nav-bar/tokens.d.ts +1 -1
- package/dist/types/components/notice-bar/NoticeBar.d.ts +1 -1
- package/dist/types/components/notice-bar/tokens.d.ts +1 -0
- package/dist/types/components/notify/Notify.d.ts +2 -2
- package/dist/types/components/notify/index.d.ts +1 -1
- package/dist/types/components/number-keyboard/tokens.d.ts +5 -0
- package/dist/types/components/overlay/Overlay.d.ts +1 -5
- package/dist/types/components/overlay/tokens.d.ts +3 -0
- package/dist/types/components/password-input/PasswordInput.d.ts +1 -1
- package/dist/types/components/picker/Picker.d.ts +6 -6
- package/dist/types/components/popup/Popup.d.ts +3 -42
- package/dist/types/components/popup/tokens.d.ts +1 -0
- package/dist/types/components/portal/Portal.d.ts +9 -6
- package/dist/types/components/portal/PortalHost.d.ts +1 -1
- package/dist/types/components/radio/RadioGroup.d.ts +1 -1
- package/dist/types/components/safe-area-view/SafeAreaView.d.ts +1 -1
- package/dist/types/components/search/Search.d.ts +1 -1
- package/dist/types/components/share-sheet/ShareSheet.d.ts +1 -1
- package/dist/types/components/share-sheet/tokens.d.ts +1 -0
- package/dist/types/components/sidebar/Sidebar.d.ts +1 -1
- package/dist/types/components/sidebar/SidebarContext.d.ts +1 -1
- package/dist/types/components/sidebar/SidebarItem.d.ts +1 -1
- package/dist/types/components/sidebar/index.d.ts +2 -2
- package/dist/types/components/skeleton/Skeleton.d.ts +1 -1
- package/dist/types/components/slider/Slider.d.ts +1 -1
- package/dist/types/components/stepper/Stepper.d.ts +1 -1
- package/dist/types/components/stepper/tokens.d.ts +1 -0
- package/dist/types/components/swiper/Swiper.d.ts +1 -1
- package/dist/types/components/swiper/index.d.ts +1 -1
- package/dist/types/components/swiper/tokens.d.ts +8 -0
- package/dist/types/components/tabbar/Tabbar.d.ts +2 -2
- package/dist/types/components/tabbar/TabbarContext.d.ts +1 -1
- package/dist/types/components/tabbar/TabbarItem.d.ts +2 -2
- package/dist/types/components/tabs/Tabs.d.ts +1 -1
- package/dist/types/components/tabs/index.d.ts +1 -1
- package/dist/types/components/tabs/tokens.d.ts +1 -0
- package/dist/types/components/tag/Tag.d.ts +1 -1
- package/dist/types/components/toast/Toast.d.ts +2 -2
- package/dist/types/components/toast/index.d.ts +1 -1
- package/dist/types/components/toast/tokens.d.ts +1 -0
- package/dist/types/components/water-mark/WaterMark.d.ts +1 -1
- package/dist/types/design-system/Text.d.ts +3 -0
- package/dist/types/design-system/index.d.ts +1 -0
- package/dist/types/design-system/tokens.d.ts +0 -1
- package/dist/types/hooks/animation/index.d.ts +3 -0
- package/dist/types/hooks/animation/useAnimatedTransition.d.ts +13 -0
- package/dist/types/hooks/animation/useReducedMotion.d.ts +3 -0
- package/dist/types/hooks/aria/useAriaOverlay.d.ts +1 -1
- package/dist/types/hooks/gesture/useGestureScroll.d.ts +11 -10
- package/dist/types/hooks/index.d.ts +1 -0
- package/dist/types/hooks/overlay/OverlayStackStore.d.ts +8 -8
- package/dist/types/hooks/useCountDown.d.ts +1 -1
- package/dist/types/hooks/useHairline.d.ts +1 -1
- package/dist/types/index.d.ts +5 -0
- package/dist/types/platform/animation.d.ts +8 -0
- package/dist/types/platform/measure.d.ts +1 -1
- package/dist/types/utils/color.d.ts +0 -2
- package/dist/types/utils/compare.d.ts +1 -1
- package/dist/types/utils/createPlatformShadow.d.ts +2 -2
- package/dist/types/utils/date.d.ts +2 -2
- package/dist/types/utils/hairline.d.ts +5 -10
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/number.d.ts +2 -2
- package/dist/types/utils/render.d.ts +5 -0
- package/dist/types/utils/rtl.d.ts +5 -0
- package/dist/types/utils/validate.d.ts +0 -1
- package/package.json +25 -4
|
@@ -3,12 +3,7 @@ import { Platform } from 'react-native';
|
|
|
3
3
|
import { useFocus, useFocusRing } from '@react-native-aria/focus';
|
|
4
4
|
import { useHover, usePress } from '@react-native-aria/interactions';
|
|
5
5
|
import { mergeProps } from '@react-native-aria/utils';
|
|
6
|
-
const
|
|
7
|
-
if (typeof mergeProps === 'function') {
|
|
8
|
-
return mergeProps(...args);
|
|
9
|
-
}
|
|
10
|
-
return Object.assign({}, ...args);
|
|
11
|
-
};
|
|
6
|
+
const mp = (...args) => typeof mergeProps === 'function' ? mergeProps(...args) : Object.assign({}, ...args);
|
|
12
7
|
export const useAriaPress = ({
|
|
13
8
|
disabled = false,
|
|
14
9
|
allowHover = Platform.OS === 'web',
|
|
@@ -29,32 +24,24 @@ export const useAriaPress = ({
|
|
|
29
24
|
} = useHover({
|
|
30
25
|
isDisabled: disabled || !allowHover
|
|
31
26
|
});
|
|
32
|
-
const useFocusCompat = useFocus;
|
|
33
27
|
const {
|
|
34
28
|
isFocused,
|
|
35
29
|
focusProps
|
|
36
|
-
} =
|
|
30
|
+
} = useFocus({
|
|
37
31
|
isDisabled: disabled
|
|
38
32
|
});
|
|
39
|
-
const useFocusRingCompat = useFocusRing;
|
|
40
33
|
const {
|
|
41
34
|
focusProps: focusRingProps,
|
|
42
35
|
isFocusVisible
|
|
43
|
-
} =
|
|
36
|
+
} = useFocusRing({
|
|
44
37
|
isDisabled: disabled
|
|
45
38
|
});
|
|
46
39
|
const interactionProps = useMemo(() => {
|
|
47
|
-
let
|
|
48
|
-
if (allowHover)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
merged = mergePropsCompat(merged, focusProps, focusRingProps);
|
|
53
|
-
}
|
|
54
|
-
if (extraProps) {
|
|
55
|
-
merged = mergePropsCompat(merged, extraProps);
|
|
56
|
-
}
|
|
57
|
-
return merged;
|
|
40
|
+
let m = pressProps;
|
|
41
|
+
if (allowHover) m = mp(m, hoverProps);
|
|
42
|
+
if (allowFocus && !disabled) m = mp(m, focusProps, focusRingProps);
|
|
43
|
+
if (extraProps) m = mp(m, extraProps);
|
|
44
|
+
return m;
|
|
58
45
|
}, [allowFocus, allowHover, disabled, extraProps, focusProps, focusRingProps, hoverProps, pressProps]);
|
|
59
46
|
const states = useMemo(() => ({
|
|
60
47
|
hovered: !!isHovered,
|
|
@@ -2,15 +2,15 @@ import { useMemo, useRef } from 'react';
|
|
|
2
2
|
import { useToggle } from '@react-native-aria/toggle';
|
|
3
3
|
import { useToggleState } from '@react-stately/toggle';
|
|
4
4
|
export const useAriaToggle = props => {
|
|
5
|
-
const
|
|
5
|
+
const fallbackRef = useRef(null);
|
|
6
|
+
const inputRef = props.inputRef ?? fallbackRef;
|
|
6
7
|
const state = useToggleState(props);
|
|
7
8
|
const {
|
|
8
9
|
inputProps
|
|
9
10
|
} = useToggle(props, state, inputRef);
|
|
10
|
-
const resolvedInputProps = useMemo(() => inputProps, [inputProps]);
|
|
11
11
|
return {
|
|
12
12
|
state,
|
|
13
|
-
inputProps:
|
|
13
|
+
inputProps: useMemo(() => inputProps, [inputProps]),
|
|
14
14
|
inputRef
|
|
15
15
|
};
|
|
16
16
|
};
|
|
@@ -1,51 +1,52 @@
|
|
|
1
1
|
import { useCallback, useMemo, useRef, useState } from 'react';
|
|
2
2
|
import { Animated } from 'react-native';
|
|
3
|
-
const DEFAULT_THROTTLE = 16;
|
|
4
|
-
const VELOCITY_NORMALIZER = 1000;
|
|
5
3
|
export const useGestureScroll = (options = {}) => {
|
|
6
4
|
const {
|
|
7
5
|
axis = 'y',
|
|
8
|
-
scrollEventThrottle =
|
|
6
|
+
scrollEventThrottle = 16,
|
|
9
7
|
onScroll,
|
|
10
8
|
onScrollBeginDrag,
|
|
11
9
|
onScrollEndDrag,
|
|
12
10
|
onMomentumScrollBegin,
|
|
13
11
|
onMomentumScrollEnd
|
|
14
12
|
} = options;
|
|
13
|
+
const onScrollRef = useRef(onScroll);
|
|
14
|
+
onScrollRef.current = onScroll;
|
|
15
|
+
const onBeginDragRef = useRef(onScrollBeginDrag);
|
|
16
|
+
onBeginDragRef.current = onScrollBeginDrag;
|
|
17
|
+
const onEndDragRef = useRef(onScrollEndDrag);
|
|
18
|
+
onEndDragRef.current = onScrollEndDrag;
|
|
19
|
+
const onMomBeginRef = useRef(onMomentumScrollBegin);
|
|
20
|
+
onMomBeginRef.current = onMomentumScrollBegin;
|
|
21
|
+
const onMomEndRef = useRef(onMomentumScrollEnd);
|
|
22
|
+
onMomEndRef.current = onMomentumScrollEnd;
|
|
15
23
|
const scrollValue = useRef(new Animated.Value(0)).current;
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
24
|
+
const lastOffRef = useRef(0);
|
|
25
|
+
const lastTsRef = useRef(null);
|
|
26
|
+
const velRef = useRef(0);
|
|
27
|
+
const dirRef = useRef(null);
|
|
20
28
|
const [direction, setDirection] = useState(null);
|
|
21
29
|
const [isDragging, setIsDragging] = useState(false);
|
|
22
30
|
const [isMomentum, setIsMomentum] = useState(false);
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
setDirection(
|
|
31
|
+
const updateDir = useCallback(n => {
|
|
32
|
+
if (dirRef.current !== n) {
|
|
33
|
+
dirRef.current = n;
|
|
34
|
+
setDirection(n);
|
|
27
35
|
}
|
|
28
36
|
}, []);
|
|
29
|
-
const handleScroll = useCallback(
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const delta =
|
|
34
|
-
const
|
|
35
|
-
if (delta > 0)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
velocityRef.current = delta / elapsed * VELOCITY_NORMALIZER;
|
|
43
|
-
}
|
|
44
|
-
lastTimestampRef.current = timestamp;
|
|
45
|
-
lastOffsetRef.current = current;
|
|
46
|
-
}, [axis, onScroll, updateDirection]);
|
|
47
|
-
const animatedScrollHandler = useMemo(() => {
|
|
48
|
-
const mapping = axis === 'x' ? [{
|
|
37
|
+
const handleScroll = useCallback(e => {
|
|
38
|
+
onScrollRef.current?.(e);
|
|
39
|
+
const o = e.nativeEvent.contentOffset;
|
|
40
|
+
const cur = axis === 'x' ? o.x ?? 0 : o.y ?? 0;
|
|
41
|
+
const delta = cur - lastOffRef.current;
|
|
42
|
+
const ts = e.timeStamp ?? Date.now();
|
|
43
|
+
if (delta > 0) updateDir('forward');else if (delta < 0) updateDir('backward');
|
|
44
|
+
if (lastTsRef.current != null) velRef.current = delta / Math.max(ts - lastTsRef.current, 1) * 1000;
|
|
45
|
+
lastTsRef.current = ts;
|
|
46
|
+
lastOffRef.current = cur;
|
|
47
|
+
}, [axis, updateDir]);
|
|
48
|
+
const animHandler = useMemo(() => {
|
|
49
|
+
const m = axis === 'x' ? [{
|
|
49
50
|
nativeEvent: {
|
|
50
51
|
contentOffset: {
|
|
51
52
|
x: scrollValue
|
|
@@ -58,53 +59,51 @@ export const useGestureScroll = (options = {}) => {
|
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
}];
|
|
61
|
-
return Animated.event(
|
|
62
|
+
return Animated.event(m, {
|
|
62
63
|
useNativeDriver: false,
|
|
63
64
|
listener: handleScroll
|
|
64
65
|
});
|
|
65
66
|
}, [axis, handleScroll, scrollValue]);
|
|
66
|
-
const
|
|
67
|
+
const hBeginDrag = useCallback(e => {
|
|
67
68
|
setIsDragging(true);
|
|
68
|
-
|
|
69
|
-
}, [
|
|
70
|
-
const
|
|
69
|
+
onBeginDragRef.current?.(e);
|
|
70
|
+
}, []);
|
|
71
|
+
const hEndDrag = useCallback(e => {
|
|
71
72
|
setIsDragging(false);
|
|
72
|
-
|
|
73
|
-
}, [
|
|
74
|
-
const
|
|
73
|
+
onEndDragRef.current?.(e);
|
|
74
|
+
}, []);
|
|
75
|
+
const hMomBegin = useCallback(e => {
|
|
75
76
|
setIsMomentum(true);
|
|
76
|
-
|
|
77
|
-
}, [
|
|
78
|
-
const
|
|
77
|
+
onMomBeginRef.current?.(e);
|
|
78
|
+
}, []);
|
|
79
|
+
const hMomEnd = useCallback(e => {
|
|
79
80
|
setIsMomentum(false);
|
|
80
|
-
|
|
81
|
-
}, [
|
|
82
|
-
const resetOffset = useCallback((
|
|
81
|
+
onMomEndRef.current?.(e);
|
|
82
|
+
}, []);
|
|
83
|
+
const resetOffset = useCallback((v = 0) => {
|
|
83
84
|
scrollValue.stopAnimation();
|
|
84
|
-
scrollValue.setValue(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}, [scrollValue,
|
|
90
|
-
const getVelocity = useCallback(() => velocityRef.current, []);
|
|
91
|
-
const getCurrentOffset = useCallback(() => lastOffsetRef.current, []);
|
|
85
|
+
scrollValue.setValue(v);
|
|
86
|
+
lastOffRef.current = v;
|
|
87
|
+
lastTsRef.current = null;
|
|
88
|
+
velRef.current = 0;
|
|
89
|
+
updateDir(null);
|
|
90
|
+
}, [scrollValue, updateDir]);
|
|
92
91
|
const scrollProps = useMemo(() => ({
|
|
93
|
-
onScroll:
|
|
92
|
+
onScroll: animHandler,
|
|
94
93
|
scrollEventThrottle,
|
|
95
|
-
onScrollBeginDrag:
|
|
96
|
-
onScrollEndDrag:
|
|
97
|
-
onMomentumScrollBegin:
|
|
98
|
-
onMomentumScrollEnd:
|
|
99
|
-
}), [
|
|
94
|
+
onScrollBeginDrag: hBeginDrag,
|
|
95
|
+
onScrollEndDrag: hEndDrag,
|
|
96
|
+
onMomentumScrollBegin: hMomBegin,
|
|
97
|
+
onMomentumScrollEnd: hMomEnd
|
|
98
|
+
}), [animHandler, hBeginDrag, hEndDrag, hMomBegin, hMomEnd, scrollEventThrottle]);
|
|
100
99
|
return {
|
|
101
100
|
scrollValue,
|
|
102
101
|
scrollProps,
|
|
103
102
|
direction,
|
|
104
103
|
isDragging,
|
|
105
104
|
isMomentum,
|
|
106
|
-
getVelocity,
|
|
107
|
-
getCurrentOffset,
|
|
105
|
+
getVelocity: useCallback(() => velRef.current, []),
|
|
106
|
+
getCurrentOffset: useCallback(() => lastOffRef.current, []),
|
|
108
107
|
resetOffset
|
|
109
108
|
};
|
|
110
109
|
};
|
package/dist/es/hooks/index.js
CHANGED
|
@@ -1,94 +1,78 @@
|
|
|
1
1
|
import { BackHandler, Platform } from 'react-native';
|
|
2
2
|
import { setBodyScrollLocked } from '../../platform';
|
|
3
3
|
import { isNumber } from '../../utils';
|
|
4
|
-
const DEFAULT_BASE_Z_INDEX = 1000;
|
|
5
|
-
const DEFAULT_Z_INDEX_STEP = 2;
|
|
6
4
|
export class OverlayStackStore {
|
|
7
5
|
listeners = new Set();
|
|
8
6
|
entries = [];
|
|
9
7
|
keySeed = 0;
|
|
10
|
-
constructor(
|
|
11
|
-
this.
|
|
12
|
-
this.
|
|
8
|
+
constructor(baseZ = 1000, zStep = 2) {
|
|
9
|
+
this.baseZ = baseZ;
|
|
10
|
+
this.zStep = zStep;
|
|
13
11
|
}
|
|
14
|
-
subscribe =
|
|
15
|
-
this.listeners.add(
|
|
12
|
+
subscribe = l => {
|
|
13
|
+
this.listeners.add(l);
|
|
16
14
|
return () => {
|
|
17
|
-
this.listeners.delete(
|
|
15
|
+
this.listeners.delete(l);
|
|
18
16
|
};
|
|
19
17
|
};
|
|
20
18
|
getSnapshot = () => this.entries;
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
peek = () => this.entries[this.entries.length - 1];
|
|
20
|
+
size = () => this.entries.length;
|
|
21
|
+
getBaseZIndex = () => this.baseZ;
|
|
22
|
+
mount = o => {
|
|
23
23
|
const entry = {
|
|
24
|
-
key,
|
|
25
|
-
zIndex: this.
|
|
26
|
-
onClose:
|
|
27
|
-
closeOnBack:
|
|
28
|
-
lockScroll:
|
|
29
|
-
type:
|
|
30
|
-
meta:
|
|
24
|
+
key: ++this.keySeed,
|
|
25
|
+
zIndex: this.resolveZ(o.zIndex),
|
|
26
|
+
onClose: o.onClose,
|
|
27
|
+
closeOnBack: o.closeOnBack,
|
|
28
|
+
lockScroll: o.lockScroll,
|
|
29
|
+
type: o.type,
|
|
30
|
+
meta: o.meta
|
|
31
31
|
};
|
|
32
32
|
this.entries = [...this.entries, entry];
|
|
33
33
|
this.emit();
|
|
34
34
|
return entry;
|
|
35
35
|
};
|
|
36
|
-
update = (key,
|
|
37
|
-
const
|
|
38
|
-
if (
|
|
39
|
-
const prev = this.entries[index];
|
|
36
|
+
update = (key, o) => {
|
|
37
|
+
const i = this.entries.findIndex(e => e.key === key);
|
|
38
|
+
if (i === -1) return undefined;
|
|
40
39
|
const next = {
|
|
41
|
-
...
|
|
42
|
-
...
|
|
43
|
-
zIndex: isNumber(
|
|
40
|
+
...this.entries[i],
|
|
41
|
+
...o,
|
|
42
|
+
zIndex: isNumber(o.zIndex) ? this.resolveZ(o.zIndex) : this.entries[i].zIndex
|
|
44
43
|
};
|
|
45
|
-
this.entries = [...this.entries.slice(0,
|
|
44
|
+
this.entries = [...this.entries.slice(0, i), next, ...this.entries.slice(i + 1)];
|
|
46
45
|
this.emit();
|
|
47
46
|
return next;
|
|
48
47
|
};
|
|
49
48
|
unmount = key => {
|
|
50
|
-
const next = this.entries.filter(
|
|
51
|
-
if (next.length
|
|
52
|
-
|
|
49
|
+
const next = this.entries.filter(e => e.key !== key);
|
|
50
|
+
if (next.length !== this.entries.length) {
|
|
51
|
+
this.entries = next;
|
|
52
|
+
this.emit();
|
|
53
53
|
}
|
|
54
|
-
this.entries = next;
|
|
55
|
-
this.emit();
|
|
56
54
|
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
getBaseZIndex = () => this.baseZIndex;
|
|
60
|
-
resolveZIndex = provided => {
|
|
61
|
-
if (isNumber(provided)) {
|
|
62
|
-
if (!Number.isFinite(provided) || provided < 0) {
|
|
63
|
-
return this.baseZIndex;
|
|
64
|
-
}
|
|
65
|
-
return provided >= this.baseZIndex ? provided : this.baseZIndex + provided;
|
|
66
|
-
}
|
|
55
|
+
resolveZ = v => {
|
|
56
|
+
if (isNumber(v)) return !Number.isFinite(v) || v < 0 ? this.baseZ : v >= this.baseZ ? v : this.baseZ + v;
|
|
67
57
|
const top = this.peek();
|
|
68
|
-
|
|
69
|
-
return this.baseZIndex;
|
|
70
|
-
}
|
|
71
|
-
return top.zIndex + this.zIndexStep;
|
|
58
|
+
return top ? top.zIndex + this.zStep : this.baseZ;
|
|
72
59
|
};
|
|
73
60
|
emit = () => {
|
|
74
|
-
this.listeners.forEach(
|
|
75
|
-
listener();
|
|
76
|
-
});
|
|
61
|
+
this.listeners.forEach(l => l());
|
|
77
62
|
};
|
|
78
63
|
}
|
|
79
64
|
export const overlayStackStore = new OverlayStackStore();
|
|
80
|
-
let
|
|
81
|
-
const
|
|
65
|
+
let backSub = null;
|
|
66
|
+
const syncBack = () => {
|
|
82
67
|
if (Platform.OS === 'web') return;
|
|
83
68
|
const entries = overlayStackStore.getSnapshot();
|
|
84
|
-
const
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
for (let i =
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
entry.onClose();
|
|
69
|
+
const has = entries.some(e => e.closeOnBack && e.onClose);
|
|
70
|
+
if (has && !backSub && BackHandler?.addEventListener) {
|
|
71
|
+
backSub = BackHandler.addEventListener('hardwareBackPress', () => {
|
|
72
|
+
const cur = overlayStackStore.getSnapshot();
|
|
73
|
+
for (let i = cur.length - 1; i >= 0; i--) {
|
|
74
|
+
if (cur[i].closeOnBack && cur[i].onClose) {
|
|
75
|
+
cur[i].onClose();
|
|
92
76
|
return true;
|
|
93
77
|
}
|
|
94
78
|
}
|
|
@@ -96,18 +80,14 @@ const syncBackHandler = () => {
|
|
|
96
80
|
});
|
|
97
81
|
return;
|
|
98
82
|
}
|
|
99
|
-
if (!
|
|
100
|
-
|
|
101
|
-
|
|
83
|
+
if (!has && backSub) {
|
|
84
|
+
backSub.remove();
|
|
85
|
+
backSub = null;
|
|
102
86
|
}
|
|
103
87
|
};
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
setBodyScrollLocked(
|
|
107
|
-
};
|
|
108
|
-
const handleStoreChange = () => {
|
|
109
|
-
syncBackHandler();
|
|
110
|
-
syncScrollLock();
|
|
88
|
+
const onChange = () => {
|
|
89
|
+
syncBack();
|
|
90
|
+
setBodyScrollLocked(overlayStackStore.getSnapshot().some(e => e.lockScroll));
|
|
111
91
|
};
|
|
112
|
-
overlayStackStore.subscribe(
|
|
113
|
-
|
|
92
|
+
overlayStackStore.subscribe(onChange);
|
|
93
|
+
onChange();
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { useEffect, useRef, useSyncExternalStore } from 'react';
|
|
2
2
|
import { overlayStackStore } from './OverlayStackStore';
|
|
3
|
-
const
|
|
3
|
+
const useEntries = () => useSyncExternalStore(overlayStackStore.subscribe, overlayStackStore.getSnapshot, overlayStackStore.getSnapshot);
|
|
4
4
|
export const useOverlayStack = ({
|
|
5
5
|
visible,
|
|
6
6
|
...options
|
|
7
7
|
}) => {
|
|
8
|
-
const entries =
|
|
8
|
+
const entries = useEntries();
|
|
9
9
|
const entryRef = useRef(null);
|
|
10
|
-
const
|
|
11
|
-
if (
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
const stableOptions = optionsRef.current;
|
|
10
|
+
const optRef = useRef(options);
|
|
11
|
+
if (optRef.current.onClose !== options.onClose || optRef.current.closeOnBack !== options.closeOnBack || optRef.current.lockScroll !== options.lockScroll || optRef.current.zIndex !== options.zIndex || optRef.current.type !== options.type || optRef.current.meta !== options.meta) optRef.current = options;
|
|
12
|
+
const opts = optRef.current;
|
|
15
13
|
useEffect(() => {
|
|
16
14
|
if (!visible) {
|
|
17
15
|
if (entryRef.current) {
|
|
@@ -20,8 +18,7 @@ export const useOverlayStack = ({
|
|
|
20
18
|
}
|
|
21
19
|
return;
|
|
22
20
|
}
|
|
23
|
-
|
|
24
|
-
entryRef.current = entry;
|
|
21
|
+
entryRef.current = overlayStackStore.mount(opts);
|
|
25
22
|
return () => {
|
|
26
23
|
if (entryRef.current) {
|
|
27
24
|
overlayStackStore.unmount(entryRef.current.key);
|
|
@@ -30,17 +27,14 @@ export const useOverlayStack = ({
|
|
|
30
27
|
};
|
|
31
28
|
}, [visible]);
|
|
32
29
|
useEffect(() => {
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}, [stableOptions, visible]);
|
|
38
|
-
const current = entryRef.current;
|
|
39
|
-
const snapshotEntry = current ? entries.find(entry => entry.key === current.key) : undefined;
|
|
30
|
+
if (visible && entryRef.current) overlayStackStore.update(entryRef.current.key, opts);
|
|
31
|
+
}, [opts, visible]);
|
|
32
|
+
const cur = entryRef.current;
|
|
33
|
+
const snap = cur ? entries.find(e => e.key === cur.key) : undefined;
|
|
40
34
|
const top = entries[entries.length - 1];
|
|
41
35
|
return {
|
|
42
|
-
entryKey:
|
|
43
|
-
zIndex:
|
|
44
|
-
isTopMost: !!
|
|
36
|
+
entryKey: snap?.key ?? null,
|
|
37
|
+
zIndex: snap?.zIndex ?? opts.zIndex,
|
|
38
|
+
isTopMost: !!snap && !!top && top.key === snap.key
|
|
45
39
|
};
|
|
46
40
|
};
|
|
@@ -8,33 +8,22 @@ function useControllableValue(props = {}, options = {}) {
|
|
|
8
8
|
valuePropName = 'value',
|
|
9
9
|
trigger = 'onChange'
|
|
10
10
|
} = options;
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const [
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
if (hasProp(props, defaultValuePropName)) {
|
|
19
|
-
return propsRecord[defaultValuePropName];
|
|
20
|
-
}
|
|
11
|
+
const p = props;
|
|
12
|
+
const ctrl = hasProp(props, valuePropName);
|
|
13
|
+
const val = p[valuePropName];
|
|
14
|
+
const [intVal, setIntVal] = useState(() => {
|
|
15
|
+
if (ctrl) return val;
|
|
16
|
+
if (hasProp(props, defaultValuePropName)) return p[defaultValuePropName];
|
|
21
17
|
return defaultValue;
|
|
22
18
|
});
|
|
23
|
-
const
|
|
24
|
-
const handlerRef = useRef(propsRecord[trigger]);
|
|
19
|
+
const hRef = useRef(p[trigger]);
|
|
25
20
|
useEffect(() => {
|
|
26
|
-
|
|
21
|
+
hRef.current = p[trigger];
|
|
27
22
|
}, [props, trigger]);
|
|
28
|
-
const
|
|
29
|
-
if (!
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (isFunction(handler)) {
|
|
34
|
-
;
|
|
35
|
-
handler(nextValue, ...args);
|
|
36
|
-
}
|
|
37
|
-
}, [isControlled]);
|
|
38
|
-
return [mergedValue, triggerChange];
|
|
23
|
+
const setVal = useCallback((next, ...args) => {
|
|
24
|
+
if (!ctrl) setIntVal(next);
|
|
25
|
+
if (isFunction(hRef.current)) hRef.current(next, ...args);
|
|
26
|
+
}, [ctrl]);
|
|
27
|
+
return [ctrl ? val : intVal, setVal];
|
|
39
28
|
}
|
|
40
29
|
export default useControllableValue;
|
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { isNumber } from '../utils/validate';
|
|
3
3
|
const parseTime = time => {
|
|
4
|
-
const
|
|
5
|
-
const days = Math.floor(total / (24 * 60 * 60 * 1000));
|
|
6
|
-
const hours = Math.floor(total % (24 * 60 * 60 * 1000) / (60 * 60 * 1000));
|
|
7
|
-
const minutes = Math.floor(total % (60 * 60 * 1000) / (60 * 1000));
|
|
8
|
-
const seconds = Math.floor(total % (60 * 1000) / 1000);
|
|
9
|
-
const milliseconds = total % 1000;
|
|
4
|
+
const t = Math.max(time, 0);
|
|
10
5
|
return {
|
|
11
|
-
total,
|
|
12
|
-
days,
|
|
13
|
-
hours,
|
|
14
|
-
minutes,
|
|
15
|
-
seconds,
|
|
16
|
-
milliseconds
|
|
6
|
+
total: t,
|
|
7
|
+
days: Math.floor(t / 86400000),
|
|
8
|
+
hours: Math.floor(t % 86400000 / 3600000),
|
|
9
|
+
minutes: Math.floor(t % 3600000 / 60000),
|
|
10
|
+
seconds: Math.floor(t % 60000 / 1000),
|
|
11
|
+
milliseconds: t % 1000
|
|
17
12
|
};
|
|
18
13
|
};
|
|
19
14
|
const useCountDown = options => {
|
|
@@ -24,11 +19,11 @@ const useCountDown = options => {
|
|
|
24
19
|
onFinish
|
|
25
20
|
} = options;
|
|
26
21
|
const timeRef = useRef(time);
|
|
27
|
-
const
|
|
22
|
+
const msRef = useRef(millisecond);
|
|
28
23
|
const onChangeRef = useRef(onChange);
|
|
29
24
|
const onFinishRef = useRef(onFinish);
|
|
30
25
|
timeRef.current = time;
|
|
31
|
-
|
|
26
|
+
msRef.current = millisecond;
|
|
32
27
|
onChangeRef.current = onChange;
|
|
33
28
|
onFinishRef.current = onFinish;
|
|
34
29
|
const remainRef = useRef(Math.max(0, time));
|
|
@@ -36,34 +31,31 @@ const useCountDown = options => {
|
|
|
36
31
|
const timerRef = useRef(null);
|
|
37
32
|
const countingRef = useRef(false);
|
|
38
33
|
const [current, setCurrent] = useState(() => parseTime(remainRef.current));
|
|
39
|
-
const
|
|
34
|
+
const clear = useCallback(() => {
|
|
40
35
|
if (timerRef.current) {
|
|
41
36
|
clearTimeout(timerRef.current);
|
|
42
37
|
timerRef.current = null;
|
|
43
38
|
}
|
|
44
39
|
}, []);
|
|
45
|
-
const update = useCallback(
|
|
46
|
-
remainRef.current =
|
|
47
|
-
const next = parseTime(
|
|
40
|
+
const update = useCallback(rem => {
|
|
41
|
+
remainRef.current = rem;
|
|
42
|
+
const next = parseTime(rem);
|
|
48
43
|
setCurrent(next);
|
|
49
44
|
onChangeRef.current?.(next);
|
|
50
|
-
if (
|
|
45
|
+
if (rem === 0) {
|
|
51
46
|
countingRef.current = false;
|
|
52
|
-
|
|
47
|
+
clear();
|
|
53
48
|
onFinishRef.current?.();
|
|
54
49
|
}
|
|
55
|
-
}, [
|
|
50
|
+
}, [clear]);
|
|
56
51
|
const tick = useCallback(() => {
|
|
57
52
|
if (!countingRef.current) return;
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
update(
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
tick();
|
|
65
|
-
}, delay);
|
|
66
|
-
}, [clearTimer, update]);
|
|
53
|
+
clear();
|
|
54
|
+
const rem = Math.max(endTimeRef.current - Date.now(), 0);
|
|
55
|
+
update(rem);
|
|
56
|
+
if (rem <= 0) return;
|
|
57
|
+
timerRef.current = setTimeout(tick, msRef.current ? Math.max(1, Math.min(30, rem)) : Math.max(1, Math.min(rem, rem % 1000 + 1)));
|
|
58
|
+
}, [clear, update]);
|
|
67
59
|
const start = useCallback(() => {
|
|
68
60
|
if (countingRef.current || remainRef.current <= 0) return;
|
|
69
61
|
countingRef.current = true;
|
|
@@ -74,16 +66,16 @@ const useCountDown = options => {
|
|
|
74
66
|
if (!countingRef.current) return;
|
|
75
67
|
countingRef.current = false;
|
|
76
68
|
remainRef.current = Math.max(endTimeRef.current - Date.now(), 0);
|
|
77
|
-
|
|
78
|
-
}, [
|
|
79
|
-
const reset = useCallback(
|
|
69
|
+
clear();
|
|
70
|
+
}, [clear]);
|
|
71
|
+
const reset = useCallback(newT => {
|
|
80
72
|
pause();
|
|
81
|
-
const
|
|
82
|
-
remainRef.current =
|
|
83
|
-
endTimeRef.current = Date.now() +
|
|
84
|
-
setCurrent(parseTime(
|
|
73
|
+
const n = Math.max(0, isNumber(newT) ? newT : timeRef.current);
|
|
74
|
+
remainRef.current = n;
|
|
75
|
+
endTimeRef.current = Date.now() + n;
|
|
76
|
+
setCurrent(parseTime(n));
|
|
85
77
|
}, [pause]);
|
|
86
|
-
useEffect(() => () =>
|
|
78
|
+
useEffect(() => () => clear(), [clear]);
|
|
87
79
|
return {
|
|
88
80
|
start,
|
|
89
81
|
pause,
|