zkit-ui 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +267 -0
- package/dist/ComponentLibProvider.d.ts +15 -0
- package/dist/ComponentLibProvider.d.ts.map +1 -0
- package/dist/ComponentLibProvider.js +18 -0
- package/dist/assets/animations/spinner.json +1 -0
- package/dist/assets/icons/check.svg +4 -0
- package/dist/assets/icons/toast/error.webp +0 -0
- package/dist/assets/icons/toast/success.webp +0 -0
- package/dist/assets/icons/toast/warning.webp +0 -0
- package/dist/config.d.ts +16 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +42 -0
- package/dist/i18n/I18nProvider.d.ts +11 -0
- package/dist/i18n/I18nProvider.d.ts.map +1 -0
- package/dist/i18n/I18nProvider.js +84 -0
- package/dist/i18n/locale.d.ts +7 -0
- package/dist/i18n/locale.d.ts.map +1 -0
- package/dist/i18n/locale.js +87 -0
- package/dist/i18n/locales/de.d.ts +51 -0
- package/dist/i18n/locales/de.d.ts.map +1 -0
- package/dist/i18n/locales/de.js +62 -0
- package/dist/i18n/locales/en-US.d.ts +51 -0
- package/dist/i18n/locales/en-US.d.ts.map +1 -0
- package/dist/i18n/locales/en-US.js +62 -0
- package/dist/i18n/locales/index.d.ts +9 -0
- package/dist/i18n/locales/index.d.ts.map +1 -0
- package/dist/i18n/locales/index.js +23 -0
- package/dist/i18n/locales/ja.d.ts +51 -0
- package/dist/i18n/locales/ja.d.ts.map +1 -0
- package/dist/i18n/locales/ja.js +62 -0
- package/dist/i18n/locales/zh-CN.d.ts +51 -0
- package/dist/i18n/locales/zh-CN.d.ts.map +1 -0
- package/dist/i18n/locales/zh-CN.js +62 -0
- package/dist/i18n/locales/zh-TW.d.ts +51 -0
- package/dist/i18n/locales/zh-TW.d.ts.map +1 -0
- package/dist/i18n/locales/zh-TW.js +62 -0
- package/dist/i18n/types.d.ts +11 -0
- package/dist/i18n/types.d.ts.map +1 -0
- package/dist/i18n/types.js +2 -0
- package/dist/i18n/useI18n.d.ts +2 -0
- package/dist/i18n/useI18n.d.ts.map +1 -0
- package/dist/i18n/useI18n.js +41 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +90 -0
- package/dist/services/ActionDialogService/ActionDialog.d.ts +4 -0
- package/dist/services/ActionDialogService/ActionDialog.d.ts.map +1 -0
- package/dist/services/ActionDialogService/ActionDialog.js +531 -0
- package/dist/services/ActionDialogService/index.d.ts +4 -0
- package/dist/services/ActionDialogService/index.d.ts.map +1 -0
- package/dist/services/ActionDialogService/index.js +8 -0
- package/dist/services/ActionDialogService/service.d.ts +7 -0
- package/dist/services/ActionDialogService/service.d.ts.map +1 -0
- package/dist/services/ActionDialogService/service.js +309 -0
- package/dist/services/ActionDialogService/shared.d.ts +17 -0
- package/dist/services/ActionDialogService/shared.d.ts.map +1 -0
- package/dist/services/ActionDialogService/shared.js +167 -0
- package/dist/services/ActionDialogService/types.d.ts +160 -0
- package/dist/services/ActionDialogService/types.d.ts.map +1 -0
- package/dist/services/ActionDialogService/types.js +2 -0
- package/dist/services/CardToastService/index.d.ts +115 -0
- package/dist/services/CardToastService/index.d.ts.map +1 -0
- package/dist/services/CardToastService/index.js +899 -0
- package/dist/services/ImagePreviewService/index.d.ts +179 -0
- package/dist/services/ImagePreviewService/index.d.ts.map +1 -0
- package/dist/services/ImagePreviewService/index.js +1383 -0
- package/dist/services/LoadingService/index.d.ts +146 -0
- package/dist/services/LoadingService/index.d.ts.map +1 -0
- package/dist/services/LoadingService/index.js +827 -0
- package/dist/services/PermissionPurposeDialogService/index.d.ts +99 -0
- package/dist/services/PermissionPurposeDialogService/index.d.ts.map +1 -0
- package/dist/services/PermissionPurposeDialogService/index.js +360 -0
- package/dist/services/PickerService/index.d.ts +128 -0
- package/dist/services/PickerService/index.d.ts.map +1 -0
- package/dist/services/PickerService/index.js +250 -0
- package/dist/theme/ThemeProvider.d.ts +15 -0
- package/dist/theme/ThemeProvider.d.ts.map +1 -0
- package/dist/theme/ThemeProvider.js +61 -0
- package/dist/theme/defaultTheme.d.ts +3 -0
- package/dist/theme/defaultTheme.d.ts.map +1 -0
- package/dist/theme/defaultTheme.js +28 -0
- package/dist/theme/mergeTheme.d.ts +3 -0
- package/dist/theme/mergeTheme.d.ts.map +1 -0
- package/dist/theme/mergeTheme.js +19 -0
- package/dist/theme/types.d.ts +17 -0
- package/dist/theme/types.d.ts.map +1 -0
- package/dist/theme/types.js +2 -0
- package/dist/theme/useTheme.d.ts +2 -0
- package/dist/theme/useTheme.d.ts.map +1 -0
- package/dist/theme/useTheme.js +46 -0
- package/dist/ui/Accordion/index.d.ts +99 -0
- package/dist/ui/Accordion/index.d.ts.map +1 -0
- package/dist/ui/Accordion/index.js +777 -0
- package/dist/ui/AddressCascader/index.d.ts +58 -0
- package/dist/ui/AddressCascader/index.d.ts.map +1 -0
- package/dist/ui/AddressCascader/index.js +710 -0
- package/dist/ui/BetweenTime/index.d.ts +82 -0
- package/dist/ui/BetweenTime/index.d.ts.map +1 -0
- package/dist/ui/BetweenTime/index.js +702 -0
- package/dist/ui/Button/index.d.ts +93 -0
- package/dist/ui/Button/index.d.ts.map +1 -0
- package/dist/ui/Button/index.js +832 -0
- package/dist/ui/Checkbox/index.d.ts +103 -0
- package/dist/ui/Checkbox/index.d.ts.map +1 -0
- package/dist/ui/Checkbox/index.js +694 -0
- package/dist/ui/DatePicker/index.d.ts +5 -0
- package/dist/ui/DatePicker/index.d.ts.map +1 -0
- package/dist/ui/DatePicker/index.js +157 -0
- package/dist/ui/DatePicker/types.d.ts +99 -0
- package/dist/ui/DatePicker/types.d.ts.map +1 -0
- package/dist/ui/DatePicker/types.js +2 -0
- package/dist/ui/DatePicker/utils.d.ts +32 -0
- package/dist/ui/DatePicker/utils.d.ts.map +1 -0
- package/dist/ui/DatePicker/utils.js +316 -0
- package/dist/ui/LinkedScroll/index.d.ts +78 -0
- package/dist/ui/LinkedScroll/index.d.ts.map +1 -0
- package/dist/ui/LinkedScroll/index.js +470 -0
- package/dist/ui/LoadingSpinner/index.d.ts +8 -0
- package/dist/ui/LoadingSpinner/index.d.ts.map +1 -0
- package/dist/ui/LoadingSpinner/index.js +122 -0
- package/dist/ui/Picker/actionBar.d.ts +14 -0
- package/dist/ui/Picker/actionBar.d.ts.map +1 -0
- package/dist/ui/Picker/actionBar.js +28 -0
- package/dist/ui/Picker/index.d.ts +5 -0
- package/dist/ui/Picker/index.d.ts.map +1 -0
- package/dist/ui/Picker/index.js +412 -0
- package/dist/ui/Picker/types.d.ts +80 -0
- package/dist/ui/Picker/types.d.ts.map +1 -0
- package/dist/ui/Picker/types.js +2 -0
- package/dist/ui/Picker/utils.d.ts +27 -0
- package/dist/ui/Picker/utils.d.ts.map +1 -0
- package/dist/ui/Picker/utils.js +182 -0
- package/dist/ui/Radio/index.d.ts +95 -0
- package/dist/ui/Radio/index.d.ts.map +1 -0
- package/dist/ui/Radio/index.js +633 -0
- package/dist/ui/Sheet/index.d.ts +12 -0
- package/dist/ui/Sheet/index.d.ts.map +1 -0
- package/dist/ui/Sheet/index.js +832 -0
- package/dist/ui/Sheet/nativeBottom.d.ts +52 -0
- package/dist/ui/Sheet/nativeBottom.d.ts.map +1 -0
- package/dist/ui/Sheet/nativeBottom.js +442 -0
- package/dist/ui/Sheet/nativeBottom.web.d.ts +18 -0
- package/dist/ui/Sheet/nativeBottom.web.d.ts.map +1 -0
- package/dist/ui/Sheet/nativeBottom.web.js +46 -0
- package/dist/ui/Sheet/slots.d.ts +5 -0
- package/dist/ui/Sheet/slots.d.ts.map +1 -0
- package/dist/ui/Sheet/slots.js +40 -0
- package/dist/ui/Sheet/types.d.ts +131 -0
- package/dist/ui/Sheet/types.d.ts.map +1 -0
- package/dist/ui/Sheet/types.js +2 -0
- package/dist/ui/SliderCaptcha/index.d.ts +57 -0
- package/dist/ui/SliderCaptcha/index.d.ts.map +1 -0
- package/dist/ui/SliderCaptcha/index.js +586 -0
- package/dist/ui/Switch/index.d.ts +72 -0
- package/dist/ui/Switch/index.d.ts.map +1 -0
- package/dist/ui/Switch/index.js +671 -0
- package/dist/ui/Text/index.d.ts +41 -0
- package/dist/ui/Text/index.d.ts.map +1 -0
- package/dist/ui/Text/index.js +325 -0
- package/dist/ui/TextInput/TextInputPrimitive.d.ts +8 -0
- package/dist/ui/TextInput/TextInputPrimitive.d.ts.map +1 -0
- package/dist/ui/TextInput/TextInputPrimitive.js +54 -0
- package/dist/ui/TextInput/index.d.ts +89 -0
- package/dist/ui/TextInput/index.d.ts.map +1 -0
- package/dist/ui/TextInput/index.js +545 -0
- package/dist/ui/WheelColumn/ZKitWheelPickerNativeComponent.d.ts +39 -0
- package/dist/ui/WheelColumn/ZKitWheelPickerNativeComponent.d.ts.map +1 -0
- package/dist/ui/WheelColumn/ZKitWheelPickerNativeComponent.js +60 -0
- package/dist/ui/WheelColumn/constants.d.ts +2 -0
- package/dist/ui/WheelColumn/constants.d.ts.map +1 -0
- package/dist/ui/WheelColumn/constants.js +4 -0
- package/dist/ui/WheelColumn/index.d.ts +59 -0
- package/dist/ui/WheelColumn/index.d.ts.map +1 -0
- package/dist/ui/WheelColumn/index.js +547 -0
- package/ios/ZKitWheelPicker.h +18 -0
- package/ios/ZKitWheelPicker.mm +230 -0
- package/ios/ZKitWheelPickerLabel.h +10 -0
- package/ios/ZKitWheelPickerLabel.mm +31 -0
- package/ios/ZKitWheelPickerManager.h +5 -0
- package/ios/ZKitWheelPickerManager.mm +53 -0
- package/package.json +75 -0
- package/react-native.config.js +10 -0
- package/src/ComponentLibProvider.tsx +56 -0
- package/src/assets/animations/spinner.json +1 -0
- package/src/assets/icons/check.svg +4 -0
- package/src/assets/icons/toast/error.webp +0 -0
- package/src/assets/icons/toast/success.webp +0 -0
- package/src/assets/icons/toast/warning.webp +0 -0
- package/src/config.ts +65 -0
- package/src/i18n/I18nProvider.tsx +69 -0
- package/src/i18n/locale.ts +108 -0
- package/src/i18n/locales/de.ts +67 -0
- package/src/i18n/locales/en-US.ts +67 -0
- package/src/i18n/locales/index.ts +19 -0
- package/src/i18n/locales/ja.ts +67 -0
- package/src/i18n/locales/zh-CN.ts +67 -0
- package/src/i18n/locales/zh-TW.ts +67 -0
- package/src/i18n/types.ts +21 -0
- package/src/i18n/useI18n.ts +7 -0
- package/src/index.ts +395 -0
- package/src/services/ActionDialogService/ActionDialog.tsx +756 -0
- package/src/services/ActionDialogService/README.md +146 -0
- package/src/services/ActionDialogService/index.tsx +39 -0
- package/src/services/ActionDialogService/service.tsx +355 -0
- package/src/services/ActionDialogService/shared.ts +204 -0
- package/src/services/ActionDialogService/types.ts +197 -0
- package/src/services/CardToastService/README.md +128 -0
- package/src/services/CardToastService/index.tsx +1284 -0
- package/src/services/ImagePreviewService/README.md +67 -0
- package/src/services/ImagePreviewService/index.tsx +2148 -0
- package/src/services/LoadingService/README.md +128 -0
- package/src/services/LoadingService/index.tsx +1113 -0
- package/src/services/PermissionPurposeDialogService/README.md +80 -0
- package/src/services/PermissionPurposeDialogService/index.tsx +449 -0
- package/src/services/PickerService/README.md +154 -0
- package/src/services/PickerService/index.tsx +410 -0
- package/src/theme/ThemeProvider.tsx +40 -0
- package/src/theme/defaultTheme.ts +30 -0
- package/src/theme/mergeTheme.ts +16 -0
- package/src/theme/types.ts +36 -0
- package/src/theme/useTheme.ts +10 -0
- package/src/types/svg.d.ts +9 -0
- package/src/types/vant-area-data.d.ts +19 -0
- package/src/ui/Accordion/README.md +67 -0
- package/src/ui/Accordion/index.tsx +1221 -0
- package/src/ui/AddressCascader/README.md +144 -0
- package/src/ui/AddressCascader/index.tsx +1084 -0
- package/src/ui/BetweenTime/README.md +490 -0
- package/src/ui/BetweenTime/index.tsx +1001 -0
- package/src/ui/Button/README.md +186 -0
- package/src/ui/Button/index.tsx +1356 -0
- package/src/ui/Checkbox/README.md +211 -0
- package/src/ui/Checkbox/index.tsx +1231 -0
- package/src/ui/DatePicker/README.md +117 -0
- package/src/ui/DatePicker/index.tsx +295 -0
- package/src/ui/DatePicker/types.ts +115 -0
- package/src/ui/DatePicker/utils.ts +405 -0
- package/src/ui/LinkedScroll/README.md +55 -0
- package/src/ui/LinkedScroll/index.tsx +809 -0
- package/src/ui/LoadingSpinner/index.tsx +104 -0
- package/src/ui/Picker/README.md +190 -0
- package/src/ui/Picker/actionBar.tsx +70 -0
- package/src/ui/Picker/index.tsx +694 -0
- package/src/ui/Picker/types.ts +94 -0
- package/src/ui/Picker/utils.ts +239 -0
- package/src/ui/Radio/README.md +207 -0
- package/src/ui/Radio/index.tsx +1117 -0
- package/src/ui/Sheet/README.md +82 -0
- package/src/ui/Sheet/index.tsx +1163 -0
- package/src/ui/Sheet/nativeBottom.tsx +683 -0
- package/src/ui/Sheet/nativeBottom.web.tsx +40 -0
- package/src/ui/Sheet/slots.tsx +75 -0
- package/src/ui/Sheet/types.ts +195 -0
- package/src/ui/SliderCaptcha/README.md +61 -0
- package/src/ui/SliderCaptcha/index.tsx +816 -0
- package/src/ui/Switch/README.md +143 -0
- package/src/ui/Switch/index.tsx +1092 -0
- package/src/ui/Text/README.md +157 -0
- package/src/ui/Text/index.tsx +450 -0
- package/src/ui/TextInput/README.md +197 -0
- package/src/ui/TextInput/TextInputPrimitive.tsx +44 -0
- package/src/ui/TextInput/index.tsx +942 -0
- package/src/ui/WheelColumn/README.md +104 -0
- package/src/ui/WheelColumn/ZKitWheelPickerNativeComponent.tsx +68 -0
- package/src/ui/WheelColumn/constants.ts +1 -0
- package/src/ui/WheelColumn/index.tsx +826 -0
- package/zkit-ui.podspec +19 -0
|
@@ -0,0 +1,694 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Platform,
|
|
4
|
+
Pressable,
|
|
5
|
+
StyleSheet,
|
|
6
|
+
useWindowDimensions,
|
|
7
|
+
View,
|
|
8
|
+
type AccessibilityState,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
import { LinearGradient } from 'expo-linear-gradient';
|
|
11
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
12
|
+
import { sp, wp } from 'zkit-tools';
|
|
13
|
+
import { useI18n } from '../../i18n/useI18n';
|
|
14
|
+
import { useTheme } from '../../theme/useTheme';
|
|
15
|
+
import { Sheet, type SheetOpenChangeDetails } from '../Sheet';
|
|
16
|
+
import { Text } from '../Text';
|
|
17
|
+
import {
|
|
18
|
+
WheelColumn,
|
|
19
|
+
WHEEL_AREA_HEIGHT,
|
|
20
|
+
WHEEL_AREA_VERTICAL_INSET,
|
|
21
|
+
WHEEL_ITEM_HEIGHT,
|
|
22
|
+
WHEEL_SELECTION_BACKGROUND_COLOR,
|
|
23
|
+
WHEEL_VISIBLE_ITEMS,
|
|
24
|
+
type WheelColumnHandle,
|
|
25
|
+
type WheelOption,
|
|
26
|
+
} from '../WheelColumn';
|
|
27
|
+
import type {
|
|
28
|
+
PickerCascadeState,
|
|
29
|
+
} from './utils';
|
|
30
|
+
import {
|
|
31
|
+
clampNumber,
|
|
32
|
+
createPickerSelection,
|
|
33
|
+
findNearestEnabledIndex,
|
|
34
|
+
resolveCascade,
|
|
35
|
+
resolveOptionDisabled,
|
|
36
|
+
resolveOptionChildren,
|
|
37
|
+
resolveOptionLabel,
|
|
38
|
+
resolveOptionValue,
|
|
39
|
+
toArrayValue,
|
|
40
|
+
transparentizeColor,
|
|
41
|
+
} from './utils';
|
|
42
|
+
import { PickerActionBar, getPickerActionBarBottomInset } from './actionBar';
|
|
43
|
+
import type {
|
|
44
|
+
PickerColumnHeaderContext,
|
|
45
|
+
PickerDraftChangePayload,
|
|
46
|
+
PickerHandle,
|
|
47
|
+
PickerOptionAccessors,
|
|
48
|
+
PickerPrimitiveValue,
|
|
49
|
+
PickerProps,
|
|
50
|
+
PickerSelection,
|
|
51
|
+
PickerTriggerContext,
|
|
52
|
+
PickerValue,
|
|
53
|
+
PickerValueMode,
|
|
54
|
+
} from './types';
|
|
55
|
+
|
|
56
|
+
export type {
|
|
57
|
+
PickerChangePayload,
|
|
58
|
+
PickerColumnHeaderContext,
|
|
59
|
+
PickerConfirmPayload,
|
|
60
|
+
PickerDraftChangePayload,
|
|
61
|
+
PickerHandle,
|
|
62
|
+
PickerOption,
|
|
63
|
+
PickerPrimitiveValue,
|
|
64
|
+
PickerProps,
|
|
65
|
+
PickerSelection,
|
|
66
|
+
PickerTriggerContext,
|
|
67
|
+
PickerValue,
|
|
68
|
+
PickerValueMode,
|
|
69
|
+
} from './types';
|
|
70
|
+
|
|
71
|
+
const ITEM_HEIGHT = WHEEL_ITEM_HEIGHT;
|
|
72
|
+
const VISIBLE_ITEMS = WHEEL_VISIBLE_ITEMS;
|
|
73
|
+
const DEFAULT_MAX_COLUMNS = 5;
|
|
74
|
+
const MAX_COLUMNS_LIMIT = 8;
|
|
75
|
+
|
|
76
|
+
type TriggerChildProps = {
|
|
77
|
+
onPress?: (...args: unknown[]) => void;
|
|
78
|
+
disabled?: boolean;
|
|
79
|
+
accessibilityState?: AccessibilityState;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
type WheelColumnSlotProps<TOption> = {
|
|
83
|
+
options: TOption[];
|
|
84
|
+
columnIndex: number;
|
|
85
|
+
parentPath: TOption[];
|
|
86
|
+
accessors: PickerOptionAccessors<TOption>;
|
|
87
|
+
selectedIndex: number;
|
|
88
|
+
onIndexChange: (columnIndex: number, index: number) => void;
|
|
89
|
+
width: number;
|
|
90
|
+
disabled: boolean;
|
|
91
|
+
wheelsRef: React.RefObject<Array<WheelColumnHandle | null>>;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
function toWheelOptions<TOption>(
|
|
95
|
+
options: TOption[],
|
|
96
|
+
parentPath: TOption[],
|
|
97
|
+
accessors: PickerOptionAccessors<TOption>
|
|
98
|
+
): WheelOption[] {
|
|
99
|
+
return options.map((option, index) => {
|
|
100
|
+
const path = [...parentPath, option];
|
|
101
|
+
const value = resolveOptionValue(option, index, path, accessors);
|
|
102
|
+
const label = resolveOptionLabel(option, index, path, accessors);
|
|
103
|
+
const record = option != null && typeof option === 'object' ? (option as Record<string, unknown>) : {};
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
value,
|
|
107
|
+
label,
|
|
108
|
+
disabled: resolveOptionDisabled(option, index, path, accessors),
|
|
109
|
+
key: typeof record.key === 'string' || typeof record.key === 'number' ? record.key : value,
|
|
110
|
+
testID: typeof record.testID === 'string' ? record.testID : undefined,
|
|
111
|
+
accessibilityLabel: typeof record.accessibilityLabel === 'string' ? record.accessibilityLabel : undefined,
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const WheelColumnSlot = React.memo(function WheelColumnSlot<TOption>({
|
|
117
|
+
options,
|
|
118
|
+
columnIndex,
|
|
119
|
+
parentPath,
|
|
120
|
+
accessors,
|
|
121
|
+
selectedIndex,
|
|
122
|
+
onIndexChange,
|
|
123
|
+
width,
|
|
124
|
+
disabled,
|
|
125
|
+
wheelsRef,
|
|
126
|
+
}: WheelColumnSlotProps<TOption>) {
|
|
127
|
+
const wheelOptions = React.useMemo(
|
|
128
|
+
() => toWheelOptions(options, parentPath, accessors),
|
|
129
|
+
[accessors, options, parentPath]
|
|
130
|
+
);
|
|
131
|
+
const selectedValue = wheelOptions[Math.max(0, selectedIndex)]?.value ?? null;
|
|
132
|
+
const handleChange = React.useCallback(
|
|
133
|
+
(payload: { index: number }) => onIndexChange(columnIndex, payload.index),
|
|
134
|
+
[columnIndex, onIndexChange]
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<WheelColumn
|
|
139
|
+
ref={(element) => {
|
|
140
|
+
wheelsRef.current[columnIndex] = element;
|
|
141
|
+
}}
|
|
142
|
+
options={wheelOptions}
|
|
143
|
+
value={selectedValue}
|
|
144
|
+
onChange={handleChange}
|
|
145
|
+
width={width}
|
|
146
|
+
disabled={disabled}
|
|
147
|
+
/>
|
|
148
|
+
);
|
|
149
|
+
}) as <TOption>(props: WheelColumnSlotProps<TOption>) => React.ReactElement;
|
|
150
|
+
|
|
151
|
+
function createEmptyCascadeState<TOption>(): PickerCascadeState<TOption> {
|
|
152
|
+
return {
|
|
153
|
+
columns: [],
|
|
154
|
+
indices: [],
|
|
155
|
+
values: [],
|
|
156
|
+
labels: [],
|
|
157
|
+
items: [],
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function getPreferPathValue(value: PickerValue | undefined, valueMode: PickerValueMode, resolvedColumns: number) {
|
|
162
|
+
if (valueMode === 'path') return true;
|
|
163
|
+
if (valueMode === 'single') return false;
|
|
164
|
+
if (Array.isArray(value)) return true;
|
|
165
|
+
if (value !== undefined) return false;
|
|
166
|
+
return resolvedColumns > 1;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function composeTrigger<TOption>(
|
|
170
|
+
children: PickerProps<TOption>['children'],
|
|
171
|
+
context: PickerTriggerContext<TOption>
|
|
172
|
+
): React.ReactNode {
|
|
173
|
+
if (typeof children === 'function') {
|
|
174
|
+
return composeTrigger(children(context), context);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (React.isValidElement(children)) {
|
|
178
|
+
const child = children as React.ReactElement<TriggerChildProps>;
|
|
179
|
+
const previousOnPress = child.props.onPress;
|
|
180
|
+
const previousAccessibilityState = child.props.accessibilityState;
|
|
181
|
+
|
|
182
|
+
return React.cloneElement(child, {
|
|
183
|
+
onPress: (...args: unknown[]) => {
|
|
184
|
+
previousOnPress?.(...args);
|
|
185
|
+
context.open();
|
|
186
|
+
},
|
|
187
|
+
disabled: context.disabled || child.props.disabled,
|
|
188
|
+
accessibilityState: {
|
|
189
|
+
...previousAccessibilityState,
|
|
190
|
+
disabled: context.disabled || previousAccessibilityState?.disabled,
|
|
191
|
+
expanded: context.isOpen,
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (children == null) return null;
|
|
197
|
+
|
|
198
|
+
return (
|
|
199
|
+
<Pressable
|
|
200
|
+
accessibilityRole="button"
|
|
201
|
+
accessibilityState={{ disabled: context.disabled, expanded: context.isOpen }}
|
|
202
|
+
disabled={context.disabled}
|
|
203
|
+
onPress={context.open}
|
|
204
|
+
>
|
|
205
|
+
{children}
|
|
206
|
+
</Pressable>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function normalizeMaxColumns(maxColumns: number | undefined) {
|
|
211
|
+
if (maxColumns == null) return DEFAULT_MAX_COLUMNS;
|
|
212
|
+
if (!Number.isFinite(maxColumns)) return DEFAULT_MAX_COLUMNS;
|
|
213
|
+
return clampNumber(Math.round(maxColumns), 1, MAX_COLUMNS_LIMIT);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export const Picker = React.forwardRef<PickerHandle, PickerProps>(function Picker<TOption>(
|
|
217
|
+
{
|
|
218
|
+
options,
|
|
219
|
+
value: valueProp,
|
|
220
|
+
defaultValue,
|
|
221
|
+
onChange,
|
|
222
|
+
valueMode = 'auto',
|
|
223
|
+
open: openProp,
|
|
224
|
+
defaultOpen,
|
|
225
|
+
onOpenChange,
|
|
226
|
+
onDismissComplete,
|
|
227
|
+
title,
|
|
228
|
+
placeholder = '',
|
|
229
|
+
cancelText,
|
|
230
|
+
confirmText,
|
|
231
|
+
emptyText,
|
|
232
|
+
separator = '-',
|
|
233
|
+
formatLabel,
|
|
234
|
+
renderColumnHeader,
|
|
235
|
+
maxColumns,
|
|
236
|
+
getOptionValue,
|
|
237
|
+
getOptionLabel,
|
|
238
|
+
getOptionChildren,
|
|
239
|
+
isOptionDisabled,
|
|
240
|
+
lazyContent = true,
|
|
241
|
+
sheetHeight = 'auto',
|
|
242
|
+
disabled = false,
|
|
243
|
+
onCancel,
|
|
244
|
+
onConfirm,
|
|
245
|
+
onDraftChange,
|
|
246
|
+
children,
|
|
247
|
+
}: PickerProps<TOption>,
|
|
248
|
+
ref: React.ForwardedRef<PickerHandle>
|
|
249
|
+
) {
|
|
250
|
+
const { t } = useI18n();
|
|
251
|
+
const theme = useTheme();
|
|
252
|
+
const { height: screenH, width: screenW } = useWindowDimensions();
|
|
253
|
+
const insets = useSafeAreaInsets();
|
|
254
|
+
const safeBottom = getPickerActionBarBottomInset(insets.bottom);
|
|
255
|
+
const effectiveMaxColumns = React.useMemo(() => normalizeMaxColumns(maxColumns), [maxColumns]);
|
|
256
|
+
|
|
257
|
+
const accessors = React.useMemo<PickerOptionAccessors<TOption>>(
|
|
258
|
+
() => ({ getOptionValue, getOptionLabel, getOptionChildren, isOptionDisabled }),
|
|
259
|
+
[getOptionChildren, getOptionLabel, getOptionValue, isOptionDisabled]
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
const isValueControlled = valueProp !== undefined;
|
|
263
|
+
const [innerValue, setInnerValue] = React.useState<PickerValue | undefined>(defaultValue);
|
|
264
|
+
const value = isValueControlled ? valueProp : innerValue;
|
|
265
|
+
|
|
266
|
+
const isOpenControlled = openProp !== undefined;
|
|
267
|
+
const [innerOpen, setInnerOpen] = React.useState(!!defaultOpen);
|
|
268
|
+
const visible = isOpenControlled ? !!openProp : innerOpen;
|
|
269
|
+
const wheelsRef = React.useRef<Array<WheelColumnHandle | null>>([]);
|
|
270
|
+
const confirmingRef = React.useRef(false);
|
|
271
|
+
|
|
272
|
+
const resolveFromValue = React.useCallback(
|
|
273
|
+
(nextValue: PickerValue | undefined) =>
|
|
274
|
+
resolveCascade(options, toArrayValue(nextValue), accessors, effectiveMaxColumns),
|
|
275
|
+
[accessors, effectiveMaxColumns, options]
|
|
276
|
+
);
|
|
277
|
+
|
|
278
|
+
const createSelection = React.useCallback(
|
|
279
|
+
(state: PickerCascadeState<TOption>, nextValue: PickerValue | undefined = value) =>
|
|
280
|
+
createPickerSelection(state, {
|
|
281
|
+
separator,
|
|
282
|
+
valueMode,
|
|
283
|
+
preferPathValue: getPreferPathValue(nextValue, valueMode, state.columns.length),
|
|
284
|
+
formatLabel,
|
|
285
|
+
}),
|
|
286
|
+
[formatLabel, separator, value, valueMode]
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
const initialDraft = React.useMemo(() => resolveFromValue(value), [resolveFromValue, value]);
|
|
290
|
+
const [{ columns: draftColumns, indices: draftIndices, values: draftValues, labels: draftLabels, items: draftItems }, setDraft] =
|
|
291
|
+
React.useState<PickerCascadeState<TOption>>(initialDraft);
|
|
292
|
+
|
|
293
|
+
React.useEffect(() => {
|
|
294
|
+
setDraft(resolveFromValue(value));
|
|
295
|
+
}, [resolveFromValue, value]);
|
|
296
|
+
|
|
297
|
+
React.useEffect(() => {
|
|
298
|
+
if (!visible) return;
|
|
299
|
+
setDraft(resolveFromValue(value));
|
|
300
|
+
}, [resolveFromValue, value, visible]);
|
|
301
|
+
|
|
302
|
+
const committedSelection = React.useMemo<PickerSelection<TOption>>(() => {
|
|
303
|
+
const state = value === undefined ? createEmptyCascadeState<TOption>() : resolveFromValue(value);
|
|
304
|
+
return createSelection(state, value);
|
|
305
|
+
}, [createSelection, resolveFromValue, value]);
|
|
306
|
+
|
|
307
|
+
const draftState = React.useMemo<PickerCascadeState<TOption>>(
|
|
308
|
+
() => ({
|
|
309
|
+
columns: draftColumns,
|
|
310
|
+
indices: draftIndices,
|
|
311
|
+
values: draftValues,
|
|
312
|
+
labels: draftLabels,
|
|
313
|
+
items: draftItems,
|
|
314
|
+
}),
|
|
315
|
+
[draftColumns, draftIndices, draftItems, draftLabels, draftValues]
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
const draftSelection = React.useMemo(() => createSelection(draftState), [createSelection, draftState]);
|
|
319
|
+
|
|
320
|
+
const detents = React.useMemo<Array<'auto' | number>>(() => {
|
|
321
|
+
if (sheetHeight === 'auto' || sheetHeight == null) return ['auto'];
|
|
322
|
+
if (!Number.isFinite(sheetHeight) || sheetHeight <= 0) return ['auto'];
|
|
323
|
+
return [clampNumber(sheetHeight / screenH, 0.1, 0.92)];
|
|
324
|
+
}, [screenH, sheetHeight]);
|
|
325
|
+
|
|
326
|
+
const setPickerOpen = React.useCallback((nextOpen: boolean) => {
|
|
327
|
+
onOpenChange?.(nextOpen);
|
|
328
|
+
if (!isOpenControlled) setInnerOpen(nextOpen);
|
|
329
|
+
}, [isOpenControlled, onOpenChange]);
|
|
330
|
+
|
|
331
|
+
const close = React.useCallback(() => {
|
|
332
|
+
setPickerOpen(false);
|
|
333
|
+
}, [setPickerOpen]);
|
|
334
|
+
|
|
335
|
+
const openPicker = React.useCallback(() => {
|
|
336
|
+
if (disabled) return;
|
|
337
|
+
|
|
338
|
+
setDraft(resolveFromValue(value));
|
|
339
|
+
if (!visible) {
|
|
340
|
+
setPickerOpen(true);
|
|
341
|
+
}
|
|
342
|
+
}, [disabled, resolveFromValue, setPickerOpen, value, visible]);
|
|
343
|
+
|
|
344
|
+
React.useImperativeHandle(
|
|
345
|
+
ref,
|
|
346
|
+
() => ({
|
|
347
|
+
open: openPicker,
|
|
348
|
+
close,
|
|
349
|
+
}),
|
|
350
|
+
[close, openPicker]
|
|
351
|
+
);
|
|
352
|
+
|
|
353
|
+
const columnsCount = React.useMemo(
|
|
354
|
+
() => Math.max(1, Math.min(effectiveMaxColumns, draftColumns.length || 1)),
|
|
355
|
+
[draftColumns.length, effectiveMaxColumns]
|
|
356
|
+
);
|
|
357
|
+
const columnWidth = React.useMemo(() => (screenW - wp(32)) / columnsCount, [columnsCount, screenW]);
|
|
358
|
+
const confirmDisabled = disabled || !draftSelection.isComplete;
|
|
359
|
+
const transparentSurface = React.useMemo(() => transparentizeColor(theme.colors.surface), [theme.colors.surface]);
|
|
360
|
+
|
|
361
|
+
React.useEffect(() => {
|
|
362
|
+
wheelsRef.current.length = columnsCount;
|
|
363
|
+
}, [columnsCount]);
|
|
364
|
+
|
|
365
|
+
const emitDraftChange = React.useCallback(
|
|
366
|
+
(nextState: PickerCascadeState<TOption>) => {
|
|
367
|
+
const selection = createSelection(nextState) as PickerDraftChangePayload<TOption>;
|
|
368
|
+
onDraftChange?.(selection);
|
|
369
|
+
},
|
|
370
|
+
[createSelection, onDraftChange]
|
|
371
|
+
);
|
|
372
|
+
|
|
373
|
+
const syncDraftFromWheels = React.useCallback(async () => {
|
|
374
|
+
const settledIndices = await Promise.all(
|
|
375
|
+
Array.from({ length: effectiveMaxColumns }, async (_, columnIndex) => {
|
|
376
|
+
const wheel = wheelsRef.current[columnIndex];
|
|
377
|
+
if (Platform.OS === 'ios') {
|
|
378
|
+
return wheel?.syncCurrentSelection();
|
|
379
|
+
}
|
|
380
|
+
return wheel?.settleToNearest(false);
|
|
381
|
+
})
|
|
382
|
+
);
|
|
383
|
+
|
|
384
|
+
const desiredValues: PickerPrimitiveValue[] = [];
|
|
385
|
+
let currentOptions = Array.isArray(options) ? (options as TOption[]) : [];
|
|
386
|
+
let path: TOption[] = [];
|
|
387
|
+
|
|
388
|
+
for (let columnIndex = 0; columnIndex < effectiveMaxColumns; columnIndex += 1) {
|
|
389
|
+
if (!currentOptions.length) break;
|
|
390
|
+
|
|
391
|
+
const safeIndex = findNearestEnabledIndex(
|
|
392
|
+
currentOptions,
|
|
393
|
+
settledIndices[columnIndex] ?? draftIndices[columnIndex] ?? 0,
|
|
394
|
+
path,
|
|
395
|
+
accessors
|
|
396
|
+
);
|
|
397
|
+
if (safeIndex < 0) break;
|
|
398
|
+
|
|
399
|
+
const item = currentOptions[safeIndex];
|
|
400
|
+
if (item == null) break;
|
|
401
|
+
|
|
402
|
+
const nextPath = [...path, item];
|
|
403
|
+
desiredValues[columnIndex] = resolveOptionValue(item, safeIndex, nextPath, accessors);
|
|
404
|
+
currentOptions = resolveOptionChildren(item, safeIndex, nextPath, accessors);
|
|
405
|
+
path = nextPath;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const nextState = resolveCascade(options, desiredValues, accessors, effectiveMaxColumns);
|
|
409
|
+
setDraft(nextState);
|
|
410
|
+
|
|
411
|
+
requestAnimationFrame(() => {
|
|
412
|
+
for (let i = 0; i < nextState.indices.length; i += 1) {
|
|
413
|
+
wheelsRef.current[i]?.scrollToIndex(nextState.indices[i] ?? 0, false);
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
return nextState;
|
|
418
|
+
}, [accessors, draftIndices, effectiveMaxColumns, options]);
|
|
419
|
+
|
|
420
|
+
const handleWheelIndexChange = React.useCallback(
|
|
421
|
+
(columnIndex: number, nextIndex: number) => {
|
|
422
|
+
const columnOptions = draftColumns[columnIndex] ?? [];
|
|
423
|
+
if (!columnOptions.length) return;
|
|
424
|
+
|
|
425
|
+
const parentPath = draftItems.slice(0, columnIndex);
|
|
426
|
+
const safeIndex = findNearestEnabledIndex(columnOptions, nextIndex, parentPath, accessors);
|
|
427
|
+
if (safeIndex < 0) return;
|
|
428
|
+
|
|
429
|
+
if (safeIndex !== nextIndex) {
|
|
430
|
+
wheelsRef.current[columnIndex]?.scrollToIndex(safeIndex, true);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
const item = columnOptions[safeIndex];
|
|
434
|
+
if (item == null) return;
|
|
435
|
+
|
|
436
|
+
const nextPath = [...parentPath, item];
|
|
437
|
+
const nextDesired = [...draftValues];
|
|
438
|
+
nextDesired[columnIndex] = resolveOptionValue(item, safeIndex, nextPath, accessors);
|
|
439
|
+
nextDesired.length = columnIndex + 1;
|
|
440
|
+
|
|
441
|
+
const nextState = resolveCascade(options, nextDesired, accessors, effectiveMaxColumns);
|
|
442
|
+
setDraft(nextState);
|
|
443
|
+
|
|
444
|
+
requestAnimationFrame(() => {
|
|
445
|
+
for (let i = columnIndex + 1; i < nextState.indices.length; i += 1) {
|
|
446
|
+
wheelsRef.current[i]?.scrollToIndex(nextState.indices[i] ?? 0, false);
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
emitDraftChange(nextState);
|
|
451
|
+
},
|
|
452
|
+
[accessors, draftColumns, draftItems, draftValues, effectiveMaxColumns, emitDraftChange, options]
|
|
453
|
+
);
|
|
454
|
+
|
|
455
|
+
const handleCancel = React.useCallback(() => {
|
|
456
|
+
onCancel?.();
|
|
457
|
+
close();
|
|
458
|
+
}, [close, onCancel]);
|
|
459
|
+
|
|
460
|
+
const handleConfirm = React.useCallback(async () => {
|
|
461
|
+
if (confirmDisabled || confirmingRef.current) return;
|
|
462
|
+
confirmingRef.current = true;
|
|
463
|
+
|
|
464
|
+
try {
|
|
465
|
+
const syncedState = await syncDraftFromWheels();
|
|
466
|
+
const selection = createSelection(syncedState);
|
|
467
|
+
if (!selection.isComplete) return;
|
|
468
|
+
|
|
469
|
+
if (!isValueControlled) {
|
|
470
|
+
setInnerValue(selection.value);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
onChange?.(selection.value, selection);
|
|
474
|
+
onConfirm?.(selection);
|
|
475
|
+
close();
|
|
476
|
+
} finally {
|
|
477
|
+
confirmingRef.current = false;
|
|
478
|
+
}
|
|
479
|
+
}, [close, confirmDisabled, createSelection, isValueControlled, onChange, onConfirm, syncDraftFromWheels]);
|
|
480
|
+
|
|
481
|
+
const handleSheetOpenChange = React.useCallback((nextOpen: boolean, meta: SheetOpenChangeDetails) => {
|
|
482
|
+
if (!nextOpen && visible && meta.reason !== 'api') {
|
|
483
|
+
onCancel?.();
|
|
484
|
+
}
|
|
485
|
+
setPickerOpen(nextOpen);
|
|
486
|
+
}, [onCancel, setPickerOpen, visible]);
|
|
487
|
+
|
|
488
|
+
const triggerContext = React.useMemo<PickerTriggerContext<TOption>>(
|
|
489
|
+
() => ({
|
|
490
|
+
...committedSelection,
|
|
491
|
+
label: committedSelection.label,
|
|
492
|
+
open: openPicker,
|
|
493
|
+
close,
|
|
494
|
+
isOpen: visible,
|
|
495
|
+
disabled,
|
|
496
|
+
placeholder,
|
|
497
|
+
}),
|
|
498
|
+
[close, committedSelection, disabled, openPicker, placeholder, visible]
|
|
499
|
+
);
|
|
500
|
+
|
|
501
|
+
const triggerNode = React.useMemo(
|
|
502
|
+
() => composeTrigger(children, triggerContext),
|
|
503
|
+
[children, triggerContext]
|
|
504
|
+
);
|
|
505
|
+
|
|
506
|
+
const sheetNode = (
|
|
507
|
+
<Sheet
|
|
508
|
+
placement="bottom"
|
|
509
|
+
open={visible}
|
|
510
|
+
onOpenChange={handleSheetOpenChange}
|
|
511
|
+
onCloseComplete={onDismissComplete}
|
|
512
|
+
detents={detents}
|
|
513
|
+
backgroundColor={theme.colors.surface}
|
|
514
|
+
handle={false}
|
|
515
|
+
draggable={false}
|
|
516
|
+
dismissible={!disabled}
|
|
517
|
+
nativeProps={{ insetAdjustment: 'never' }}
|
|
518
|
+
>
|
|
519
|
+
<View
|
|
520
|
+
accessibilityViewIsModal
|
|
521
|
+
style={[
|
|
522
|
+
styles.sheetInner,
|
|
523
|
+
{
|
|
524
|
+
backgroundColor: theme.colors.surface,
|
|
525
|
+
paddingBottom: safeBottom,
|
|
526
|
+
},
|
|
527
|
+
]}
|
|
528
|
+
pointerEvents={disabled ? 'none' : 'auto'}
|
|
529
|
+
>
|
|
530
|
+
<View style={styles.header}>
|
|
531
|
+
<Text style={[styles.headerTitle, { color: theme.colors.onSurface }]} numberOfLines={1}>
|
|
532
|
+
{title ?? t('picker.title')}
|
|
533
|
+
</Text>
|
|
534
|
+
</View>
|
|
535
|
+
|
|
536
|
+
{draftColumns.length > 0 ? (
|
|
537
|
+
<View style={styles.pickerArea}>
|
|
538
|
+
{renderColumnHeader && (
|
|
539
|
+
<View style={styles.columnLabelsRow}>
|
|
540
|
+
{draftColumns.slice(0, columnsCount).map((columnOptions, columnIndex) => {
|
|
541
|
+
const headerContext: PickerColumnHeaderContext<TOption> = {
|
|
542
|
+
columnIndex,
|
|
543
|
+
columnCount: columnsCount,
|
|
544
|
+
options: columnOptions,
|
|
545
|
+
selectedItem: draftItems[columnIndex],
|
|
546
|
+
selectedValue: draftValues[columnIndex],
|
|
547
|
+
selectedLabel: draftLabels[columnIndex],
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
return (
|
|
551
|
+
<View key={`header-${columnIndex}`} style={[styles.columnLabelItem, { width: columnWidth }]}>
|
|
552
|
+
{renderColumnHeader(headerContext)}
|
|
553
|
+
</View>
|
|
554
|
+
);
|
|
555
|
+
})}
|
|
556
|
+
</View>
|
|
557
|
+
)}
|
|
558
|
+
|
|
559
|
+
<View style={styles.pickerWrapper}>
|
|
560
|
+
{Platform.OS !== 'ios' && (
|
|
561
|
+
<View style={styles.highlightBar} pointerEvents="none" />
|
|
562
|
+
)}
|
|
563
|
+
|
|
564
|
+
<View style={styles.columnsRow}>
|
|
565
|
+
{draftColumns.slice(0, columnsCount).map((columnOptions, columnIndex) => (
|
|
566
|
+
<WheelColumnSlot
|
|
567
|
+
key={`column-${columnIndex}-${columnsCount}`}
|
|
568
|
+
options={columnOptions}
|
|
569
|
+
columnIndex={columnIndex}
|
|
570
|
+
parentPath={draftItems.slice(0, columnIndex)}
|
|
571
|
+
accessors={accessors}
|
|
572
|
+
selectedIndex={Math.max(0, draftIndices[columnIndex] ?? 0)}
|
|
573
|
+
onIndexChange={handleWheelIndexChange}
|
|
574
|
+
width={columnWidth}
|
|
575
|
+
disabled={disabled}
|
|
576
|
+
wheelsRef={wheelsRef}
|
|
577
|
+
/>
|
|
578
|
+
))}
|
|
579
|
+
</View>
|
|
580
|
+
|
|
581
|
+
{Platform.OS !== 'ios' && (
|
|
582
|
+
<View style={styles.topMask} pointerEvents="none">
|
|
583
|
+
<LinearGradient colors={[theme.colors.surface, transparentSurface]} style={StyleSheet.absoluteFill} />
|
|
584
|
+
</View>
|
|
585
|
+
)}
|
|
586
|
+
{Platform.OS !== 'ios' && (
|
|
587
|
+
<View style={styles.bottomMask} pointerEvents="none">
|
|
588
|
+
<LinearGradient colors={[transparentSurface, theme.colors.surface]} style={StyleSheet.absoluteFill} />
|
|
589
|
+
</View>
|
|
590
|
+
)}
|
|
591
|
+
</View>
|
|
592
|
+
</View>
|
|
593
|
+
) : (
|
|
594
|
+
<View style={styles.emptyState}>
|
|
595
|
+
<Text tone="muted" align="center">
|
|
596
|
+
{emptyText ?? t('picker.empty')}
|
|
597
|
+
</Text>
|
|
598
|
+
</View>
|
|
599
|
+
)}
|
|
600
|
+
|
|
601
|
+
<PickerActionBar
|
|
602
|
+
cancelText={cancelText ?? t('picker.cancel')}
|
|
603
|
+
confirmText={confirmText ?? t('picker.confirm')}
|
|
604
|
+
onCancel={handleCancel}
|
|
605
|
+
onConfirm={handleConfirm}
|
|
606
|
+
disabled={disabled}
|
|
607
|
+
confirmDisabled={confirmDisabled}
|
|
608
|
+
/>
|
|
609
|
+
</View>
|
|
610
|
+
</Sheet>
|
|
611
|
+
);
|
|
612
|
+
|
|
613
|
+
return (
|
|
614
|
+
<>
|
|
615
|
+
{triggerNode}
|
|
616
|
+
{sheetNode}
|
|
617
|
+
</>
|
|
618
|
+
);
|
|
619
|
+
}) as <TOption = import('./types').PickerOption>(
|
|
620
|
+
props: PickerProps<TOption> & React.RefAttributes<PickerHandle>
|
|
621
|
+
) => React.ReactElement | null;
|
|
622
|
+
|
|
623
|
+
const styles = StyleSheet.create({
|
|
624
|
+
sheetInner: {
|
|
625
|
+
width: '100%',
|
|
626
|
+
paddingHorizontal: wp(16),
|
|
627
|
+
paddingTop: wp(12),
|
|
628
|
+
},
|
|
629
|
+
header: {
|
|
630
|
+
minHeight: wp(32),
|
|
631
|
+
alignItems: 'center',
|
|
632
|
+
justifyContent: 'center',
|
|
633
|
+
paddingHorizontal: wp(12),
|
|
634
|
+
},
|
|
635
|
+
headerTitle: {
|
|
636
|
+
fontSize: sp(16),
|
|
637
|
+
fontWeight: '600',
|
|
638
|
+
},
|
|
639
|
+
pickerArea: {
|
|
640
|
+
marginTop: wp(4),
|
|
641
|
+
paddingVertical: WHEEL_AREA_VERTICAL_INSET,
|
|
642
|
+
},
|
|
643
|
+
emptyState: {
|
|
644
|
+
minHeight: WHEEL_AREA_HEIGHT + wp(18),
|
|
645
|
+
alignItems: 'center',
|
|
646
|
+
justifyContent: 'center',
|
|
647
|
+
paddingHorizontal: wp(24),
|
|
648
|
+
},
|
|
649
|
+
columnLabelsRow: {
|
|
650
|
+
flexDirection: 'row',
|
|
651
|
+
justifyContent: 'space-between',
|
|
652
|
+
marginBottom: wp(6),
|
|
653
|
+
},
|
|
654
|
+
columnLabelItem: {
|
|
655
|
+
alignItems: 'center',
|
|
656
|
+
},
|
|
657
|
+
pickerWrapper: {
|
|
658
|
+
height: ITEM_HEIGHT * VISIBLE_ITEMS,
|
|
659
|
+
position: 'relative',
|
|
660
|
+
width: '100%',
|
|
661
|
+
overflow: 'visible',
|
|
662
|
+
},
|
|
663
|
+
highlightBar: {
|
|
664
|
+
position: 'absolute',
|
|
665
|
+
top: ITEM_HEIGHT * ((VISIBLE_ITEMS - 1) / 2),
|
|
666
|
+
left: -wp(16),
|
|
667
|
+
right: -wp(16),
|
|
668
|
+
height: ITEM_HEIGHT,
|
|
669
|
+
backgroundColor: WHEEL_SELECTION_BACKGROUND_COLOR,
|
|
670
|
+
zIndex: 0,
|
|
671
|
+
},
|
|
672
|
+
topMask: {
|
|
673
|
+
position: 'absolute',
|
|
674
|
+
top: 0,
|
|
675
|
+
left: 0,
|
|
676
|
+
right: 0,
|
|
677
|
+
height: ITEM_HEIGHT * ((VISIBLE_ITEMS - 1) / 2),
|
|
678
|
+
zIndex: 2,
|
|
679
|
+
},
|
|
680
|
+
bottomMask: {
|
|
681
|
+
position: 'absolute',
|
|
682
|
+
bottom: 0,
|
|
683
|
+
left: 0,
|
|
684
|
+
right: 0,
|
|
685
|
+
height: ITEM_HEIGHT * ((VISIBLE_ITEMS - 1) / 2),
|
|
686
|
+
zIndex: 2,
|
|
687
|
+
},
|
|
688
|
+
columnsRow: {
|
|
689
|
+
flexDirection: 'row',
|
|
690
|
+
alignItems: 'stretch',
|
|
691
|
+
justifyContent: 'space-between',
|
|
692
|
+
zIndex: 1,
|
|
693
|
+
},
|
|
694
|
+
});
|