react-native-system-ui 0.0.5 → 0.0.7
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 +12 -4
- package/dist/cjs/components/action-sheet/ActionSheet.js +28 -22
- package/dist/cjs/components/area/Area.js +72 -6
- package/dist/cjs/components/area/tokens.js +11 -0
- package/dist/cjs/components/avatar/Avatar.js +42 -10
- package/dist/cjs/components/badge/Badge.js +10 -10
- package/dist/cjs/components/badge/tokens.js +4 -0
- package/dist/cjs/components/button/Button.js +16 -65
- package/dist/cjs/components/button/ButtonContext.js +7 -10
- package/dist/cjs/components/button/ButtonGroup.js +13 -15
- package/dist/cjs/components/button/tokens.js +1 -5
- package/dist/cjs/components/calendar/Calendar.js +23 -12
- package/dist/cjs/components/cascader/Cascader.js +18 -13
- package/dist/cjs/components/cell/Cell.js +3 -3
- package/dist/cjs/components/cell/CellGroup.js +26 -21
- package/dist/cjs/components/checkbox/Checkbox.js +5 -4
- package/dist/cjs/components/checkbox/CheckboxContext.js +7 -10
- package/dist/cjs/components/checkbox/CheckboxGroup.js +24 -21
- package/dist/cjs/components/circle/Circle.js +6 -6
- package/dist/cjs/components/collapse/Collapse.js +10 -10
- package/dist/cjs/components/config-provider/locale/en-US.js +66 -4
- package/dist/cjs/components/config-provider/locale/zh-CN.js +74 -2
- package/dist/cjs/components/config-provider/tokens.js +11 -0
- package/dist/cjs/components/count-down/CountDown.js +6 -6
- package/dist/cjs/components/datetime-picker/DatetimePicker.js +6 -6
- package/dist/cjs/components/datetime-picker/tokens.js +11 -0
- package/dist/cjs/components/dialog/Dialog.js +39 -34
- package/dist/cjs/components/dialog/tokens.js +1 -4
- package/dist/cjs/components/divider/Divider.js +36 -1
- package/dist/cjs/components/field/Field.js +303 -201
- package/dist/cjs/components/flex/Flex.js +7 -3
- package/dist/cjs/components/flex/FlexContext.js +7 -14
- package/dist/cjs/components/form/Form.js +112 -122
- package/dist/cjs/components/form/FormContext.js +7 -10
- package/dist/cjs/components/form/FormItem.js +30 -4
- package/dist/cjs/components/form/FormList.js +16 -3
- package/dist/cjs/components/form/tokens.js +11 -0
- package/dist/cjs/components/form/utils.js +2 -1
- package/dist/cjs/components/grid/Grid.js +45 -31
- package/dist/cjs/components/grid/GridContext.js +7 -10
- package/dist/cjs/components/grid/GridItem.js +22 -22
- package/dist/cjs/components/image/Image.js +17 -13
- package/dist/cjs/components/image-preview/ImagePreview.js +43 -41
- package/dist/cjs/components/index.js +43 -141
- package/dist/cjs/components/input/Input.js +19 -5
- package/dist/cjs/components/loading/Loading.js +10 -139
- package/dist/cjs/components/loading/tokens.js +0 -24
- package/dist/cjs/components/notice-bar/NoticeBar.js +45 -41
- package/dist/cjs/components/notify/Notify.js +63 -22
- package/dist/cjs/components/notify/imperative.js +2 -2
- package/dist/cjs/components/notify/tokens.js +11 -1
- package/dist/cjs/components/number-keyboard/NumberKeyboard.js +6 -6
- package/dist/cjs/components/overlay/Overlay.js +70 -77
- package/dist/cjs/components/overlay/index.js +13 -27
- package/dist/cjs/components/overlay/tokens.js +4 -31
- package/dist/cjs/components/password-input/PasswordInput.js +2 -41
- package/dist/cjs/components/password-input/tokens.js +53 -0
- package/dist/cjs/components/picker/Picker.js +618 -38
- package/dist/cjs/components/popup/Popup.js +60 -47
- package/dist/cjs/components/portal/Portal.js +39 -31
- package/dist/cjs/components/portal/PortalHost.js +258 -213
- package/dist/cjs/components/portal/tokens.js +11 -0
- package/dist/cjs/components/progress/Progress.js +77 -36
- package/dist/cjs/components/progress/index.js +6 -0
- package/dist/cjs/components/radio/Radio.js +35 -12
- package/dist/cjs/components/radio/RadioContext.js +7 -10
- package/dist/cjs/components/radio/RadioGroup.js +23 -20
- package/dist/cjs/components/safe-area-view/tokens.js +11 -0
- package/dist/cjs/components/search/Search.js +16 -16
- package/dist/cjs/components/selector/Selector.js +6 -6
- package/dist/cjs/components/share-sheet/ShareSheet.js +50 -46
- package/dist/cjs/components/sidebar/Sidebar.js +27 -22
- package/dist/cjs/components/sidebar/SidebarItem.js +27 -22
- package/dist/cjs/components/skeleton/Skeleton.js +34 -21
- package/dist/cjs/components/slider/Slider.js +135 -78
- package/dist/cjs/components/stepper/Stepper.js +12 -10
- package/dist/cjs/components/swiper/Swiper.js +247 -710
- package/dist/cjs/components/swiper/SwiperItem.js +5 -33
- package/dist/cjs/components/swiper/tokens.js +11 -0
- package/dist/cjs/components/switch/Switch.js +46 -98
- package/dist/cjs/components/switch/tokens.js +1 -55
- package/dist/cjs/components/tabbar/Tabbar.js +26 -22
- package/dist/cjs/components/tabbar/TabbarItem.js +23 -22
- package/dist/cjs/components/tabbar/tokens.js +0 -2
- package/dist/cjs/components/tabs/Tabs.js +268 -94
- package/dist/cjs/components/tabs/index.js +4 -5
- package/dist/cjs/components/toast/Toast.js +72 -27
- package/dist/cjs/components/toast/imperative.js +2 -2
- package/dist/cjs/hooks/gesture/useGestureScroll.js +1 -2
- package/dist/cjs/hooks/index.js +12 -12
- package/dist/cjs/hooks/overlay/index.js +27 -0
- package/dist/cjs/hooks/useHairline.js +0 -4
- package/dist/cjs/platform/scrollLock.js +1 -1
- package/dist/cjs/utils/compare.js +26 -0
- package/dist/cjs/utils/index.js +11 -0
- package/dist/es/components/action-sheet/ActionSheet.js +29 -23
- package/dist/es/components/area/Area.js +73 -7
- package/dist/es/components/area/tokens.js +5 -0
- package/dist/es/components/avatar/Avatar.js +42 -10
- package/dist/es/components/badge/Badge.js +11 -11
- package/dist/es/components/badge/tokens.js +4 -0
- package/dist/es/components/button/Button.js +17 -65
- package/dist/es/components/button/ButtonContext.js +1 -2
- package/dist/es/components/button/ButtonGroup.js +10 -12
- package/dist/es/components/button/tokens.js +1 -5
- package/dist/es/components/calendar/Calendar.js +24 -13
- package/dist/es/components/cascader/Cascader.js +16 -11
- package/dist/es/components/cell/Cell.js +4 -4
- package/dist/es/components/cell/CellGroup.js +25 -20
- package/dist/es/components/checkbox/Checkbox.js +5 -4
- package/dist/es/components/checkbox/CheckboxContext.js +1 -2
- package/dist/es/components/checkbox/CheckboxGroup.js +24 -21
- package/dist/es/components/circle/Circle.js +7 -7
- package/dist/es/components/collapse/Collapse.js +11 -11
- package/dist/es/components/config-provider/locale/en-US.js +66 -4
- package/dist/es/components/config-provider/locale/zh-CN.js +74 -2
- package/dist/es/components/config-provider/tokens.js +5 -0
- package/dist/es/components/count-down/CountDown.js +7 -7
- package/dist/es/components/datetime-picker/DatetimePicker.js +7 -7
- package/dist/es/components/datetime-picker/tokens.js +5 -0
- package/dist/es/components/dialog/Dialog.js +40 -35
- package/dist/es/components/dialog/tokens.js +1 -4
- package/dist/es/components/divider/Divider.js +36 -1
- package/dist/es/components/field/Field.js +304 -202
- package/dist/es/components/flex/Flex.js +5 -1
- package/dist/es/components/flex/FlexContext.js +1 -6
- package/dist/es/components/form/Form.js +89 -99
- package/dist/es/components/form/FormContext.js +1 -2
- package/dist/es/components/form/FormItem.js +32 -6
- package/dist/es/components/form/FormList.js +18 -5
- package/dist/es/components/form/tokens.js +5 -0
- package/dist/es/components/form/utils.js +1 -0
- package/dist/es/components/grid/Grid.js +43 -29
- package/dist/es/components/grid/GridContext.js +1 -2
- package/dist/es/components/grid/GridItem.js +24 -24
- package/dist/es/components/image/Image.js +18 -14
- package/dist/es/components/image-preview/ImagePreview.js +44 -42
- package/dist/es/components/index.js +2 -17
- package/dist/es/components/input/Input.js +20 -6
- package/dist/es/components/loading/Loading.js +10 -139
- package/dist/es/components/loading/tokens.js +0 -24
- package/dist/es/components/notice-bar/NoticeBar.js +46 -42
- package/dist/es/components/notify/Notify.js +63 -22
- package/dist/es/components/notify/imperative.js +2 -2
- package/dist/es/components/notify/tokens.js +5 -1
- package/dist/es/components/number-keyboard/NumberKeyboard.js +7 -7
- package/dist/es/components/overlay/Overlay.js +58 -75
- package/dist/es/components/overlay/index.js +3 -4
- package/dist/es/components/overlay/tokens.js +3 -29
- package/dist/es/components/password-input/PasswordInput.js +1 -40
- package/dist/es/components/password-input/tokens.js +41 -0
- package/dist/es/components/picker/Picker.js +610 -34
- package/dist/es/components/popup/Popup.js +62 -49
- package/dist/es/components/portal/Portal.js +37 -31
- package/dist/es/components/portal/PortalHost.js +257 -211
- package/dist/es/components/portal/tokens.js +5 -0
- package/dist/es/components/progress/Progress.js +76 -36
- package/dist/es/components/progress/index.js +2 -1
- package/dist/es/components/radio/Radio.js +37 -14
- package/dist/es/components/radio/RadioContext.js +1 -2
- package/dist/es/components/radio/RadioGroup.js +23 -20
- package/dist/es/components/safe-area-view/tokens.js +5 -0
- package/dist/es/components/search/Search.js +17 -17
- package/dist/es/components/selector/Selector.js +7 -7
- package/dist/es/components/share-sheet/ShareSheet.js +51 -47
- package/dist/es/components/sidebar/Sidebar.js +26 -21
- package/dist/es/components/sidebar/SidebarItem.js +26 -22
- package/dist/es/components/skeleton/Skeleton.js +35 -22
- package/dist/es/components/slider/Slider.js +132 -75
- package/dist/es/components/stepper/Stepper.js +13 -11
- package/dist/es/components/swiper/Swiper.js +248 -711
- package/dist/es/components/swiper/SwiperItem.js +1 -21
- package/dist/es/components/swiper/tokens.js +5 -0
- package/dist/es/components/switch/Switch.js +49 -101
- package/dist/es/components/switch/tokens.js +1 -49
- package/dist/es/components/tabbar/Tabbar.js +27 -23
- package/dist/es/components/tabbar/TabbarItem.js +22 -22
- package/dist/es/components/tabbar/tokens.js +0 -2
- package/dist/es/components/tabs/Tabs.js +264 -90
- package/dist/es/components/tabs/index.js +1 -2
- package/dist/es/components/toast/Toast.js +72 -28
- package/dist/es/components/toast/imperative.js +2 -2
- package/dist/es/hooks/gesture/useGestureScroll.js +1 -2
- package/dist/es/hooks/index.js +1 -1
- package/dist/es/hooks/overlay/index.js +3 -0
- package/dist/es/hooks/useHairline.js +0 -4
- package/dist/es/platform/scrollLock.js +1 -1
- package/dist/es/utils/compare.js +18 -0
- package/dist/es/utils/index.js +1 -1
- package/dist/types/components/area/tokens.d.ts +3 -0
- package/dist/types/components/avatar/Avatar.d.ts +4 -2
- package/dist/types/components/button/ButtonContext.d.ts +2 -16
- package/dist/types/components/button/ButtonGroup.d.ts +14 -1
- package/dist/types/components/button/index.d.ts +1 -1
- package/dist/types/components/checkbox/CheckboxContext.d.ts +2 -16
- package/dist/types/components/checkbox/CheckboxGroup.d.ts +15 -1
- package/dist/types/components/collapse/Collapse.d.ts +0 -1
- package/dist/types/components/config-provider/LocaleContext.d.ts +2 -74
- package/dist/types/components/config-provider/tokens.d.ts +3 -0
- package/dist/types/components/config-provider/useLocale.d.ts +1 -74
- package/dist/types/components/datetime-picker/tokens.d.ts +3 -0
- package/dist/types/components/flex/Flex.d.ts +6 -0
- package/dist/types/components/flex/FlexContext.d.ts +2 -8
- package/dist/types/components/form/Form.d.ts +15 -1
- package/dist/types/components/form/FormContext.d.ts +2 -17
- package/dist/types/components/form/tokens.d.ts +3 -0
- package/dist/types/components/form/utils.d.ts +1 -0
- package/dist/types/components/grid/Grid.d.ts +16 -1
- package/dist/types/components/grid/GridContext.d.ts +2 -17
- package/dist/types/components/index.d.ts +3 -33
- package/dist/types/components/loading/index.d.ts +1 -1
- package/dist/types/components/notify/Notify.d.ts +1 -0
- package/dist/types/components/overlay/Overlay.d.ts +6 -1
- package/dist/types/components/overlay/index.d.ts +2 -3
- package/dist/types/components/overlay/tokens.d.ts +2 -3
- package/dist/types/components/password-input/PasswordInput.d.ts +0 -39
- package/dist/types/components/password-input/tokens.d.ts +40 -0
- package/dist/types/components/picker/Picker.d.ts +18 -2
- package/dist/types/components/picker/index.d.ts +1 -1
- package/dist/types/components/portal/Portal.d.ts +4 -6
- package/dist/types/components/portal/PortalHost.d.ts +1 -15
- package/dist/types/components/portal/tokens.d.ts +3 -0
- package/dist/types/components/progress/Progress.d.ts +4 -0
- package/dist/types/components/progress/index.d.ts +2 -1
- package/dist/types/components/radio/RadioContext.d.ts +2 -13
- package/dist/types/components/radio/RadioGroup.d.ts +12 -1
- package/dist/types/components/safe-area-view/tokens.d.ts +3 -0
- package/dist/types/components/swiper/Swiper.d.ts +4 -2
- package/dist/types/components/swiper/SwiperItem.d.ts +1 -5
- package/dist/types/components/swiper/tokens.d.ts +3 -0
- package/dist/types/components/tabs/Tabs.d.ts +8 -4
- package/dist/types/components/tabs/index.d.ts +3 -1
- package/dist/types/components/toast/Toast.d.ts +1 -4
- package/dist/types/hooks/aria/useAriaListBox.d.ts +0 -6
- package/dist/types/hooks/aria/useAriaOverlay.d.ts +0 -10
- package/dist/types/hooks/aria/useAriaPress.d.ts +0 -20
- package/dist/types/hooks/aria/useAriaToggle.d.ts +0 -3
- package/dist/types/hooks/index.d.ts +1 -1
- package/dist/types/hooks/overlay/index.d.ts +2 -0
- package/dist/types/hooks/useHairline.d.ts +0 -21
- package/dist/types/utils/compare.d.ts +2 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/package.json +10 -48
- package/dist/cjs/components/area/utils.js +0 -74
- package/dist/cjs/components/cascader/utils.js +0 -20
- package/dist/cjs/components/config-provider/locale/base.js +0 -80
- package/dist/cjs/components/dropdown-menu/DropdownItem.js +0 -288
- package/dist/cjs/components/dropdown-menu/DropdownMenu.js +0 -340
- package/dist/cjs/components/dropdown-menu/DropdownMenuContext.js +0 -21
- package/dist/cjs/components/dropdown-menu/index.js +0 -25
- package/dist/cjs/components/dropdown-menu/tokens.js +0 -67
- package/dist/cjs/components/field/utils.js +0 -24
- package/dist/cjs/components/index-bar/IndexAnchor.js +0 -74
- package/dist/cjs/components/index-bar/IndexBar.js +0 -436
- package/dist/cjs/components/index-bar/index.js +0 -25
- package/dist/cjs/components/index-bar/tokens.js +0 -45
- package/dist/cjs/components/list/List.js +0 -165
- package/dist/cjs/components/list/index.js +0 -9
- package/dist/cjs/components/list/tokens.js +0 -39
- package/dist/cjs/components/notify/defaults.js +0 -15
- package/dist/cjs/components/pagination/Pagination.js +0 -160
- package/dist/cjs/components/pagination/index.js +0 -22
- package/dist/cjs/components/pagination/tokens.js +0 -103
- package/dist/cjs/components/picker/WheelPicker.js +0 -492
- package/dist/cjs/components/picker/utils.js +0 -138
- package/dist/cjs/components/pull-refresh/PullRefresh.js +0 -378
- package/dist/cjs/components/pull-refresh/index.js +0 -16
- package/dist/cjs/components/pull-refresh/tokens.js +0 -22
- package/dist/cjs/components/rate/Rate.js +0 -269
- package/dist/cjs/components/rate/index.js +0 -15
- package/dist/cjs/components/rate/tokens.js +0 -60
- package/dist/cjs/components/slider/utils.js +0 -60
- package/dist/cjs/components/swiper/useSwiperWeb.js +0 -209
- package/dist/cjs/components/swiper/utils.js +0 -49
- package/dist/cjs/components/tabs/TabPane.js +0 -9
- package/dist/cjs/components/tabs/useTabsAnimation.js +0 -74
- package/dist/cjs/components/tabs/useTabsScroll.js +0 -133
- package/dist/cjs/components/tabs/utils.js +0 -34
- package/dist/cjs/components/types.js +0 -1
- package/dist/cjs/components/uploader/Uploader.js +0 -557
- package/dist/cjs/components/uploader/index.js +0 -22
- package/dist/cjs/components/uploader/tokens.js +0 -58
- package/dist/cjs/components/uploader/utils.js +0 -72
- package/dist/cjs/hooks/usePresenceAnimation.js +0 -70
- package/dist/es/components/area/utils.js +0 -67
- package/dist/es/components/cascader/utils.js +0 -13
- package/dist/es/components/config-provider/locale/base.js +0 -74
- package/dist/es/components/dropdown-menu/DropdownItem.js +0 -269
- package/dist/es/components/dropdown-menu/DropdownMenu.js +0 -320
- package/dist/es/components/dropdown-menu/DropdownMenuContext.js +0 -7
- package/dist/es/components/dropdown-menu/index.js +0 -7
- package/dist/es/components/dropdown-menu/tokens.js +0 -61
- package/dist/es/components/field/utils.js +0 -17
- package/dist/es/components/index-bar/IndexAnchor.js +0 -55
- package/dist/es/components/index-bar/IndexBar.js +0 -417
- package/dist/es/components/index-bar/index.js +0 -7
- package/dist/es/components/index-bar/tokens.js +0 -39
- package/dist/es/components/list/List.js +0 -145
- package/dist/es/components/list/index.js +0 -2
- package/dist/es/components/list/tokens.js +0 -32
- package/dist/es/components/notify/defaults.js +0 -9
- package/dist/es/components/pagination/Pagination.js +0 -141
- package/dist/es/components/pagination/index.js +0 -4
- package/dist/es/components/pagination/tokens.js +0 -91
- package/dist/es/components/picker/WheelPicker.js +0 -473
- package/dist/es/components/picker/utils.js +0 -127
- package/dist/es/components/pull-refresh/PullRefresh.js +0 -359
- package/dist/es/components/pull-refresh/index.js +0 -3
- package/dist/es/components/pull-refresh/tokens.js +0 -16
- package/dist/es/components/rate/Rate.js +0 -250
- package/dist/es/components/rate/index.js +0 -3
- package/dist/es/components/rate/tokens.js +0 -53
- package/dist/es/components/slider/utils.js +0 -49
- package/dist/es/components/swiper/useSwiperWeb.js +0 -190
- package/dist/es/components/swiper/utils.js +0 -37
- package/dist/es/components/tabs/TabPane.js +0 -3
- package/dist/es/components/tabs/useTabsAnimation.js +0 -55
- package/dist/es/components/tabs/useTabsScroll.js +0 -114
- package/dist/es/components/tabs/utils.js +0 -19
- package/dist/es/components/types.js +0 -1
- package/dist/es/components/uploader/Uploader.js +0 -537
- package/dist/es/components/uploader/index.js +0 -4
- package/dist/es/components/uploader/tokens.js +0 -52
- package/dist/es/components/uploader/utils.js +0 -60
- package/dist/es/hooks/usePresenceAnimation.js +0 -51
- package/dist/types/components/area/utils.d.ts +0 -2
- package/dist/types/components/cascader/utils.d.ts +0 -6
- package/dist/types/components/config-provider/locale/base.d.ts +0 -74
- package/dist/types/components/dropdown-menu/DropdownItem.d.ts +0 -4
- package/dist/types/components/dropdown-menu/DropdownMenu.d.ts +0 -4
- package/dist/types/components/dropdown-menu/DropdownMenuContext.d.ts +0 -17
- package/dist/types/components/dropdown-menu/index.d.ts +0 -8
- package/dist/types/components/dropdown-menu/tokens.d.ts +0 -52
- package/dist/types/components/field/utils.d.ts +0 -4
- package/dist/types/components/index-bar/IndexAnchor.d.ts +0 -4
- package/dist/types/components/index-bar/IndexBar.d.ts +0 -4
- package/dist/types/components/index-bar/index.d.ts +0 -9
- package/dist/types/components/index-bar/tokens.d.ts +0 -31
- package/dist/types/components/list/List.d.ts +0 -4
- package/dist/types/components/list/index.d.ts +0 -3
- package/dist/types/components/list/tokens.d.ts +0 -4
- package/dist/types/components/notify/defaults.d.ts +0 -10
- package/dist/types/components/pagination/Pagination.d.ts +0 -5
- package/dist/types/components/pagination/index.d.ts +0 -5
- package/dist/types/components/pagination/tokens.d.ts +0 -2
- package/dist/types/components/picker/WheelPicker.d.ts +0 -21
- package/dist/types/components/picker/utils.d.ts +0 -17
- package/dist/types/components/pull-refresh/PullRefresh.d.ts +0 -5
- package/dist/types/components/pull-refresh/index.d.ts +0 -4
- package/dist/types/components/pull-refresh/tokens.d.ts +0 -10
- package/dist/types/components/rate/Rate.d.ts +0 -4
- package/dist/types/components/rate/index.d.ts +0 -4
- package/dist/types/components/rate/tokens.d.ts +0 -4
- package/dist/types/components/slider/utils.d.ts +0 -42
- package/dist/types/components/swiper/useSwiperWeb.d.ts +0 -41
- package/dist/types/components/swiper/utils.d.ts +0 -17
- package/dist/types/components/tabs/TabPane.d.ts +0 -4
- package/dist/types/components/tabs/useTabsAnimation.d.ts +0 -30
- package/dist/types/components/tabs/useTabsScroll.d.ts +0 -23
- package/dist/types/components/tabs/utils.d.ts +0 -5
- package/dist/types/components/types.d.ts +0 -59
- package/dist/types/components/uploader/Uploader.d.ts +0 -4
- package/dist/types/components/uploader/index.d.ts +0 -5
- package/dist/types/components/uploader/tokens.d.ts +0 -42
- package/dist/types/components/uploader/utils.d.ts +0 -11
- package/dist/types/hooks/usePresenceAnimation.d.ts +0 -20
- /package/dist/cjs/{components → hooks}/overlay/OverlayStackStore.js +0 -0
- /package/dist/cjs/{components → hooks}/overlay/useOverlayStack.js +0 -0
- /package/dist/es/{components → hooks}/overlay/OverlayStackStore.js +0 -0
- /package/dist/es/{components → hooks}/overlay/useOverlayStack.js +0 -0
- /package/dist/types/{components → hooks}/overlay/OverlayStackStore.d.ts +0 -0
- /package/dist/types/{components → hooks}/overlay/useOverlayStack.d.ts +0 -0
|
@@ -1,12 +1,596 @@
|
|
|
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, { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
-
import { Pressable, Text, View, Platform, StyleSheet } from 'react-native';
|
|
2
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { Pressable, Text, View, Platform, StyleSheet, ScrollView, PanResponder } from 'react-native';
|
|
4
4
|
import Loading from '../loading';
|
|
5
5
|
import { withAlpha } from '../../utils/color';
|
|
6
|
-
import { isFiniteNumber,
|
|
6
|
+
import { isFiniteNumber, isText } from '../../utils/validate';
|
|
7
|
+
import { clamp, isObject, shallowEqualArray } from '../../utils';
|
|
7
8
|
import { usePickerTokens } from './tokens';
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
export const toArrayValue = value => {
|
|
10
|
+
if (Array.isArray(value)) return value.filter(v => v !== undefined && v !== null);
|
|
11
|
+
if (value === undefined || value === null) return [];
|
|
12
|
+
return [value];
|
|
13
|
+
};
|
|
14
|
+
const isColumnWithOptions = col => !!col && isObject(col) && 'options' in col && Array.isArray(col.options);
|
|
15
|
+
const hasChildren = option => {
|
|
16
|
+
return !!option && isObject(option) && Array.isArray(option.children) && option.children.length > 0;
|
|
17
|
+
};
|
|
18
|
+
export const findEnabledIndex = (options, startIndex) => {
|
|
19
|
+
if (!options.length) return -1;
|
|
20
|
+
const clampIndex = Math.min(Math.max(startIndex, 0), options.length - 1);
|
|
21
|
+
if (!options[clampIndex]?.disabled) return clampIndex;
|
|
22
|
+
for (let i = clampIndex + 1; i < options.length; i += 1) {
|
|
23
|
+
if (!options[i]?.disabled) return i;
|
|
24
|
+
}
|
|
25
|
+
for (let i = clampIndex - 1; i >= 0; i -= 1) {
|
|
26
|
+
if (!options[i]?.disabled) return i;
|
|
27
|
+
}
|
|
28
|
+
return -1;
|
|
29
|
+
};
|
|
30
|
+
const normalizeMultiple = (columnsList, defaults, rawValue) => {
|
|
31
|
+
const values = [];
|
|
32
|
+
const options = [];
|
|
33
|
+
columnsList.forEach((opts, index) => {
|
|
34
|
+
const current = rawValue[index];
|
|
35
|
+
const defaultIndex = defaults[index] !== undefined ? opts.findIndex(item => item.value === defaults[index]) : -1;
|
|
36
|
+
const currentIndex = opts.findIndex(item => item.value === current);
|
|
37
|
+
const startIndex = currentIndex >= 0 ? currentIndex : defaultIndex >= 0 ? defaultIndex : 0;
|
|
38
|
+
const targetIndex = findEnabledIndex(opts, startIndex);
|
|
39
|
+
const target = targetIndex >= 0 ? opts[targetIndex] : undefined;
|
|
40
|
+
const valid = currentIndex >= 0 && !opts[currentIndex]?.disabled;
|
|
41
|
+
values[index] = valid ? current : target?.value ?? defaults[index] ?? opts[0]?.value;
|
|
42
|
+
options[index] = target;
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
columns: columnsList,
|
|
46
|
+
values,
|
|
47
|
+
options
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
const normalizeCascade = (rootOptions, rawValue) => {
|
|
51
|
+
const columns = [];
|
|
52
|
+
const values = [];
|
|
53
|
+
const options = [];
|
|
54
|
+
let currentOptions = rootOptions;
|
|
55
|
+
let depth = 0;
|
|
56
|
+
while (currentOptions && currentOptions.length && depth < 10) {
|
|
57
|
+
columns.push(currentOptions);
|
|
58
|
+
const current = rawValue[depth];
|
|
59
|
+
const startIndex = currentOptions.findIndex(item => item.value === current || String(item.value) === String(current));
|
|
60
|
+
const targetIndex = findEnabledIndex(currentOptions, startIndex >= 0 ? startIndex : 0);
|
|
61
|
+
const target = targetIndex >= 0 ? currentOptions[targetIndex] : currentOptions[0];
|
|
62
|
+
values[depth] = target?.value;
|
|
63
|
+
options[depth] = target;
|
|
64
|
+
if (target && hasChildren(target)) {
|
|
65
|
+
currentOptions = target.children;
|
|
66
|
+
depth += 1;
|
|
67
|
+
} else {
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
columns,
|
|
73
|
+
values,
|
|
74
|
+
options
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
export const prepareColumns = (columnsInput = []) => {
|
|
78
|
+
if (!Array.isArray(columnsInput) || columnsInput.length === 0) {
|
|
79
|
+
return {
|
|
80
|
+
type: 'single',
|
|
81
|
+
columnsList: [],
|
|
82
|
+
defaults: [],
|
|
83
|
+
cascadeRoot: []
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const everyPlainOption = columnsInput.every(item => !Array.isArray(item) && !isColumnWithOptions(item));
|
|
87
|
+
const cascade = everyPlainOption && columnsInput.some(item => hasChildren(item));
|
|
88
|
+
if (cascade) {
|
|
89
|
+
return {
|
|
90
|
+
type: 'cascade',
|
|
91
|
+
columnsList: [],
|
|
92
|
+
defaults: [],
|
|
93
|
+
cascadeRoot: columnsInput
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const asArray = columnsInput;
|
|
97
|
+
const columnsList = [];
|
|
98
|
+
const defaults = [];
|
|
99
|
+
const treatAsSingleColumn = everyPlainOption && !cascade;
|
|
100
|
+
if (treatAsSingleColumn) {
|
|
101
|
+
columnsList.push(columnsInput);
|
|
102
|
+
defaults.push(undefined);
|
|
103
|
+
} else {
|
|
104
|
+
asArray.forEach(col => {
|
|
105
|
+
if (Array.isArray(col)) {
|
|
106
|
+
columnsList.push(col);
|
|
107
|
+
defaults.push(undefined);
|
|
108
|
+
} else if (isColumnWithOptions(col)) {
|
|
109
|
+
const c = col;
|
|
110
|
+
columnsList.push(c.options ?? []);
|
|
111
|
+
defaults.push(c.defaultValue);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
type: 'multiple',
|
|
117
|
+
columnsList,
|
|
118
|
+
defaults
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
export const normalizePicker = (prepared, rawValueInput = []) => {
|
|
122
|
+
const rawValue = Array.isArray(rawValueInput) ? rawValueInput : [];
|
|
123
|
+
if (prepared.type === 'cascade' && prepared.cascadeRoot?.length) {
|
|
124
|
+
return normalizeCascade(prepared.cascadeRoot, rawValue);
|
|
125
|
+
}
|
|
126
|
+
return normalizeMultiple(prepared.columnsList, prepared.defaults, rawValue);
|
|
127
|
+
};
|
|
128
|
+
const wheelStyles = StyleSheet.create({
|
|
129
|
+
column: {
|
|
130
|
+
flex: 1
|
|
131
|
+
},
|
|
132
|
+
option: {
|
|
133
|
+
justifyContent: 'center',
|
|
134
|
+
alignItems: 'center'
|
|
135
|
+
},
|
|
136
|
+
indicator: {
|
|
137
|
+
position: 'absolute',
|
|
138
|
+
left: 0,
|
|
139
|
+
right: 0,
|
|
140
|
+
borderTopWidth: StyleSheet.hairlineWidth,
|
|
141
|
+
borderBottomWidth: StyleSheet.hairlineWidth,
|
|
142
|
+
zIndex: 3
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
const WheelPickerItemInner = ({
|
|
146
|
+
item,
|
|
147
|
+
index,
|
|
148
|
+
itemHeight,
|
|
149
|
+
active,
|
|
150
|
+
disabled,
|
|
151
|
+
renderItem
|
|
152
|
+
}) => {
|
|
153
|
+
const content = renderItem(item, index, {
|
|
154
|
+
active,
|
|
155
|
+
disabled
|
|
156
|
+
});
|
|
157
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
158
|
+
style: [wheelStyles.option, {
|
|
159
|
+
height: itemHeight
|
|
160
|
+
}]
|
|
161
|
+
}, content);
|
|
162
|
+
};
|
|
163
|
+
const WheelPickerItem = /*#__PURE__*/React.memo(WheelPickerItemInner, (prev, next) => prev.item === next.item && prev.index === next.index && prev.itemHeight === next.itemHeight && prev.active === next.active && prev.disabled === next.disabled && prev.renderItem === next.renderItem);
|
|
164
|
+
const getVelocityBucket = velocity => {
|
|
165
|
+
const abs = Math.abs(velocity);
|
|
166
|
+
if (abs > 1.2) return 2;
|
|
167
|
+
if (abs > 0.6) return 1;
|
|
168
|
+
return 0;
|
|
169
|
+
};
|
|
170
|
+
const adjustIndex = (index, options) => {
|
|
171
|
+
const total = options.length;
|
|
172
|
+
if (!total) return 0;
|
|
173
|
+
const i = clamp(index, 0, total - 1);
|
|
174
|
+
const next = findEnabledIndex(options, i);
|
|
175
|
+
return next >= 0 ? next : i;
|
|
176
|
+
};
|
|
177
|
+
const indexToOffset = (index, itemHeight) => -index * itemHeight;
|
|
178
|
+
const offsetToIndex = (offset, itemHeight, total, options) => {
|
|
179
|
+
const minOffset = -Math.max(0, total - 1) * itemHeight;
|
|
180
|
+
const off = clamp(offset, minOffset, 0);
|
|
181
|
+
let index = Math.round(-off / itemHeight);
|
|
182
|
+
index = adjustIndex(index, options);
|
|
183
|
+
const snapOffset = indexToOffset(index, itemHeight);
|
|
184
|
+
return {
|
|
185
|
+
index,
|
|
186
|
+
snapOffset
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
const shouldMomentum = (distance, duration) => duration < 500 && Math.abs(distance) > 8;
|
|
190
|
+
const momentumTarget = (distance, duration, currentOffset, itemHeight, minOffset) => {
|
|
191
|
+
const speed = Math.abs(distance / duration);
|
|
192
|
+
const extra = speed / 0.0025 * (distance < 0 ? -1 : 1);
|
|
193
|
+
const target = clamp(currentOffset + extra, minOffset, 0);
|
|
194
|
+
const snapIndex = Math.round(-target / itemHeight);
|
|
195
|
+
return indexToOffset(snapIndex, itemHeight);
|
|
196
|
+
};
|
|
197
|
+
const WheelPickerInner = ({
|
|
198
|
+
data,
|
|
199
|
+
selectedIndex,
|
|
200
|
+
onChange,
|
|
201
|
+
onInteractStart,
|
|
202
|
+
onInteractEnd,
|
|
203
|
+
renderItem,
|
|
204
|
+
itemHeight,
|
|
205
|
+
visibleRest,
|
|
206
|
+
readOnly,
|
|
207
|
+
indicatorColor,
|
|
208
|
+
decelerationRate = Platform.select({
|
|
209
|
+
ios: 0.9985,
|
|
210
|
+
android: 0.995,
|
|
211
|
+
default: 0.995
|
|
212
|
+
}) ?? 'normal',
|
|
213
|
+
scrollEventThrottle = 16,
|
|
214
|
+
swipeDuration = 300
|
|
215
|
+
}) => {
|
|
216
|
+
const isWeb = Platform.OS === 'web';
|
|
217
|
+
const listRef = useRef(null);
|
|
218
|
+
const scrollRef = useRef(null);
|
|
219
|
+
const spacerHeight = visibleRest * itemHeight;
|
|
220
|
+
const total = data.length;
|
|
221
|
+
const maxIndex = Math.max(0, total - 1);
|
|
222
|
+
const minOffset = -maxIndex * itemHeight;
|
|
223
|
+
const containerHeight = itemHeight * (visibleRest * 2 + 1);
|
|
224
|
+
const rawSelectedIndex = clamp(selectedIndex, 0, maxIndex);
|
|
225
|
+
const enabledSelectedIndex = findEnabledIndex(data, rawSelectedIndex);
|
|
226
|
+
const safeSelectedIndex = enabledSelectedIndex >= 0 ? enabledSelectedIndex : rawSelectedIndex;
|
|
227
|
+
const visibleCount = visibleRest * 2 + 1;
|
|
228
|
+
const effectiveScrollThrottle = total > visibleCount * 20 ? 32 : scrollEventThrottle;
|
|
229
|
+
const webVirtualEnabled = total > visibleCount * 4;
|
|
230
|
+
const Spacer = useCallback(() => /*#__PURE__*/React.createElement(View, {
|
|
231
|
+
style: {
|
|
232
|
+
height: spacerHeight
|
|
233
|
+
}
|
|
234
|
+
}), [spacerHeight]);
|
|
235
|
+
const indicatorStyle = useMemo(() => [wheelStyles.indicator, {
|
|
236
|
+
height: itemHeight,
|
|
237
|
+
top: itemHeight * visibleRest,
|
|
238
|
+
borderColor: indicatorColor
|
|
239
|
+
}], [itemHeight, visibleRest, indicatorColor]);
|
|
240
|
+
const dragEndTimerRef = useRef(null);
|
|
241
|
+
const momentumRef = useRef(false);
|
|
242
|
+
const lastOffsetRef = useRef(0);
|
|
243
|
+
const clearDragEndTimer = useCallback(() => {
|
|
244
|
+
if (dragEndTimerRef.current) {
|
|
245
|
+
clearTimeout(dragEndTimerRef.current);
|
|
246
|
+
dragEndTimerRef.current = null;
|
|
247
|
+
}
|
|
248
|
+
}, []);
|
|
249
|
+
const emitIndexFromOffset = useCallback((offsetY, animated) => {
|
|
250
|
+
if (readOnly) return;
|
|
251
|
+
const {
|
|
252
|
+
index,
|
|
253
|
+
snapOffset
|
|
254
|
+
} = offsetToIndex(-offsetY, itemHeight, total, data);
|
|
255
|
+
const nextOffset = -snapOffset;
|
|
256
|
+
if (Math.abs(nextOffset - offsetY) > 0.5) {
|
|
257
|
+
listRef.current?.scrollToOffset({
|
|
258
|
+
offset: nextOffset,
|
|
259
|
+
animated
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
onChange(index);
|
|
263
|
+
}, [data, itemHeight, onChange, readOnly, total]);
|
|
264
|
+
useEffect(() => {
|
|
265
|
+
const offset = safeSelectedIndex * itemHeight;
|
|
266
|
+
if (isWeb) return;
|
|
267
|
+
scrollRef.current?.scrollTo({
|
|
268
|
+
y: offset,
|
|
269
|
+
animated: false
|
|
270
|
+
});
|
|
271
|
+
}, [isWeb, itemHeight, safeSelectedIndex]);
|
|
272
|
+
const [webOffset, setWebOffset] = useState(() => indexToOffset(safeSelectedIndex, itemHeight));
|
|
273
|
+
const webOffsetRef = useRef(webOffset);
|
|
274
|
+
const startOffsetRef = useRef(0);
|
|
275
|
+
const startTimeRef = useRef(0);
|
|
276
|
+
const [webTransition, setWebTransition] = useState(0);
|
|
277
|
+
const [webVelocityBucket, setWebVelocityBucket] = useState(0);
|
|
278
|
+
const webVelocityBucketRef = useRef(0);
|
|
279
|
+
const lastWheelTimeRef = useRef(null);
|
|
280
|
+
const wheelDeltaRef = useRef(0);
|
|
281
|
+
const wheelRafRef = useRef(null);
|
|
282
|
+
const pendingIndexRef = useRef(null);
|
|
283
|
+
const pendingTimerRef = useRef(null);
|
|
284
|
+
const rafIdRef = useRef(null);
|
|
285
|
+
const isInteractingRef = useRef(false);
|
|
286
|
+
const notifyInteractStart = useCallback(() => {
|
|
287
|
+
if (readOnly) return;
|
|
288
|
+
if (isInteractingRef.current) return;
|
|
289
|
+
isInteractingRef.current = true;
|
|
290
|
+
onInteractStart?.();
|
|
291
|
+
}, [onInteractStart, readOnly]);
|
|
292
|
+
const notifyInteractEnd = useCallback(() => {
|
|
293
|
+
if (!isInteractingRef.current) return;
|
|
294
|
+
isInteractingRef.current = false;
|
|
295
|
+
onInteractEnd?.();
|
|
296
|
+
}, [onInteractEnd]);
|
|
297
|
+
const stopRaf = useCallback(() => {
|
|
298
|
+
if (rafIdRef.current != null && typeof cancelAnimationFrame !== 'undefined') {
|
|
299
|
+
cancelAnimationFrame(rafIdRef.current);
|
|
300
|
+
rafIdRef.current = null;
|
|
301
|
+
}
|
|
302
|
+
if (wheelRafRef.current != null && typeof cancelAnimationFrame !== 'undefined') {
|
|
303
|
+
cancelAnimationFrame(wheelRafRef.current);
|
|
304
|
+
wheelRafRef.current = null;
|
|
305
|
+
}
|
|
306
|
+
}, []);
|
|
307
|
+
const clearPendingTimer = useCallback(() => {
|
|
308
|
+
if (pendingTimerRef.current) {
|
|
309
|
+
clearTimeout(pendingTimerRef.current);
|
|
310
|
+
pendingTimerRef.current = null;
|
|
311
|
+
}
|
|
312
|
+
}, []);
|
|
313
|
+
useEffect(() => {
|
|
314
|
+
return () => {
|
|
315
|
+
clearDragEndTimer();
|
|
316
|
+
clearPendingTimer();
|
|
317
|
+
stopRaf();
|
|
318
|
+
};
|
|
319
|
+
}, [clearDragEndTimer, clearPendingTimer, stopRaf]);
|
|
320
|
+
const setVelocityBucket = useCallback(velocity => {
|
|
321
|
+
const next = getVelocityBucket(velocity);
|
|
322
|
+
if (next !== webVelocityBucketRef.current) {
|
|
323
|
+
webVelocityBucketRef.current = next;
|
|
324
|
+
setWebVelocityBucket(next);
|
|
325
|
+
}
|
|
326
|
+
}, []);
|
|
327
|
+
const updateWheelVelocity = useCallback(delta => {
|
|
328
|
+
const now = Date.now();
|
|
329
|
+
const last = lastWheelTimeRef.current;
|
|
330
|
+
if (last != null) {
|
|
331
|
+
const dt = Math.max(1, now - last);
|
|
332
|
+
setVelocityBucket(delta / dt);
|
|
333
|
+
}
|
|
334
|
+
lastWheelTimeRef.current = now;
|
|
335
|
+
}, [setVelocityBucket]);
|
|
336
|
+
useEffect(() => {
|
|
337
|
+
if (!isWeb) return;
|
|
338
|
+
clearPendingTimer();
|
|
339
|
+
pendingIndexRef.current = null;
|
|
340
|
+
setWebTransition(0);
|
|
341
|
+
const next = indexToOffset(safeSelectedIndex, itemHeight);
|
|
342
|
+
webOffsetRef.current = next;
|
|
343
|
+
setWebOffset(next);
|
|
344
|
+
}, [clearPendingTimer, isWeb, itemHeight, safeSelectedIndex, setWebTransition]);
|
|
345
|
+
const finalizePendingChange = useCallback(() => {
|
|
346
|
+
if (readOnly) return;
|
|
347
|
+
const nextIndex = pendingIndexRef.current;
|
|
348
|
+
if (nextIndex == null) return;
|
|
349
|
+
pendingIndexRef.current = null;
|
|
350
|
+
clearPendingTimer();
|
|
351
|
+
setWebTransition(0);
|
|
352
|
+
notifyInteractEnd();
|
|
353
|
+
onChange(nextIndex);
|
|
354
|
+
}, [clearPendingTimer, onChange, readOnly, setWebTransition]);
|
|
355
|
+
const startWebSnap = useCallback(targetIndex => {
|
|
356
|
+
if (readOnly) return;
|
|
357
|
+
notifyInteractStart();
|
|
358
|
+
const clampedIndex = clamp(targetIndex, 0, maxIndex);
|
|
359
|
+
const targetOffset = indexToOffset(clampedIndex, itemHeight);
|
|
360
|
+
clearPendingTimer();
|
|
361
|
+
pendingIndexRef.current = clampedIndex;
|
|
362
|
+
webOffsetRef.current = targetOffset;
|
|
363
|
+
setWebTransition(swipeDuration);
|
|
364
|
+
setWebOffset(targetOffset);
|
|
365
|
+
if (swipeDuration <= 0) {
|
|
366
|
+
finalizePendingChange();
|
|
367
|
+
} else {
|
|
368
|
+
pendingTimerRef.current = setTimeout(finalizePendingChange, swipeDuration + 80);
|
|
369
|
+
}
|
|
370
|
+
}, [clearPendingTimer, finalizePendingChange, itemHeight, maxIndex, readOnly, swipeDuration]);
|
|
371
|
+
const handleWheel = useCallback(event => {
|
|
372
|
+
if (readOnly) return;
|
|
373
|
+
const delta = event.nativeEvent?.deltaY ?? 0;
|
|
374
|
+
if (!delta) return;
|
|
375
|
+
wheelDeltaRef.current += delta;
|
|
376
|
+
if (wheelRafRef.current != null || typeof requestAnimationFrame === 'undefined') {
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
wheelRafRef.current = requestAnimationFrame(() => {
|
|
380
|
+
wheelRafRef.current = null;
|
|
381
|
+
const queued = wheelDeltaRef.current;
|
|
382
|
+
wheelDeltaRef.current = 0;
|
|
383
|
+
if (!queued) return;
|
|
384
|
+
updateWheelVelocity(queued);
|
|
385
|
+
const direction = queued > 0 ? 1 : -1;
|
|
386
|
+
const {
|
|
387
|
+
index
|
|
388
|
+
} = offsetToIndex(webOffsetRef.current, itemHeight, total, data);
|
|
389
|
+
const nextIndex = clamp(index + direction, 0, maxIndex);
|
|
390
|
+
startWebSnap(nextIndex);
|
|
391
|
+
});
|
|
392
|
+
}, [data, itemHeight, maxIndex, readOnly, startWebSnap, total, updateWheelVelocity]);
|
|
393
|
+
const webIndex = clamp(Math.round(-webOffset / itemHeight), 0, maxIndex);
|
|
394
|
+
const webRender = useMemo(() => {
|
|
395
|
+
if (!isWeb || total <= 0) {
|
|
396
|
+
return {
|
|
397
|
+
items: null,
|
|
398
|
+
topSpacer: null,
|
|
399
|
+
bottomSpacer: null
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
let startIndex = 0;
|
|
403
|
+
let endIndex = maxIndex;
|
|
404
|
+
if (webVirtualEnabled) {
|
|
405
|
+
const baseBuffer = Math.max(visibleCount * 2, 8);
|
|
406
|
+
const velocityBoost = webVelocityBucket === 2 ? visibleCount * 4 : webVelocityBucket === 1 ? visibleCount * 2 : 0;
|
|
407
|
+
const buffer = Math.min(baseBuffer + velocityBoost, Math.max(visibleCount * 6, 24));
|
|
408
|
+
startIndex = clamp(webIndex - buffer, 0, maxIndex);
|
|
409
|
+
endIndex = clamp(webIndex + buffer, 0, maxIndex);
|
|
410
|
+
}
|
|
411
|
+
const items = [];
|
|
412
|
+
for (let index = startIndex; index <= endIndex; index += 1) {
|
|
413
|
+
const item = data[index];
|
|
414
|
+
if (!item) continue;
|
|
415
|
+
items.push(/*#__PURE__*/React.createElement(WheelPickerItem, {
|
|
416
|
+
key: `${index}-${String(item.value ?? '')}`,
|
|
417
|
+
item: item,
|
|
418
|
+
index: index,
|
|
419
|
+
itemHeight: itemHeight,
|
|
420
|
+
active: index === safeSelectedIndex,
|
|
421
|
+
disabled: !!item.disabled,
|
|
422
|
+
renderItem: renderItem
|
|
423
|
+
}));
|
|
424
|
+
}
|
|
425
|
+
const topHeight = startIndex * itemHeight;
|
|
426
|
+
const bottomHeight = (maxIndex - endIndex) * itemHeight;
|
|
427
|
+
return {
|
|
428
|
+
items,
|
|
429
|
+
topSpacer: topHeight > 0 && /*#__PURE__*/React.createElement(View, {
|
|
430
|
+
style: {
|
|
431
|
+
height: topHeight
|
|
432
|
+
}
|
|
433
|
+
}),
|
|
434
|
+
bottomSpacer: bottomHeight > 0 && /*#__PURE__*/React.createElement(View, {
|
|
435
|
+
style: {
|
|
436
|
+
height: bottomHeight
|
|
437
|
+
}
|
|
438
|
+
})
|
|
439
|
+
};
|
|
440
|
+
}, [data, isWeb, itemHeight, maxIndex, renderItem, safeSelectedIndex, total, visibleCount, webIndex, webVelocityBucket, webVirtualEnabled]);
|
|
441
|
+
const webTransform = useMemo(() => ({
|
|
442
|
+
transform: [{
|
|
443
|
+
translateY: webOffset
|
|
444
|
+
}]
|
|
445
|
+
}), [webOffset]);
|
|
446
|
+
const webTransitionStyle = useMemo(() => webTransition ? {
|
|
447
|
+
transitionProperty: 'transform',
|
|
448
|
+
transitionDuration: `${webTransition}ms`,
|
|
449
|
+
transitionTimingFunction: 'cubic-bezier(0.23, 1, 0.68, 1)',
|
|
450
|
+
willChange: 'transform'
|
|
451
|
+
} : undefined, [webTransition]);
|
|
452
|
+
const handleWebTransitionEnd = useCallback(event => {
|
|
453
|
+
const propertyName = event.nativeEvent?.propertyName ?? event.propertyName;
|
|
454
|
+
if (propertyName && propertyName !== 'transform' && propertyName !== 'webkitTransform') return;
|
|
455
|
+
finalizePendingChange();
|
|
456
|
+
}, [finalizePendingChange]);
|
|
457
|
+
const panResponder = useMemo(() => PanResponder.create({
|
|
458
|
+
onStartShouldSetPanResponder: () => !readOnly,
|
|
459
|
+
onMoveShouldSetPanResponder: () => !readOnly,
|
|
460
|
+
onPanResponderGrant: () => {
|
|
461
|
+
stopRaf();
|
|
462
|
+
pendingIndexRef.current = null;
|
|
463
|
+
notifyInteractStart();
|
|
464
|
+
setWebTransition(0);
|
|
465
|
+
startOffsetRef.current = webOffsetRef.current;
|
|
466
|
+
startTimeRef.current = Date.now();
|
|
467
|
+
},
|
|
468
|
+
onPanResponderMove: (_, gesture) => {
|
|
469
|
+
if (readOnly) return;
|
|
470
|
+
setVelocityBucket(gesture.vy);
|
|
471
|
+
const next = clamp(startOffsetRef.current + gesture.dy, minOffset, 0);
|
|
472
|
+
webOffsetRef.current = next;
|
|
473
|
+
if (typeof requestAnimationFrame === 'undefined') {
|
|
474
|
+
setWebOffset(next);
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
if (rafIdRef.current != null) return;
|
|
478
|
+
rafIdRef.current = requestAnimationFrame(() => {
|
|
479
|
+
rafIdRef.current = null;
|
|
480
|
+
setWebOffset(webOffsetRef.current);
|
|
481
|
+
});
|
|
482
|
+
},
|
|
483
|
+
onPanResponderRelease: (_, gesture) => {
|
|
484
|
+
if (readOnly) return;
|
|
485
|
+
setVelocityBucket(0);
|
|
486
|
+
const duration = Date.now() - startTimeRef.current;
|
|
487
|
+
const distance = gesture.dy;
|
|
488
|
+
let target = clamp(startOffsetRef.current + distance, minOffset, 0);
|
|
489
|
+
if (shouldMomentum(distance, duration)) {
|
|
490
|
+
target = momentumTarget(distance, duration, startOffsetRef.current, itemHeight, minOffset);
|
|
491
|
+
}
|
|
492
|
+
const {
|
|
493
|
+
index
|
|
494
|
+
} = offsetToIndex(target, itemHeight, total, data);
|
|
495
|
+
startWebSnap(index);
|
|
496
|
+
},
|
|
497
|
+
onPanResponderTerminationRequest: () => false,
|
|
498
|
+
onPanResponderTerminate: () => {
|
|
499
|
+
notifyInteractEnd();
|
|
500
|
+
setWebTransition(0);
|
|
501
|
+
}
|
|
502
|
+
}), [data, itemHeight, minOffset, notifyInteractEnd, notifyInteractStart, readOnly, setVelocityBucket, startWebSnap, stopRaf, total]);
|
|
503
|
+
if (isWeb) {
|
|
504
|
+
return /*#__PURE__*/React.createElement(View, _extends({
|
|
505
|
+
style: [wheelStyles.column, {
|
|
506
|
+
height: containerHeight
|
|
507
|
+
}, webOnlyStyles.grab],
|
|
508
|
+
onWheel: handleWheel
|
|
509
|
+
}, panResponder.panHandlers), /*#__PURE__*/React.createElement(View, {
|
|
510
|
+
style: indicatorStyle,
|
|
511
|
+
pointerEvents: "none"
|
|
512
|
+
}), /*#__PURE__*/React.createElement(View, {
|
|
513
|
+
style: [webTransform, isWeb ? webTransitionStyle : undefined],
|
|
514
|
+
onTransitionEnd: handleWebTransitionEnd
|
|
515
|
+
}, /*#__PURE__*/React.createElement(Spacer, null), webRender.topSpacer, webRender.items, webRender.bottomSpacer, /*#__PURE__*/React.createElement(Spacer, null)));
|
|
516
|
+
}
|
|
517
|
+
const shouldCapture = !readOnly;
|
|
518
|
+
const contentContainerStyle = useMemo(() => ({
|
|
519
|
+
paddingVertical: spacerHeight
|
|
520
|
+
}), [spacerHeight]);
|
|
521
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
522
|
+
style: [wheelStyles.column, {
|
|
523
|
+
height: containerHeight
|
|
524
|
+
}],
|
|
525
|
+
collapsable: false
|
|
526
|
+
}, /*#__PURE__*/React.createElement(View, {
|
|
527
|
+
style: indicatorStyle,
|
|
528
|
+
pointerEvents: "none"
|
|
529
|
+
}), /*#__PURE__*/React.createElement(ScrollView, {
|
|
530
|
+
ref: scrollRef,
|
|
531
|
+
showsVerticalScrollIndicator: false,
|
|
532
|
+
scrollEventThrottle: effectiveScrollThrottle,
|
|
533
|
+
decelerationRate: decelerationRate,
|
|
534
|
+
snapToInterval: itemHeight,
|
|
535
|
+
snapToAlignment: "start",
|
|
536
|
+
bounces: false,
|
|
537
|
+
overScrollMode: "never",
|
|
538
|
+
nestedScrollEnabled: true,
|
|
539
|
+
contentContainerStyle: contentContainerStyle,
|
|
540
|
+
onStartShouldSetResponderCapture: () => shouldCapture,
|
|
541
|
+
onMoveShouldSetResponderCapture: () => shouldCapture,
|
|
542
|
+
onScroll: e => {
|
|
543
|
+
lastOffsetRef.current = e.nativeEvent.contentOffset.y;
|
|
544
|
+
},
|
|
545
|
+
onScrollBeginDrag: () => {
|
|
546
|
+
momentumRef.current = false;
|
|
547
|
+
clearDragEndTimer();
|
|
548
|
+
notifyInteractStart();
|
|
549
|
+
},
|
|
550
|
+
onScrollEndDrag: e => {
|
|
551
|
+
if (readOnly) return;
|
|
552
|
+
const y = e.nativeEvent.contentOffset.y;
|
|
553
|
+
lastOffsetRef.current = y;
|
|
554
|
+
clearDragEndTimer();
|
|
555
|
+
dragEndTimerRef.current = setTimeout(() => {
|
|
556
|
+
if (!momentumRef.current) {
|
|
557
|
+
emitIndexFromOffset(lastOffsetRef.current, true);
|
|
558
|
+
notifyInteractEnd();
|
|
559
|
+
}
|
|
560
|
+
}, 80);
|
|
561
|
+
},
|
|
562
|
+
onMomentumScrollBegin: () => {
|
|
563
|
+
momentumRef.current = true;
|
|
564
|
+
clearDragEndTimer();
|
|
565
|
+
notifyInteractStart();
|
|
566
|
+
},
|
|
567
|
+
onMomentumScrollEnd: e => {
|
|
568
|
+
momentumRef.current = false;
|
|
569
|
+
clearDragEndTimer();
|
|
570
|
+
const y = e.nativeEvent.contentOffset.y;
|
|
571
|
+
lastOffsetRef.current = y;
|
|
572
|
+
emitIndexFromOffset(y, false);
|
|
573
|
+
notifyInteractEnd();
|
|
574
|
+
},
|
|
575
|
+
scrollEnabled: !readOnly
|
|
576
|
+
}, data.map((item, index) => /*#__PURE__*/React.createElement(WheelPickerItem, {
|
|
577
|
+
key: `${index}-${String(item.value ?? '')}`,
|
|
578
|
+
item: item,
|
|
579
|
+
index: index,
|
|
580
|
+
itemHeight: itemHeight,
|
|
581
|
+
active: index === safeSelectedIndex,
|
|
582
|
+
disabled: !!item.disabled,
|
|
583
|
+
renderItem: renderItem
|
|
584
|
+
}))));
|
|
585
|
+
};
|
|
586
|
+
const WheelPicker = /*#__PURE__*/React.memo(WheelPickerInner);
|
|
587
|
+
const webOnlyStyles = StyleSheet.create({
|
|
588
|
+
grab: {
|
|
589
|
+
cursor: 'pointer',
|
|
590
|
+
userSelect: 'none',
|
|
591
|
+
touchAction: 'none'
|
|
592
|
+
}
|
|
593
|
+
});
|
|
10
594
|
export function usePickerValue({
|
|
11
595
|
columns,
|
|
12
596
|
valueProp,
|
|
@@ -15,7 +599,7 @@ export function usePickerValue({
|
|
|
15
599
|
onChange,
|
|
16
600
|
onConfirm
|
|
17
601
|
}) {
|
|
18
|
-
const preparedColumns = prepareColumns(columns);
|
|
602
|
+
const preparedColumns = useMemo(() => prepareColumns(columns), [columns]);
|
|
19
603
|
const isControlled = valueProp !== undefined;
|
|
20
604
|
const [innerValue, setInnerValue] = useState(() => {
|
|
21
605
|
const initial = toArrayValue(valueProp ?? defaultValue);
|
|
@@ -33,7 +617,7 @@ export function usePickerValue({
|
|
|
33
617
|
commitValue(next);
|
|
34
618
|
}
|
|
35
619
|
}, [commitValue, isControlled, valueProp]);
|
|
36
|
-
const normalized = normalizePicker(preparedColumns, innerValue);
|
|
620
|
+
const normalized = useMemo(() => normalizePicker(preparedColumns, innerValue), [preparedColumns, innerValue]);
|
|
37
621
|
useEffect(() => {
|
|
38
622
|
if (isControlled) return;
|
|
39
623
|
if (!shallowEqualArray(innerValue, normalized.values)) {
|
|
@@ -59,6 +643,7 @@ export function usePickerValue({
|
|
|
59
643
|
onConfirm?.(normalized.values, normalized.options);
|
|
60
644
|
}, [normalized, onConfirm]);
|
|
61
645
|
return {
|
|
646
|
+
preparedColumns,
|
|
62
647
|
normalized,
|
|
63
648
|
handleSelect,
|
|
64
649
|
handleConfirm
|
|
@@ -69,7 +654,7 @@ const getVisibleCount = count => {
|
|
|
69
654
|
return normalized % 2 === 0 ? normalized + 1 : normalized;
|
|
70
655
|
};
|
|
71
656
|
const GRADIENT_OVERLAY_ALPHA = 0.25;
|
|
72
|
-
const GRADIENT_STEPS = [0.
|
|
657
|
+
const GRADIENT_STEPS = [0.95, 0.75, 0.55, 0.35];
|
|
73
658
|
const GRADIENT_STEPS_REVERSED = [...GRADIENT_STEPS].reverse();
|
|
74
659
|
const GradientMask = ({
|
|
75
660
|
height,
|
|
@@ -78,14 +663,14 @@ const GradientMask = ({
|
|
|
78
663
|
maskType
|
|
79
664
|
}) => {
|
|
80
665
|
const isWeb = Platform.OS === 'web';
|
|
81
|
-
const baseStyle = [styles.gradientMask, {
|
|
666
|
+
const baseStyle = useMemo(() => [styles.gradientMask, {
|
|
82
667
|
height
|
|
83
668
|
}, position === 'top' ? {
|
|
84
669
|
top: 0
|
|
85
670
|
} : {
|
|
86
671
|
bottom: 0
|
|
87
|
-
}];
|
|
88
|
-
const overlayColor = withAlpha(color, GRADIENT_OVERLAY_ALPHA);
|
|
672
|
+
}], [height, position]);
|
|
673
|
+
const overlayColor = useMemo(() => withAlpha(color, GRADIENT_OVERLAY_ALPHA), [color]);
|
|
89
674
|
if (maskType === 'solid') {
|
|
90
675
|
return /*#__PURE__*/React.createElement(View, {
|
|
91
676
|
pointerEvents: "none",
|
|
@@ -120,17 +705,6 @@ const GradientMask = ({
|
|
|
120
705
|
}
|
|
121
706
|
})));
|
|
122
707
|
};
|
|
123
|
-
const isCascadeColumns = columns => {
|
|
124
|
-
if (!Array.isArray(columns) || columns.length === 0) return false;
|
|
125
|
-
const first = columns[0];
|
|
126
|
-
if (Array.isArray(first)) return false;
|
|
127
|
-
if (isObject(first) && 'options' in first) return false;
|
|
128
|
-
return columns.some(option => {
|
|
129
|
-
if (!isObject(option)) return false;
|
|
130
|
-
const children = option.children;
|
|
131
|
-
return Array.isArray(children) && children.length > 0;
|
|
132
|
-
});
|
|
133
|
-
};
|
|
134
708
|
const PickerColumn = /*#__PURE__*/React.memo(props => {
|
|
135
709
|
const {
|
|
136
710
|
columnIndex,
|
|
@@ -149,11 +723,13 @@ const PickerColumn = /*#__PURE__*/React.memo(props => {
|
|
|
149
723
|
swipeDuration
|
|
150
724
|
} = props;
|
|
151
725
|
const restVisible = Math.max(1, Math.floor((visibleItemCount - 1) / 2));
|
|
152
|
-
const
|
|
726
|
+
const valueIndexMap = useMemo(() => new Map(options.map((option, idx) => [option.value, idx])), [options]);
|
|
727
|
+
const selectedIndex = useMemo(() => {
|
|
153
728
|
if (!options.length) return 0;
|
|
154
|
-
const idx =
|
|
155
|
-
|
|
156
|
-
|
|
729
|
+
const idx = valueIndexMap.get(value);
|
|
730
|
+
const startIndex = typeof idx === 'number' && idx >= 0 ? idx : 0;
|
|
731
|
+
return findEnabledIndex(options, startIndex);
|
|
732
|
+
}, [options, value, valueIndexMap]);
|
|
157
733
|
const handleChange = useCallback(index => {
|
|
158
734
|
const target = findEnabledIndex(options, index);
|
|
159
735
|
const option = options[target];
|
|
@@ -175,10 +751,9 @@ const PickerColumn = /*#__PURE__*/React.memo(props => {
|
|
|
175
751
|
decelerationRate: decelerationRate,
|
|
176
752
|
scrollEventThrottle: scrollEventThrottle,
|
|
177
753
|
swipeDuration: swipeDuration,
|
|
178
|
-
renderItem: item => {
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
const disabled = !!item.disabled;
|
|
754
|
+
renderItem: (item, _index, meta) => {
|
|
755
|
+
const active = meta?.active ?? false;
|
|
756
|
+
const disabled = meta?.disabled ?? false;
|
|
182
757
|
const textColor = disabled ? tokens.colors.textDisabled : active ? tokens.colors.text : tokens.colors.textMuted;
|
|
183
758
|
const content = optionRender ? optionRender(item, {
|
|
184
759
|
columnIndex,
|
|
@@ -231,8 +806,8 @@ const Picker = props => {
|
|
|
231
806
|
loading = false,
|
|
232
807
|
readOnly = false,
|
|
233
808
|
decelerationRate = Platform.select({
|
|
234
|
-
ios: 0.
|
|
235
|
-
android: 0.
|
|
809
|
+
ios: 0.999,
|
|
810
|
+
android: 0.997,
|
|
236
811
|
default: 0.989
|
|
237
812
|
}) ?? 'normal',
|
|
238
813
|
swipeDuration = tokens.defaults.swipeDuration,
|
|
@@ -253,11 +828,11 @@ const Picker = props => {
|
|
|
253
828
|
...rest
|
|
254
829
|
} = props;
|
|
255
830
|
const visibleItemCount = getVisibleCount(visibleItemCountProp ?? tokens.defaults.visibleItemCount);
|
|
256
|
-
const isCascade = isCascadeColumns(columns);
|
|
257
831
|
const {
|
|
258
832
|
normalized,
|
|
259
833
|
handleSelect,
|
|
260
|
-
handleConfirm
|
|
834
|
+
handleConfirm,
|
|
835
|
+
preparedColumns
|
|
261
836
|
} = usePickerValue({
|
|
262
837
|
columns,
|
|
263
838
|
valueProp,
|
|
@@ -266,6 +841,7 @@ const Picker = props => {
|
|
|
266
841
|
onChange,
|
|
267
842
|
onConfirm
|
|
268
843
|
});
|
|
844
|
+
const isCascade = preparedColumns.type === 'cascade';
|
|
269
845
|
const renderActionContent = (content, color) => {
|
|
270
846
|
if (/*#__PURE__*/React.isValidElement(content)) return /*#__PURE__*/React.createElement(View, {
|
|
271
847
|
style: {
|