react-native-system-ui 1.0.1 → 1.0.3
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 +44 -24
- package/dist/cjs/components/action-sheet/ActionSheet.js +1 -297
- package/dist/cjs/components/action-sheet/index.js +1 -16
- package/dist/cjs/components/action-sheet/tokens.js +1 -133
- package/dist/cjs/components/area/Area.js +1 -127
- package/dist/cjs/components/area/index.js +1 -9
- package/dist/cjs/components/area/tokens.js +1 -14
- package/dist/cjs/components/avatar/Avatar.js +1 -125
- package/dist/cjs/components/avatar/index.js +1 -18
- package/dist/cjs/components/avatar/tokens.js +1 -56
- package/dist/cjs/components/badge/Badge.js +1 -166
- package/dist/cjs/components/badge/index.js +1 -8
- package/dist/cjs/components/badge/tokens.js +1 -81
- package/dist/cjs/components/button/Button.js +1 -203
- package/dist/cjs/components/button/ButtonContext.js +1 -12
- package/dist/cjs/components/button/ButtonGroup.js +1 -65
- package/dist/cjs/components/button/index.js +1 -12
- package/dist/cjs/components/button/tokens.js +1 -176
- package/dist/cjs/components/calendar/Calendar.js +1 -452
- package/dist/cjs/components/calendar/index.js +1 -9
- package/dist/cjs/components/calendar/tokens.js +1 -129
- package/dist/cjs/components/cascader/Cascader.js +1 -481
- package/dist/cjs/components/cascader/index.js +1 -15
- package/dist/cjs/components/cascader/tokens.js +1 -138
- package/dist/cjs/components/cascader/useCascaderExtend.js +1 -39
- package/dist/cjs/components/cell/Cell.js +1 -181
- package/dist/cjs/components/cell/CellContext.js +1 -19
- package/dist/cjs/components/cell/CellGroup.js +1 -100
- package/dist/cjs/components/cell/index.js +1 -19
- package/dist/cjs/components/cell/tokens.js +1 -173
- package/dist/cjs/components/checkbox/Checkbox.js +1 -251
- package/dist/cjs/components/checkbox/CheckboxContext.js +1 -12
- package/dist/cjs/components/checkbox/CheckboxGroup.js +1 -148
- package/dist/cjs/components/checkbox/index.js +1 -16
- package/dist/cjs/components/checkbox/tokens.js +1 -97
- package/dist/cjs/components/circle/Circle.js +1 -212
- package/dist/cjs/components/circle/index.js +1 -9
- package/dist/cjs/components/circle/tokens.js +1 -55
- package/dist/cjs/components/collapse/Collapse.js +1 -311
- package/dist/cjs/components/collapse/index.js +1 -8
- package/dist/cjs/components/collapse/tokens.js +1 -81
- package/dist/cjs/components/config-provider/ConfigProvider.js +1 -44
- package/dist/cjs/components/config-provider/DirectionContext.js +1 -15
- package/dist/cjs/components/config-provider/LocaleContext.js +1 -16
- package/dist/cjs/components/config-provider/index.js +1 -40
- package/dist/cjs/components/config-provider/locale/en-US.js +1 -112
- package/dist/cjs/components/config-provider/locale/zh-CN.js +1 -112
- package/dist/cjs/components/config-provider/tokens.js +1 -11
- package/dist/cjs/components/config-provider/useDirection.js +1 -16
- package/dist/cjs/components/config-provider/useLocale.js +1 -16
- package/dist/cjs/components/count-down/CountDown.js +1 -88
- package/dist/cjs/components/count-down/index.js +1 -15
- package/dist/cjs/components/count-down/tokens.js +1 -34
- package/dist/cjs/components/datetime-picker/DatetimePicker.js +1 -319
- package/dist/cjs/components/datetime-picker/index.js +1 -9
- package/dist/cjs/components/datetime-picker/tokens.js +1 -22
- package/dist/cjs/components/dialog/Dialog.js +1 -433
- package/dist/cjs/components/dialog/imperative.js +1 -199
- package/dist/cjs/components/dialog/index.js +1 -23
- package/dist/cjs/components/dialog/tokens.js +1 -64
- package/dist/cjs/components/divider/Divider.js +1 -126
- package/dist/cjs/components/divider/index.js +1 -8
- package/dist/cjs/components/divider/tokens.js +1 -62
- package/dist/cjs/components/empty/Empty.js +1 -125
- package/dist/cjs/components/empty/index.js +1 -8
- package/dist/cjs/components/empty/tokens.js +1 -55
- package/dist/cjs/components/error-boundary/ErrorBoundary.js +1 -74
- package/dist/cjs/components/error-boundary/index.js +1 -19
- package/dist/cjs/components/field/Field.js +1 -565
- package/dist/cjs/components/field/index.js +1 -29
- package/dist/cjs/components/field/tokens.js +1 -150
- package/dist/cjs/components/flex/Flex.js +1 -85
- package/dist/cjs/components/flex/FlexContext.js +1 -12
- package/dist/cjs/components/flex/FlexItem.js +1 -95
- package/dist/cjs/components/flex/index.js +1 -19
- package/dist/cjs/components/flex/tokens.js +1 -21
- package/dist/cjs/components/form/Form.js +1 -340
- package/dist/cjs/components/form/FormContext.js +1 -12
- package/dist/cjs/components/form/FormItem.js +1 -151
- package/dist/cjs/components/form/FormList.js +1 -95
- package/dist/cjs/components/form/index.js +1 -50
- package/dist/cjs/components/form/tokens.js +1 -14
- package/dist/cjs/components/form/utils.js +1 -56
- package/dist/cjs/components/grid/Grid.js +1 -118
- package/dist/cjs/components/grid/GridContext.js +1 -12
- package/dist/cjs/components/grid/GridItem.js +1 -158
- package/dist/cjs/components/grid/index.js +1 -12
- package/dist/cjs/components/grid/tokens.js +1 -105
- package/dist/cjs/components/image/Image.js +1 -263
- package/dist/cjs/components/image/index.js +1 -16
- package/dist/cjs/components/image/tokens.js +1 -66
- package/dist/cjs/components/image-preview/ImagePreview.js +1 -398
- package/dist/cjs/components/image-preview/imperative.js +1 -72
- package/dist/cjs/components/image-preview/index.js +1 -17
- package/dist/cjs/components/image-preview/tokens.js +1 -43
- package/dist/cjs/components/index.js +1 -769
- package/dist/cjs/components/input/Input.js +1 -122
- package/dist/cjs/components/input/index.js +1 -15
- package/dist/cjs/components/input/tokens.js +1 -22
- package/dist/cjs/components/loading/Loading.js +1 -76
- package/dist/cjs/components/loading/index.js +1 -8
- package/dist/cjs/components/loading/tokens.js +1 -32
- package/dist/cjs/components/nav-bar/NavBar.js +1 -196
- package/dist/cjs/components/nav-bar/index.js +1 -16
- package/dist/cjs/components/nav-bar/tokens.js +1 -90
- package/dist/cjs/components/notice-bar/NoticeBar.js +1 -369
- package/dist/cjs/components/notice-bar/index.js +1 -8
- package/dist/cjs/components/notice-bar/tokens.js +1 -39
- package/dist/cjs/components/notify/Notify.js +1 -262
- package/dist/cjs/components/notify/imperative.js +1 -145
- package/dist/cjs/components/notify/index.js +1 -10
- package/dist/cjs/components/notify/tokens.js +1 -74
- package/dist/cjs/components/number-keyboard/NumberKeyboard.js +1 -487
- package/dist/cjs/components/number-keyboard/index.js +1 -15
- package/dist/cjs/components/number-keyboard/tokens.js +1 -59
- package/dist/cjs/components/overlay/Overlay.js +1 -81
- package/dist/cjs/components/overlay/index.js +1 -28
- package/dist/cjs/components/overlay/tokens.js +1 -13
- package/dist/cjs/components/password-input/PasswordInput.js +1 -346
- package/dist/cjs/components/password-input/index.js +1 -13
- package/dist/cjs/components/password-input/tokens.js +1 -53
- package/dist/cjs/components/picker/Picker.js +1 -1056
- package/dist/cjs/components/picker/index.js +1 -15
- package/dist/cjs/components/picker/tokens.js +1 -53
- package/dist/cjs/components/popup/Popup.js +1 -518
- package/dist/cjs/components/popup/index.js +1 -15
- package/dist/cjs/components/popup/tokens.js +1 -62
- package/dist/cjs/components/portal/Portal.js +1 -50
- package/dist/cjs/components/portal/PortalContext.js +1 -15
- package/dist/cjs/components/portal/PortalHost.js +1 -253
- package/dist/cjs/components/portal/index.js +1 -25
- package/dist/cjs/components/portal/tokens.js +1 -11
- package/dist/cjs/components/progress/Progress.js +1 -216
- package/dist/cjs/components/progress/index.js +1 -14
- package/dist/cjs/components/progress/tokens.js +1 -52
- package/dist/cjs/components/radio/Radio.js +1 -245
- package/dist/cjs/components/radio/RadioContext.js +1 -12
- package/dist/cjs/components/radio/RadioGroup.js +1 -113
- package/dist/cjs/components/radio/index.js +1 -16
- package/dist/cjs/components/radio/tokens.js +1 -92
- package/dist/cjs/components/safe-area-view/SafeAreaView.js +1 -59
- package/dist/cjs/components/safe-area-view/index.js +1 -12
- package/dist/cjs/components/safe-area-view/tokens.js +1 -11
- package/dist/cjs/components/search/Search.js +1 -215
- package/dist/cjs/components/search/index.js +1 -15
- package/dist/cjs/components/search/tokens.js +1 -54
- package/dist/cjs/components/selector/Selector.js +1 -185
- package/dist/cjs/components/selector/index.js +1 -15
- package/dist/cjs/components/selector/tokens.js +1 -100
- package/dist/cjs/components/share-sheet/ShareSheet.js +1 -286
- package/dist/cjs/components/share-sheet/index.js +1 -16
- package/dist/cjs/components/share-sheet/tokens.js +1 -55
- package/dist/cjs/components/sidebar/Sidebar.js +1 -103
- package/dist/cjs/components/sidebar/SidebarContext.js +1 -17
- package/dist/cjs/components/sidebar/SidebarItem.js +1 -103
- package/dist/cjs/components/sidebar/index.js +1 -26
- package/dist/cjs/components/sidebar/tokens.js +1 -93
- package/dist/cjs/components/skeleton/Skeleton.js +1 -162
- package/dist/cjs/components/skeleton/index.js +1 -22
- package/dist/cjs/components/skeleton/tokens.js +1 -39
- package/dist/cjs/components/slider/Slider.js +1 -633
- package/dist/cjs/components/slider/index.js +1 -8
- package/dist/cjs/components/slider/tokens.js +1 -37
- package/dist/cjs/components/space/Space.js +1 -134
- package/dist/cjs/components/space/index.js +1 -18
- package/dist/cjs/components/space/tokens.js +1 -39
- package/dist/cjs/components/stepper/Stepper.js +1 -484
- package/dist/cjs/components/stepper/index.js +1 -15
- package/dist/cjs/components/stepper/tokens.js +1 -60
- package/dist/cjs/components/swiper/Swiper.js +1 -364
- package/dist/cjs/components/swiper/SwiperItem.js +1 -12
- package/dist/cjs/components/swiper/SwiperPagIndicator.js +1 -106
- package/dist/cjs/components/swiper/index.js +1 -40
- package/dist/cjs/components/swiper/tokens.js +1 -18
- package/dist/cjs/components/switch/Switch.js +1 -102
- package/dist/cjs/components/switch/index.js +1 -15
- package/dist/cjs/components/switch/tokens.js +1 -31
- package/dist/cjs/components/tabbar/Tabbar.js +1 -149
- package/dist/cjs/components/tabbar/TabbarContext.js +1 -17
- package/dist/cjs/components/tabbar/TabbarItem.js +1 -153
- package/dist/cjs/components/tabbar/index.js +1 -25
- package/dist/cjs/components/tabbar/tokens.js +1 -41
- package/dist/cjs/components/tabs/Tabs.js +1 -860
- package/dist/cjs/components/tabs/index.js +1 -25
- package/dist/cjs/components/tabs/tokens.js +1 -111
- package/dist/cjs/components/tag/Tag.js +1 -130
- package/dist/cjs/components/tag/index.js +1 -8
- package/dist/cjs/components/tag/tokens.js +1 -104
- package/dist/cjs/components/toast/Toast.js +1 -303
- package/dist/cjs/components/toast/imperative.js +1 -144
- package/dist/cjs/components/toast/index.js +1 -10
- package/dist/cjs/components/toast/tokens.js +1 -43
- package/dist/cjs/components/typography/Typography.js +1 -181
- package/dist/cjs/components/typography/index.js +1 -9
- package/dist/cjs/components/typography/tokens.js +1 -88
- package/dist/cjs/components/water-mark/WaterMark.js +1 -172
- package/dist/cjs/components/water-mark/index.js +1 -22
- package/dist/cjs/components/water-mark/tokens.js +1 -54
- package/dist/cjs/design-system/Text.js +1 -38
- package/dist/cjs/design-system/ThemeContext.js +1 -19
- package/dist/cjs/design-system/ThemeProvider.js +1 -31
- package/dist/cjs/design-system/createComponentTokensHook.js +1 -28
- package/dist/cjs/design-system/index.js +1 -66
- package/dist/cjs/design-system/mergeTokensOverride.js +1 -9
- package/dist/cjs/design-system/presets.js +1 -146
- package/dist/cjs/design-system/tokens.js +1 -135
- package/dist/cjs/design-system/useTheme.js +1 -16
- package/dist/cjs/hooks/animation/index.js +1 -25
- package/dist/cjs/hooks/animation/useAnimatedTransition.js +1 -72
- package/dist/cjs/hooks/animation/useReducedMotion.js +1 -75
- package/dist/cjs/hooks/aria/index.js +1 -49
- package/dist/cjs/hooks/aria/useAriaListBox.js +1 -50
- package/dist/cjs/hooks/aria/useAriaOverlay.js +1 -50
- package/dist/cjs/hooks/aria/useAriaPress.js +1 -94
- package/dist/cjs/hooks/aria/useAriaToggle.js +1 -41
- package/dist/cjs/hooks/gesture/index.js +1 -16
- package/dist/cjs/hooks/gesture/useGestureScroll.js +1 -129
- package/dist/cjs/hooks/index.js +1 -96
- package/dist/cjs/hooks/overlay/OverlayStackStore.js +1 -106
- package/dist/cjs/hooks/overlay/index.js +1 -27
- package/dist/cjs/hooks/overlay/useOverlayStack.js +1 -53
- package/dist/cjs/hooks/useControllableValue.js +1 -41
- package/dist/cjs/hooks/useCountDown.js +1 -99
- package/dist/cjs/hooks/useHairline.js +1 -46
- package/dist/cjs/hooks/useSafeAreaPadding.js +1 -38
- package/dist/cjs/index.js +1 -104
- package/dist/cjs/nativewind.js +1 -0
- package/dist/cjs/platform/animation.js +1 -22
- package/dist/cjs/platform/history.js +1 -14
- package/dist/cjs/platform/index.js +1 -60
- package/dist/cjs/platform/measure.js +1 -39
- package/dist/cjs/platform/runtime.js +1 -19
- package/dist/cjs/platform/scrollLock.js +1 -24
- package/dist/cjs/utils/array.js +1 -12
- package/dist/cjs/utils/color.js +1 -33
- package/dist/cjs/utils/compare.js +1 -21
- package/dist/cjs/utils/createPlatformShadow.js +1 -52
- package/dist/cjs/utils/date.js +1 -45
- package/dist/cjs/utils/deepMerge.js +1 -27
- package/dist/cjs/utils/hairline.js +1 -107
- package/dist/cjs/utils/index.js +1 -148
- package/dist/cjs/utils/number.js +1 -65
- package/dist/cjs/utils/promise.js +1 -9
- package/dist/cjs/utils/render.js +1 -21
- package/dist/cjs/utils/rtl.js +1 -25
- package/dist/cjs/utils/string.js +1 -22
- package/dist/cjs/utils/validate.js +1 -39
- package/dist/es/components/action-sheet/ActionSheet.js +1 -271
- package/dist/es/components/action-sheet/index.js +1 -3
- package/dist/es/components/action-sheet/tokens.js +1 -126
- package/dist/es/components/area/Area.js +1 -113
- package/dist/es/components/area/index.js +1 -2
- package/dist/es/components/area/tokens.js +1 -8
- package/dist/es/components/avatar/Avatar.js +1 -106
- package/dist/es/components/avatar/index.js +1 -1
- package/dist/es/components/avatar/tokens.js +1 -49
- package/dist/es/components/badge/Badge.js +1 -147
- package/dist/es/components/badge/index.js +1 -2
- package/dist/es/components/badge/tokens.js +1 -75
- package/dist/es/components/button/Button.js +1 -184
- package/dist/es/components/button/ButtonContext.js +1 -1
- package/dist/es/components/button/ButtonGroup.js +1 -46
- package/dist/es/components/button/index.js +1 -7
- package/dist/es/components/button/tokens.js +1 -170
- package/dist/es/components/calendar/Calendar.js +1 -432
- package/dist/es/components/calendar/index.js +1 -2
- package/dist/es/components/calendar/tokens.js +1 -122
- package/dist/es/components/cascader/Cascader.js +1 -455
- package/dist/es/components/cascader/index.js +1 -3
- package/dist/es/components/cascader/tokens.js +1 -131
- package/dist/es/components/cascader/useCascaderExtend.js +1 -32
- package/dist/es/components/cell/Cell.js +1 -156
- package/dist/es/components/cell/CellContext.js +1 -6
- package/dist/es/components/cell/CellGroup.js +1 -81
- package/dist/es/components/cell/index.js +1 -8
- package/dist/es/components/cell/tokens.js +1 -160
- package/dist/es/components/checkbox/Checkbox.js +1 -220
- package/dist/es/components/checkbox/CheckboxContext.js +1 -1
- package/dist/es/components/checkbox/CheckboxGroup.js +1 -117
- package/dist/es/components/checkbox/index.js +1 -5
- package/dist/es/components/checkbox/tokens.js +1 -85
- package/dist/es/components/circle/Circle.js +1 -187
- package/dist/es/components/circle/index.js +1 -2
- package/dist/es/components/circle/tokens.js +1 -48
- package/dist/es/components/collapse/Collapse.js +1 -286
- package/dist/es/components/collapse/index.js +1 -2
- package/dist/es/components/collapse/tokens.js +1 -74
- package/dist/es/components/config-provider/ConfigProvider.js +1 -25
- package/dist/es/components/config-provider/DirectionContext.js +1 -2
- package/dist/es/components/config-provider/LocaleContext.js +1 -3
- package/dist/es/components/config-provider/index.js +1 -5
- package/dist/es/components/config-provider/locale/en-US.js +1 -106
- package/dist/es/components/config-provider/locale/zh-CN.js +1 -106
- package/dist/es/components/config-provider/tokens.js +1 -5
- package/dist/es/components/config-provider/useDirection.js +1 -3
- package/dist/es/components/config-provider/useLocale.js +1 -3
- package/dist/es/components/count-down/CountDown.js +1 -69
- package/dist/es/components/count-down/index.js +1 -3
- package/dist/es/components/count-down/tokens.js +1 -27
- package/dist/es/components/datetime-picker/DatetimePicker.js +1 -305
- package/dist/es/components/datetime-picker/index.js +1 -2
- package/dist/es/components/datetime-picker/tokens.js +1 -16
- package/dist/es/components/dialog/Dialog.js +1 -407
- package/dist/es/components/dialog/imperative.js +1 -185
- package/dist/es/components/dialog/index.js +1 -17
- package/dist/es/components/dialog/tokens.js +1 -57
- package/dist/es/components/divider/Divider.js +1 -107
- package/dist/es/components/divider/index.js +1 -2
- package/dist/es/components/divider/tokens.js +1 -55
- package/dist/es/components/empty/Empty.js +1 -100
- package/dist/es/components/empty/index.js +1 -2
- package/dist/es/components/empty/tokens.js +1 -48
- package/dist/es/components/error-boundary/ErrorBoundary.js +1 -62
- package/dist/es/components/error-boundary/index.js +1 -1
- package/dist/es/components/field/Field.js +1 -539
- package/dist/es/components/field/index.js +1 -6
- package/dist/es/components/field/tokens.js +1 -138
- package/dist/es/components/flex/Flex.js +1 -66
- package/dist/es/components/flex/FlexContext.js +1 -1
- package/dist/es/components/flex/FlexItem.js +1 -76
- package/dist/es/components/flex/index.js +1 -8
- package/dist/es/components/flex/tokens.js +1 -15
- package/dist/es/components/form/Form.js +1 -319
- package/dist/es/components/form/FormContext.js +1 -1
- package/dist/es/components/form/FormItem.js +1 -138
- package/dist/es/components/form/FormList.js +1 -81
- package/dist/es/components/form/index.js +1 -13
- package/dist/es/components/form/tokens.js +1 -8
- package/dist/es/components/form/utils.js +1 -45
- package/dist/es/components/grid/Grid.js +1 -99
- package/dist/es/components/grid/GridContext.js +1 -1
- package/dist/es/components/grid/GridItem.js +1 -138
- package/dist/es/components/grid/index.js +1 -6
- package/dist/es/components/grid/tokens.js +1 -98
- package/dist/es/components/image/Image.js +1 -238
- package/dist/es/components/image/index.js +1 -3
- package/dist/es/components/image/tokens.js +1 -60
- package/dist/es/components/image-preview/ImagePreview.js +1 -378
- package/dist/es/components/image-preview/imperative.js +1 -58
- package/dist/es/components/image-preview/index.js +1 -11
- package/dist/es/components/image-preview/tokens.js +1 -37
- package/dist/es/components/index.js +1 -110
- package/dist/es/components/input/Input.js +1 -109
- package/dist/es/components/input/index.js +1 -3
- package/dist/es/components/input/tokens.js +1 -16
- package/dist/es/components/loading/Loading.js +1 -57
- package/dist/es/components/loading/index.js +1 -2
- package/dist/es/components/loading/tokens.js +1 -25
- package/dist/es/components/nav-bar/NavBar.js +1 -171
- package/dist/es/components/nav-bar/index.js +1 -3
- package/dist/es/components/nav-bar/tokens.js +1 -83
- package/dist/es/components/notice-bar/NoticeBar.js +1 -344
- package/dist/es/components/notice-bar/index.js +1 -2
- package/dist/es/components/notice-bar/tokens.js +1 -32
- package/dist/es/components/notify/Notify.js +1 -242
- package/dist/es/components/notify/imperative.js +1 -131
- package/dist/es/components/notify/index.js +1 -5
- package/dist/es/components/notify/tokens.js +1 -67
- package/dist/es/components/number-keyboard/NumberKeyboard.js +1 -467
- package/dist/es/components/number-keyboard/index.js +1 -3
- package/dist/es/components/number-keyboard/tokens.js +1 -53
- package/dist/es/components/overlay/Overlay.js +1 -50
- package/dist/es/components/overlay/index.js +1 -4
- package/dist/es/components/overlay/tokens.js +1 -7
- package/dist/es/components/password-input/PasswordInput.js +1 -327
- package/dist/es/components/password-input/index.js +1 -1
- package/dist/es/components/password-input/tokens.js +1 -41
- package/dist/es/components/picker/Picker.js +1 -1031
- package/dist/es/components/picker/index.js +1 -3
- package/dist/es/components/picker/tokens.js +1 -47
- package/dist/es/components/popup/Popup.js +1 -492
- package/dist/es/components/popup/index.js +1 -3
- package/dist/es/components/popup/tokens.js +1 -55
- package/dist/es/components/portal/Portal.js +1 -37
- package/dist/es/components/portal/PortalContext.js +1 -2
- package/dist/es/components/portal/PortalHost.js +1 -234
- package/dist/es/components/portal/index.js +1 -3
- package/dist/es/components/portal/tokens.js +1 -5
- package/dist/es/components/progress/Progress.js +1 -196
- package/dist/es/components/progress/index.js +1 -3
- package/dist/es/components/progress/tokens.js +1 -45
- package/dist/es/components/radio/Radio.js +1 -214
- package/dist/es/components/radio/RadioContext.js +1 -1
- package/dist/es/components/radio/RadioGroup.js +1 -82
- package/dist/es/components/radio/index.js +1 -5
- package/dist/es/components/radio/tokens.js +1 -80
- package/dist/es/components/safe-area-view/SafeAreaView.js +1 -40
- package/dist/es/components/safe-area-view/index.js +1 -1
- package/dist/es/components/safe-area-view/tokens.js +1 -5
- package/dist/es/components/search/Search.js +1 -189
- package/dist/es/components/search/index.js +1 -3
- package/dist/es/components/search/tokens.js +1 -48
- package/dist/es/components/selector/Selector.js +1 -166
- package/dist/es/components/selector/index.js +1 -3
- package/dist/es/components/selector/tokens.js +1 -88
- package/dist/es/components/share-sheet/ShareSheet.js +1 -266
- package/dist/es/components/share-sheet/index.js +1 -3
- package/dist/es/components/share-sheet/tokens.js +1 -49
- package/dist/es/components/sidebar/Sidebar.js +1 -84
- package/dist/es/components/sidebar/SidebarContext.js +1 -3
- package/dist/es/components/sidebar/SidebarItem.js +1 -84
- package/dist/es/components/sidebar/index.js +1 -8
- package/dist/es/components/sidebar/tokens.js +1 -80
- package/dist/es/components/skeleton/Skeleton.js +1 -143
- package/dist/es/components/skeleton/index.js +1 -4
- package/dist/es/components/skeleton/tokens.js +1 -33
- package/dist/es/components/slider/Slider.js +1 -596
- package/dist/es/components/slider/index.js +1 -2
- package/dist/es/components/slider/tokens.js +1 -31
- package/dist/es/components/space/Space.js +1 -115
- package/dist/es/components/space/index.js +1 -2
- package/dist/es/components/space/tokens.js +1 -32
- package/dist/es/components/stepper/Stepper.js +1 -465
- package/dist/es/components/stepper/index.js +1 -3
- package/dist/es/components/stepper/tokens.js +1 -54
- package/dist/es/components/swiper/Swiper.js +1 -344
- package/dist/es/components/swiper/SwiperItem.js +1 -1
- package/dist/es/components/swiper/SwiperPagIndicator.js +1 -87
- package/dist/es/components/swiper/index.js +1 -10
- package/dist/es/components/swiper/tokens.js +1 -12
- package/dist/es/components/switch/Switch.js +1 -83
- package/dist/es/components/switch/index.js +1 -3
- package/dist/es/components/switch/tokens.js +1 -25
- package/dist/es/components/tabbar/Tabbar.js +1 -130
- package/dist/es/components/tabbar/TabbarContext.js +1 -3
- package/dist/es/components/tabbar/TabbarItem.js +1 -133
- package/dist/es/components/tabbar/index.js +1 -7
- package/dist/es/components/tabbar/tokens.js +1 -35
- package/dist/es/components/tabs/Tabs.js +1 -841
- package/dist/es/components/tabs/index.js +1 -7
- package/dist/es/components/tabs/tokens.js +1 -105
- package/dist/es/components/tag/Tag.js +1 -105
- package/dist/es/components/tag/index.js +1 -2
- package/dist/es/components/tag/tokens.js +1 -97
- package/dist/es/components/toast/Toast.js +1 -277
- package/dist/es/components/toast/imperative.js +1 -130
- package/dist/es/components/toast/index.js +1 -5
- package/dist/es/components/toast/tokens.js +1 -36
- package/dist/es/components/typography/Typography.js +1 -162
- package/dist/es/components/typography/index.js +1 -2
- package/dist/es/components/typography/tokens.js +1 -82
- package/dist/es/components/water-mark/WaterMark.js +1 -153
- package/dist/es/components/water-mark/index.js +1 -4
- package/dist/es/components/water-mark/tokens.js +1 -42
- package/dist/es/design-system/Text.js +1 -19
- package/dist/es/design-system/ThemeContext.js +1 -6
- package/dist/es/design-system/ThemeProvider.js +1 -17
- package/dist/es/design-system/createComponentTokensHook.js +1 -15
- package/dist/es/design-system/index.js +1 -7
- package/dist/es/design-system/mergeTokensOverride.js +1 -2
- package/dist/es/design-system/presets.js +1 -139
- package/dist/es/design-system/tokens.js +1 -128
- package/dist/es/design-system/useTheme.js +1 -3
- package/dist/es/hooks/animation/index.js +1 -2
- package/dist/es/hooks/animation/useAnimatedTransition.js +1 -53
- package/dist/es/hooks/animation/useReducedMotion.js +1 -54
- package/dist/es/hooks/aria/index.js +1 -5
- package/dist/es/hooks/aria/useAriaListBox.js +1 -25
- package/dist/es/hooks/aria/useAriaOverlay.js +1 -25
- package/dist/es/hooks/aria/useAriaPress.js +1 -57
- package/dist/es/hooks/aria/useAriaToggle.js +1 -16
- package/dist/es/hooks/gesture/index.js +1 -2
- package/dist/es/hooks/gesture/useGestureScroll.js +1 -110
- package/dist/es/hooks/index.js +1 -8
- package/dist/es/hooks/overlay/OverlayStackStore.js +1 -93
- package/dist/es/hooks/overlay/index.js +1 -3
- package/dist/es/hooks/overlay/useOverlayStack.js +1 -40
- package/dist/es/hooks/useControllableValue.js +1 -29
- package/dist/es/hooks/useCountDown.js +1 -87
- package/dist/es/hooks/useHairline.js +1 -26
- package/dist/es/hooks/useSafeAreaPadding.js +1 -20
- package/dist/es/index.js +1 -11
- package/dist/es/nativewind.js +1 -0
- package/dist/es/platform/animation.js +1 -10
- package/dist/es/platform/history.js +1 -7
- package/dist/es/platform/index.js +1 -6
- package/dist/es/platform/measure.js +1 -32
- package/dist/es/platform/runtime.js +1 -4
- package/dist/es/platform/scrollLock.js +1 -16
- package/dist/es/types.js +1 -1
- package/dist/es/utils/array.js +1 -5
- package/dist/es/utils/color.js +1 -25
- package/dist/es/utils/compare.js +1 -13
- package/dist/es/utils/createPlatformShadow.js +1 -39
- package/dist/es/utils/date.js +1 -33
- package/dist/es/utils/deepMerge.js +1 -21
- package/dist/es/utils/hairline.js +1 -93
- package/dist/es/utils/index.js +1 -14
- package/dist/es/utils/number.js +1 -48
- package/dist/es/utils/promise.js +1 -2
- package/dist/es/utils/render.js +1 -7
- package/dist/es/utils/rtl.js +1 -17
- package/dist/es/utils/string.js +1 -13
- package/dist/es/utils/validate.js +1 -14
- package/dist/types/nativewind.d.ts +4 -0
- package/package.json +15 -3
|
@@ -1,1031 +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, useMemo, useRef, useState } from 'react';
|
|
3
|
-
import { Pressable, Text, View, Platform, StyleSheet, ScrollView, PanResponder } from 'react-native';
|
|
4
|
-
import Loading from '../loading';
|
|
5
|
-
import { useLocale } from '../config-provider/useLocale';
|
|
6
|
-
import { withAlpha } from '../../utils/color';
|
|
7
|
-
import { isFiniteNumber, isText } from '../../utils/validate';
|
|
8
|
-
import { clamp, isObject, shallowEqualArray } from '../../utils';
|
|
9
|
-
import { usePickerTokens } from './tokens';
|
|
10
|
-
import { createHairlineView } from '../../utils/hairline';
|
|
11
|
-
export const toArrayValue = value => Array.isArray(value) ? value.filter(v => v !== undefined && v !== null) : value == null ? [] : [value];
|
|
12
|
-
const isColumnWithOptions = col => !!col && isObject(col) && 'options' in col && Array.isArray(col.options);
|
|
13
|
-
const hasChildren = option => !!option && isObject(option) && Array.isArray(option.children) && option.children.length > 0;
|
|
14
|
-
export const findEnabledIndex = (options, startIdx) => {
|
|
15
|
-
if (!options.length) return -1;
|
|
16
|
-
const clampIdx = Math.min(Math.max(startIdx, 0), options.length - 1);
|
|
17
|
-
if (!options[clampIdx]?.disabled) return clampIdx;
|
|
18
|
-
for (let i = clampIdx + 1; i < options.length; i += 1) {
|
|
19
|
-
if (!options[i]?.disabled) return i;
|
|
20
|
-
}
|
|
21
|
-
for (let i = clampIdx - 1; i >= 0; i -= 1) {
|
|
22
|
-
if (!options[i]?.disabled) return i;
|
|
23
|
-
}
|
|
24
|
-
return -1;
|
|
25
|
-
};
|
|
26
|
-
const normalizeMultiple = (cols, defs, raw) => {
|
|
27
|
-
const vals = [],
|
|
28
|
-
opts = [];
|
|
29
|
-
cols.forEach((colOpts, idx) => {
|
|
30
|
-
const curr = raw[idx];
|
|
31
|
-
const defIdx = defs[idx] !== undefined ? colOpts.findIndex(item => item.value === defs[idx]) : -1;
|
|
32
|
-
const currIdx = colOpts.findIndex(item => item.value === curr);
|
|
33
|
-
const startIdx = currIdx >= 0 ? currIdx : defIdx >= 0 ? defIdx : 0;
|
|
34
|
-
const tgtIdx = findEnabledIndex(colOpts, startIdx);
|
|
35
|
-
const tgt = tgtIdx >= 0 ? colOpts[tgtIdx] : undefined;
|
|
36
|
-
const valid = currIdx >= 0 && !colOpts[currIdx]?.disabled;
|
|
37
|
-
vals[idx] = valid ? curr : tgt?.value ?? defs[idx] ?? colOpts[0]?.value;
|
|
38
|
-
opts[idx] = tgt;
|
|
39
|
-
});
|
|
40
|
-
return {
|
|
41
|
-
columns: cols,
|
|
42
|
-
values: vals,
|
|
43
|
-
options: opts
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
const normalizeCascade = (root, raw) => {
|
|
47
|
-
const cols = [],
|
|
48
|
-
vals = [],
|
|
49
|
-
opts = [];
|
|
50
|
-
let curr = root;
|
|
51
|
-
let d = 0;
|
|
52
|
-
while (curr && curr.length && d < 10) {
|
|
53
|
-
cols.push(curr);
|
|
54
|
-
const c = raw[d];
|
|
55
|
-
const startIdx = curr.findIndex(item => item.value === c || String(item.value) === String(c));
|
|
56
|
-
const tgtIdx = findEnabledIndex(curr, startIdx >= 0 ? startIdx : 0);
|
|
57
|
-
const tgt = tgtIdx >= 0 ? curr[tgtIdx] : curr[0];
|
|
58
|
-
vals[d] = tgt?.value;
|
|
59
|
-
opts[d] = tgt;
|
|
60
|
-
if (tgt && hasChildren(tgt)) {
|
|
61
|
-
curr = tgt.children;
|
|
62
|
-
d += 1;
|
|
63
|
-
} else break;
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
columns: cols,
|
|
67
|
-
values: vals,
|
|
68
|
-
options: opts
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
export const prepareColumns = (input = []) => {
|
|
72
|
-
if (!Array.isArray(input) || input.length === 0) return {
|
|
73
|
-
type: 'single',
|
|
74
|
-
columnsList: [],
|
|
75
|
-
defaults: [],
|
|
76
|
-
cascadeRoot: []
|
|
77
|
-
};
|
|
78
|
-
const everyPlain = input.every(item => !Array.isArray(item) && !isColumnWithOptions(item));
|
|
79
|
-
const cascade = everyPlain && input.some(item => hasChildren(item));
|
|
80
|
-
if (cascade) return {
|
|
81
|
-
type: 'cascade',
|
|
82
|
-
columnsList: [],
|
|
83
|
-
defaults: [],
|
|
84
|
-
cascadeRoot: input
|
|
85
|
-
};
|
|
86
|
-
const asArray = input;
|
|
87
|
-
const cols = [],
|
|
88
|
-
defs = [];
|
|
89
|
-
const treatAsSingle = everyPlain && !cascade;
|
|
90
|
-
if (treatAsSingle) {
|
|
91
|
-
cols.push(input);
|
|
92
|
-
defs.push(undefined);
|
|
93
|
-
} else asArray.forEach(col => {
|
|
94
|
-
if (Array.isArray(col)) {
|
|
95
|
-
cols.push(col);
|
|
96
|
-
defs.push(undefined);
|
|
97
|
-
} else if (isColumnWithOptions(col)) {
|
|
98
|
-
const c = col;
|
|
99
|
-
cols.push(c.options ?? []);
|
|
100
|
-
defs.push(c.defaultValue);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
return {
|
|
104
|
-
type: 'multiple',
|
|
105
|
-
columnsList: cols,
|
|
106
|
-
defaults: defs
|
|
107
|
-
};
|
|
108
|
-
};
|
|
109
|
-
export const normalizePicker = (prep, raw = []) => {
|
|
110
|
-
const rawVal = Array.isArray(raw) ? raw : [];
|
|
111
|
-
return prep.type === 'cascade' && prep.cascadeRoot?.length ? normalizeCascade(prep.cascadeRoot, rawVal) : normalizeMultiple(prep.columnsList, prep.defaults, rawVal);
|
|
112
|
-
};
|
|
113
|
-
const W = StyleSheet.create({
|
|
114
|
-
column: {
|
|
115
|
-
flex: 1
|
|
116
|
-
},
|
|
117
|
-
option: {
|
|
118
|
-
justifyContent: 'center',
|
|
119
|
-
alignItems: 'center'
|
|
120
|
-
},
|
|
121
|
-
grab: {
|
|
122
|
-
cursor: 'pointer',
|
|
123
|
-
userSelect: 'none',
|
|
124
|
-
touchAction: 'none'
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
const WheelPickerItemInner = ({
|
|
128
|
-
item,
|
|
129
|
-
index,
|
|
130
|
-
itemHeight,
|
|
131
|
-
active,
|
|
132
|
-
disabled,
|
|
133
|
-
renderItem
|
|
134
|
-
}) => {
|
|
135
|
-
const content = renderItem(item, index, {
|
|
136
|
-
active,
|
|
137
|
-
disabled
|
|
138
|
-
});
|
|
139
|
-
return /*#__PURE__*/React.createElement(View, {
|
|
140
|
-
style: [W.option, {
|
|
141
|
-
height: itemHeight
|
|
142
|
-
}]
|
|
143
|
-
}, content);
|
|
144
|
-
};
|
|
145
|
-
const WheelPickerItem = /*#__PURE__*/React.memo(WheelPickerItemInner);
|
|
146
|
-
const getVelocityBucket = v => {
|
|
147
|
-
const abs = Math.abs(v);
|
|
148
|
-
if (abs > 1.2) return 2;
|
|
149
|
-
if (abs > 0.6) return 1;
|
|
150
|
-
return 0;
|
|
151
|
-
};
|
|
152
|
-
const adjustIndex = (idx, opts) => {
|
|
153
|
-
const total = opts.length;
|
|
154
|
-
if (!total) return 0;
|
|
155
|
-
const i = clamp(idx, 0, total - 1);
|
|
156
|
-
const next = findEnabledIndex(opts, i);
|
|
157
|
-
return next >= 0 ? next : i;
|
|
158
|
-
};
|
|
159
|
-
const indexToOffset = (idx, h) => -idx * h;
|
|
160
|
-
const offsetToIndex = (off, h, total, opts) => {
|
|
161
|
-
const minOff = -Math.max(0, total - 1) * h;
|
|
162
|
-
const offClamped = clamp(off, minOff, 0);
|
|
163
|
-
let idx = Math.round(-offClamped / h);
|
|
164
|
-
idx = adjustIndex(idx, opts);
|
|
165
|
-
const snapOff = indexToOffset(idx, h);
|
|
166
|
-
return {
|
|
167
|
-
index: idx,
|
|
168
|
-
snapOffset: snapOff
|
|
169
|
-
};
|
|
170
|
-
};
|
|
171
|
-
const shouldMomentum = (dist, dur) => dur < 500 && Math.abs(dist) > 8;
|
|
172
|
-
const momentumTarget = (dist, dur, currOff, h, minOff) => {
|
|
173
|
-
const speed = Math.abs(dist / dur);
|
|
174
|
-
const extra = speed / 0.0025 * (dist < 0 ? -1 : 1);
|
|
175
|
-
const tgt = clamp(currOff + extra, minOff, 0);
|
|
176
|
-
const snapIdx = Math.round(-tgt / h);
|
|
177
|
-
return indexToOffset(snapIdx, h);
|
|
178
|
-
};
|
|
179
|
-
const WheelPickerInner = ({
|
|
180
|
-
data,
|
|
181
|
-
selectedIndex,
|
|
182
|
-
onChange,
|
|
183
|
-
onInteractStart,
|
|
184
|
-
onInteractEnd,
|
|
185
|
-
renderItem,
|
|
186
|
-
itemHeight,
|
|
187
|
-
visibleRest,
|
|
188
|
-
readOnly,
|
|
189
|
-
indicatorColor,
|
|
190
|
-
decelerationRate = Platform.select({
|
|
191
|
-
ios: 0.9985,
|
|
192
|
-
android: 0.995,
|
|
193
|
-
default: 0.995
|
|
194
|
-
}) ?? 'normal',
|
|
195
|
-
scrollEventThrottle = 16,
|
|
196
|
-
swipeDuration = 300
|
|
197
|
-
}) => {
|
|
198
|
-
const isWeb = Platform.OS === 'web';
|
|
199
|
-
const listRef = useRef(null),
|
|
200
|
-
scrollRef = useRef(null);
|
|
201
|
-
const spacerHeight = visibleRest * itemHeight;
|
|
202
|
-
const total = data.length;
|
|
203
|
-
const maxIdx = Math.max(0, total - 1);
|
|
204
|
-
const minOff = -maxIdx * itemHeight;
|
|
205
|
-
const containerHeight = itemHeight * (visibleRest * 2 + 1);
|
|
206
|
-
const rawSelIdx = clamp(selectedIndex, 0, maxIdx);
|
|
207
|
-
const enabledSelIdx = findEnabledIndex(data, rawSelIdx);
|
|
208
|
-
const safeSelIdx = enabledSelIdx >= 0 ? enabledSelIdx : rawSelIdx;
|
|
209
|
-
const visibleCnt = visibleRest * 2 + 1;
|
|
210
|
-
const effectiveScrollThrottle = total > visibleCnt * 20 ? 32 : scrollEventThrottle;
|
|
211
|
-
const webVirtualEnabled = total > visibleCnt * 4;
|
|
212
|
-
const Spacer = useCallback(() => /*#__PURE__*/React.createElement(View, {
|
|
213
|
-
style: {
|
|
214
|
-
height: spacerHeight
|
|
215
|
-
}
|
|
216
|
-
}), [spacerHeight]);
|
|
217
|
-
const indicatorStyle = useMemo(() => [S.indicator, {
|
|
218
|
-
height: itemHeight,
|
|
219
|
-
top: itemHeight * visibleRest
|
|
220
|
-
}], [itemHeight, visibleRest]);
|
|
221
|
-
const dragEndTimerRef = useRef(null),
|
|
222
|
-
momentumRef = useRef(false),
|
|
223
|
-
lastOffsetRef = useRef(0);
|
|
224
|
-
const clearDragEndTimer = useCallback(() => {
|
|
225
|
-
if (dragEndTimerRef.current) {
|
|
226
|
-
clearTimeout(dragEndTimerRef.current);
|
|
227
|
-
dragEndTimerRef.current = null;
|
|
228
|
-
}
|
|
229
|
-
}, []);
|
|
230
|
-
const emitIdx = useCallback((offsetY, animated) => {
|
|
231
|
-
if (readOnly) return;
|
|
232
|
-
const {
|
|
233
|
-
index,
|
|
234
|
-
snapOffset
|
|
235
|
-
} = offsetToIndex(-offsetY, itemHeight, total, data);
|
|
236
|
-
const nextOff = -snapOffset;
|
|
237
|
-
if (Math.abs(nextOff - offsetY) > 0.5) {
|
|
238
|
-
listRef.current?.scrollToOffset({
|
|
239
|
-
offset: nextOff,
|
|
240
|
-
animated
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
onChange(index);
|
|
244
|
-
}, [data, itemHeight, onChange, readOnly, total]);
|
|
245
|
-
useEffect(() => {
|
|
246
|
-
const offset = safeSelIdx * itemHeight;
|
|
247
|
-
if (isWeb) return;
|
|
248
|
-
scrollRef.current?.scrollTo({
|
|
249
|
-
y: offset,
|
|
250
|
-
animated: false
|
|
251
|
-
});
|
|
252
|
-
}, [isWeb, itemHeight, safeSelIdx]);
|
|
253
|
-
const [webOffset, setWebOffset] = useState(() => indexToOffset(safeSelIdx, itemHeight));
|
|
254
|
-
const webOffsetRef = useRef(webOffset),
|
|
255
|
-
startOffsetRef = useRef(0),
|
|
256
|
-
startTimeRef = useRef(0);
|
|
257
|
-
const [webTransition, setWebTransition] = useState(0);
|
|
258
|
-
const [webVelocityBucket, setWebVelocityBucket] = useState(0);
|
|
259
|
-
const webVelocityBucketRef = useRef(0),
|
|
260
|
-
lastWheelTimeRef = useRef(null),
|
|
261
|
-
wheelDeltaRef = useRef(0),
|
|
262
|
-
wheelRafRef = useRef(null),
|
|
263
|
-
pendingIndexRef = useRef(null),
|
|
264
|
-
pendingTimerRef = useRef(null),
|
|
265
|
-
rafIdRef = useRef(null),
|
|
266
|
-
isInteractingRef = useRef(false);
|
|
267
|
-
const onInteractStartRef = useRef(onInteractStart);
|
|
268
|
-
onInteractStartRef.current = onInteractStart;
|
|
269
|
-
const onInteractEndRef = useRef(onInteractEnd);
|
|
270
|
-
onInteractEndRef.current = onInteractEnd;
|
|
271
|
-
const notifyStart = useCallback(() => {
|
|
272
|
-
if (readOnly) return;
|
|
273
|
-
if (isInteractingRef.current) return;
|
|
274
|
-
isInteractingRef.current = true;
|
|
275
|
-
onInteractStartRef.current?.();
|
|
276
|
-
}, [readOnly]);
|
|
277
|
-
const notifyEnd = useCallback(() => {
|
|
278
|
-
if (!isInteractingRef.current) return;
|
|
279
|
-
isInteractingRef.current = false;
|
|
280
|
-
onInteractEndRef.current?.();
|
|
281
|
-
}, []);
|
|
282
|
-
const stopRaf = useCallback(() => {
|
|
283
|
-
if (rafIdRef.current != null && typeof cancelAnimationFrame !== 'undefined') {
|
|
284
|
-
cancelAnimationFrame(rafIdRef.current);
|
|
285
|
-
rafIdRef.current = null;
|
|
286
|
-
}
|
|
287
|
-
if (wheelRafRef.current != null && typeof cancelAnimationFrame !== 'undefined') {
|
|
288
|
-
cancelAnimationFrame(wheelRafRef.current);
|
|
289
|
-
wheelRafRef.current = null;
|
|
290
|
-
}
|
|
291
|
-
}, []);
|
|
292
|
-
const clearPendingTimer = useCallback(() => {
|
|
293
|
-
if (pendingTimerRef.current) {
|
|
294
|
-
clearTimeout(pendingTimerRef.current);
|
|
295
|
-
pendingTimerRef.current = null;
|
|
296
|
-
}
|
|
297
|
-
}, []);
|
|
298
|
-
useEffect(() => {
|
|
299
|
-
return () => {
|
|
300
|
-
clearDragEndTimer();
|
|
301
|
-
clearPendingTimer();
|
|
302
|
-
stopRaf();
|
|
303
|
-
};
|
|
304
|
-
}, [clearDragEndTimer, clearPendingTimer, stopRaf]);
|
|
305
|
-
const setVelocityBucket = useCallback(velocity => {
|
|
306
|
-
const next = getVelocityBucket(velocity);
|
|
307
|
-
if (next !== webVelocityBucketRef.current) {
|
|
308
|
-
webVelocityBucketRef.current = next;
|
|
309
|
-
setWebVelocityBucket(next);
|
|
310
|
-
}
|
|
311
|
-
}, []);
|
|
312
|
-
const updateWheelVelocity = useCallback(delta => {
|
|
313
|
-
const now = Date.now();
|
|
314
|
-
const last = lastWheelTimeRef.current;
|
|
315
|
-
if (last != null) {
|
|
316
|
-
const dt = Math.max(1, now - last);
|
|
317
|
-
setVelocityBucket(delta / dt);
|
|
318
|
-
}
|
|
319
|
-
lastWheelTimeRef.current = now;
|
|
320
|
-
}, [setVelocityBucket]);
|
|
321
|
-
useEffect(() => {
|
|
322
|
-
if (!isWeb) return;
|
|
323
|
-
clearPendingTimer();
|
|
324
|
-
pendingIndexRef.current = null;
|
|
325
|
-
setWebTransition(0);
|
|
326
|
-
const next = indexToOffset(safeSelIdx, itemHeight);
|
|
327
|
-
webOffsetRef.current = next;
|
|
328
|
-
setWebOffset(next);
|
|
329
|
-
}, [clearPendingTimer, isWeb, itemHeight, safeSelIdx, setWebTransition]);
|
|
330
|
-
const finalizePendingChange = useCallback(() => {
|
|
331
|
-
if (readOnly) return;
|
|
332
|
-
const nextIdx = pendingIndexRef.current;
|
|
333
|
-
if (nextIdx == null) return;
|
|
334
|
-
pendingIndexRef.current = null;
|
|
335
|
-
clearPendingTimer();
|
|
336
|
-
setWebTransition(0);
|
|
337
|
-
notifyEnd();
|
|
338
|
-
onChange(nextIdx);
|
|
339
|
-
}, [clearPendingTimer, onChange, readOnly, setWebTransition]);
|
|
340
|
-
const startWebSnap = useCallback(targetIdx => {
|
|
341
|
-
if (readOnly) return;
|
|
342
|
-
notifyStart();
|
|
343
|
-
const clampedIdx = clamp(targetIdx, 0, maxIdx);
|
|
344
|
-
const targetOff = indexToOffset(clampedIdx, itemHeight);
|
|
345
|
-
clearPendingTimer();
|
|
346
|
-
pendingIndexRef.current = clampedIdx;
|
|
347
|
-
webOffsetRef.current = targetOff;
|
|
348
|
-
setWebTransition(swipeDuration);
|
|
349
|
-
setWebOffset(targetOff);
|
|
350
|
-
if (swipeDuration <= 0) {
|
|
351
|
-
finalizePendingChange();
|
|
352
|
-
} else {
|
|
353
|
-
pendingTimerRef.current = setTimeout(finalizePendingChange, swipeDuration + 80);
|
|
354
|
-
}
|
|
355
|
-
}, [clearPendingTimer, finalizePendingChange, itemHeight, maxIdx, readOnly, swipeDuration]);
|
|
356
|
-
const handleWheel = useCallback(event => {
|
|
357
|
-
if (readOnly) return;
|
|
358
|
-
const delta = event.nativeEvent?.deltaY ?? 0;
|
|
359
|
-
if (!delta) return;
|
|
360
|
-
wheelDeltaRef.current += delta;
|
|
361
|
-
if (wheelRafRef.current != null || typeof requestAnimationFrame === 'undefined') return;
|
|
362
|
-
wheelRafRef.current = requestAnimationFrame(() => {
|
|
363
|
-
wheelRafRef.current = null;
|
|
364
|
-
const queued = wheelDeltaRef.current;
|
|
365
|
-
wheelDeltaRef.current = 0;
|
|
366
|
-
if (!queued) return;
|
|
367
|
-
updateWheelVelocity(queued);
|
|
368
|
-
const direction = queued > 0 ? 1 : -1;
|
|
369
|
-
const {
|
|
370
|
-
index
|
|
371
|
-
} = offsetToIndex(webOffsetRef.current, itemHeight, total, data);
|
|
372
|
-
const nextIdx = clamp(index + direction, 0, maxIdx);
|
|
373
|
-
startWebSnap(nextIdx);
|
|
374
|
-
});
|
|
375
|
-
}, [data, itemHeight, maxIdx, readOnly, startWebSnap, total, updateWheelVelocity]);
|
|
376
|
-
const webIdx = clamp(Math.round(-webOffset / itemHeight), 0, maxIdx);
|
|
377
|
-
const webRender = useMemo(() => {
|
|
378
|
-
if (!isWeb || total <= 0) {
|
|
379
|
-
return {
|
|
380
|
-
items: null,
|
|
381
|
-
topSpacer: null,
|
|
382
|
-
bottomSpacer: null
|
|
383
|
-
};
|
|
384
|
-
}
|
|
385
|
-
let startIdx = 0;
|
|
386
|
-
let endIdx = maxIdx;
|
|
387
|
-
if (webVirtualEnabled) {
|
|
388
|
-
const baseBuffer = Math.max(visibleCnt * 2, 8);
|
|
389
|
-
const velocityBoost = webVelocityBucket === 2 ? visibleCnt * 4 : webVelocityBucket === 1 ? visibleCnt * 2 : 0;
|
|
390
|
-
const buffer = Math.min(baseBuffer + velocityBoost, Math.max(visibleCnt * 6, 24));
|
|
391
|
-
startIdx = clamp(webIdx - buffer, 0, maxIdx);
|
|
392
|
-
endIdx = clamp(webIdx + buffer, 0, maxIdx);
|
|
393
|
-
}
|
|
394
|
-
const items = [];
|
|
395
|
-
for (let index = startIdx; index <= endIdx; index += 1) {
|
|
396
|
-
const item = data[index];
|
|
397
|
-
if (!item) continue;
|
|
398
|
-
items.push(/*#__PURE__*/React.createElement(WheelPickerItem, {
|
|
399
|
-
key: `${index}-${String(item.value ?? '')}`,
|
|
400
|
-
item: item,
|
|
401
|
-
index: index,
|
|
402
|
-
itemHeight: itemHeight,
|
|
403
|
-
active: index === safeSelIdx,
|
|
404
|
-
disabled: !!item.disabled,
|
|
405
|
-
renderItem: renderItem
|
|
406
|
-
}));
|
|
407
|
-
}
|
|
408
|
-
const topH = startIdx * itemHeight;
|
|
409
|
-
const bottomH = (maxIdx - endIdx) * itemHeight;
|
|
410
|
-
return {
|
|
411
|
-
items,
|
|
412
|
-
topSpacer: topH > 0 && /*#__PURE__*/React.createElement(View, {
|
|
413
|
-
style: {
|
|
414
|
-
height: topH
|
|
415
|
-
}
|
|
416
|
-
}),
|
|
417
|
-
bottomSpacer: bottomH > 0 && /*#__PURE__*/React.createElement(View, {
|
|
418
|
-
style: {
|
|
419
|
-
height: bottomH
|
|
420
|
-
}
|
|
421
|
-
})
|
|
422
|
-
};
|
|
423
|
-
}, [data, isWeb, itemHeight, maxIdx, renderItem, safeSelIdx, total, visibleCnt, webIdx, webVelocityBucket, webVirtualEnabled]);
|
|
424
|
-
const webTransform = useMemo(() => ({
|
|
425
|
-
transform: [{
|
|
426
|
-
translateY: webOffset
|
|
427
|
-
}]
|
|
428
|
-
}), [webOffset]);
|
|
429
|
-
const webTransitionStyle = useMemo(() => webTransition ? {
|
|
430
|
-
transitionProperty: 'transform',
|
|
431
|
-
transitionDuration: webTransition + 'ms',
|
|
432
|
-
transitionTimingFunction: 'cubic-bezier(0.23, 1, 0.68, 1)',
|
|
433
|
-
willChange: 'transform'
|
|
434
|
-
} : undefined, [webTransition]);
|
|
435
|
-
const handleWebTransitionEnd = useCallback(event => {
|
|
436
|
-
const propertyName = event.nativeEvent?.propertyName ?? event.propertyName;
|
|
437
|
-
if (propertyName && propertyName !== 'transform' && propertyName !== 'webkitTransform') return;
|
|
438
|
-
finalizePendingChange();
|
|
439
|
-
}, [finalizePendingChange]);
|
|
440
|
-
const panResponder = useMemo(() => PanResponder.create({
|
|
441
|
-
onStartShouldSetPanResponder: () => !readOnly,
|
|
442
|
-
onMoveShouldSetPanResponder: () => !readOnly,
|
|
443
|
-
onPanResponderGrant: () => {
|
|
444
|
-
stopRaf();
|
|
445
|
-
pendingIndexRef.current = null;
|
|
446
|
-
notifyStart();
|
|
447
|
-
setWebTransition(0);
|
|
448
|
-
startOffsetRef.current = webOffsetRef.current;
|
|
449
|
-
startTimeRef.current = Date.now();
|
|
450
|
-
},
|
|
451
|
-
onPanResponderMove: (_, gesture) => {
|
|
452
|
-
if (readOnly) return;
|
|
453
|
-
setVelocityBucket(gesture.vy);
|
|
454
|
-
const next = clamp(startOffsetRef.current + gesture.dy, minOff, 0);
|
|
455
|
-
webOffsetRef.current = next;
|
|
456
|
-
if (typeof requestAnimationFrame === 'undefined') {
|
|
457
|
-
setWebOffset(next);
|
|
458
|
-
return;
|
|
459
|
-
}
|
|
460
|
-
if (rafIdRef.current != null) return;
|
|
461
|
-
rafIdRef.current = requestAnimationFrame(() => {
|
|
462
|
-
rafIdRef.current = null;
|
|
463
|
-
setWebOffset(webOffsetRef.current);
|
|
464
|
-
});
|
|
465
|
-
},
|
|
466
|
-
onPanResponderRelease: (_, gesture) => {
|
|
467
|
-
if (readOnly) return;
|
|
468
|
-
setVelocityBucket(0);
|
|
469
|
-
const duration = Date.now() - startTimeRef.current;
|
|
470
|
-
const distance = gesture.dy;
|
|
471
|
-
let target = clamp(startOffsetRef.current + distance, minOff, 0);
|
|
472
|
-
if (shouldMomentum(distance, duration)) {
|
|
473
|
-
target = momentumTarget(distance, duration, startOffsetRef.current, itemHeight, minOff);
|
|
474
|
-
}
|
|
475
|
-
const {
|
|
476
|
-
index
|
|
477
|
-
} = offsetToIndex(target, itemHeight, total, data);
|
|
478
|
-
startWebSnap(index);
|
|
479
|
-
},
|
|
480
|
-
onPanResponderTerminationRequest: () => false,
|
|
481
|
-
onPanResponderTerminate: () => {
|
|
482
|
-
notifyEnd();
|
|
483
|
-
setWebTransition(0);
|
|
484
|
-
}
|
|
485
|
-
}), [data, itemHeight, minOff, notifyEnd, notifyStart, readOnly, setVelocityBucket, startWebSnap, stopRaf, total]);
|
|
486
|
-
const shouldCapture = !readOnly;
|
|
487
|
-
const handleResponderCapture = useCallback(() => shouldCapture, [shouldCapture]);
|
|
488
|
-
const nativeContainerStyle = useMemo(() => ({
|
|
489
|
-
paddingVertical: spacerHeight
|
|
490
|
-
}), [spacerHeight]);
|
|
491
|
-
const handleScroll = useCallback(e => {
|
|
492
|
-
lastOffsetRef.current = e.nativeEvent.contentOffset.y;
|
|
493
|
-
}, []);
|
|
494
|
-
const onDragStart = useCallback(() => {
|
|
495
|
-
momentumRef.current = false;
|
|
496
|
-
clearDragEndTimer();
|
|
497
|
-
notifyStart();
|
|
498
|
-
}, [clearDragEndTimer, notifyStart]);
|
|
499
|
-
const handleScrollEndDrag = useCallback(e => {
|
|
500
|
-
if (readOnly) return;
|
|
501
|
-
const y = e.nativeEvent.contentOffset.y;
|
|
502
|
-
lastOffsetRef.current = y;
|
|
503
|
-
clearDragEndTimer();
|
|
504
|
-
dragEndTimerRef.current = setTimeout(() => {
|
|
505
|
-
if (!momentumRef.current) {
|
|
506
|
-
emitIdx(lastOffsetRef.current, true);
|
|
507
|
-
notifyEnd();
|
|
508
|
-
}
|
|
509
|
-
}, 80);
|
|
510
|
-
}, [clearDragEndTimer, emitIdx, notifyEnd, readOnly]);
|
|
511
|
-
const handleMomentumScrollBegin = useCallback(() => {
|
|
512
|
-
momentumRef.current = true;
|
|
513
|
-
clearDragEndTimer();
|
|
514
|
-
notifyStart();
|
|
515
|
-
}, [clearDragEndTimer, notifyStart]);
|
|
516
|
-
const onMomEnd = useCallback(e => {
|
|
517
|
-
momentumRef.current = false;
|
|
518
|
-
clearDragEndTimer();
|
|
519
|
-
const y = e.nativeEvent.contentOffset.y;
|
|
520
|
-
lastOffsetRef.current = y;
|
|
521
|
-
emitIdx(y, false);
|
|
522
|
-
notifyEnd();
|
|
523
|
-
}, [clearDragEndTimer, emitIdx, notifyEnd]);
|
|
524
|
-
if (isWeb) {
|
|
525
|
-
return /*#__PURE__*/React.createElement(View, _extends({
|
|
526
|
-
style: [W.column, {
|
|
527
|
-
height: containerHeight
|
|
528
|
-
}, W.grab],
|
|
529
|
-
onWheel: handleWheel
|
|
530
|
-
}, panResponder.panHandlers), /*#__PURE__*/React.createElement(View, {
|
|
531
|
-
style: indicatorStyle,
|
|
532
|
-
pointerEvents: "none"
|
|
533
|
-
}, /*#__PURE__*/React.createElement(View, {
|
|
534
|
-
style: createHairlineView({
|
|
535
|
-
position: 'top',
|
|
536
|
-
color: indicatorColor,
|
|
537
|
-
left: 0,
|
|
538
|
-
right: 0
|
|
539
|
-
})
|
|
540
|
-
}), /*#__PURE__*/React.createElement(View, {
|
|
541
|
-
style: createHairlineView({
|
|
542
|
-
position: 'bottom',
|
|
543
|
-
color: indicatorColor,
|
|
544
|
-
left: 0,
|
|
545
|
-
right: 0
|
|
546
|
-
})
|
|
547
|
-
})), /*#__PURE__*/React.createElement(View, {
|
|
548
|
-
style: [webTransform, webTransitionStyle],
|
|
549
|
-
onTransitionEnd: handleWebTransitionEnd
|
|
550
|
-
}, /*#__PURE__*/React.createElement(Spacer, null), webRender.topSpacer, webRender.items, webRender.bottomSpacer, /*#__PURE__*/React.createElement(Spacer, null)));
|
|
551
|
-
}
|
|
552
|
-
return /*#__PURE__*/React.createElement(View, {
|
|
553
|
-
style: [W.column, {
|
|
554
|
-
height: containerHeight
|
|
555
|
-
}],
|
|
556
|
-
collapsable: false
|
|
557
|
-
}, /*#__PURE__*/React.createElement(View, {
|
|
558
|
-
style: indicatorStyle,
|
|
559
|
-
pointerEvents: "none"
|
|
560
|
-
}, /*#__PURE__*/React.createElement(View, {
|
|
561
|
-
style: createHairlineView({
|
|
562
|
-
position: 'top',
|
|
563
|
-
color: indicatorColor,
|
|
564
|
-
left: 0,
|
|
565
|
-
right: 0
|
|
566
|
-
})
|
|
567
|
-
}), /*#__PURE__*/React.createElement(View, {
|
|
568
|
-
style: createHairlineView({
|
|
569
|
-
position: 'bottom',
|
|
570
|
-
color: indicatorColor,
|
|
571
|
-
left: 0,
|
|
572
|
-
right: 0
|
|
573
|
-
})
|
|
574
|
-
})), /*#__PURE__*/React.createElement(ScrollView, {
|
|
575
|
-
ref: scrollRef,
|
|
576
|
-
showsVerticalScrollIndicator: false,
|
|
577
|
-
scrollEventThrottle: effectiveScrollThrottle,
|
|
578
|
-
decelerationRate: decelerationRate,
|
|
579
|
-
snapToInterval: itemHeight,
|
|
580
|
-
snapToAlignment: "start",
|
|
581
|
-
bounces: false,
|
|
582
|
-
overScrollMode: "never",
|
|
583
|
-
nestedScrollEnabled: true,
|
|
584
|
-
contentContainerStyle: nativeContainerStyle,
|
|
585
|
-
onStartShouldSetResponderCapture: handleResponderCapture,
|
|
586
|
-
onMoveShouldSetResponderCapture: handleResponderCapture,
|
|
587
|
-
onScroll: handleScroll,
|
|
588
|
-
onScrollBeginDrag: onDragStart,
|
|
589
|
-
onScrollEndDrag: handleScrollEndDrag,
|
|
590
|
-
onMomentumScrollBegin: handleMomentumScrollBegin,
|
|
591
|
-
onMomentumScrollEnd: onMomEnd,
|
|
592
|
-
scrollEnabled: !readOnly
|
|
593
|
-
}, data.map((item, index) => /*#__PURE__*/React.createElement(WheelPickerItem, {
|
|
594
|
-
key: `${index}-${String(item.value ?? '')}`,
|
|
595
|
-
item: item,
|
|
596
|
-
index: index,
|
|
597
|
-
itemHeight: itemHeight,
|
|
598
|
-
active: index === safeSelIdx,
|
|
599
|
-
disabled: !!item.disabled,
|
|
600
|
-
renderItem: renderItem
|
|
601
|
-
}))));
|
|
602
|
-
};
|
|
603
|
-
const WheelPicker = /*#__PURE__*/React.memo(WheelPickerInner);
|
|
604
|
-
export function usePickerValue({
|
|
605
|
-
columns,
|
|
606
|
-
valueProp,
|
|
607
|
-
defaultValue,
|
|
608
|
-
emitConfirmOnAutoSelect = true,
|
|
609
|
-
onChange,
|
|
610
|
-
onConfirm
|
|
611
|
-
}) {
|
|
612
|
-
const prep = useMemo(() => prepareColumns(columns), [columns]);
|
|
613
|
-
const isControlled = valueProp !== undefined;
|
|
614
|
-
const onChangeRef = useRef(onChange);
|
|
615
|
-
const onConfirmRef = useRef(onConfirm);
|
|
616
|
-
onChangeRef.current = onChange;
|
|
617
|
-
onConfirmRef.current = onConfirm;
|
|
618
|
-
const [innerValue, setInnerValue] = useState(() => normalizePicker(prep, toArrayValue(valueProp ?? defaultValue)).values);
|
|
619
|
-
const innerValueRef = useRef(innerValue);
|
|
620
|
-
innerValueRef.current = innerValue;
|
|
621
|
-
const commitValue = useCallback(next => {
|
|
622
|
-
innerValueRef.current = next;
|
|
623
|
-
setInnerValue(next);
|
|
624
|
-
}, []);
|
|
625
|
-
useEffect(() => {
|
|
626
|
-
if (!isControlled) return;
|
|
627
|
-
const next = toArrayValue(valueProp);
|
|
628
|
-
if (!shallowEqualArray(innerValueRef.current, next)) commitValue(next);
|
|
629
|
-
}, [commitValue, isControlled, valueProp]);
|
|
630
|
-
const norm = useMemo(() => normalizePicker(prep, innerValue), [prep, innerValue]);
|
|
631
|
-
useEffect(() => {
|
|
632
|
-
if (isControlled) return;
|
|
633
|
-
if (!shallowEqualArray(innerValue, norm.values)) {
|
|
634
|
-
commitValue(norm.values);
|
|
635
|
-
onChangeRef.current?.(norm.values, norm.options);
|
|
636
|
-
if (emitConfirmOnAutoSelect) onConfirmRef.current?.(norm.values, norm.options);
|
|
637
|
-
}
|
|
638
|
-
}, [commitValue, emitConfirmOnAutoSelect, innerValue, isControlled, norm]);
|
|
639
|
-
const handleSelect = useCallback((option, colIdx) => {
|
|
640
|
-
const next = [...innerValueRef.current];
|
|
641
|
-
next[colIdx] = option.value;
|
|
642
|
-
if (prep.type === 'cascade') next.length = colIdx + 1;
|
|
643
|
-
const final = normalizePicker(prep, next);
|
|
644
|
-
if (shallowEqualArray(innerValueRef.current, final.values)) return;
|
|
645
|
-
commitValue(final.values);
|
|
646
|
-
onChangeRef.current?.(final.values, final.options);
|
|
647
|
-
}, [commitValue, prep]);
|
|
648
|
-
const handleConfirm = useCallback(() => {
|
|
649
|
-
onConfirmRef.current?.(norm.values, norm.options);
|
|
650
|
-
}, [norm]);
|
|
651
|
-
return {
|
|
652
|
-
preparedColumns: prep,
|
|
653
|
-
normalized: norm,
|
|
654
|
-
handleSelect,
|
|
655
|
-
handleConfirm
|
|
656
|
-
};
|
|
657
|
-
}
|
|
658
|
-
const getVisibleCount = count => {
|
|
659
|
-
const n = isFiniteNumber(count) ? Math.max(3, Math.floor(count)) : 5;
|
|
660
|
-
return n % 2 === 0 ? n + 1 : n;
|
|
661
|
-
};
|
|
662
|
-
const GRADIENT_OVERLAY_ALPHA = 0.25;
|
|
663
|
-
const GRADIENT_STEPS = [0.95, 0.75, 0.55, 0.35];
|
|
664
|
-
const GRADIENT_STEPS_REVERSED = [0.35, 0.55, 0.75, 0.95];
|
|
665
|
-
const GradientMask = ({
|
|
666
|
-
height,
|
|
667
|
-
color,
|
|
668
|
-
position,
|
|
669
|
-
maskType
|
|
670
|
-
}) => {
|
|
671
|
-
const baseStyle = [S.gMask, {
|
|
672
|
-
height
|
|
673
|
-
}, position === 'top' ? {
|
|
674
|
-
top: 0
|
|
675
|
-
} : {
|
|
676
|
-
bottom: 0
|
|
677
|
-
}];
|
|
678
|
-
const overlayColor = withAlpha(color, GRADIENT_OVERLAY_ALPHA);
|
|
679
|
-
if (maskType === 'solid') return /*#__PURE__*/React.createElement(View, {
|
|
680
|
-
pointerEvents: "none",
|
|
681
|
-
style: [...baseStyle, {
|
|
682
|
-
backgroundColor: withAlpha(color, 0.9)
|
|
683
|
-
}]
|
|
684
|
-
});
|
|
685
|
-
if (Platform.OS === 'web') {
|
|
686
|
-
const angle = position === 'top' ? '180deg' : '0deg';
|
|
687
|
-
return /*#__PURE__*/React.createElement(View, {
|
|
688
|
-
pointerEvents: "none",
|
|
689
|
-
style: [...baseStyle, {
|
|
690
|
-
backgroundColor: overlayColor,
|
|
691
|
-
backgroundImage: `linear-gradient(${angle}, ${withAlpha(color, 0.98)}, ${withAlpha(color, 0.4)})`
|
|
692
|
-
}]
|
|
693
|
-
});
|
|
694
|
-
}
|
|
695
|
-
return /*#__PURE__*/React.createElement(View, {
|
|
696
|
-
pointerEvents: "none",
|
|
697
|
-
style: [...baseStyle, {
|
|
698
|
-
backgroundColor: overlayColor
|
|
699
|
-
}]
|
|
700
|
-
}, (position === 'top' ? GRADIENT_STEPS : GRADIENT_STEPS_REVERSED).map((opacity, idx) => /*#__PURE__*/React.createElement(View, {
|
|
701
|
-
key: idx,
|
|
702
|
-
style: {
|
|
703
|
-
flex: 1,
|
|
704
|
-
backgroundColor: withAlpha(color, opacity)
|
|
705
|
-
}
|
|
706
|
-
})));
|
|
707
|
-
};
|
|
708
|
-
const PickerColumn = /*#__PURE__*/React.memo(props => {
|
|
709
|
-
const {
|
|
710
|
-
columnIndex,
|
|
711
|
-
options,
|
|
712
|
-
value,
|
|
713
|
-
itemHeight,
|
|
714
|
-
visibleItemCount,
|
|
715
|
-
optionRender,
|
|
716
|
-
getOptionTestID,
|
|
717
|
-
getOptionA11yLabel,
|
|
718
|
-
onSelect,
|
|
719
|
-
tokens,
|
|
720
|
-
readOnly,
|
|
721
|
-
decelerationRate,
|
|
722
|
-
scrollEventThrottle,
|
|
723
|
-
swipeDuration
|
|
724
|
-
} = props;
|
|
725
|
-
const restVisible = Math.max(1, Math.floor((visibleItemCount - 1) / 2));
|
|
726
|
-
const valueIndexMap = useMemo(() => new Map(options.map((opt, idx) => [opt.value, idx])), [options]);
|
|
727
|
-
const selIdx = useMemo(() => {
|
|
728
|
-
if (!options.length) return 0;
|
|
729
|
-
const idx = valueIndexMap.get(value);
|
|
730
|
-
const startIdx = typeof idx === 'number' && idx >= 0 ? idx : 0;
|
|
731
|
-
return findEnabledIndex(options, startIdx);
|
|
732
|
-
}, [options, value, valueIndexMap]);
|
|
733
|
-
const handleChange = useCallback(index => {
|
|
734
|
-
const tgt = findEnabledIndex(options, index);
|
|
735
|
-
const opt = options[tgt];
|
|
736
|
-
if (!opt || opt.disabled) return;
|
|
737
|
-
onSelect(opt, columnIndex, tgt);
|
|
738
|
-
}, [columnIndex, onSelect, options]);
|
|
739
|
-
const {
|
|
740
|
-
text: cText,
|
|
741
|
-
textDisabled: cDisabled,
|
|
742
|
-
textMuted: cMuted
|
|
743
|
-
} = tokens.colors;
|
|
744
|
-
const optFont = {
|
|
745
|
-
fontSize: tokens.typography.optionSize,
|
|
746
|
-
fontFamily: tokens.typography.fontFamily,
|
|
747
|
-
fontWeight: tokens.typography.optionWeight
|
|
748
|
-
};
|
|
749
|
-
const renderItemStable = useCallback((item, _index, meta) => {
|
|
750
|
-
const {
|
|
751
|
-
active = false,
|
|
752
|
-
disabled = false
|
|
753
|
-
} = meta ?? {};
|
|
754
|
-
const clr = disabled ? cDisabled : active ? cText : cMuted;
|
|
755
|
-
const cnt = optionRender ? optionRender(item, {
|
|
756
|
-
columnIndex,
|
|
757
|
-
active
|
|
758
|
-
}) : item.label ?? item.value;
|
|
759
|
-
const testID = getOptionTestID?.(item, {
|
|
760
|
-
columnIndex,
|
|
761
|
-
active
|
|
762
|
-
});
|
|
763
|
-
const a11y = getOptionA11yLabel?.(item, {
|
|
764
|
-
columnIndex,
|
|
765
|
-
active
|
|
766
|
-
});
|
|
767
|
-
return /*#__PURE__*/React.createElement(View, {
|
|
768
|
-
style: [W.option, {
|
|
769
|
-
opacity: disabled ? 0.5 : 1,
|
|
770
|
-
minHeight: itemHeight
|
|
771
|
-
}],
|
|
772
|
-
testID: testID,
|
|
773
|
-
accessible: !!a11y,
|
|
774
|
-
accessibilityLabel: a11y
|
|
775
|
-
}, isText(cnt) ? /*#__PURE__*/React.createElement(Text, {
|
|
776
|
-
numberOfLines: 1,
|
|
777
|
-
style: [S.optTxt, optFont, {
|
|
778
|
-
color: clr
|
|
779
|
-
}]
|
|
780
|
-
}, cnt) : cnt);
|
|
781
|
-
}, [cText, cDisabled, cMuted, columnIndex, getOptionA11yLabel, getOptionTestID, itemHeight, optFont, optionRender]);
|
|
782
|
-
return /*#__PURE__*/React.createElement(View, {
|
|
783
|
-
style: [W.column, {
|
|
784
|
-
height: itemHeight * visibleItemCount
|
|
785
|
-
}]
|
|
786
|
-
}, /*#__PURE__*/React.createElement(WheelPicker, {
|
|
787
|
-
data: options,
|
|
788
|
-
itemHeight: itemHeight,
|
|
789
|
-
visibleRest: restVisible,
|
|
790
|
-
selectedIndex: Math.max(0, selIdx),
|
|
791
|
-
onChange: handleChange,
|
|
792
|
-
readOnly: readOnly,
|
|
793
|
-
indicatorColor: tokens.colors.indicator,
|
|
794
|
-
decelerationRate: decelerationRate,
|
|
795
|
-
scrollEventThrottle: scrollEventThrottle,
|
|
796
|
-
swipeDuration: swipeDuration,
|
|
797
|
-
renderItem: renderItemStable
|
|
798
|
-
}));
|
|
799
|
-
});
|
|
800
|
-
const PickerImpl = props => {
|
|
801
|
-
const {
|
|
802
|
-
tokensOverride
|
|
803
|
-
} = props;
|
|
804
|
-
const locale = useLocale();
|
|
805
|
-
const tokens = usePickerTokens(tokensOverride);
|
|
806
|
-
const {
|
|
807
|
-
columns = [],
|
|
808
|
-
value: valueProp,
|
|
809
|
-
defaultValue,
|
|
810
|
-
title,
|
|
811
|
-
showToolbar = tokens.defaults.showToolbar,
|
|
812
|
-
toolbarPosition = tokens.defaults.toolbarPosition,
|
|
813
|
-
confirmButtonText = locale?.confirm ?? 'Confirm',
|
|
814
|
-
cancelButtonText = locale?.cancel ?? 'Cancel',
|
|
815
|
-
itemHeight = tokens.defaults.itemHeight,
|
|
816
|
-
visibleItemCount: visibleItemCountProp = tokens.defaults.visibleItemCount,
|
|
817
|
-
loading = false,
|
|
818
|
-
readOnly = false,
|
|
819
|
-
decelerationRate = Platform.select({
|
|
820
|
-
ios: 0.999,
|
|
821
|
-
android: 0.997,
|
|
822
|
-
default: 0.989
|
|
823
|
-
}) ?? 'normal',
|
|
824
|
-
swipeDuration = tokens.defaults.swipeDuration,
|
|
825
|
-
scrollEventThrottle = 16,
|
|
826
|
-
columnsTop,
|
|
827
|
-
columnsBottom,
|
|
828
|
-
optionRender,
|
|
829
|
-
getOptionTestID,
|
|
830
|
-
getOptionA11yLabel,
|
|
831
|
-
emitConfirmOnAutoSelect = true,
|
|
832
|
-
maskColor,
|
|
833
|
-
maskType = tokens.defaults.maskType,
|
|
834
|
-
onChange,
|
|
835
|
-
onConfirm,
|
|
836
|
-
onCancel,
|
|
837
|
-
style,
|
|
838
|
-
testID,
|
|
839
|
-
...rest
|
|
840
|
-
} = props;
|
|
841
|
-
const visCnt = getVisibleCount(visibleItemCountProp ?? tokens.defaults.visibleItemCount);
|
|
842
|
-
const {
|
|
843
|
-
normalized: norm,
|
|
844
|
-
handleSelect,
|
|
845
|
-
handleConfirm,
|
|
846
|
-
preparedColumns: prep
|
|
847
|
-
} = usePickerValue({
|
|
848
|
-
columns,
|
|
849
|
-
valueProp,
|
|
850
|
-
defaultValue,
|
|
851
|
-
emitConfirmOnAutoSelect,
|
|
852
|
-
onChange,
|
|
853
|
-
onConfirm
|
|
854
|
-
});
|
|
855
|
-
const isCascade = prep.type === 'cascade';
|
|
856
|
-
const toolbarFont = {
|
|
857
|
-
fontSize: tokens.typography.toolbarSize,
|
|
858
|
-
fontFamily: tokens.typography.fontFamily,
|
|
859
|
-
fontWeight: tokens.typography.toolbarWeight
|
|
860
|
-
};
|
|
861
|
-
const renderActionContent = (content, color) => /*#__PURE__*/React.isValidElement(content) ? /*#__PURE__*/React.createElement(View, {
|
|
862
|
-
style: S.actW
|
|
863
|
-
}, content) : isText(content) ? /*#__PURE__*/React.createElement(Text, {
|
|
864
|
-
numberOfLines: 1,
|
|
865
|
-
style: [S.actTxt, toolbarFont, {
|
|
866
|
-
color
|
|
867
|
-
}]
|
|
868
|
-
}, content) : /*#__PURE__*/React.createElement(View, {
|
|
869
|
-
style: S.actW
|
|
870
|
-
});
|
|
871
|
-
const renderTitleContent = content => content == null ? /*#__PURE__*/React.createElement(View, null) : /*#__PURE__*/React.isValidElement(content) ? /*#__PURE__*/React.createElement(View, {
|
|
872
|
-
style: S.ttlW
|
|
873
|
-
}, content) : /*#__PURE__*/React.createElement(Text, {
|
|
874
|
-
style: [S.title, toolbarFont, {
|
|
875
|
-
color: tokens.colors.text
|
|
876
|
-
}],
|
|
877
|
-
numberOfLines: 1
|
|
878
|
-
}, content);
|
|
879
|
-
const toolbar = showToolbar ? /*#__PURE__*/React.createElement(View, {
|
|
880
|
-
style: [S.toolbar, {
|
|
881
|
-
height: tokens.spacing.toolbarHeight,
|
|
882
|
-
paddingHorizontal: tokens.spacing.actionPadding
|
|
883
|
-
}]
|
|
884
|
-
}, /*#__PURE__*/React.createElement(Pressable, {
|
|
885
|
-
onPress: onCancel,
|
|
886
|
-
accessibilityRole: "button"
|
|
887
|
-
}, renderActionContent(cancelButtonText, tokens.colors.cancel)), renderTitleContent(title), /*#__PURE__*/React.createElement(Pressable, {
|
|
888
|
-
onPress: handleConfirm,
|
|
889
|
-
accessibilityRole: "button"
|
|
890
|
-
}, renderActionContent(confirmButtonText, tokens.colors.confirm)), /*#__PURE__*/React.createElement(View, {
|
|
891
|
-
style: createHairlineView({
|
|
892
|
-
position: 'bottom',
|
|
893
|
-
color: tokens.colors.indicator,
|
|
894
|
-
left: 0,
|
|
895
|
-
right: 0
|
|
896
|
-
})
|
|
897
|
-
})) : null;
|
|
898
|
-
const wrapperH = itemHeight * visCnt;
|
|
899
|
-
const maskVisCnt = Math.max(1, Math.floor((visCnt - 1) / 2));
|
|
900
|
-
const indicatorOff = itemHeight * maskVisCnt;
|
|
901
|
-
const maskH = indicatorOff;
|
|
902
|
-
const hasCols = norm.columns.length > 0;
|
|
903
|
-
const effMaskColor = maskColor ?? tokens.colors.mask;
|
|
904
|
-
const columnsContent = hasCols ? norm.columns.map((column, colIdx) => {
|
|
905
|
-
const key = isCascade ? `${colIdx}-${norm.values.slice(0, colIdx).map(String).join('|')}` : String(colIdx);
|
|
906
|
-
return /*#__PURE__*/React.createElement(PickerColumn, {
|
|
907
|
-
key: key,
|
|
908
|
-
columnIndex: colIdx,
|
|
909
|
-
options: column,
|
|
910
|
-
value: norm.values[colIdx],
|
|
911
|
-
itemHeight: itemHeight,
|
|
912
|
-
visibleItemCount: visCnt,
|
|
913
|
-
decelerationRate: decelerationRate,
|
|
914
|
-
scrollEventThrottle: scrollEventThrottle,
|
|
915
|
-
optionRender: optionRender,
|
|
916
|
-
getOptionTestID: getOptionTestID,
|
|
917
|
-
getOptionA11yLabel: getOptionA11yLabel,
|
|
918
|
-
readOnly: readOnly,
|
|
919
|
-
swipeDuration: swipeDuration,
|
|
920
|
-
onSelect: handleSelect,
|
|
921
|
-
tokens: tokens
|
|
922
|
-
});
|
|
923
|
-
}) : null;
|
|
924
|
-
return /*#__PURE__*/React.createElement(View, _extends({}, rest, {
|
|
925
|
-
style: [{
|
|
926
|
-
backgroundColor: tokens.colors.background,
|
|
927
|
-
borderRadius: tokens.radius.container
|
|
928
|
-
}, style],
|
|
929
|
-
testID: testID
|
|
930
|
-
}), toolbarPosition === 'top' && toolbar, /*#__PURE__*/React.createElement(View, {
|
|
931
|
-
style: [S.body, {
|
|
932
|
-
height: wrapperH
|
|
933
|
-
}]
|
|
934
|
-
}, /*#__PURE__*/React.createElement(View, {
|
|
935
|
-
style: S.columns,
|
|
936
|
-
pointerEvents: loading ? 'none' : 'auto'
|
|
937
|
-
}, columnsTop, columnsContent, columnsBottom, hasCols && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(View, {
|
|
938
|
-
pointerEvents: "none",
|
|
939
|
-
style: [S.indicator, {
|
|
940
|
-
top: indicatorOff,
|
|
941
|
-
height: itemHeight
|
|
942
|
-
}]
|
|
943
|
-
}, /*#__PURE__*/React.createElement(View, {
|
|
944
|
-
style: createHairlineView({
|
|
945
|
-
position: 'top',
|
|
946
|
-
color: tokens.colors.indicator,
|
|
947
|
-
left: 0,
|
|
948
|
-
right: 0
|
|
949
|
-
})
|
|
950
|
-
}), /*#__PURE__*/React.createElement(View, {
|
|
951
|
-
style: createHairlineView({
|
|
952
|
-
position: 'bottom',
|
|
953
|
-
color: tokens.colors.indicator,
|
|
954
|
-
left: 0,
|
|
955
|
-
right: 0
|
|
956
|
-
})
|
|
957
|
-
})), /*#__PURE__*/React.createElement(GradientMask, {
|
|
958
|
-
position: "top",
|
|
959
|
-
height: maskH,
|
|
960
|
-
color: effMaskColor,
|
|
961
|
-
maskType: maskType
|
|
962
|
-
}), /*#__PURE__*/React.createElement(GradientMask, {
|
|
963
|
-
position: "bottom",
|
|
964
|
-
height: maskH,
|
|
965
|
-
color: effMaskColor,
|
|
966
|
-
maskType: maskType
|
|
967
|
-
}))), loading && /*#__PURE__*/React.createElement(View, {
|
|
968
|
-
style: [S.loading, {
|
|
969
|
-
backgroundColor: tokens.colors.loadingMask
|
|
970
|
-
}]
|
|
971
|
-
}, /*#__PURE__*/React.createElement(Loading, null))), toolbarPosition === 'bottom' && toolbar);
|
|
972
|
-
};
|
|
973
|
-
const S = StyleSheet.create({
|
|
974
|
-
body: {
|
|
975
|
-
position: 'relative',
|
|
976
|
-
overflow: 'hidden'
|
|
977
|
-
},
|
|
978
|
-
columns: {
|
|
979
|
-
flex: 1,
|
|
980
|
-
flexDirection: 'row'
|
|
981
|
-
},
|
|
982
|
-
optTxt: {
|
|
983
|
-
includeFontPadding: false
|
|
984
|
-
},
|
|
985
|
-
indicator: {
|
|
986
|
-
position: 'absolute',
|
|
987
|
-
left: 0,
|
|
988
|
-
right: 0,
|
|
989
|
-
zIndex: 3
|
|
990
|
-
},
|
|
991
|
-
gMask: {
|
|
992
|
-
position: 'absolute',
|
|
993
|
-
left: 0,
|
|
994
|
-
right: 0,
|
|
995
|
-
zIndex: 2
|
|
996
|
-
},
|
|
997
|
-
toolbar: {
|
|
998
|
-
flexDirection: 'row',
|
|
999
|
-
alignItems: 'center',
|
|
1000
|
-
justifyContent: 'space-between'
|
|
1001
|
-
},
|
|
1002
|
-
title: {
|
|
1003
|
-
flex: 1,
|
|
1004
|
-
textAlign: 'center'
|
|
1005
|
-
},
|
|
1006
|
-
ttlW: {
|
|
1007
|
-
flex: 1,
|
|
1008
|
-
alignItems: 'center',
|
|
1009
|
-
justifyContent: 'center'
|
|
1010
|
-
},
|
|
1011
|
-
actTxt: {
|
|
1012
|
-
minWidth: 44,
|
|
1013
|
-
textAlign: 'center'
|
|
1014
|
-
},
|
|
1015
|
-
actW: {
|
|
1016
|
-
minWidth: 44,
|
|
1017
|
-
alignItems: 'center',
|
|
1018
|
-
justifyContent: 'center'
|
|
1019
|
-
},
|
|
1020
|
-
loading: {
|
|
1021
|
-
position: 'absolute',
|
|
1022
|
-
top: 0,
|
|
1023
|
-
left: 0,
|
|
1024
|
-
right: 0,
|
|
1025
|
-
bottom: 0,
|
|
1026
|
-
alignItems: 'center',
|
|
1027
|
-
justifyContent: 'center'
|
|
1028
|
-
}
|
|
1029
|
-
});
|
|
1030
|
-
const Picker = /*#__PURE__*/React.memo(PickerImpl);
|
|
1031
|
-
export default Picker;
|
|
1
|
+
function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},_extends.apply(null,arguments)}import React,{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Pressable,Text,View,Platform,StyleSheet,ScrollView,PanResponder}from"react-native";import Loading from"../loading";import{useLocale}from"../config-provider/useLocale";import{withAlpha}from"../../utils/color";import{isFiniteNumber,isText}from"../../utils/validate";import{clamp,isObject,shallowEqualArray}from"../../utils";import{usePickerTokens}from"./tokens";import{createHairlineView}from"../../utils/hairline";export const toArrayValue=e=>Array.isArray(e)?e.filter(e=>null!=e):null==e?[]:[e];const isColumnWithOptions=e=>!!e&&isObject(e)&&"options"in e&&Array.isArray(e.options),hasChildren=e=>!!e&&isObject(e)&&Array.isArray(e.children)&&e.children.length>0;export const findEnabledIndex=(e,t)=>{if(!e.length)return-1;const n=Math.min(Math.max(t,0),e.length-1);if(!e[n]?.disabled)return n;for(let t=n+1;t<e.length;t+=1)if(!e[t]?.disabled)return t;for(let t=n-1;t>=0;t-=1)if(!e[t]?.disabled)return t;return-1};const normalizeMultiple=(e,t,n)=>{const r=[],o=[];return e.forEach((e,a)=>{const l=n[a],i=void 0!==t[a]?e.findIndex(e=>e.value===t[a]):-1,c=e.findIndex(e=>e.value===l),s=findEnabledIndex(e,c>=0?c:i>=0?i:0),u=s>=0?e[s]:void 0,m=c>=0&&!e[c]?.disabled;r[a]=m?l:u?.value??t[a]??e[0]?.value,o[a]=u}),{columns:e,values:r,options:o}},normalizeCascade=(e,t)=>{const n=[],r=[],o=[];let a=e,l=0;for(;a&&a.length&&l<10;){n.push(a);const e=t[l],i=a.findIndex(t=>t.value===e||String(t.value)===String(e)),c=findEnabledIndex(a,i>=0?i:0),s=c>=0?a[c]:a[0];if(r[l]=s?.value,o[l]=s,!s||!hasChildren(s))break;a=s.children,l+=1}return{columns:n,values:r,options:o}};export const prepareColumns=(e=[])=>{if(!Array.isArray(e)||0===e.length)return{type:"single",columnsList:[],defaults:[],cascadeRoot:[]};const t=e.every(e=>!Array.isArray(e)&&!isColumnWithOptions(e)),n=t&&e.some(e=>hasChildren(e));if(n)return{type:"cascade",columnsList:[],defaults:[],cascadeRoot:e};const r=e,o=[],a=[];return t&&!n?(o.push(e),a.push(void 0)):r.forEach(e=>{if(Array.isArray(e))o.push(e),a.push(void 0);else if(isColumnWithOptions(e)){const t=e;o.push(t.options??[]),a.push(t.defaultValue)}}),{type:"multiple",columnsList:o,defaults:a}};export const normalizePicker=(e,t=[])=>{const n=Array.isArray(t)?t:[];return"cascade"===e.type&&e.cascadeRoot?.length?normalizeCascade(e.cascadeRoot,n):normalizeMultiple(e.columnsList,e.defaults,n)};const W=StyleSheet.create({column:{flex:1},option:{justifyContent:"center",alignItems:"center"},grab:{cursor:"pointer",userSelect:"none",touchAction:"none"}}),WheelPickerItemInner=({item:e,index:t,itemHeight:n,active:r,disabled:o,renderItem:a})=>{const l=a(e,t,{active:r,disabled:o});return React.createElement(View,{style:[W.option,{height:n}]},l)},WheelPickerItem=React.memo(WheelPickerItemInner),getVelocityBucket=e=>{const t=Math.abs(e);return t>1.2?2:t>.6?1:0},adjustIndex=(e,t)=>{const n=t.length;if(!n)return 0;const r=clamp(e,0,n-1),o=findEnabledIndex(t,r);return o>=0?o:r},indexToOffset=(e,t)=>-e*t,offsetToIndex=(e,t,n,r)=>{const o=-Math.max(0,n-1)*t,a=clamp(e,o,0);let l=Math.round(-a/t);l=adjustIndex(l,r);return{index:l,snapOffset:indexToOffset(l,t)}},shouldMomentum=(e,t)=>t<500&&Math.abs(e)>8,momentumTarget=(e,t,n,r,o)=>{const a=Math.abs(e/t),l=clamp(n+a/.0025*(e<0?-1:1),o,0),i=Math.round(-l/r);return indexToOffset(i,r)},WheelPickerInner=({data:e,selectedIndex:t,onChange:n,onInteractStart:r,onInteractEnd:o,renderItem:a,itemHeight:l,visibleRest:i,readOnly:c,indicatorColor:s,decelerationRate:u=Platform.select({ios:.9985,android:.995,default:.995})??"normal",scrollEventThrottle:m=16,swipeDuration:d=300})=>{const f="web"===Platform.OS,p=useRef(null),h=useRef(null),b=i*l,g=e.length,y=Math.max(0,g-1),R=-y*l,E=l*(2*i+1),v=clamp(t,0,y),x=findEnabledIndex(e,v),k=x>=0?x:v,C=2*i+1,w=g>20*C?32:m,I=g>4*C,T=useCallback(()=>React.createElement(View,{style:{height:b}}),[b]),V=useMemo(()=>[S.indicator,{height:l,top:l*i}],[l,i]),P=useRef(null),A=useRef(!1),M=useRef(0),O=useCallback(()=>{P.current&&(clearTimeout(P.current),P.current=null)},[]),D=useCallback((t,r)=>{if(c)return;const{index:o,snapOffset:a}=offsetToIndex(-t,l,g,e),i=-a;Math.abs(i-t)>.5&&p.current?.scrollToOffset({offset:i,animated:r}),n(o)},[e,l,n,c,g]);useEffect(()=>{const e=k*l;f||h.current?.scrollTo({y:e,animated:!1})},[f,l,k]);const[H,z]=useState(()=>indexToOffset(k,l)),L=useRef(H),F=useRef(0),j=useRef(0),[_,q]=useState(0),[G,N]=useState(0),$=useRef(0),B=useRef(null),Y=useRef(0),J=useRef(null),K=useRef(null),Q=useRef(null),U=useRef(null),X=useRef(!1),Z=useRef(r);Z.current=r;const ee=useRef(o);ee.current=o;const te=useCallback(()=>{c||X.current||(X.current=!0,Z.current?.())},[c]),ne=useCallback(()=>{X.current&&(X.current=!1,ee.current?.())},[]),re=useCallback(()=>{null!=U.current&&"undefined"!=typeof cancelAnimationFrame&&(cancelAnimationFrame(U.current),U.current=null),null!=J.current&&"undefined"!=typeof cancelAnimationFrame&&(cancelAnimationFrame(J.current),J.current=null)},[]),oe=useCallback(()=>{Q.current&&(clearTimeout(Q.current),Q.current=null)},[]);useEffect(()=>()=>{O(),oe(),re()},[O,oe,re]);const ae=useCallback(e=>{const t=getVelocityBucket(e);t!==$.current&&($.current=t,N(t))},[]),le=useCallback(e=>{const t=Date.now(),n=B.current;if(null!=n){const r=Math.max(1,t-n);ae(e/r)}B.current=t},[ae]);useEffect(()=>{if(!f)return;oe(),K.current=null,q(0);const e=indexToOffset(k,l);L.current=e,z(e)},[oe,f,l,k,q]);const ie=useCallback(()=>{if(c)return;const e=K.current;null!=e&&(K.current=null,oe(),q(0),ne(),n(e))},[oe,n,c,q]),ce=useCallback(e=>{if(c)return;te();const t=clamp(e,0,y),n=indexToOffset(t,l);oe(),K.current=t,L.current=n,q(d),z(n),d<=0?ie():Q.current=setTimeout(ie,d+80)},[oe,ie,l,y,c,d]),se=useCallback(t=>{if(c)return;const n=t.nativeEvent?.deltaY??0;n&&(Y.current+=n,null==J.current&&"undefined"!=typeof requestAnimationFrame&&(J.current=requestAnimationFrame(()=>{J.current=null;const t=Y.current;if(Y.current=0,!t)return;le(t);const n=t>0?1:-1,{index:r}=offsetToIndex(L.current,l,g,e),o=clamp(r+n,0,y);ce(o)})))},[e,l,y,c,ce,g,le]),ue=clamp(Math.round(-H/l),0,y),me=useMemo(()=>{if(!f||g<=0)return{items:null,topSpacer:null,bottomSpacer:null};let t=0,n=y;if(I){const e=Math.max(2*C,8),r=2===G?4*C:1===G?2*C:0,o=Math.min(e+r,Math.max(6*C,24));t=clamp(ue-o,0,y),n=clamp(ue+o,0,y)}const r=[];for(let o=t;o<=n;o+=1){const t=e[o];t&&r.push(React.createElement(WheelPickerItem,{key:`${o}-${String(t.value??"")}`,item:t,index:o,itemHeight:l,active:o===k,disabled:!!t.disabled,renderItem:a}))}const o=t*l,i=(y-n)*l;return{items:r,topSpacer:o>0&&React.createElement(View,{style:{height:o}}),bottomSpacer:i>0&&React.createElement(View,{style:{height:i}})}},[e,f,l,y,a,k,g,C,ue,G,I]),de=useMemo(()=>({transform:[{translateY:H}]}),[H]),fe=useMemo(()=>_?{transitionProperty:"transform",transitionDuration:_+"ms",transitionTimingFunction:"cubic-bezier(0.23, 1, 0.68, 1)",willChange:"transform"}:void 0,[_]),pe=useCallback(e=>{const t=e.nativeEvent?.propertyName??e.propertyName;t&&"transform"!==t&&"webkitTransform"!==t||ie()},[ie]),he=useMemo(()=>PanResponder.create({onStartShouldSetPanResponder:()=>!c,onMoveShouldSetPanResponder:()=>!c,onPanResponderGrant:()=>{re(),K.current=null,te(),q(0),F.current=L.current,j.current=Date.now()},onPanResponderMove:(e,t)=>{if(c)return;ae(t.vy);const n=clamp(F.current+t.dy,R,0);L.current=n,"undefined"!=typeof requestAnimationFrame?null==U.current&&(U.current=requestAnimationFrame(()=>{U.current=null,z(L.current)})):z(n)},onPanResponderRelease:(t,n)=>{if(c)return;ae(0);const r=Date.now()-j.current,o=n.dy;let a=clamp(F.current+o,R,0);shouldMomentum(o,r)&&(a=momentumTarget(o,r,F.current,l,R));const{index:i}=offsetToIndex(a,l,g,e);ce(i)},onPanResponderTerminationRequest:()=>!1,onPanResponderTerminate:()=>{ne(),q(0)}}),[e,l,R,ne,te,c,ae,ce,re,g]),be=!c,ge=useCallback(()=>be,[be]),ye=useMemo(()=>({paddingVertical:b}),[b]),Re=useCallback(e=>{M.current=e.nativeEvent.contentOffset.y},[]),Ee=useCallback(()=>{A.current=!1,O(),te()},[O,te]),ve=useCallback(e=>{if(c)return;const t=e.nativeEvent.contentOffset.y;M.current=t,O(),P.current=setTimeout(()=>{A.current||(D(M.current,!0),ne())},80)},[O,D,ne,c]),xe=useCallback(()=>{A.current=!0,O(),te()},[O,te]),ke=useCallback(e=>{A.current=!1,O();const t=e.nativeEvent.contentOffset.y;M.current=t,D(t,!1),ne()},[O,D,ne]);return f?React.createElement(View,_extends({style:[W.column,{height:E},W.grab],onWheel:se},he.panHandlers),React.createElement(View,{style:V,pointerEvents:"none"},React.createElement(View,{style:createHairlineView({position:"top",color:s,left:0,right:0})}),React.createElement(View,{style:createHairlineView({position:"bottom",color:s,left:0,right:0})})),React.createElement(View,{style:[de,fe],onTransitionEnd:pe},React.createElement(T,null),me.topSpacer,me.items,me.bottomSpacer,React.createElement(T,null))):React.createElement(View,{style:[W.column,{height:E}],collapsable:!1},React.createElement(View,{style:V,pointerEvents:"none"},React.createElement(View,{style:createHairlineView({position:"top",color:s,left:0,right:0})}),React.createElement(View,{style:createHairlineView({position:"bottom",color:s,left:0,right:0})})),React.createElement(ScrollView,{ref:h,showsVerticalScrollIndicator:!1,scrollEventThrottle:w,decelerationRate:u,snapToInterval:l,snapToAlignment:"start",bounces:!1,overScrollMode:"never",nestedScrollEnabled:!0,contentContainerStyle:ye,onStartShouldSetResponderCapture:ge,onMoveShouldSetResponderCapture:ge,onScroll:Re,onScrollBeginDrag:Ee,onScrollEndDrag:ve,onMomentumScrollBegin:xe,onMomentumScrollEnd:ke,scrollEnabled:!c},e.map((e,t)=>React.createElement(WheelPickerItem,{key:`${t}-${String(e.value??"")}`,item:e,index:t,itemHeight:l,active:t===k,disabled:!!e.disabled,renderItem:a}))))},WheelPicker=React.memo(WheelPickerInner);export function usePickerValue({columns:e,valueProp:t,defaultValue:n,emitConfirmOnAutoSelect:r=!0,onChange:o,onConfirm:a}){const l=useMemo(()=>prepareColumns(e),[e]),i=void 0!==t,c=useRef(o),s=useRef(a);c.current=o,s.current=a;const[u,m]=useState(()=>normalizePicker(l,toArrayValue(t??n)).values),d=useRef(u);d.current=u;const f=useCallback(e=>{d.current=e,m(e)},[]);useEffect(()=>{if(!i)return;const e=toArrayValue(t);shallowEqualArray(d.current,e)||f(e)},[f,i,t]);const p=useMemo(()=>normalizePicker(l,u),[l,u]);useEffect(()=>{i||shallowEqualArray(u,p.values)||(f(p.values),c.current?.(p.values,p.options),r&&s.current?.(p.values,p.options))},[f,r,u,i,p]);const h=useCallback((e,t)=>{const n=[...d.current];n[t]=e.value,"cascade"===l.type&&(n.length=t+1);const r=normalizePicker(l,n);shallowEqualArray(d.current,r.values)||(f(r.values),c.current?.(r.values,r.options))},[f,l]),b=useCallback(()=>{s.current?.(p.values,p.options)},[p]);return{preparedColumns:l,normalized:p,handleSelect:h,handleConfirm:b}}const getVisibleCount=e=>{const t=isFiniteNumber(e)?Math.max(3,Math.floor(e)):5;return t%2==0?t+1:t},GRADIENT_OVERLAY_ALPHA=.25,GRADIENT_STEPS=[.95,.75,.55,.35],GRADIENT_STEPS_REVERSED=[.35,.55,.75,.95],GradientMask=({height:e,color:t,position:n,maskType:r})=>{const o=[S.gMask,{height:e},"top"===n?{top:0}:{bottom:0}],a=withAlpha(t,.25);if("solid"===r)return React.createElement(View,{pointerEvents:"none",style:[...o,{backgroundColor:withAlpha(t,.9)}]});if("web"===Platform.OS){const e="top"===n?"180deg":"0deg";return React.createElement(View,{pointerEvents:"none",style:[...o,{backgroundColor:a,backgroundImage:`linear-gradient(${e}, ${withAlpha(t,.98)}, ${withAlpha(t,.4)})`}]})}return React.createElement(View,{pointerEvents:"none",style:[...o,{backgroundColor:a}]},("top"===n?GRADIENT_STEPS:GRADIENT_STEPS_REVERSED).map((e,n)=>React.createElement(View,{key:n,style:{flex:1,backgroundColor:withAlpha(t,e)}})))},PickerColumn=React.memo(e=>{const{columnIndex:t,options:n,value:r,itemHeight:o,visibleItemCount:a,optionRender:l,getOptionTestID:i,getOptionA11yLabel:c,onSelect:s,tokens:u,readOnly:m,decelerationRate:d,scrollEventThrottle:f,swipeDuration:p}=e,h=Math.max(1,Math.floor((a-1)/2)),b=useMemo(()=>new Map(n.map((e,t)=>[e.value,t])),[n]),g=useMemo(()=>{if(!n.length)return 0;const e=b.get(r);return findEnabledIndex(n,"number"==typeof e&&e>=0?e:0)},[n,r,b]),y=useCallback(e=>{const r=findEnabledIndex(n,e),o=n[r];o&&!o.disabled&&s(o,t,r)},[t,s,n]),{text:R,textDisabled:E,textMuted:v}=u.colors,x={fontSize:u.typography.optionSize,fontFamily:u.typography.fontFamily,fontWeight:u.typography.optionWeight},k=useCallback((e,n,r)=>{const{active:a=!1,disabled:s=!1}=r??{},u=s?E:a?R:v,m=l?l(e,{columnIndex:t,active:a}):e.label??e.value,d=i?.(e,{columnIndex:t,active:a}),f=c?.(e,{columnIndex:t,active:a});return React.createElement(View,{style:[W.option,{opacity:s?.5:1,minHeight:o}],testID:d,accessible:!!f,accessibilityLabel:f},isText(m)?React.createElement(Text,{numberOfLines:1,style:[S.optTxt,x,{color:u}]},m):m)},[R,E,v,t,c,i,o,x,l]);return React.createElement(View,{style:[W.column,{height:o*a}]},React.createElement(WheelPicker,{data:n,itemHeight:o,visibleRest:h,selectedIndex:Math.max(0,g),onChange:y,readOnly:m,indicatorColor:u.colors.indicator,decelerationRate:d,scrollEventThrottle:f,swipeDuration:p,renderItem:k}))}),PickerImpl=e=>{const{tokensOverride:t}=e,n=useLocale(),r=usePickerTokens(t),{columns:o=[],value:a,defaultValue:l,title:i,showToolbar:c=r.defaults.showToolbar,toolbarPosition:s=r.defaults.toolbarPosition,confirmButtonText:u=n?.confirm??"Confirm",cancelButtonText:m=n?.cancel??"Cancel",itemHeight:d=r.defaults.itemHeight,visibleItemCount:f=r.defaults.visibleItemCount,loading:p=!1,readOnly:h=!1,decelerationRate:b=Platform.select({ios:.999,android:.997,default:.989})??"normal",swipeDuration:g=r.defaults.swipeDuration,scrollEventThrottle:y=16,columnsTop:R,columnsBottom:E,optionRender:v,getOptionTestID:x,getOptionA11yLabel:k,emitConfirmOnAutoSelect:C=!0,maskColor:w,maskType:I=r.defaults.maskType,onChange:T,onConfirm:V,onCancel:P,style:A,testID:M,...O}=e,W=getVisibleCount(f??r.defaults.visibleItemCount),{normalized:D,handleSelect:H,handleConfirm:z,preparedColumns:L}=usePickerValue({columns:o,valueProp:a,defaultValue:l,emitConfirmOnAutoSelect:C,onChange:T,onConfirm:V}),F="cascade"===L.type,j={fontSize:r.typography.toolbarSize,fontFamily:r.typography.fontFamily,fontWeight:r.typography.toolbarWeight},_=(e,t)=>React.isValidElement(e)?React.createElement(View,{style:S.actW},e):isText(e)?React.createElement(Text,{numberOfLines:1,style:[S.actTxt,j,{color:t}]},e):React.createElement(View,{style:S.actW}),q=c?React.createElement(View,{style:[S.toolbar,{height:r.spacing.toolbarHeight,paddingHorizontal:r.spacing.actionPadding}]},React.createElement(Pressable,{onPress:P,accessibilityRole:"button"},_(m,r.colors.cancel)),null==(G=i)?React.createElement(View,null):React.isValidElement(G)?React.createElement(View,{style:S.ttlW},G):React.createElement(Text,{style:[S.title,j,{color:r.colors.text}],numberOfLines:1},G),React.createElement(Pressable,{onPress:z,accessibilityRole:"button"},_(u,r.colors.confirm)),React.createElement(View,{style:createHairlineView({position:"bottom",color:r.colors.indicator,left:0,right:0})})):null;var G;const N=d*W,$=Math.max(1,Math.floor((W-1)/2)),B=d*$,Y=B,J=D.columns.length>0,K=w??r.colors.mask,Q=J?D.columns.map((e,t)=>{const n=F?`${t}-${D.values.slice(0,t).map(String).join("|")}`:String(t);return React.createElement(PickerColumn,{key:n,columnIndex:t,options:e,value:D.values[t],itemHeight:d,visibleItemCount:W,decelerationRate:b,scrollEventThrottle:y,optionRender:v,getOptionTestID:x,getOptionA11yLabel:k,readOnly:h,swipeDuration:g,onSelect:H,tokens:r})}):null;return React.createElement(View,_extends({},O,{style:[{backgroundColor:r.colors.background,borderRadius:r.radius.container},A],testID:M}),"top"===s&&q,React.createElement(View,{style:[S.body,{height:N}]},React.createElement(View,{style:S.columns,pointerEvents:p?"none":"auto"},R,Q,E,J&&React.createElement(React.Fragment,null,React.createElement(View,{pointerEvents:"none",style:[S.indicator,{top:B,height:d}]},React.createElement(View,{style:createHairlineView({position:"top",color:r.colors.indicator,left:0,right:0})}),React.createElement(View,{style:createHairlineView({position:"bottom",color:r.colors.indicator,left:0,right:0})})),React.createElement(GradientMask,{position:"top",height:Y,color:K,maskType:I}),React.createElement(GradientMask,{position:"bottom",height:Y,color:K,maskType:I}))),p&&React.createElement(View,{style:[S.loading,{backgroundColor:r.colors.loadingMask}]},React.createElement(Loading,null))),"bottom"===s&&q)},S=StyleSheet.create({body:{position:"relative",overflow:"hidden"},columns:{flex:1,flexDirection:"row"},optTxt:{includeFontPadding:!1},indicator:{position:"absolute",left:0,right:0,zIndex:3},gMask:{position:"absolute",left:0,right:0,zIndex:2},toolbar:{flexDirection:"row",alignItems:"center",justifyContent:"space-between"},title:{flex:1,textAlign:"center"},ttlW:{flex:1,alignItems:"center",justifyContent:"center"},actTxt:{minWidth:44,textAlign:"center"},actW:{minWidth:44,alignItems:"center",justifyContent:"center"},loading:{position:"absolute",top:0,left:0,right:0,bottom:0,alignItems:"center",justifyContent:"center"}}),Picker=React.memo(PickerImpl);export default Picker;
|