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,59 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { type StyleProp, type TextStyle, type ViewProps, type ViewStyle } from 'react-native';
|
|
3
|
+
export { WHEEL_SELECTION_BACKGROUND_COLOR } from './constants';
|
|
4
|
+
export declare const WHEEL_VISIBLE_ITEMS = 5;
|
|
5
|
+
export declare const WHEEL_VIEWPORT_HEIGHT: number;
|
|
6
|
+
export declare const WHEEL_AREA_HEIGHT: number;
|
|
7
|
+
export declare const WHEEL_AREA_VERTICAL_INSET: number;
|
|
8
|
+
export declare const WHEEL_ITEM_HEIGHT: number;
|
|
9
|
+
export type WheelColumnValue = string | number;
|
|
10
|
+
export type WheelColumnOption<TValue extends WheelColumnValue = WheelColumnValue> = {
|
|
11
|
+
value: TValue;
|
|
12
|
+
label: string;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
key?: React.Key;
|
|
15
|
+
testID?: string;
|
|
16
|
+
accessibilityLabel?: string;
|
|
17
|
+
};
|
|
18
|
+
export type WheelColumnChangeSource = 'user' | 'accessibility';
|
|
19
|
+
export type WheelColumnChangePayload<TValue extends WheelColumnValue = WheelColumnValue> = {
|
|
20
|
+
value: TValue;
|
|
21
|
+
index: number;
|
|
22
|
+
option: WheelColumnOption<TValue>;
|
|
23
|
+
source: WheelColumnChangeSource;
|
|
24
|
+
};
|
|
25
|
+
export type WheelColumnHandle = {
|
|
26
|
+
scrollToIndex: (index: number, animated?: boolean) => void;
|
|
27
|
+
scrollToValue: (value: WheelColumnValue, animated?: boolean) => void;
|
|
28
|
+
settleToNearest: (animated?: boolean) => number;
|
|
29
|
+
syncCurrentSelection: () => Promise<number>;
|
|
30
|
+
};
|
|
31
|
+
type NativeViewProps = Omit<ViewProps, 'children' | 'style' | 'onChange'>;
|
|
32
|
+
export type WheelColumnProps<TValue extends WheelColumnValue = WheelColumnValue> = NativeViewProps & {
|
|
33
|
+
options: WheelColumnOption<TValue>[];
|
|
34
|
+
value?: TValue | null;
|
|
35
|
+
defaultValue?: TValue | null;
|
|
36
|
+
onChange?: (payload: WheelColumnChangePayload<TValue>) => void;
|
|
37
|
+
disabled?: boolean;
|
|
38
|
+
width?: number;
|
|
39
|
+
style?: StyleProp<ViewStyle>;
|
|
40
|
+
itemTextStyle?: StyleProp<TextStyle>;
|
|
41
|
+
selectedItemTextStyle?: StyleProp<TextStyle>;
|
|
42
|
+
disabledItemTextStyle?: StyleProp<TextStyle>;
|
|
43
|
+
numberOfLines?: number;
|
|
44
|
+
};
|
|
45
|
+
export type WheelOption<TValue extends WheelColumnValue = WheelColumnValue> = WheelColumnOption<TValue>;
|
|
46
|
+
export declare const WheelColumn: React.NamedExoticComponent<NativeViewProps & {
|
|
47
|
+
options: WheelColumnOption<WheelColumnValue>[];
|
|
48
|
+
value?: WheelColumnValue | null | undefined;
|
|
49
|
+
defaultValue?: WheelColumnValue | null | undefined;
|
|
50
|
+
onChange?: ((payload: WheelColumnChangePayload<WheelColumnValue>) => void) | undefined;
|
|
51
|
+
disabled?: boolean;
|
|
52
|
+
width?: number;
|
|
53
|
+
style?: StyleProp<ViewStyle>;
|
|
54
|
+
itemTextStyle?: StyleProp<TextStyle>;
|
|
55
|
+
selectedItemTextStyle?: StyleProp<TextStyle>;
|
|
56
|
+
disabledItemTextStyle?: StyleProp<TextStyle>;
|
|
57
|
+
numberOfLines?: number;
|
|
58
|
+
} & React.RefAttributes<WheelColumnHandle>>;
|
|
59
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/WheelColumn/index.tsx"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.WheelColumn = exports.WHEEL_ITEM_HEIGHT = exports.WHEEL_AREA_VERTICAL_INSET = exports.WHEEL_AREA_HEIGHT = exports.WHEEL_VIEWPORT_HEIGHT = exports.WHEEL_VISIBLE_ITEMS = exports.WHEEL_SELECTION_BACKGROUND_COLOR = void 0;
|
|
37
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
38
|
+
const React = __importStar(require("react"));
|
|
39
|
+
const react_native_1 = require("react-native");
|
|
40
|
+
const react_native_reanimated_1 = __importStar(require("react-native-reanimated"));
|
|
41
|
+
const react_native_worklets_1 = require("react-native-worklets");
|
|
42
|
+
const zkit_tools_1 = require("zkit-tools");
|
|
43
|
+
const useTheme_1 = require("../../theme/useTheme");
|
|
44
|
+
const ZKitWheelPickerNativeComponent_1 = require("./ZKitWheelPickerNativeComponent");
|
|
45
|
+
var constants_1 = require("./constants");
|
|
46
|
+
Object.defineProperty(exports, "WHEEL_SELECTION_BACKGROUND_COLOR", { enumerable: true, get: function () { return constants_1.WHEEL_SELECTION_BACKGROUND_COLOR; } });
|
|
47
|
+
exports.WHEEL_VISIBLE_ITEMS = 5;
|
|
48
|
+
// iOS 走系统 UIPickerView,Android/Web 走自绘 transform 路径。
|
|
49
|
+
// 这些尺寸是当前 app 端多轮调校后的稳定观感,保留为默认公共规格。
|
|
50
|
+
const IOS_CONFIRM_SYNC_TIMEOUT_MS = 64;
|
|
51
|
+
const IOS_NATIVE_PICKER_HEIGHT = (0, zkit_tools_1.wp)(260);
|
|
52
|
+
const IOS_NATIVE_PICKER_ROW_HEIGHT = (0, zkit_tools_1.wp)(50);
|
|
53
|
+
const IOS_NATIVE_PICKER_FONT_SIZE = (0, zkit_tools_1.sp)(22);
|
|
54
|
+
const BASE_WHEEL_ITEM_HEIGHT = (0, zkit_tools_1.wp)(44);
|
|
55
|
+
const BASE_WHEEL_AREA_HEIGHT = BASE_WHEEL_ITEM_HEIGHT * exports.WHEEL_VISIBLE_ITEMS;
|
|
56
|
+
exports.WHEEL_VIEWPORT_HEIGHT = react_native_1.Platform.OS === 'ios' ? IOS_NATIVE_PICKER_HEIGHT : BASE_WHEEL_AREA_HEIGHT;
|
|
57
|
+
exports.WHEEL_AREA_HEIGHT = react_native_1.Platform.OS === 'ios' ? Math.max(IOS_NATIVE_PICKER_HEIGHT, BASE_WHEEL_AREA_HEIGHT) : BASE_WHEEL_AREA_HEIGHT;
|
|
58
|
+
exports.WHEEL_AREA_VERTICAL_INSET = Math.max(0, exports.WHEEL_AREA_HEIGHT - exports.WHEEL_VIEWPORT_HEIGHT) / 2;
|
|
59
|
+
exports.WHEEL_ITEM_HEIGHT = react_native_1.Platform.OS === 'ios' ? IOS_NATIVE_PICKER_HEIGHT / exports.WHEEL_VISIBLE_ITEMS : BASE_WHEEL_ITEM_HEIGHT;
|
|
60
|
+
const CENTER_OFFSET = exports.WHEEL_ITEM_HEIGHT * Math.floor(exports.WHEEL_VISIBLE_ITEMS / 2);
|
|
61
|
+
const IOS_SETTLE_DELAY_MS = 90;
|
|
62
|
+
const SNAP_DURATION_MIN = 140;
|
|
63
|
+
const SNAP_DURATION_MAX = 280;
|
|
64
|
+
const SNAP_DURATION_PER_ITEM = 24;
|
|
65
|
+
const RELEASE_VELOCITY_DEADZONE = 220;
|
|
66
|
+
const RELEASE_LOCK_DISTANCE_ITEMS = 0.1;
|
|
67
|
+
const RELEASE_LOCK_MAX_VELOCITY = 380;
|
|
68
|
+
const MAX_FLING_ITEMS = 7;
|
|
69
|
+
const ANDROID_VELOCITY_WINDOW_MS = 90;
|
|
70
|
+
const SNAP_EASING = react_native_reanimated_1.Easing.bezier(0.22, 1, 0.36, 1);
|
|
71
|
+
function clampNumber(n, min, max) {
|
|
72
|
+
'worklet';
|
|
73
|
+
return Math.max(min, Math.min(max, n));
|
|
74
|
+
}
|
|
75
|
+
function indexToOffset(index) {
|
|
76
|
+
'worklet';
|
|
77
|
+
return index * exports.WHEEL_ITEM_HEIGHT;
|
|
78
|
+
}
|
|
79
|
+
function getReleaseDeltaItems(velocityY) {
|
|
80
|
+
const speed = Math.abs(velocityY);
|
|
81
|
+
if (speed < RELEASE_VELOCITY_DEADZONE)
|
|
82
|
+
return 0;
|
|
83
|
+
const projected = Math.pow(speed / 1400, 1.05) * 3.6;
|
|
84
|
+
return clampNumber(projected, 0, MAX_FLING_ITEMS);
|
|
85
|
+
}
|
|
86
|
+
function getTargetIndexFromRelease(offset, velocityY, maxIndex) {
|
|
87
|
+
const currentIndexFloat = offset / exports.WHEEL_ITEM_HEIGHT;
|
|
88
|
+
const nearestIndex = Math.round(currentIndexFloat);
|
|
89
|
+
const distanceToNearest = Math.abs(currentIndexFloat - nearestIndex);
|
|
90
|
+
const speed = Math.abs(velocityY);
|
|
91
|
+
if (speed < RELEASE_VELOCITY_DEADZONE) {
|
|
92
|
+
return clampNumber(nearestIndex, 0, maxIndex);
|
|
93
|
+
}
|
|
94
|
+
if (distanceToNearest < RELEASE_LOCK_DISTANCE_ITEMS && speed < RELEASE_LOCK_MAX_VELOCITY) {
|
|
95
|
+
return clampNumber(nearestIndex, 0, maxIndex);
|
|
96
|
+
}
|
|
97
|
+
const deltaItems = getReleaseDeltaItems(velocityY);
|
|
98
|
+
if (deltaItems <= 0) {
|
|
99
|
+
return clampNumber(nearestIndex, 0, maxIndex);
|
|
100
|
+
}
|
|
101
|
+
const direction = velocityY < 0 ? 1 : -1;
|
|
102
|
+
let targetIndex = Math.round(currentIndexFloat + direction * deltaItems);
|
|
103
|
+
if (targetIndex === nearestIndex) {
|
|
104
|
+
targetIndex = nearestIndex + direction;
|
|
105
|
+
}
|
|
106
|
+
return clampNumber(targetIndex, 0, maxIndex);
|
|
107
|
+
}
|
|
108
|
+
function getSnapDuration(fromOffset, toOffset) {
|
|
109
|
+
const distanceItems = Math.abs(toOffset - fromOffset) / exports.WHEEL_ITEM_HEIGHT;
|
|
110
|
+
return clampNumber(Math.round(SNAP_DURATION_MIN + distanceItems * SNAP_DURATION_PER_ITEM), SNAP_DURATION_MIN, SNAP_DURATION_MAX);
|
|
111
|
+
}
|
|
112
|
+
function findOptionIndex(options, value) {
|
|
113
|
+
if (value == null)
|
|
114
|
+
return -1;
|
|
115
|
+
return options.findIndex((option) => Object.is(option.value, value));
|
|
116
|
+
}
|
|
117
|
+
function findNearestEnabledIndex(options, index, direction = 0) {
|
|
118
|
+
var _a, _b, _c;
|
|
119
|
+
if (!options.length)
|
|
120
|
+
return -1;
|
|
121
|
+
const clampedIndex = clampNumber(Math.round(index), 0, options.length - 1);
|
|
122
|
+
if (!((_a = options[clampedIndex]) === null || _a === void 0 ? void 0 : _a.disabled))
|
|
123
|
+
return clampedIndex;
|
|
124
|
+
const walkForward = () => {
|
|
125
|
+
var _a;
|
|
126
|
+
for (let i = clampedIndex + 1; i < options.length; i += 1) {
|
|
127
|
+
if (!((_a = options[i]) === null || _a === void 0 ? void 0 : _a.disabled))
|
|
128
|
+
return i;
|
|
129
|
+
}
|
|
130
|
+
return -1;
|
|
131
|
+
};
|
|
132
|
+
const walkBackward = () => {
|
|
133
|
+
var _a;
|
|
134
|
+
for (let i = clampedIndex - 1; i >= 0; i -= 1) {
|
|
135
|
+
if (!((_a = options[i]) === null || _a === void 0 ? void 0 : _a.disabled))
|
|
136
|
+
return i;
|
|
137
|
+
}
|
|
138
|
+
return -1;
|
|
139
|
+
};
|
|
140
|
+
if (direction > 0) {
|
|
141
|
+
const next = walkForward();
|
|
142
|
+
return next >= 0 ? next : walkBackward();
|
|
143
|
+
}
|
|
144
|
+
if (direction < 0) {
|
|
145
|
+
const previous = walkBackward();
|
|
146
|
+
return previous >= 0 ? previous : walkForward();
|
|
147
|
+
}
|
|
148
|
+
for (let distance = 1; distance < options.length; distance += 1) {
|
|
149
|
+
const previous = clampedIndex - distance;
|
|
150
|
+
if (previous >= 0 && !((_b = options[previous]) === null || _b === void 0 ? void 0 : _b.disabled))
|
|
151
|
+
return previous;
|
|
152
|
+
const next = clampedIndex + distance;
|
|
153
|
+
if (next < options.length && !((_c = options[next]) === null || _c === void 0 ? void 0 : _c.disabled))
|
|
154
|
+
return next;
|
|
155
|
+
}
|
|
156
|
+
return -1;
|
|
157
|
+
}
|
|
158
|
+
function resolveDisplayIndex(options, value) {
|
|
159
|
+
if (!options.length)
|
|
160
|
+
return 0;
|
|
161
|
+
const selectedIndex = findOptionIndex(options, value);
|
|
162
|
+
if (selectedIndex >= 0)
|
|
163
|
+
return selectedIndex;
|
|
164
|
+
const firstEnabledIndex = findNearestEnabledIndex(options, 0);
|
|
165
|
+
return firstEnabledIndex >= 0 ? firstEnabledIndex : 0;
|
|
166
|
+
}
|
|
167
|
+
function normalizeFontWeight(fontWeight) {
|
|
168
|
+
if (fontWeight == null)
|
|
169
|
+
return undefined;
|
|
170
|
+
return String(fontWeight);
|
|
171
|
+
}
|
|
172
|
+
function normalizeFontStyle(fontStyle) {
|
|
173
|
+
if (fontStyle == null)
|
|
174
|
+
return undefined;
|
|
175
|
+
return fontStyle;
|
|
176
|
+
}
|
|
177
|
+
function optionKey(option, index) {
|
|
178
|
+
var _a, _b;
|
|
179
|
+
return (_b = (_a = option.key) !== null && _a !== void 0 ? _a : option.value) !== null && _b !== void 0 ? _b : index;
|
|
180
|
+
}
|
|
181
|
+
function resolveWebInteractionStyle(disabled) {
|
|
182
|
+
if (react_native_1.Platform.OS !== 'web')
|
|
183
|
+
return undefined;
|
|
184
|
+
return {
|
|
185
|
+
cursor: disabled ? 'not-allowed' : 'grab',
|
|
186
|
+
touchAction: 'none',
|
|
187
|
+
userSelect: 'none',
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
const WheelColumnBase = React.forwardRef(function WheelColumn({ options, value, defaultValue, onChange, disabled = false, width, style, itemTextStyle, selectedItemTextStyle, disabledItemTextStyle, numberOfLines = 1, accessibilityLabel, accessibilityHint, accessibilityState, testID, ...viewProps }, ref) {
|
|
191
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
192
|
+
const theme = (0, useTheme_1.useTheme)();
|
|
193
|
+
const isControlled = value !== undefined;
|
|
194
|
+
const firstDefaultValue = React.useMemo(() => {
|
|
195
|
+
var _a, _b, _c, _d;
|
|
196
|
+
if (defaultValue != null && findOptionIndex(options, defaultValue) >= 0)
|
|
197
|
+
return defaultValue;
|
|
198
|
+
const firstEnabledIndex = findNearestEnabledIndex(options, 0);
|
|
199
|
+
if (firstEnabledIndex >= 0)
|
|
200
|
+
return (_b = (_a = options[firstEnabledIndex]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null;
|
|
201
|
+
return (_d = (_c = options[0]) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : null;
|
|
202
|
+
}, [defaultValue, options]);
|
|
203
|
+
const [uncontrolledValue, setUncontrolledValue] = React.useState(firstDefaultValue);
|
|
204
|
+
const resolvedValue = isControlled ? value : uncontrolledValue;
|
|
205
|
+
const maxIndex = Math.max(0, options.length - 1);
|
|
206
|
+
const maxOffset = indexToOffset(maxIndex);
|
|
207
|
+
const displayIndex = resolveDisplayIndex(options, resolvedValue);
|
|
208
|
+
const offsetY = (0, react_native_reanimated_1.useSharedValue)(indexToOffset(displayIndex));
|
|
209
|
+
const dragStartOffset = (0, react_native_reanimated_1.useSharedValue)(indexToOffset(displayIndex));
|
|
210
|
+
const isUserInteracting = (0, react_native_reanimated_1.useSharedValue)(false);
|
|
211
|
+
const iosPickerRef = React.useRef(null);
|
|
212
|
+
const iosSelectedIndexRef = React.useRef(displayIndex);
|
|
213
|
+
const iosSettleTimerRef = React.useRef(null);
|
|
214
|
+
const iosSyncTimerRef = React.useRef(null);
|
|
215
|
+
const iosSyncResolverRef = React.useRef(null);
|
|
216
|
+
const [iosSelectedIndex, setIosSelectedIndex] = React.useState(displayIndex);
|
|
217
|
+
const selectedValueRef = React.useRef(resolvedValue);
|
|
218
|
+
const displayIndexRef = React.useRef(displayIndex);
|
|
219
|
+
const flattenedItemTextStyle = React.useMemo(() => { var _a; return (_a = react_native_1.StyleSheet.flatten(itemTextStyle)) !== null && _a !== void 0 ? _a : {}; }, [itemTextStyle]);
|
|
220
|
+
const flattenedSelectedItemTextStyle = React.useMemo(() => { var _a; return (_a = react_native_1.StyleSheet.flatten(selectedItemTextStyle)) !== null && _a !== void 0 ? _a : {}; }, [selectedItemTextStyle]);
|
|
221
|
+
const flattenedDisabledItemTextStyle = React.useMemo(() => { var _a; return (_a = react_native_1.StyleSheet.flatten(disabledItemTextStyle)) !== null && _a !== void 0 ? _a : {}; }, [disabledItemTextStyle]);
|
|
222
|
+
const selectedTextColor = ((_b = (_a = flattenedSelectedItemTextStyle.color) !== null && _a !== void 0 ? _a : flattenedItemTextStyle.color) !== null && _b !== void 0 ? _b : theme.colors.onSurface);
|
|
223
|
+
const itemTextColor = ((_c = flattenedItemTextStyle.color) !== null && _c !== void 0 ? _c : theme.colors.muted);
|
|
224
|
+
const disabledTextColor = ((_d = flattenedDisabledItemTextStyle.color) !== null && _d !== void 0 ? _d : theme.colors.disabled);
|
|
225
|
+
const nativeFontSize = typeof flattenedSelectedItemTextStyle.fontSize === 'number'
|
|
226
|
+
? flattenedSelectedItemTextStyle.fontSize
|
|
227
|
+
: typeof flattenedItemTextStyle.fontSize === 'number'
|
|
228
|
+
? flattenedItemTextStyle.fontSize
|
|
229
|
+
: IOS_NATIVE_PICKER_FONT_SIZE;
|
|
230
|
+
const nativeFontWeight = (_f = (_e = normalizeFontWeight(flattenedSelectedItemTextStyle.fontWeight)) !== null && _e !== void 0 ? _e : normalizeFontWeight(flattenedItemTextStyle.fontWeight)) !== null && _f !== void 0 ? _f : '500';
|
|
231
|
+
const nativeFontFamily = (_g = flattenedSelectedItemTextStyle.fontFamily) !== null && _g !== void 0 ? _g : flattenedItemTextStyle.fontFamily;
|
|
232
|
+
const nativeFontStyle = (_h = normalizeFontStyle(flattenedSelectedItemTextStyle.fontStyle)) !== null && _h !== void 0 ? _h : normalizeFontStyle(flattenedItemTextStyle.fontStyle);
|
|
233
|
+
const clearIOSSettleTimer = React.useCallback(() => {
|
|
234
|
+
if (iosSettleTimerRef.current != null) {
|
|
235
|
+
clearTimeout(iosSettleTimerRef.current);
|
|
236
|
+
iosSettleTimerRef.current = null;
|
|
237
|
+
}
|
|
238
|
+
}, []);
|
|
239
|
+
const clearIOSSyncTimer = React.useCallback(() => {
|
|
240
|
+
if (iosSyncTimerRef.current != null) {
|
|
241
|
+
clearTimeout(iosSyncTimerRef.current);
|
|
242
|
+
iosSyncTimerRef.current = null;
|
|
243
|
+
}
|
|
244
|
+
}, []);
|
|
245
|
+
const resolveSelectableIndex = React.useCallback((index, direction = 0) => {
|
|
246
|
+
const next = findNearestEnabledIndex(options, index, direction);
|
|
247
|
+
return next >= 0 ? next : clampNumber(Math.round(index), 0, maxIndex);
|
|
248
|
+
}, [maxIndex, options]);
|
|
249
|
+
const resolveIOSSyncRequest = React.useCallback((index) => {
|
|
250
|
+
const resolver = iosSyncResolverRef.current;
|
|
251
|
+
if (!resolver)
|
|
252
|
+
return;
|
|
253
|
+
iosSyncResolverRef.current = null;
|
|
254
|
+
clearIOSSyncTimer();
|
|
255
|
+
resolver(resolveSelectableIndex(index));
|
|
256
|
+
}, [clearIOSSyncTimer, resolveSelectableIndex]);
|
|
257
|
+
const syncIOSSelectedIndex = React.useCallback((index) => {
|
|
258
|
+
const nextIndex = clampNumber(index, 0, maxIndex);
|
|
259
|
+
iosSelectedIndexRef.current = nextIndex;
|
|
260
|
+
setIosSelectedIndex((previous) => (previous === nextIndex ? previous : nextIndex));
|
|
261
|
+
return nextIndex;
|
|
262
|
+
}, [maxIndex]);
|
|
263
|
+
const emitSelectedIndex = React.useCallback((index, source) => {
|
|
264
|
+
if (!options.length)
|
|
265
|
+
return;
|
|
266
|
+
const nextIndex = resolveSelectableIndex(index, index - displayIndexRef.current);
|
|
267
|
+
const option = options[nextIndex];
|
|
268
|
+
if (!option || option.disabled)
|
|
269
|
+
return;
|
|
270
|
+
const sameAsCurrent = displayIndexRef.current === nextIndex && Object.is(selectedValueRef.current, option.value);
|
|
271
|
+
if (sameAsCurrent)
|
|
272
|
+
return;
|
|
273
|
+
selectedValueRef.current = option.value;
|
|
274
|
+
displayIndexRef.current = nextIndex;
|
|
275
|
+
if (!isControlled) {
|
|
276
|
+
setUncontrolledValue(option.value);
|
|
277
|
+
}
|
|
278
|
+
onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
279
|
+
value: option.value,
|
|
280
|
+
index: nextIndex,
|
|
281
|
+
option,
|
|
282
|
+
source,
|
|
283
|
+
});
|
|
284
|
+
}, [isControlled, onChange, options, resolveSelectableIndex]);
|
|
285
|
+
const scheduleIOSSettle = React.useCallback((index) => {
|
|
286
|
+
clearIOSSettleTimer();
|
|
287
|
+
iosSettleTimerRef.current = setTimeout(() => {
|
|
288
|
+
iosSettleTimerRef.current = null;
|
|
289
|
+
const nextIndex = resolveSelectableIndex(index, index - displayIndexRef.current);
|
|
290
|
+
if (nextIndex !== index) {
|
|
291
|
+
syncIOSSelectedIndex(nextIndex);
|
|
292
|
+
}
|
|
293
|
+
emitSelectedIndex(nextIndex, 'user');
|
|
294
|
+
}, IOS_SETTLE_DELAY_MS);
|
|
295
|
+
}, [clearIOSSettleTimer, emitSelectedIndex, resolveSelectableIndex, syncIOSSelectedIndex]);
|
|
296
|
+
const scrollToIndex = React.useCallback((index, animated = false) => {
|
|
297
|
+
const nextIndex = clampNumber(index, 0, maxIndex);
|
|
298
|
+
if (react_native_1.Platform.OS === 'ios') {
|
|
299
|
+
clearIOSSettleTimer();
|
|
300
|
+
syncIOSSelectedIndex(nextIndex);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
const nextOffset = indexToOffset(nextIndex);
|
|
304
|
+
(0, react_native_reanimated_1.cancelAnimation)(offsetY);
|
|
305
|
+
isUserInteracting.value = false;
|
|
306
|
+
if (animated) {
|
|
307
|
+
offsetY.value = (0, react_native_reanimated_1.withTiming)(nextOffset, {
|
|
308
|
+
duration: getSnapDuration(offsetY.value, nextOffset),
|
|
309
|
+
easing: SNAP_EASING,
|
|
310
|
+
});
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
offsetY.value = nextOffset;
|
|
314
|
+
}, [clearIOSSettleTimer, isUserInteracting, maxIndex, offsetY, syncIOSSelectedIndex]);
|
|
315
|
+
const scrollToValue = React.useCallback((nextValue, animated = false) => {
|
|
316
|
+
const index = findOptionIndex(options, nextValue);
|
|
317
|
+
if (index < 0)
|
|
318
|
+
return;
|
|
319
|
+
scrollToIndex(index, animated);
|
|
320
|
+
}, [options, scrollToIndex]);
|
|
321
|
+
const settleToNearest = React.useCallback((animated = false) => {
|
|
322
|
+
const rawIndex = react_native_1.Platform.OS === 'ios'
|
|
323
|
+
? iosSelectedIndexRef.current
|
|
324
|
+
: Math.round(clampNumber(offsetY.value, 0, maxOffset) / exports.WHEEL_ITEM_HEIGHT);
|
|
325
|
+
const nextIndex = resolveSelectableIndex(rawIndex, rawIndex - displayIndexRef.current);
|
|
326
|
+
scrollToIndex(nextIndex, animated);
|
|
327
|
+
return nextIndex;
|
|
328
|
+
}, [maxOffset, offsetY, resolveSelectableIndex, scrollToIndex]);
|
|
329
|
+
const syncCurrentSelection = React.useCallback(() => {
|
|
330
|
+
if (react_native_1.Platform.OS !== 'ios') {
|
|
331
|
+
return Promise.resolve(settleToNearest(false));
|
|
332
|
+
}
|
|
333
|
+
clearIOSSettleTimer();
|
|
334
|
+
resolveIOSSyncRequest(iosSelectedIndexRef.current);
|
|
335
|
+
return new Promise((resolve) => {
|
|
336
|
+
iosSyncResolverRef.current = resolve;
|
|
337
|
+
if (iosPickerRef.current != null && (0, ZKitWheelPickerNativeComponent_1.syncZKitWheelPickerCurrentSelection)(iosPickerRef.current)) {
|
|
338
|
+
iosSyncTimerRef.current = setTimeout(() => {
|
|
339
|
+
resolveIOSSyncRequest(iosSelectedIndexRef.current);
|
|
340
|
+
}, IOS_CONFIRM_SYNC_TIMEOUT_MS);
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
resolveIOSSyncRequest(iosSelectedIndexRef.current);
|
|
344
|
+
});
|
|
345
|
+
}, [clearIOSSettleTimer, resolveIOSSyncRequest, settleToNearest]);
|
|
346
|
+
React.useImperativeHandle(ref, () => ({ scrollToIndex, scrollToValue, settleToNearest, syncCurrentSelection }), [scrollToIndex, scrollToValue, settleToNearest, syncCurrentSelection]);
|
|
347
|
+
React.useEffect(() => {
|
|
348
|
+
selectedValueRef.current = resolvedValue;
|
|
349
|
+
displayIndexRef.current = displayIndex;
|
|
350
|
+
}, [displayIndex, resolvedValue]);
|
|
351
|
+
React.useEffect(() => {
|
|
352
|
+
var _a, _b;
|
|
353
|
+
if (isControlled || !options.length)
|
|
354
|
+
return;
|
|
355
|
+
if (findOptionIndex(options, uncontrolledValue) >= 0)
|
|
356
|
+
return;
|
|
357
|
+
const firstEnabledIndex = findNearestEnabledIndex(options, 0);
|
|
358
|
+
const nextValue = firstEnabledIndex >= 0 ? (_a = options[firstEnabledIndex]) === null || _a === void 0 ? void 0 : _a.value : (_b = options[0]) === null || _b === void 0 ? void 0 : _b.value;
|
|
359
|
+
setUncontrolledValue(nextValue !== null && nextValue !== void 0 ? nextValue : null);
|
|
360
|
+
}, [isControlled, options, uncontrolledValue]);
|
|
361
|
+
React.useEffect(() => {
|
|
362
|
+
if (!options.length) {
|
|
363
|
+
clearIOSSettleTimer();
|
|
364
|
+
iosSelectedIndexRef.current = 0;
|
|
365
|
+
setIosSelectedIndex(0);
|
|
366
|
+
(0, react_native_reanimated_1.cancelAnimation)(offsetY);
|
|
367
|
+
offsetY.value = 0;
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
clearIOSSettleTimer();
|
|
371
|
+
syncIOSSelectedIndex(displayIndex);
|
|
372
|
+
scrollToIndex(displayIndex, false);
|
|
373
|
+
}, [clearIOSSettleTimer, displayIndex, offsetY, options.length, scrollToIndex, syncIOSSelectedIndex]);
|
|
374
|
+
React.useEffect(() => () => {
|
|
375
|
+
clearIOSSettleTimer();
|
|
376
|
+
resolveIOSSyncRequest(iosSelectedIndexRef.current);
|
|
377
|
+
}, [clearIOSSettleTimer, resolveIOSSyncRequest]);
|
|
378
|
+
const handleIOSChange = React.useCallback((event) => {
|
|
379
|
+
const rawIndex = syncIOSSelectedIndex(event.nativeEvent.newIndex);
|
|
380
|
+
const nextIndex = resolveSelectableIndex(rawIndex, rawIndex - displayIndexRef.current);
|
|
381
|
+
resolveIOSSyncRequest(nextIndex);
|
|
382
|
+
scheduleIOSSettle(nextIndex);
|
|
383
|
+
}, [resolveIOSSyncRequest, resolveSelectableIndex, scheduleIOSSettle, syncIOSSelectedIndex]);
|
|
384
|
+
const startInteraction = React.useCallback(() => {
|
|
385
|
+
(0, react_native_reanimated_1.cancelAnimation)(offsetY);
|
|
386
|
+
isUserInteracting.value = true;
|
|
387
|
+
dragStartOffset.value = offsetY.value;
|
|
388
|
+
}, [dragStartOffset, isUserInteracting, offsetY]);
|
|
389
|
+
const updateInteraction = React.useCallback((translationY) => {
|
|
390
|
+
offsetY.value = clampNumber(dragStartOffset.value - translationY, 0, maxOffset);
|
|
391
|
+
}, [dragStartOffset, maxOffset, offsetY]);
|
|
392
|
+
const finishInteraction = React.useCallback((velocityY) => {
|
|
393
|
+
const currentOffset = clampNumber(offsetY.value, 0, maxOffset);
|
|
394
|
+
const rawIndex = getTargetIndexFromRelease(currentOffset, velocityY, maxIndex);
|
|
395
|
+
const currentIndex = Math.round(currentOffset / exports.WHEEL_ITEM_HEIGHT);
|
|
396
|
+
const nextIndex = resolveSelectableIndex(rawIndex, rawIndex - currentIndex);
|
|
397
|
+
const nextOffset = indexToOffset(nextIndex);
|
|
398
|
+
offsetY.value = (0, react_native_reanimated_1.withTiming)(nextOffset, {
|
|
399
|
+
duration: getSnapDuration(currentOffset, nextOffset),
|
|
400
|
+
easing: SNAP_EASING,
|
|
401
|
+
}, (finished) => {
|
|
402
|
+
if (!finished)
|
|
403
|
+
return;
|
|
404
|
+
isUserInteracting.value = false;
|
|
405
|
+
(0, react_native_worklets_1.scheduleOnRN)(emitSelectedIndex, nextIndex, 'user');
|
|
406
|
+
});
|
|
407
|
+
}, [emitSelectedIndex, isUserInteracting, maxIndex, maxOffset, offsetY, resolveSelectableIndex]);
|
|
408
|
+
const touchStateRef = React.useRef({
|
|
409
|
+
startPageY: 0,
|
|
410
|
+
samples: [],
|
|
411
|
+
});
|
|
412
|
+
const beginTouch = React.useCallback((pageY, timestamp) => {
|
|
413
|
+
const ts = typeof timestamp === 'number' ? timestamp : Date.now();
|
|
414
|
+
touchStateRef.current = {
|
|
415
|
+
startPageY: pageY,
|
|
416
|
+
samples: [{ pageY, timestamp: ts }],
|
|
417
|
+
};
|
|
418
|
+
startInteraction();
|
|
419
|
+
}, [startInteraction]);
|
|
420
|
+
const recordTouchSample = React.useCallback((pageY, timestamp) => {
|
|
421
|
+
var _a;
|
|
422
|
+
const ts = typeof timestamp === 'number' ? timestamp : Date.now();
|
|
423
|
+
const { samples } = touchStateRef.current;
|
|
424
|
+
samples.push({ pageY, timestamp: ts });
|
|
425
|
+
while (samples.length > 6) {
|
|
426
|
+
samples.shift();
|
|
427
|
+
}
|
|
428
|
+
const minTs = ts - ANDROID_VELOCITY_WINDOW_MS;
|
|
429
|
+
while (samples.length > 2 && ((_a = samples[0]) === null || _a === void 0 ? void 0 : _a.timestamp) < minTs) {
|
|
430
|
+
samples.shift();
|
|
431
|
+
}
|
|
432
|
+
}, []);
|
|
433
|
+
const moveTouch = React.useCallback((pageY, timestamp) => {
|
|
434
|
+
updateInteraction(pageY - touchStateRef.current.startPageY);
|
|
435
|
+
recordTouchSample(pageY, timestamp);
|
|
436
|
+
}, [recordTouchSample, updateInteraction]);
|
|
437
|
+
const endTouch = React.useCallback((pageY, timestamp) => {
|
|
438
|
+
var _a, _b, _c, _d;
|
|
439
|
+
recordTouchSample(pageY, timestamp);
|
|
440
|
+
const { samples } = touchStateRef.current;
|
|
441
|
+
const firstSample = samples[0];
|
|
442
|
+
const lastSample = samples[samples.length - 1];
|
|
443
|
+
const deltaY = ((_a = lastSample === null || lastSample === void 0 ? void 0 : lastSample.pageY) !== null && _a !== void 0 ? _a : pageY) - ((_b = firstSample === null || firstSample === void 0 ? void 0 : firstSample.pageY) !== null && _b !== void 0 ? _b : pageY);
|
|
444
|
+
const deltaT = Math.max(1, ((_c = lastSample === null || lastSample === void 0 ? void 0 : lastSample.timestamp) !== null && _c !== void 0 ? _c : Date.now()) - ((_d = firstSample === null || firstSample === void 0 ? void 0 : firstSample.timestamp) !== null && _d !== void 0 ? _d : Date.now()));
|
|
445
|
+
finishInteraction((deltaY / deltaT) * 1000);
|
|
446
|
+
}, [finishInteraction, recordTouchSample]);
|
|
447
|
+
const handleAccessibilityAction = React.useCallback((event) => {
|
|
448
|
+
if (disabled)
|
|
449
|
+
return;
|
|
450
|
+
const actionName = event.nativeEvent.actionName;
|
|
451
|
+
const direction = actionName === 'increment' ? 1 : actionName === 'decrement' ? -1 : 0;
|
|
452
|
+
if (direction === 0)
|
|
453
|
+
return;
|
|
454
|
+
const nextIndex = findNearestEnabledIndex(options, displayIndexRef.current + direction, direction);
|
|
455
|
+
if (nextIndex < 0)
|
|
456
|
+
return;
|
|
457
|
+
scrollToIndex(nextIndex, true);
|
|
458
|
+
emitSelectedIndex(nextIndex, 'accessibility');
|
|
459
|
+
}, [disabled, emitSelectedIndex, options, scrollToIndex]);
|
|
460
|
+
const contentStyle = (0, react_native_reanimated_1.useAnimatedStyle)(() => ({
|
|
461
|
+
transform: [{ translateY: CENTER_OFFSET - offsetY.value }],
|
|
462
|
+
}));
|
|
463
|
+
const items = React.useMemo(() => options.map((item, index) => {
|
|
464
|
+
var _a;
|
|
465
|
+
return ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.itemContainer, children: (0, jsx_runtime_1.jsx)(react_native_reanimated_1.default.Text, { accessibilityLabel: (_a = item.accessibilityLabel) !== null && _a !== void 0 ? _a : item.label, maxFontSizeMultiplier: (0, zkit_tools_1.getMaxFontSizeMultiplier)(), numberOfLines: numberOfLines, style: [
|
|
466
|
+
styles.itemText,
|
|
467
|
+
{ color: itemTextColor },
|
|
468
|
+
itemTextStyle,
|
|
469
|
+
index === displayIndex && [styles.itemTextSelected, { color: selectedTextColor }, selectedItemTextStyle],
|
|
470
|
+
item.disabled && [styles.itemTextDisabled, { color: disabledTextColor }, disabledItemTextStyle],
|
|
471
|
+
], testID: item.testID, children: item.label }) }, `${String(optionKey(item, index))}-${index}`));
|
|
472
|
+
}), [
|
|
473
|
+
disabledItemTextStyle,
|
|
474
|
+
disabledTextColor,
|
|
475
|
+
displayIndex,
|
|
476
|
+
itemTextColor,
|
|
477
|
+
itemTextStyle,
|
|
478
|
+
numberOfLines,
|
|
479
|
+
options,
|
|
480
|
+
selectedItemTextStyle,
|
|
481
|
+
selectedTextColor,
|
|
482
|
+
]);
|
|
483
|
+
const nativeItems = React.useMemo(() => options.map((item, index) => {
|
|
484
|
+
var _a;
|
|
485
|
+
return ({
|
|
486
|
+
label: item.label,
|
|
487
|
+
value: item.value,
|
|
488
|
+
textColor: item.disabled ? disabledTextColor : undefined,
|
|
489
|
+
testID: (_a = item.testID) !== null && _a !== void 0 ? _a : `wheel-item-${String(item.value)}-${index}`,
|
|
490
|
+
});
|
|
491
|
+
}), [disabledTextColor, options]);
|
|
492
|
+
const selectedOption = options[displayIndex];
|
|
493
|
+
const canInteract = !disabled && options.length > 1 && findNearestEnabledIndex(options, displayIndex) >= 0;
|
|
494
|
+
const columnStyle = React.useMemo(() => [styles.column, width != null && { width }, resolveWebInteractionStyle(disabled), style], [disabled, style, width]);
|
|
495
|
+
const resolvedAccessibilityState = React.useMemo(() => ({
|
|
496
|
+
...accessibilityState,
|
|
497
|
+
disabled,
|
|
498
|
+
}), [accessibilityState, disabled]);
|
|
499
|
+
if (react_native_1.Platform.OS === 'ios') {
|
|
500
|
+
return ((0, jsx_runtime_1.jsx)(react_native_1.View, { ...viewProps, accessibilityHint: accessibilityHint, accessibilityLabel: accessibilityLabel, accessibilityState: resolvedAccessibilityState, accessibilityValue: { text: (_j = selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label) !== null && _j !== void 0 ? _j : '' }, style: columnStyle, pointerEvents: canInteract ? 'auto' : 'none', testID: testID, children: (0, jsx_runtime_1.jsx)(ZKitWheelPickerNativeComponent_1.ZKitWheelPicker, { ref: iosPickerRef, items: nativeItems, selectedIndex: iosSelectedIndex, onChange: handleIOSChange, numberOfLines: numberOfLines, rowHeight: IOS_NATIVE_PICKER_ROW_HEIGHT, style: styles.iosPicker, fontFamily: nativeFontFamily, fontSize: nativeFontSize, fontStyle: nativeFontStyle, fontWeight: nativeFontWeight, color: selectedTextColor }) }));
|
|
501
|
+
}
|
|
502
|
+
return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { ...viewProps, accessibilityActions: [{ name: 'increment' }, { name: 'decrement' }], accessibilityHint: accessibilityHint, accessibilityLabel: accessibilityLabel, accessibilityRole: "adjustable", accessibilityState: resolvedAccessibilityState, accessibilityValue: { text: (_k = selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label) !== null && _k !== void 0 ? _k : '' }, collapsable: false, onAccessibilityAction: handleAccessibilityAction, style: columnStyle, testID: testID, children: [(0, jsx_runtime_1.jsx)(react_native_reanimated_1.default.View, { style: [styles.content, contentStyle], pointerEvents: "none", renderToHardwareTextureAndroid: react_native_1.Platform.OS === 'android', shouldRasterizeIOS: false, children: items }), (0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.touchSurface, collapsable: false, pointerEvents: "box-only", onStartShouldSetResponder: () => canInteract, onStartShouldSetResponderCapture: () => canInteract, onMoveShouldSetResponder: () => canInteract, onMoveShouldSetResponderCapture: () => canInteract, onResponderTerminationRequest: () => false, onResponderGrant: (event) => {
|
|
503
|
+
beginTouch(event.nativeEvent.pageY, event.nativeEvent.timestamp);
|
|
504
|
+
}, onResponderMove: (event) => {
|
|
505
|
+
moveTouch(event.nativeEvent.pageY, event.nativeEvent.timestamp);
|
|
506
|
+
}, onResponderRelease: (event) => {
|
|
507
|
+
endTouch(event.nativeEvent.pageY, event.nativeEvent.timestamp);
|
|
508
|
+
}, onResponderTerminate: (event) => {
|
|
509
|
+
endTouch(event.nativeEvent.pageY, event.nativeEvent.timestamp);
|
|
510
|
+
} })] }));
|
|
511
|
+
});
|
|
512
|
+
exports.WheelColumn = React.memo(WheelColumnBase);
|
|
513
|
+
const styles = react_native_1.StyleSheet.create({
|
|
514
|
+
column: {
|
|
515
|
+
height: exports.WHEEL_VIEWPORT_HEIGHT,
|
|
516
|
+
overflow: 'hidden',
|
|
517
|
+
},
|
|
518
|
+
iosPicker: {
|
|
519
|
+
width: '100%',
|
|
520
|
+
height: IOS_NATIVE_PICKER_HEIGHT,
|
|
521
|
+
},
|
|
522
|
+
content: {
|
|
523
|
+
width: '100%',
|
|
524
|
+
},
|
|
525
|
+
touchSurface: {
|
|
526
|
+
...react_native_1.StyleSheet.absoluteFillObject,
|
|
527
|
+
backgroundColor: 'transparent',
|
|
528
|
+
zIndex: 5,
|
|
529
|
+
},
|
|
530
|
+
itemContainer: {
|
|
531
|
+
height: exports.WHEEL_ITEM_HEIGHT,
|
|
532
|
+
justifyContent: 'center',
|
|
533
|
+
alignItems: 'center',
|
|
534
|
+
paddingHorizontal: (0, zkit_tools_1.wp)(8),
|
|
535
|
+
},
|
|
536
|
+
itemText: {
|
|
537
|
+
fontSize: (0, zkit_tools_1.sp)(18),
|
|
538
|
+
textAlign: 'center',
|
|
539
|
+
fontWeight: '500',
|
|
540
|
+
},
|
|
541
|
+
itemTextSelected: {
|
|
542
|
+
opacity: 1,
|
|
543
|
+
},
|
|
544
|
+
itemTextDisabled: {
|
|
545
|
+
opacity: 0.62,
|
|
546
|
+
},
|
|
547
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#import <UIKit/UIKit.h>
|
|
2
|
+
|
|
3
|
+
#import <React/RCTComponent.h>
|
|
4
|
+
|
|
5
|
+
@interface ZKitWheelPicker : UIPickerView <UIPickerViewDataSource, UIPickerViewDelegate, UIPickerViewAccessibilityDelegate>
|
|
6
|
+
|
|
7
|
+
@property (nonatomic, copy) NSArray<NSDictionary *> *items;
|
|
8
|
+
@property (nonatomic, assign) NSInteger selectedIndex;
|
|
9
|
+
@property (nonatomic, strong) UIColor *color;
|
|
10
|
+
@property (nonatomic, strong) UIFont *font;
|
|
11
|
+
@property (nonatomic, assign) CGFloat rowHeight;
|
|
12
|
+
@property (nonatomic, assign) NSInteger numberOfLines;
|
|
13
|
+
|
|
14
|
+
@property (nonatomic, copy) RCTBubblingEventBlock onChange;
|
|
15
|
+
|
|
16
|
+
- (void)syncCurrentSelection;
|
|
17
|
+
|
|
18
|
+
@end
|