react-native-system-ui 0.0.6 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -30
- package/dist/cjs/components/action-sheet/ActionSheet.js +97 -105
- package/dist/cjs/components/action-sheet/tokens.js +16 -27
- package/dist/cjs/components/area/Area.js +54 -67
- package/dist/cjs/components/area/tokens.js +6 -3
- package/dist/cjs/components/avatar/Avatar.js +25 -23
- package/dist/cjs/components/badge/Badge.js +31 -31
- package/dist/cjs/components/badge/tokens.js +6 -8
- package/dist/cjs/components/button/Button.js +115 -151
- package/dist/cjs/components/button/ButtonGroup.js +8 -42
- 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 +177 -180
- 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 +70 -83
- package/dist/cjs/components/cell/CellGroup.js +16 -29
- package/dist/cjs/components/checkbox/Checkbox.js +139 -132
- package/dist/cjs/components/checkbox/CheckboxGroup.js +4 -35
- package/dist/cjs/components/checkbox/tokens.js +7 -10
- package/dist/cjs/components/circle/Circle.js +25 -24
- package/dist/cjs/components/collapse/Collapse.js +75 -91
- package/dist/cjs/components/config-provider/ConfigProvider.js +16 -3
- 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 +20 -15
- package/dist/cjs/components/datetime-picker/DatetimePicker.js +61 -84
- package/dist/cjs/components/datetime-picker/tokens.js +14 -3
- package/dist/cjs/components/dialog/Dialog.js +153 -121
- package/dist/cjs/components/dialog/imperative.js +17 -30
- package/dist/cjs/components/divider/Divider.js +26 -28
- package/dist/cjs/components/empty/Empty.js +35 -39
- package/dist/cjs/components/error-boundary/ErrorBoundary.js +73 -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 +18 -18
- package/dist/cjs/components/flex/FlexItem.js +26 -27
- package/dist/cjs/components/form/Form.js +142 -161
- package/dist/cjs/components/form/FormItem.js +69 -97
- package/dist/cjs/components/form/FormList.js +49 -37
- 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 +30 -29
- package/dist/cjs/components/grid/GridItem.js +84 -85
- package/dist/cjs/components/image/Image.js +55 -59
- package/dist/cjs/components/image/tokens.js +2 -2
- package/dist/cjs/components/image-preview/ImagePreview.js +124 -112
- package/dist/cjs/components/image-preview/imperative.js +4 -13
- package/dist/cjs/components/index.js +13 -0
- package/dist/cjs/components/input/Input.js +30 -22
- package/dist/cjs/components/loading/Loading.js +14 -15
- package/dist/cjs/components/nav-bar/NavBar.js +68 -83
- package/dist/cjs/components/nav-bar/tokens.js +1 -9
- package/dist/cjs/components/notice-bar/NoticeBar.js +74 -77
- package/dist/cjs/components/notify/Notify.js +88 -84
- package/dist/cjs/components/notify/imperative.js +20 -43
- package/dist/cjs/components/notify/tokens.js +1 -11
- package/dist/cjs/components/number-keyboard/NumberKeyboard.js +187 -209
- 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 +98 -79
- package/dist/cjs/components/picker/Picker.js +440 -421
- package/dist/cjs/components/picker/tokens.js +1 -1
- package/dist/cjs/components/popup/Popup.js +263 -293
- package/dist/cjs/components/portal/Portal.js +12 -29
- package/dist/cjs/components/portal/PortalHost.js +151 -234
- package/dist/cjs/components/progress/Progress.js +51 -48
- package/dist/cjs/components/radio/Radio.js +45 -42
- package/dist/cjs/components/radio/RadioGroup.js +8 -40
- 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 +51 -43
- package/dist/cjs/components/selector/Selector.js +14 -13
- package/dist/cjs/components/share-sheet/ShareSheet.js +160 -161
- package/dist/cjs/components/sidebar/Sidebar.js +39 -45
- package/dist/cjs/components/sidebar/SidebarContext.js +1 -2
- package/dist/cjs/components/sidebar/SidebarItem.js +13 -16
- package/dist/cjs/components/sidebar/tokens.js +1 -3
- package/dist/cjs/components/skeleton/Skeleton.js +30 -37
- 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 +46 -69
- package/dist/cjs/components/stepper/Stepper.js +177 -155
- package/dist/cjs/components/swiper/Swiper.js +251 -253
- package/dist/cjs/components/swiper/SwiperPagIndicator.js +25 -27
- package/dist/cjs/components/swiper/tokens.js +10 -3
- package/dist/cjs/components/switch/Switch.js +13 -15
- package/dist/cjs/components/tabbar/Tabbar.js +35 -27
- 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 +286 -313
- package/dist/cjs/components/tag/Tag.js +46 -37
- package/dist/cjs/components/toast/Toast.js +90 -90
- package/dist/cjs/components/toast/imperative.js +16 -41
- package/dist/cjs/components/typography/Typography.js +3 -5
- package/dist/cjs/components/water-mark/WaterMark.js +31 -29
- package/dist/cjs/design-system/ThemeProvider.js +5 -11
- package/dist/cjs/design-system/createComponentTokensHook.js +11 -13
- 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 +10 -21
- package/dist/cjs/hooks/useCountDown.js +14 -22
- 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 +18 -36
- package/dist/cjs/utils/color.js +21 -35
- 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 +74 -71
- package/dist/cjs/utils/index.js +22 -0
- package/dist/cjs/utils/number.js +21 -29
- package/dist/cjs/utils/render.js +27 -0
- package/dist/cjs/utils/rtl.js +25 -0
- package/dist/cjs/utils/string.js +8 -25
- package/dist/es/components/action-sheet/ActionSheet.js +99 -107
- package/dist/es/components/action-sheet/tokens.js +16 -27
- package/dist/es/components/area/Area.js +55 -68
- package/dist/es/components/area/tokens.js +6 -3
- package/dist/es/components/avatar/Avatar.js +25 -23
- package/dist/es/components/avatar/index.js +1 -2
- package/dist/es/components/badge/Badge.js +33 -33
- package/dist/es/components/badge/tokens.js +6 -8
- package/dist/es/components/button/Button.js +116 -152
- package/dist/es/components/button/ButtonGroup.js +9 -43
- 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 +180 -183
- 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 +71 -84
- package/dist/es/components/cell/CellGroup.js +16 -28
- package/dist/es/components/checkbox/Checkbox.js +140 -133
- package/dist/es/components/checkbox/CheckboxGroup.js +5 -36
- package/dist/es/components/checkbox/tokens.js +7 -10
- package/dist/es/components/circle/Circle.js +25 -23
- package/dist/es/components/collapse/Collapse.js +77 -92
- package/dist/es/components/config-provider/ConfigProvider.js +10 -3
- 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 +23 -18
- package/dist/es/components/datetime-picker/DatetimePicker.js +61 -84
- package/dist/es/components/datetime-picker/tokens.js +14 -3
- package/dist/es/components/dialog/Dialog.js +154 -121
- package/dist/es/components/dialog/imperative.js +17 -30
- package/dist/es/components/divider/Divider.js +28 -29
- package/dist/es/components/empty/Empty.js +36 -39
- package/dist/es/components/error-boundary/ErrorBoundary.js +61 -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 +18 -17
- package/dist/es/components/flex/FlexItem.js +27 -27
- package/dist/es/components/form/Form.js +143 -162
- package/dist/es/components/form/FormItem.js +68 -95
- package/dist/es/components/form/FormList.js +49 -37
- 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 +30 -28
- package/dist/es/components/grid/GridItem.js +84 -84
- package/dist/es/components/image/Image.js +58 -62
- package/dist/es/components/image/tokens.js +2 -2
- package/dist/es/components/image-preview/ImagePreview.js +124 -112
- package/dist/es/components/image-preview/imperative.js +4 -13
- package/dist/es/components/index.js +3 -1
- package/dist/es/components/input/Input.js +31 -23
- package/dist/es/components/loading/Loading.js +16 -16
- package/dist/es/components/nav-bar/NavBar.js +68 -83
- package/dist/es/components/nav-bar/tokens.js +1 -3
- package/dist/es/components/notice-bar/NoticeBar.js +74 -76
- package/dist/es/components/notify/Notify.js +92 -87
- package/dist/es/components/notify/imperative.js +21 -44
- package/dist/es/components/notify/tokens.js +1 -5
- package/dist/es/components/number-keyboard/NumberKeyboard.js +187 -209
- 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 +98 -79
- package/dist/es/components/picker/Picker.js +440 -421
- package/dist/es/components/picker/tokens.js +1 -1
- package/dist/es/components/popup/Popup.js +263 -292
- package/dist/es/components/portal/Portal.js +13 -29
- package/dist/es/components/portal/PortalHost.js +152 -234
- package/dist/es/components/progress/Progress.js +51 -48
- package/dist/es/components/radio/Radio.js +47 -44
- package/dist/es/components/radio/RadioGroup.js +10 -41
- 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 +52 -44
- package/dist/es/components/selector/Selector.js +14 -13
- package/dist/es/components/share-sheet/ShareSheet.js +162 -163
- package/dist/es/components/sidebar/Sidebar.js +41 -47
- package/dist/es/components/sidebar/SidebarContext.js +1 -2
- package/dist/es/components/sidebar/SidebarItem.js +13 -15
- package/dist/es/components/sidebar/tokens.js +1 -3
- package/dist/es/components/skeleton/Skeleton.js +30 -37
- 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 +48 -71
- package/dist/es/components/stepper/Stepper.js +178 -156
- package/dist/es/components/swiper/Swiper.js +252 -254
- package/dist/es/components/swiper/SwiperPagIndicator.js +25 -27
- package/dist/es/components/swiper/tokens.js +10 -3
- package/dist/es/components/switch/Switch.js +13 -15
- package/dist/es/components/tabbar/Tabbar.js +36 -28
- 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 +286 -313
- package/dist/es/components/tag/Tag.js +49 -39
- package/dist/es/components/toast/Toast.js +93 -91
- package/dist/es/components/toast/imperative.js +16 -41
- package/dist/es/components/typography/Typography.js +3 -5
- package/dist/es/components/water-mark/WaterMark.js +32 -30
- package/dist/es/design-system/ThemeProvider.js +5 -11
- package/dist/es/design-system/createComponentTokensHook.js +11 -13
- 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 +10 -21
- package/dist/es/hooks/useCountDown.js +14 -22
- 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 +18 -36
- package/dist/es/utils/color.js +21 -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 +73 -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/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/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/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/notice-bar/NoticeBar.d.ts +1 -1
- package/dist/types/components/notify/Notify.d.ts +2 -2
- package/dist/types/components/notify/index.d.ts +1 -1
- 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 +5 -5
- package/dist/types/components/popup/Popup.d.ts +3 -42
- 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/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/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/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/water-mark/WaterMark.d.ts +1 -1
- 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/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/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/package.json +10 -3
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
-
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { Image, Text, View, useWindowDimensions } from 'react-native';
|
|
4
4
|
import { isFiniteNumber, isString } from '../../utils';
|
|
5
5
|
import { useWaterMarkTokens } from './tokens';
|
|
6
|
-
const
|
|
6
|
+
const resolveFiniteNumber = (value, fallback) => isFiniteNumber(value) ? value : fallback;
|
|
7
|
+
const resolveNonNegativeNumber = (value, fallback) => Math.max(0, resolveFiniteNumber(value, fallback));
|
|
8
|
+
const resolvePositiveNumber = (value, fallback) => Math.max(1, resolveFiniteNumber(value, fallback));
|
|
9
|
+
const WaterMarkImpl = props => {
|
|
7
10
|
const {
|
|
8
11
|
content: contentProp,
|
|
9
12
|
width,
|
|
@@ -25,9 +28,6 @@ const WaterMark = props => {
|
|
|
25
28
|
...rest
|
|
26
29
|
} = props;
|
|
27
30
|
const tokens = useWaterMarkTokens(tokensOverride);
|
|
28
|
-
const resolveFiniteNumber = (value, fallback) => isFiniteNumber(value) ? value : fallback;
|
|
29
|
-
const resolveNonNegativeNumber = (value, fallback) => Math.max(0, resolveFiniteNumber(value, fallback));
|
|
30
|
-
const resolvePositiveNumber = (value, fallback) => Math.max(1, resolveFiniteNumber(value, fallback));
|
|
31
31
|
const content = contentProp ?? tokens.defaults.content;
|
|
32
32
|
const zIndex = resolveFiniteNumber(zIndexProp, tokens.defaults.zIndex);
|
|
33
33
|
const fullPage = fullPageProp ?? tokens.defaults.fullPage;
|
|
@@ -45,9 +45,8 @@ const WaterMark = props => {
|
|
|
45
45
|
const resolvedGapY = resolveNonNegativeNumber(gapY, tokens.defaults.gapY);
|
|
46
46
|
const resolvedRotate = resolveFiniteNumber(rotate, tokens.defaults.rotate);
|
|
47
47
|
const resolvedOpacity = Math.max(0, Math.min(1, resolveFiniteNumber(opacity, tokens.defaults.opacity)));
|
|
48
|
-
const fontSizeFromFont = isFiniteNumber(font?.size) ? font
|
|
49
|
-
const
|
|
50
|
-
const normalizedFontSize = Math.max(0, resolvedFontSize);
|
|
48
|
+
const fontSizeFromFont = isFiniteNumber(font?.size) ? font.size : isString(font?.size) ? Number.parseFloat(font.size) : undefined;
|
|
49
|
+
const normalizedFontSize = Math.max(0, resolveFiniteNumber((Number.isFinite(fontSizeFromFont ?? Number.NaN) ? fontSizeFromFont : undefined) ?? fontSize, tokens.defaults.fontSize));
|
|
51
50
|
const resolvedColor = font?.color ?? color ?? tokens.colors.mark;
|
|
52
51
|
const markWidth = resolvePositiveNumber(image?.width ?? width, tokens.defaults.width);
|
|
53
52
|
const markHeight = resolvePositiveNumber(image?.height ?? height, tokens.defaults.height);
|
|
@@ -55,15 +54,17 @@ const WaterMark = props => {
|
|
|
55
54
|
const cellHeight = Math.max(1, markHeight + resolvedGapY);
|
|
56
55
|
const rows = size.height ? Math.ceil(size.height / cellHeight) + 1 : 1;
|
|
57
56
|
const cols = size.width ? Math.ceil(size.width / cellWidth) + 1 : 1;
|
|
58
|
-
const
|
|
57
|
+
const onLayoutCalculatedRef = useRef(onLayoutCalculated);
|
|
58
|
+
onLayoutCalculatedRef.current = onLayoutCalculated;
|
|
59
|
+
const handleLayout = useCallback(event => {
|
|
59
60
|
if (fullPage) return;
|
|
60
61
|
const {
|
|
61
62
|
width,
|
|
62
63
|
height
|
|
63
64
|
} = event.nativeEvent.layout;
|
|
64
65
|
if (!isFiniteNumber(width) || !isFiniteNumber(height)) return;
|
|
65
|
-
const nextWidth = Math.max(0, width)
|
|
66
|
-
|
|
66
|
+
const nextWidth = Math.max(0, width),
|
|
67
|
+
nextHeight = Math.max(0, height);
|
|
67
68
|
if (lastLayoutRef.current.width === nextWidth && lastLayoutRef.current.height === nextHeight) return;
|
|
68
69
|
lastLayoutRef.current = {
|
|
69
70
|
width: nextWidth,
|
|
@@ -73,49 +74,47 @@ const WaterMark = props => {
|
|
|
73
74
|
width: nextWidth,
|
|
74
75
|
height: nextHeight
|
|
75
76
|
});
|
|
76
|
-
|
|
77
|
+
onLayoutCalculatedRef.current?.({
|
|
77
78
|
width: nextWidth,
|
|
78
79
|
height: nextHeight
|
|
79
80
|
});
|
|
80
|
-
};
|
|
81
|
+
}, [fullPage]);
|
|
81
82
|
useEffect(() => {
|
|
82
|
-
if (!fullPage) return;
|
|
83
|
-
|
|
84
|
-
if (window.width <= 0 || window.height <= 0) return;
|
|
85
|
-
onLayoutCalculated?.({
|
|
83
|
+
if (!fullPage || !isFiniteNumber(window.width) || !isFiniteNumber(window.height) || window.width <= 0 || window.height <= 0) return;
|
|
84
|
+
onLayoutCalculatedRef.current?.({
|
|
86
85
|
width: window.width,
|
|
87
86
|
height: window.height
|
|
88
87
|
});
|
|
89
|
-
}, [fullPage,
|
|
90
|
-
const zIndexStyle = {
|
|
88
|
+
}, [fullPage, window.width, window.height]);
|
|
89
|
+
const zIndexStyle = useMemo(() => ({
|
|
91
90
|
zIndex
|
|
92
|
-
};
|
|
93
|
-
const cellStyle = {
|
|
91
|
+
}), [zIndex]);
|
|
92
|
+
const cellStyle = useMemo(() => ({
|
|
94
93
|
width: cellWidth,
|
|
95
94
|
height: cellHeight
|
|
96
|
-
};
|
|
97
|
-
const oddRowStyle = {
|
|
95
|
+
}), [cellWidth, cellHeight]);
|
|
96
|
+
const oddRowStyle = useMemo(() => ({
|
|
98
97
|
paddingLeft: cellWidth / 2
|
|
99
|
-
};
|
|
100
|
-
const markStyle = {
|
|
98
|
+
}), [cellWidth]);
|
|
99
|
+
const markStyle = useMemo(() => ({
|
|
101
100
|
width: markWidth,
|
|
102
101
|
height: markHeight,
|
|
103
102
|
transform: [{
|
|
104
103
|
rotate: `${resolvedRotate}deg`
|
|
105
104
|
}]
|
|
106
|
-
};
|
|
107
|
-
const imageStyle = {
|
|
105
|
+
}), [markWidth, markHeight, resolvedRotate]);
|
|
106
|
+
const imageStyle = useMemo(() => ({
|
|
108
107
|
width: markWidth,
|
|
109
108
|
height: markHeight,
|
|
110
109
|
opacity: resolvedOpacity
|
|
111
|
-
};
|
|
112
|
-
const textBaseStyle = {
|
|
110
|
+
}), [markWidth, markHeight, resolvedOpacity]);
|
|
111
|
+
const textBaseStyle = useMemo(() => ({
|
|
113
112
|
fontSize: normalizedFontSize,
|
|
114
113
|
color: resolvedColor,
|
|
115
114
|
opacity: resolvedOpacity,
|
|
116
115
|
fontFamily: font?.family,
|
|
117
116
|
fontWeight: font?.weight
|
|
118
|
-
};
|
|
117
|
+
}), [normalizedFontSize, resolvedColor, resolvedOpacity, font?.family, font?.weight]);
|
|
119
118
|
const rowIndexes = Array.from({
|
|
120
119
|
length: rows
|
|
121
120
|
}, (_, i) => i);
|
|
@@ -124,6 +123,8 @@ const WaterMark = props => {
|
|
|
124
123
|
}, (_, i) => i);
|
|
125
124
|
return /*#__PURE__*/React.createElement(View, _extends({
|
|
126
125
|
pointerEvents: "none",
|
|
126
|
+
importantForAccessibility: "no-hide-descendants",
|
|
127
|
+
accessibilityElementsHidden: true,
|
|
127
128
|
style: [fullPage ? tokens.layout.absoluteFill : null, zIndexStyle, style],
|
|
128
129
|
onLayout: handleLayout
|
|
129
130
|
}, rest), /*#__PURE__*/React.createElement(View, {
|
|
@@ -147,5 +148,6 @@ const WaterMark = props => {
|
|
|
147
148
|
style: [textBaseStyle, textStyle]
|
|
148
149
|
}, content))))))));
|
|
149
150
|
};
|
|
151
|
+
const WaterMark = /*#__PURE__*/React.memo(WaterMarkImpl);
|
|
150
152
|
WaterMark.displayName = 'WaterMark';
|
|
151
153
|
export default WaterMark;
|
|
@@ -2,21 +2,15 @@ import React, { useMemo } from 'react';
|
|
|
2
2
|
import { ThemeContext } from './ThemeContext';
|
|
3
3
|
import { createTokens } from './tokens';
|
|
4
4
|
import { isObject } from '../utils/validate';
|
|
5
|
-
const
|
|
6
|
-
return Boolean(isObject(value) && 'palette' in value && 'spacing' in value);
|
|
7
|
-
};
|
|
5
|
+
const isTokens = v => Boolean(isObject(v) && 'palette' in v && 'spacing' in v);
|
|
8
6
|
export const ThemeProvider = ({
|
|
9
7
|
value,
|
|
10
8
|
children
|
|
11
9
|
}) => {
|
|
12
|
-
const resolved = useMemo(() => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
foundations,
|
|
17
|
-
components
|
|
18
|
-
};
|
|
19
|
-
}, [value]);
|
|
10
|
+
const resolved = useMemo(() => ({
|
|
11
|
+
foundations: isTokens(value) ? value : createTokens(value?.foundations),
|
|
12
|
+
components: isTokens(value) ? undefined : value?.components
|
|
13
|
+
}), [value]);
|
|
20
14
|
return /*#__PURE__*/React.createElement(ThemeContext.Provider, {
|
|
21
15
|
value: resolved
|
|
22
16
|
}, children);
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
2
|
import { deepMerge } from '../utils/deepMerge';
|
|
3
3
|
import { useTheme } from './useTheme';
|
|
4
|
-
export const createComponentTokensHook = (key, createBaseTokens) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}, [componentOverrides, foundations, overrides]);
|
|
16
|
-
};
|
|
4
|
+
export const createComponentTokensHook = (key, createBaseTokens) => overrides => {
|
|
5
|
+
const {
|
|
6
|
+
foundations,
|
|
7
|
+
components
|
|
8
|
+
} = useTheme();
|
|
9
|
+
const co = components?.[key];
|
|
10
|
+
return useMemo(() => {
|
|
11
|
+
const base = createBaseTokens(foundations);
|
|
12
|
+
const merged = co && overrides ? deepMerge(co, overrides) : co ?? overrides;
|
|
13
|
+
return merged ? deepMerge(base, merged) : base;
|
|
14
|
+
}, [co, foundations, overrides]);
|
|
17
15
|
};
|
|
@@ -131,10 +131,9 @@ const auroraOverrides = {
|
|
|
131
131
|
lineHeightMultiplier: 1.25
|
|
132
132
|
}
|
|
133
133
|
};
|
|
134
|
-
const buildPreset = overrides => createTokens(overrides);
|
|
135
134
|
export const themePresets = {
|
|
136
135
|
light: defaultTokens,
|
|
137
|
-
dark:
|
|
138
|
-
aurora:
|
|
136
|
+
dark: createTokens(darkOverrides),
|
|
137
|
+
aurora: createTokens(auroraOverrides)
|
|
139
138
|
};
|
|
140
139
|
export const getThemePreset = name => themePresets[name];
|
|
@@ -124,13 +124,5 @@ export const defaultFoundations = {
|
|
|
124
124
|
pressed: 0.85
|
|
125
125
|
}
|
|
126
126
|
};
|
|
127
|
-
export const
|
|
128
|
-
if (!overrides) {
|
|
129
|
-
return defaultFoundations;
|
|
130
|
-
}
|
|
131
|
-
return deepMerge(defaultFoundations, overrides);
|
|
132
|
-
};
|
|
133
|
-
export const createTokens = overrides => {
|
|
134
|
-
return buildFoundations(overrides);
|
|
135
|
-
};
|
|
127
|
+
export const createTokens = overrides => overrides ? deepMerge(defaultFoundations, overrides) : defaultFoundations;
|
|
136
128
|
export const defaultTokens = defaultFoundations;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { Animated, Easing } from 'react-native';
|
|
3
|
+
import { nativeDriverEnabled } from '../../platform';
|
|
4
|
+
import { useReducedMotion } from './useReducedMotion';
|
|
5
|
+
const EASE_OUT = Easing.bezier(0.075, 0.82, 0.165, 1.0);
|
|
6
|
+
const EASE_IN = Easing.bezier(0.55, 0.055, 0.675, 0.19);
|
|
7
|
+
export const useAnimatedTransition = ({
|
|
8
|
+
visible,
|
|
9
|
+
duration = 300,
|
|
10
|
+
enterEasing = EASE_OUT,
|
|
11
|
+
exitEasing = EASE_IN,
|
|
12
|
+
useNativeDriver: driver = nativeDriverEnabled
|
|
13
|
+
}) => {
|
|
14
|
+
const reduceMotion = useReducedMotion();
|
|
15
|
+
const [mounted, setMounted] = useState(visible);
|
|
16
|
+
const progress = useRef(new Animated.Value(visible ? 1 : 0)).current;
|
|
17
|
+
const animRef = useRef(null);
|
|
18
|
+
const seqRef = useRef(0);
|
|
19
|
+
const run = useCallback((show, dur, easeIn, easeOut, nd) => {
|
|
20
|
+
seqRef.current += 1;
|
|
21
|
+
const seq = seqRef.current;
|
|
22
|
+
animRef.current?.stop();
|
|
23
|
+
if (show) setMounted(true);
|
|
24
|
+
if (dur <= 0) {
|
|
25
|
+
progress.setValue(show ? 1 : 0);
|
|
26
|
+
if (!show) setMounted(false);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const anim = Animated.timing(progress, {
|
|
30
|
+
toValue: show ? 1 : 0,
|
|
31
|
+
duration: dur,
|
|
32
|
+
easing: show ? easeIn : easeOut,
|
|
33
|
+
useNativeDriver: nd,
|
|
34
|
+
isInteraction: false
|
|
35
|
+
});
|
|
36
|
+
animRef.current = anim;
|
|
37
|
+
anim.start(({
|
|
38
|
+
finished
|
|
39
|
+
}) => {
|
|
40
|
+
if (finished && seq === seqRef.current && !show) setMounted(false);
|
|
41
|
+
});
|
|
42
|
+
}, [progress]);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
run(visible, reduceMotion ? 0 : duration, enterEasing, exitEasing, driver);
|
|
45
|
+
}, [visible, reduceMotion, duration, enterEasing, exitEasing, driver, run]);
|
|
46
|
+
useEffect(() => () => {
|
|
47
|
+
animRef.current?.stop();
|
|
48
|
+
}, []);
|
|
49
|
+
return {
|
|
50
|
+
mounted,
|
|
51
|
+
progress
|
|
52
|
+
};
|
|
53
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { AccessibilityInfo, Platform } from 'react-native';
|
|
3
|
+
let _reduced = false;
|
|
4
|
+
let _inited = false;
|
|
5
|
+
const _subs = new Set();
|
|
6
|
+
const set = v => {
|
|
7
|
+
if (v === _reduced) return;
|
|
8
|
+
_reduced = v;
|
|
9
|
+
_subs.forEach(fn => fn(v));
|
|
10
|
+
};
|
|
11
|
+
const init = () => {
|
|
12
|
+
if (_inited) return;
|
|
13
|
+
_inited = true;
|
|
14
|
+
if (Platform.OS === 'web') {
|
|
15
|
+
if (typeof window !== 'undefined' && typeof window.matchMedia === 'function') {
|
|
16
|
+
try {
|
|
17
|
+
const mql = window.matchMedia('(prefers-reduced-motion: reduce)');
|
|
18
|
+
_reduced = mql.matches;
|
|
19
|
+
const h = e => set(e.matches);
|
|
20
|
+
mql.addEventListener?.('change', h) ?? mql.addListener?.(h);
|
|
21
|
+
} catch {}
|
|
22
|
+
}
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
AccessibilityInfo.isReduceMotionEnabled?.().then(v => set(!!v)).catch(() => {});
|
|
26
|
+
try {
|
|
27
|
+
AccessibilityInfo.addEventListener('reduceMotionChanged', v => set(v));
|
|
28
|
+
} catch {}
|
|
29
|
+
};
|
|
30
|
+
export const useReducedMotion = () => {
|
|
31
|
+
const r = useRef(false);
|
|
32
|
+
if (!r.current) {
|
|
33
|
+
r.current = true;
|
|
34
|
+
init();
|
|
35
|
+
}
|
|
36
|
+
const [v, sv] = useState(_reduced);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (_reduced !== v) sv(_reduced);
|
|
39
|
+
_subs.add(sv);
|
|
40
|
+
return () => {
|
|
41
|
+
_subs.delete(sv);
|
|
42
|
+
};
|
|
43
|
+
}, []);
|
|
44
|
+
return v;
|
|
45
|
+
};
|
|
46
|
+
export const getReducedMotion = () => {
|
|
47
|
+
init();
|
|
48
|
+
return _reduced;
|
|
49
|
+
};
|
|
50
|
+
export const _resetForTesting = () => {
|
|
51
|
+
_reduced = false;
|
|
52
|
+
_inited = false;
|
|
53
|
+
_subs.clear();
|
|
54
|
+
};
|
|
@@ -7,27 +7,19 @@ export const useAriaListBox = props => {
|
|
|
7
7
|
label,
|
|
8
8
|
...rest
|
|
9
9
|
} = props;
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
...(ariaLabel ? {
|
|
16
|
-
'aria-label': ariaLabel
|
|
17
|
-
} : null)
|
|
18
|
-
};
|
|
19
|
-
}, [label, rest]);
|
|
20
|
-
const state = useListState(resolvedProps);
|
|
10
|
+
const resolved = typeof label === 'string' ? {
|
|
11
|
+
...rest,
|
|
12
|
+
'aria-label': label
|
|
13
|
+
} : rest;
|
|
14
|
+
const state = useListState(resolved);
|
|
21
15
|
const {
|
|
22
16
|
listBoxProps,
|
|
23
17
|
labelProps
|
|
24
|
-
} = useListBox(
|
|
25
|
-
const resolvedListBoxProps = useMemo(() => listBoxProps, [listBoxProps]);
|
|
26
|
-
const resolvedLabelProps = useMemo(() => labelProps, [labelProps]);
|
|
18
|
+
} = useListBox(resolved, state, ref);
|
|
27
19
|
return {
|
|
28
20
|
state,
|
|
29
|
-
listBoxProps:
|
|
30
|
-
labelProps:
|
|
21
|
+
listBoxProps: useMemo(() => listBoxProps, [listBoxProps]),
|
|
22
|
+
labelProps: useMemo(() => labelProps, [labelProps]),
|
|
31
23
|
ref
|
|
32
24
|
};
|
|
33
25
|
};
|
|
@@ -6,7 +6,7 @@ export const useAriaOverlay = ({
|
|
|
6
6
|
onClose,
|
|
7
7
|
isDismissable = true,
|
|
8
8
|
shouldCloseOnInteractOutside,
|
|
9
|
-
overlayProps:
|
|
9
|
+
overlayProps: overrides
|
|
10
10
|
}) => {
|
|
11
11
|
const overlayRef = useRef(null);
|
|
12
12
|
const {
|
|
@@ -17,9 +17,9 @@ export const useAriaOverlay = ({
|
|
|
17
17
|
isDismissable,
|
|
18
18
|
shouldCloseOnInteractOutside
|
|
19
19
|
}, overlayRef);
|
|
20
|
-
const
|
|
20
|
+
const resolved = useMemo(() => mergeProps(overlayProps ?? {}, overrides ?? {}), [overrides, overlayProps]);
|
|
21
21
|
return {
|
|
22
22
|
overlayRef,
|
|
23
|
-
overlayProps:
|
|
23
|
+
overlayProps: resolved
|
|
24
24
|
};
|
|
25
25
|
};
|
|
@@ -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
|
};
|