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,122 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.LoadingSpinner = LoadingSpinner;
|
|
40
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
41
|
+
const React = __importStar(require("react"));
|
|
42
|
+
const react_native_1 = require("react-native");
|
|
43
|
+
const lottie_react_native_1 = __importDefault(require("lottie-react-native"));
|
|
44
|
+
const spinner_json_1 = __importDefault(require("../../assets/animations/spinner.json"));
|
|
45
|
+
function getColorKeyAndRgb(inputColor) {
|
|
46
|
+
const intColor = (0, react_native_1.processColor)(inputColor);
|
|
47
|
+
if (typeof intColor !== 'number')
|
|
48
|
+
return null;
|
|
49
|
+
const key = String(intColor);
|
|
50
|
+
const r = (intColor >> 16) & 255;
|
|
51
|
+
const g = (intColor >> 8) & 255;
|
|
52
|
+
const b = intColor & 255;
|
|
53
|
+
return { key, rgb: { r: r / 255, g: g / 255, b: b / 255 } };
|
|
54
|
+
}
|
|
55
|
+
function colorizeLottieJson(json, rgb) {
|
|
56
|
+
const clone = JSON.parse(JSON.stringify(json));
|
|
57
|
+
const overrideSolid = (node) => {
|
|
58
|
+
if (node.c && Array.isArray(node.c.k)) {
|
|
59
|
+
const k = node.c.k;
|
|
60
|
+
if (k.length === 3) {
|
|
61
|
+
node.c.k = [rgb.r, rgb.g, rgb.b];
|
|
62
|
+
}
|
|
63
|
+
else if (k.length === 4) {
|
|
64
|
+
node.c.k = [rgb.r, rgb.g, rgb.b, k[3]];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const overrideGradient = (node) => {
|
|
69
|
+
if (node.g && Array.isArray(node.g.k)) {
|
|
70
|
+
const arr = node.g.k;
|
|
71
|
+
for (let i = 0; i < arr.length; i += 4) {
|
|
72
|
+
if (typeof arr[i] === 'number' && i + 3 < arr.length) {
|
|
73
|
+
arr[i + 1] = rgb.r;
|
|
74
|
+
arr[i + 2] = rgb.g;
|
|
75
|
+
arr[i + 3] = rgb.b;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const traverse = (node) => {
|
|
81
|
+
if (!node || typeof node !== 'object')
|
|
82
|
+
return;
|
|
83
|
+
overrideSolid(node);
|
|
84
|
+
overrideGradient(node);
|
|
85
|
+
if (Array.isArray(node)) {
|
|
86
|
+
node.forEach(traverse);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
Object.keys(node).forEach((key) => traverse(node[key]));
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
traverse(clone);
|
|
93
|
+
return clone;
|
|
94
|
+
}
|
|
95
|
+
const MAX_CACHE_ENTRIES = 12;
|
|
96
|
+
const sourceCache = new Map();
|
|
97
|
+
function getColoredSource(color) {
|
|
98
|
+
const keyAndRgb = getColorKeyAndRgb(color);
|
|
99
|
+
if (!keyAndRgb)
|
|
100
|
+
return spinner_json_1.default;
|
|
101
|
+
const cached = sourceCache.get(keyAndRgb.key);
|
|
102
|
+
if (cached) {
|
|
103
|
+
sourceCache.delete(keyAndRgb.key);
|
|
104
|
+
sourceCache.set(keyAndRgb.key, cached);
|
|
105
|
+
return cached;
|
|
106
|
+
}
|
|
107
|
+
const colored = colorizeLottieJson(spinner_json_1.default, keyAndRgb.rgb);
|
|
108
|
+
sourceCache.set(keyAndRgb.key, colored);
|
|
109
|
+
while (sourceCache.size > MAX_CACHE_ENTRIES) {
|
|
110
|
+
const firstKey = sourceCache.keys().next().value;
|
|
111
|
+
if (firstKey == null)
|
|
112
|
+
break;
|
|
113
|
+
sourceCache.delete(firstKey);
|
|
114
|
+
}
|
|
115
|
+
return colored;
|
|
116
|
+
}
|
|
117
|
+
function LoadingSpinner({ size = 100, color = 'white', animating = true, speed = 2 }) {
|
|
118
|
+
if (!animating)
|
|
119
|
+
return null;
|
|
120
|
+
const coloredSource = React.useMemo(() => getColoredSource(color), [color]);
|
|
121
|
+
return ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: { width: size, height: size, justifyContent: 'center', alignItems: 'center' }, children: (0, jsx_runtime_1.jsx)(lottie_react_native_1.default, { source: coloredSource, style: { width: size, height: size }, autoPlay: true, loop: true, speed: speed }) }));
|
|
122
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { type StyleProp, type ViewStyle } from 'react-native';
|
|
3
|
+
export declare function getPickerActionBarBottomInset(bottomInset: number): number;
|
|
4
|
+
export type PickerActionBarProps = {
|
|
5
|
+
cancelText: React.ReactNode;
|
|
6
|
+
confirmText: React.ReactNode;
|
|
7
|
+
onCancel: () => void;
|
|
8
|
+
onConfirm: () => void;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
confirmDisabled?: boolean;
|
|
11
|
+
style?: StyleProp<ViewStyle>;
|
|
12
|
+
};
|
|
13
|
+
export declare function PickerActionBar({ cancelText, confirmText, onCancel, onConfirm, disabled, confirmDisabled, style, }: PickerActionBarProps): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
//# sourceMappingURL=actionBar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actionBar.d.ts","sourceRoot":"","sources":["../../../src/ui/Picker/actionBar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAoB,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAIhF,wBAAgB,6BAA6B,CAAC,WAAW,EAAE,MAAM,UAEhE;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC;IAC5B,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CAC9B,CAAC;AAEF,wBAAgB,eAAe,CAAC,EAC9B,UAAU,EACV,WAAW,EACX,QAAQ,EACR,SAAS,EACT,QAAgB,EAChB,eAAuB,EACvB,KAAK,GACN,EAAE,oBAAoB,2CA0BtB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPickerActionBarBottomInset = getPickerActionBarBottomInset;
|
|
4
|
+
exports.PickerActionBar = PickerActionBar;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_native_1 = require("react-native");
|
|
7
|
+
const zkit_tools_1 = require("zkit-tools");
|
|
8
|
+
const Button_1 = require("../Button");
|
|
9
|
+
function getPickerActionBarBottomInset(bottomInset) {
|
|
10
|
+
return Math.max(bottomInset, (0, zkit_tools_1.wp)(12));
|
|
11
|
+
}
|
|
12
|
+
function PickerActionBar({ cancelText, confirmText, onCancel, onConfirm, disabled = false, confirmDisabled = false, style, }) {
|
|
13
|
+
return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [styles.root, style], children: [(0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.buttonWrapper, children: (0, jsx_runtime_1.jsx)(Button_1.Button, { variant: "soft", onPress: onCancel, disabled: disabled, block: true, layout: ACTION_BUTTON_LAYOUT, children: cancelText }) }), (0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.buttonWrapper, children: (0, jsx_runtime_1.jsx)(Button_1.Button, { onPress: onConfirm, disabled: disabled || confirmDisabled, block: true, layout: ACTION_BUTTON_LAYOUT, children: confirmText }) })] }));
|
|
14
|
+
}
|
|
15
|
+
const ACTION_BUTTON_LAYOUT = {
|
|
16
|
+
minHeight: (0, zkit_tools_1.wp)(44),
|
|
17
|
+
radius: (0, zkit_tools_1.wp)(14),
|
|
18
|
+
textSize: (0, zkit_tools_1.sp)(16),
|
|
19
|
+
};
|
|
20
|
+
const styles = react_native_1.StyleSheet.create({
|
|
21
|
+
root: {
|
|
22
|
+
flexDirection: 'row',
|
|
23
|
+
gap: (0, zkit_tools_1.wp)(14),
|
|
24
|
+
},
|
|
25
|
+
buttonWrapper: {
|
|
26
|
+
flex: 1,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { PickerHandle, PickerProps } from './types';
|
|
3
|
+
export type { PickerChangePayload, PickerColumnHeaderContext, PickerConfirmPayload, PickerDraftChangePayload, PickerHandle, PickerOption, PickerPrimitiveValue, PickerProps, PickerSelection, PickerTriggerContext, PickerValue, PickerValueMode, } from './types';
|
|
4
|
+
export declare const Picker: <TOption = import("./types").PickerOption>(props: PickerProps<TOption> & React.RefAttributes<PickerHandle>) => React.ReactElement | null;
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/Picker/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AA0C/B,OAAO,KAAK,EAGV,YAAY,EAGZ,WAAW,EAKZ,MAAM,SAAS,CAAC;AAEjB,YAAY,EACV,mBAAmB,EACnB,yBAAyB,EACzB,oBAAoB,EACpB,wBAAwB,EACxB,YAAY,EACZ,YAAY,EACZ,oBAAoB,EACpB,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,WAAW,EACX,eAAe,GAChB,MAAM,SAAS,CAAC;AAmJjB,eAAO,MAAM,MAAM,EAmZb,CAAC,OAAO,GAAG,OAAO,SAAS,EAAE,YAAY,EAC7C,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,YAAY,CAAC,KAC5D,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC"}
|
|
@@ -0,0 +1,412 @@
|
|
|
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.Picker = 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 expo_linear_gradient_1 = require("expo-linear-gradient");
|
|
41
|
+
const react_native_safe_area_context_1 = require("react-native-safe-area-context");
|
|
42
|
+
const zkit_tools_1 = require("zkit-tools");
|
|
43
|
+
const useI18n_1 = require("../../i18n/useI18n");
|
|
44
|
+
const useTheme_1 = require("../../theme/useTheme");
|
|
45
|
+
const Sheet_1 = require("../Sheet");
|
|
46
|
+
const Text_1 = require("../Text");
|
|
47
|
+
const WheelColumn_1 = require("../WheelColumn");
|
|
48
|
+
const utils_1 = require("./utils");
|
|
49
|
+
const actionBar_1 = require("./actionBar");
|
|
50
|
+
const ITEM_HEIGHT = WheelColumn_1.WHEEL_ITEM_HEIGHT;
|
|
51
|
+
const VISIBLE_ITEMS = WheelColumn_1.WHEEL_VISIBLE_ITEMS;
|
|
52
|
+
const DEFAULT_MAX_COLUMNS = 5;
|
|
53
|
+
const MAX_COLUMNS_LIMIT = 8;
|
|
54
|
+
function toWheelOptions(options, parentPath, accessors) {
|
|
55
|
+
return options.map((option, index) => {
|
|
56
|
+
const path = [...parentPath, option];
|
|
57
|
+
const value = (0, utils_1.resolveOptionValue)(option, index, path, accessors);
|
|
58
|
+
const label = (0, utils_1.resolveOptionLabel)(option, index, path, accessors);
|
|
59
|
+
const record = option != null && typeof option === 'object' ? option : {};
|
|
60
|
+
return {
|
|
61
|
+
value,
|
|
62
|
+
label,
|
|
63
|
+
disabled: (0, utils_1.resolveOptionDisabled)(option, index, path, accessors),
|
|
64
|
+
key: typeof record.key === 'string' || typeof record.key === 'number' ? record.key : value,
|
|
65
|
+
testID: typeof record.testID === 'string' ? record.testID : undefined,
|
|
66
|
+
accessibilityLabel: typeof record.accessibilityLabel === 'string' ? record.accessibilityLabel : undefined,
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const WheelColumnSlot = React.memo(function WheelColumnSlot({ options, columnIndex, parentPath, accessors, selectedIndex, onIndexChange, width, disabled, wheelsRef, }) {
|
|
71
|
+
var _a, _b;
|
|
72
|
+
const wheelOptions = React.useMemo(() => toWheelOptions(options, parentPath, accessors), [accessors, options, parentPath]);
|
|
73
|
+
const selectedValue = (_b = (_a = wheelOptions[Math.max(0, selectedIndex)]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null;
|
|
74
|
+
const handleChange = React.useCallback((payload) => onIndexChange(columnIndex, payload.index), [columnIndex, onIndexChange]);
|
|
75
|
+
return ((0, jsx_runtime_1.jsx)(WheelColumn_1.WheelColumn, { ref: (element) => {
|
|
76
|
+
wheelsRef.current[columnIndex] = element;
|
|
77
|
+
}, options: wheelOptions, value: selectedValue, onChange: handleChange, width: width, disabled: disabled }));
|
|
78
|
+
});
|
|
79
|
+
function createEmptyCascadeState() {
|
|
80
|
+
return {
|
|
81
|
+
columns: [],
|
|
82
|
+
indices: [],
|
|
83
|
+
values: [],
|
|
84
|
+
labels: [],
|
|
85
|
+
items: [],
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function getPreferPathValue(value, valueMode, resolvedColumns) {
|
|
89
|
+
if (valueMode === 'path')
|
|
90
|
+
return true;
|
|
91
|
+
if (valueMode === 'single')
|
|
92
|
+
return false;
|
|
93
|
+
if (Array.isArray(value))
|
|
94
|
+
return true;
|
|
95
|
+
if (value !== undefined)
|
|
96
|
+
return false;
|
|
97
|
+
return resolvedColumns > 1;
|
|
98
|
+
}
|
|
99
|
+
function composeTrigger(children, context) {
|
|
100
|
+
if (typeof children === 'function') {
|
|
101
|
+
return composeTrigger(children(context), context);
|
|
102
|
+
}
|
|
103
|
+
if (React.isValidElement(children)) {
|
|
104
|
+
const child = children;
|
|
105
|
+
const previousOnPress = child.props.onPress;
|
|
106
|
+
const previousAccessibilityState = child.props.accessibilityState;
|
|
107
|
+
return React.cloneElement(child, {
|
|
108
|
+
onPress: (...args) => {
|
|
109
|
+
previousOnPress === null || previousOnPress === void 0 ? void 0 : previousOnPress(...args);
|
|
110
|
+
context.open();
|
|
111
|
+
},
|
|
112
|
+
disabled: context.disabled || child.props.disabled,
|
|
113
|
+
accessibilityState: {
|
|
114
|
+
...previousAccessibilityState,
|
|
115
|
+
disabled: context.disabled || (previousAccessibilityState === null || previousAccessibilityState === void 0 ? void 0 : previousAccessibilityState.disabled),
|
|
116
|
+
expanded: context.isOpen,
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
if (children == null)
|
|
121
|
+
return null;
|
|
122
|
+
return ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { accessibilityRole: "button", accessibilityState: { disabled: context.disabled, expanded: context.isOpen }, disabled: context.disabled, onPress: context.open, children: children }));
|
|
123
|
+
}
|
|
124
|
+
function normalizeMaxColumns(maxColumns) {
|
|
125
|
+
if (maxColumns == null)
|
|
126
|
+
return DEFAULT_MAX_COLUMNS;
|
|
127
|
+
if (!Number.isFinite(maxColumns))
|
|
128
|
+
return DEFAULT_MAX_COLUMNS;
|
|
129
|
+
return (0, utils_1.clampNumber)(Math.round(maxColumns), 1, MAX_COLUMNS_LIMIT);
|
|
130
|
+
}
|
|
131
|
+
exports.Picker = React.forwardRef(function Picker({ options, value: valueProp, defaultValue, onChange, valueMode = 'auto', open: openProp, defaultOpen, onOpenChange, onDismissComplete, title, placeholder = '', cancelText, confirmText, emptyText, separator = '-', formatLabel, renderColumnHeader, maxColumns, getOptionValue, getOptionLabel, getOptionChildren, isOptionDisabled, lazyContent = true, sheetHeight = 'auto', disabled = false, onCancel, onConfirm, onDraftChange, children, }, ref) {
|
|
132
|
+
const { t } = (0, useI18n_1.useI18n)();
|
|
133
|
+
const theme = (0, useTheme_1.useTheme)();
|
|
134
|
+
const { height: screenH, width: screenW } = (0, react_native_1.useWindowDimensions)();
|
|
135
|
+
const insets = (0, react_native_safe_area_context_1.useSafeAreaInsets)();
|
|
136
|
+
const safeBottom = (0, actionBar_1.getPickerActionBarBottomInset)(insets.bottom);
|
|
137
|
+
const effectiveMaxColumns = React.useMemo(() => normalizeMaxColumns(maxColumns), [maxColumns]);
|
|
138
|
+
const accessors = React.useMemo(() => ({ getOptionValue, getOptionLabel, getOptionChildren, isOptionDisabled }), [getOptionChildren, getOptionLabel, getOptionValue, isOptionDisabled]);
|
|
139
|
+
const isValueControlled = valueProp !== undefined;
|
|
140
|
+
const [innerValue, setInnerValue] = React.useState(defaultValue);
|
|
141
|
+
const value = isValueControlled ? valueProp : innerValue;
|
|
142
|
+
const isOpenControlled = openProp !== undefined;
|
|
143
|
+
const [innerOpen, setInnerOpen] = React.useState(!!defaultOpen);
|
|
144
|
+
const visible = isOpenControlled ? !!openProp : innerOpen;
|
|
145
|
+
const wheelsRef = React.useRef([]);
|
|
146
|
+
const confirmingRef = React.useRef(false);
|
|
147
|
+
const resolveFromValue = React.useCallback((nextValue) => (0, utils_1.resolveCascade)(options, (0, utils_1.toArrayValue)(nextValue), accessors, effectiveMaxColumns), [accessors, effectiveMaxColumns, options]);
|
|
148
|
+
const createSelection = React.useCallback((state, nextValue = value) => (0, utils_1.createPickerSelection)(state, {
|
|
149
|
+
separator,
|
|
150
|
+
valueMode,
|
|
151
|
+
preferPathValue: getPreferPathValue(nextValue, valueMode, state.columns.length),
|
|
152
|
+
formatLabel,
|
|
153
|
+
}), [formatLabel, separator, value, valueMode]);
|
|
154
|
+
const initialDraft = React.useMemo(() => resolveFromValue(value), [resolveFromValue, value]);
|
|
155
|
+
const [{ columns: draftColumns, indices: draftIndices, values: draftValues, labels: draftLabels, items: draftItems }, setDraft] = React.useState(initialDraft);
|
|
156
|
+
React.useEffect(() => {
|
|
157
|
+
setDraft(resolveFromValue(value));
|
|
158
|
+
}, [resolveFromValue, value]);
|
|
159
|
+
React.useEffect(() => {
|
|
160
|
+
if (!visible)
|
|
161
|
+
return;
|
|
162
|
+
setDraft(resolveFromValue(value));
|
|
163
|
+
}, [resolveFromValue, value, visible]);
|
|
164
|
+
const committedSelection = React.useMemo(() => {
|
|
165
|
+
const state = value === undefined ? createEmptyCascadeState() : resolveFromValue(value);
|
|
166
|
+
return createSelection(state, value);
|
|
167
|
+
}, [createSelection, resolveFromValue, value]);
|
|
168
|
+
const draftState = React.useMemo(() => ({
|
|
169
|
+
columns: draftColumns,
|
|
170
|
+
indices: draftIndices,
|
|
171
|
+
values: draftValues,
|
|
172
|
+
labels: draftLabels,
|
|
173
|
+
items: draftItems,
|
|
174
|
+
}), [draftColumns, draftIndices, draftItems, draftLabels, draftValues]);
|
|
175
|
+
const draftSelection = React.useMemo(() => createSelection(draftState), [createSelection, draftState]);
|
|
176
|
+
const detents = React.useMemo(() => {
|
|
177
|
+
if (sheetHeight === 'auto' || sheetHeight == null)
|
|
178
|
+
return ['auto'];
|
|
179
|
+
if (!Number.isFinite(sheetHeight) || sheetHeight <= 0)
|
|
180
|
+
return ['auto'];
|
|
181
|
+
return [(0, utils_1.clampNumber)(sheetHeight / screenH, 0.1, 0.92)];
|
|
182
|
+
}, [screenH, sheetHeight]);
|
|
183
|
+
const setPickerOpen = React.useCallback((nextOpen) => {
|
|
184
|
+
onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(nextOpen);
|
|
185
|
+
if (!isOpenControlled)
|
|
186
|
+
setInnerOpen(nextOpen);
|
|
187
|
+
}, [isOpenControlled, onOpenChange]);
|
|
188
|
+
const close = React.useCallback(() => {
|
|
189
|
+
setPickerOpen(false);
|
|
190
|
+
}, [setPickerOpen]);
|
|
191
|
+
const openPicker = React.useCallback(() => {
|
|
192
|
+
if (disabled)
|
|
193
|
+
return;
|
|
194
|
+
setDraft(resolveFromValue(value));
|
|
195
|
+
if (!visible) {
|
|
196
|
+
setPickerOpen(true);
|
|
197
|
+
}
|
|
198
|
+
}, [disabled, resolveFromValue, setPickerOpen, value, visible]);
|
|
199
|
+
React.useImperativeHandle(ref, () => ({
|
|
200
|
+
open: openPicker,
|
|
201
|
+
close,
|
|
202
|
+
}), [close, openPicker]);
|
|
203
|
+
const columnsCount = React.useMemo(() => Math.max(1, Math.min(effectiveMaxColumns, draftColumns.length || 1)), [draftColumns.length, effectiveMaxColumns]);
|
|
204
|
+
const columnWidth = React.useMemo(() => (screenW - (0, zkit_tools_1.wp)(32)) / columnsCount, [columnsCount, screenW]);
|
|
205
|
+
const confirmDisabled = disabled || !draftSelection.isComplete;
|
|
206
|
+
const transparentSurface = React.useMemo(() => (0, utils_1.transparentizeColor)(theme.colors.surface), [theme.colors.surface]);
|
|
207
|
+
React.useEffect(() => {
|
|
208
|
+
wheelsRef.current.length = columnsCount;
|
|
209
|
+
}, [columnsCount]);
|
|
210
|
+
const emitDraftChange = React.useCallback((nextState) => {
|
|
211
|
+
const selection = createSelection(nextState);
|
|
212
|
+
onDraftChange === null || onDraftChange === void 0 ? void 0 : onDraftChange(selection);
|
|
213
|
+
}, [createSelection, onDraftChange]);
|
|
214
|
+
const syncDraftFromWheels = React.useCallback(async () => {
|
|
215
|
+
var _a, _b;
|
|
216
|
+
const settledIndices = await Promise.all(Array.from({ length: effectiveMaxColumns }, async (_, columnIndex) => {
|
|
217
|
+
const wheel = wheelsRef.current[columnIndex];
|
|
218
|
+
if (react_native_1.Platform.OS === 'ios') {
|
|
219
|
+
return wheel === null || wheel === void 0 ? void 0 : wheel.syncCurrentSelection();
|
|
220
|
+
}
|
|
221
|
+
return wheel === null || wheel === void 0 ? void 0 : wheel.settleToNearest(false);
|
|
222
|
+
}));
|
|
223
|
+
const desiredValues = [];
|
|
224
|
+
let currentOptions = Array.isArray(options) ? options : [];
|
|
225
|
+
let path = [];
|
|
226
|
+
for (let columnIndex = 0; columnIndex < effectiveMaxColumns; columnIndex += 1) {
|
|
227
|
+
if (!currentOptions.length)
|
|
228
|
+
break;
|
|
229
|
+
const safeIndex = (0, utils_1.findNearestEnabledIndex)(currentOptions, (_b = (_a = settledIndices[columnIndex]) !== null && _a !== void 0 ? _a : draftIndices[columnIndex]) !== null && _b !== void 0 ? _b : 0, path, accessors);
|
|
230
|
+
if (safeIndex < 0)
|
|
231
|
+
break;
|
|
232
|
+
const item = currentOptions[safeIndex];
|
|
233
|
+
if (item == null)
|
|
234
|
+
break;
|
|
235
|
+
const nextPath = [...path, item];
|
|
236
|
+
desiredValues[columnIndex] = (0, utils_1.resolveOptionValue)(item, safeIndex, nextPath, accessors);
|
|
237
|
+
currentOptions = (0, utils_1.resolveOptionChildren)(item, safeIndex, nextPath, accessors);
|
|
238
|
+
path = nextPath;
|
|
239
|
+
}
|
|
240
|
+
const nextState = (0, utils_1.resolveCascade)(options, desiredValues, accessors, effectiveMaxColumns);
|
|
241
|
+
setDraft(nextState);
|
|
242
|
+
requestAnimationFrame(() => {
|
|
243
|
+
var _a, _b;
|
|
244
|
+
for (let i = 0; i < nextState.indices.length; i += 1) {
|
|
245
|
+
(_a = wheelsRef.current[i]) === null || _a === void 0 ? void 0 : _a.scrollToIndex((_b = nextState.indices[i]) !== null && _b !== void 0 ? _b : 0, false);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
return nextState;
|
|
249
|
+
}, [accessors, draftIndices, effectiveMaxColumns, options]);
|
|
250
|
+
const handleWheelIndexChange = React.useCallback((columnIndex, nextIndex) => {
|
|
251
|
+
var _a, _b;
|
|
252
|
+
const columnOptions = (_a = draftColumns[columnIndex]) !== null && _a !== void 0 ? _a : [];
|
|
253
|
+
if (!columnOptions.length)
|
|
254
|
+
return;
|
|
255
|
+
const parentPath = draftItems.slice(0, columnIndex);
|
|
256
|
+
const safeIndex = (0, utils_1.findNearestEnabledIndex)(columnOptions, nextIndex, parentPath, accessors);
|
|
257
|
+
if (safeIndex < 0)
|
|
258
|
+
return;
|
|
259
|
+
if (safeIndex !== nextIndex) {
|
|
260
|
+
(_b = wheelsRef.current[columnIndex]) === null || _b === void 0 ? void 0 : _b.scrollToIndex(safeIndex, true);
|
|
261
|
+
}
|
|
262
|
+
const item = columnOptions[safeIndex];
|
|
263
|
+
if (item == null)
|
|
264
|
+
return;
|
|
265
|
+
const nextPath = [...parentPath, item];
|
|
266
|
+
const nextDesired = [...draftValues];
|
|
267
|
+
nextDesired[columnIndex] = (0, utils_1.resolveOptionValue)(item, safeIndex, nextPath, accessors);
|
|
268
|
+
nextDesired.length = columnIndex + 1;
|
|
269
|
+
const nextState = (0, utils_1.resolveCascade)(options, nextDesired, accessors, effectiveMaxColumns);
|
|
270
|
+
setDraft(nextState);
|
|
271
|
+
requestAnimationFrame(() => {
|
|
272
|
+
var _a, _b;
|
|
273
|
+
for (let i = columnIndex + 1; i < nextState.indices.length; i += 1) {
|
|
274
|
+
(_a = wheelsRef.current[i]) === null || _a === void 0 ? void 0 : _a.scrollToIndex((_b = nextState.indices[i]) !== null && _b !== void 0 ? _b : 0, false);
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
emitDraftChange(nextState);
|
|
278
|
+
}, [accessors, draftColumns, draftItems, draftValues, effectiveMaxColumns, emitDraftChange, options]);
|
|
279
|
+
const handleCancel = React.useCallback(() => {
|
|
280
|
+
onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
281
|
+
close();
|
|
282
|
+
}, [close, onCancel]);
|
|
283
|
+
const handleConfirm = React.useCallback(async () => {
|
|
284
|
+
if (confirmDisabled || confirmingRef.current)
|
|
285
|
+
return;
|
|
286
|
+
confirmingRef.current = true;
|
|
287
|
+
try {
|
|
288
|
+
const syncedState = await syncDraftFromWheels();
|
|
289
|
+
const selection = createSelection(syncedState);
|
|
290
|
+
if (!selection.isComplete)
|
|
291
|
+
return;
|
|
292
|
+
if (!isValueControlled) {
|
|
293
|
+
setInnerValue(selection.value);
|
|
294
|
+
}
|
|
295
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(selection.value, selection);
|
|
296
|
+
onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm(selection);
|
|
297
|
+
close();
|
|
298
|
+
}
|
|
299
|
+
finally {
|
|
300
|
+
confirmingRef.current = false;
|
|
301
|
+
}
|
|
302
|
+
}, [close, confirmDisabled, createSelection, isValueControlled, onChange, onConfirm, syncDraftFromWheels]);
|
|
303
|
+
const handleSheetOpenChange = React.useCallback((nextOpen, meta) => {
|
|
304
|
+
if (!nextOpen && visible && meta.reason !== 'api') {
|
|
305
|
+
onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
306
|
+
}
|
|
307
|
+
setPickerOpen(nextOpen);
|
|
308
|
+
}, [onCancel, setPickerOpen, visible]);
|
|
309
|
+
const triggerContext = React.useMemo(() => ({
|
|
310
|
+
...committedSelection,
|
|
311
|
+
label: committedSelection.label,
|
|
312
|
+
open: openPicker,
|
|
313
|
+
close,
|
|
314
|
+
isOpen: visible,
|
|
315
|
+
disabled,
|
|
316
|
+
placeholder,
|
|
317
|
+
}), [close, committedSelection, disabled, openPicker, placeholder, visible]);
|
|
318
|
+
const triggerNode = React.useMemo(() => composeTrigger(children, triggerContext), [children, triggerContext]);
|
|
319
|
+
const sheetNode = ((0, jsx_runtime_1.jsx)(Sheet_1.Sheet, { placement: "bottom", open: visible, onOpenChange: handleSheetOpenChange, onCloseComplete: onDismissComplete, detents: detents, backgroundColor: theme.colors.surface, handle: false, draggable: false, dismissible: !disabled, nativeProps: { insetAdjustment: 'never' }, children: (0, jsx_runtime_1.jsxs)(react_native_1.View, { accessibilityViewIsModal: true, style: [
|
|
320
|
+
styles.sheetInner,
|
|
321
|
+
{
|
|
322
|
+
backgroundColor: theme.colors.surface,
|
|
323
|
+
paddingBottom: safeBottom,
|
|
324
|
+
},
|
|
325
|
+
], pointerEvents: disabled ? 'none' : 'auto', children: [(0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.header, children: (0, jsx_runtime_1.jsx)(Text_1.Text, { style: [styles.headerTitle, { color: theme.colors.onSurface }], numberOfLines: 1, children: title !== null && title !== void 0 ? title : t('picker.title') }) }), draftColumns.length > 0 ? ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.pickerArea, children: [renderColumnHeader && ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.columnLabelsRow, children: draftColumns.slice(0, columnsCount).map((columnOptions, columnIndex) => {
|
|
326
|
+
const headerContext = {
|
|
327
|
+
columnIndex,
|
|
328
|
+
columnCount: columnsCount,
|
|
329
|
+
options: columnOptions,
|
|
330
|
+
selectedItem: draftItems[columnIndex],
|
|
331
|
+
selectedValue: draftValues[columnIndex],
|
|
332
|
+
selectedLabel: draftLabels[columnIndex],
|
|
333
|
+
};
|
|
334
|
+
return ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: [styles.columnLabelItem, { width: columnWidth }], children: renderColumnHeader(headerContext) }, `header-${columnIndex}`));
|
|
335
|
+
}) })), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.pickerWrapper, children: [react_native_1.Platform.OS !== 'ios' && ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.highlightBar, pointerEvents: "none" })), (0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.columnsRow, children: draftColumns.slice(0, columnsCount).map((columnOptions, columnIndex) => {
|
|
336
|
+
var _a;
|
|
337
|
+
return ((0, jsx_runtime_1.jsx)(WheelColumnSlot, { options: columnOptions, columnIndex: columnIndex, parentPath: draftItems.slice(0, columnIndex), accessors: accessors, selectedIndex: Math.max(0, (_a = draftIndices[columnIndex]) !== null && _a !== void 0 ? _a : 0), onIndexChange: handleWheelIndexChange, width: columnWidth, disabled: disabled, wheelsRef: wheelsRef }, `column-${columnIndex}-${columnsCount}`));
|
|
338
|
+
}) }), react_native_1.Platform.OS !== 'ios' && ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.topMask, pointerEvents: "none", children: (0, jsx_runtime_1.jsx)(expo_linear_gradient_1.LinearGradient, { colors: [theme.colors.surface, transparentSurface], style: react_native_1.StyleSheet.absoluteFill }) })), react_native_1.Platform.OS !== 'ios' && ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.bottomMask, pointerEvents: "none", children: (0, jsx_runtime_1.jsx)(expo_linear_gradient_1.LinearGradient, { colors: [transparentSurface, theme.colors.surface], style: react_native_1.StyleSheet.absoluteFill }) }))] })] })) : ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.emptyState, children: (0, jsx_runtime_1.jsx)(Text_1.Text, { tone: "muted", align: "center", children: emptyText !== null && emptyText !== void 0 ? emptyText : t('picker.empty') }) })), (0, jsx_runtime_1.jsx)(actionBar_1.PickerActionBar, { cancelText: cancelText !== null && cancelText !== void 0 ? cancelText : t('picker.cancel'), confirmText: confirmText !== null && confirmText !== void 0 ? confirmText : t('picker.confirm'), onCancel: handleCancel, onConfirm: handleConfirm, disabled: disabled, confirmDisabled: confirmDisabled })] }) }));
|
|
339
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [triggerNode, sheetNode] }));
|
|
340
|
+
});
|
|
341
|
+
const styles = react_native_1.StyleSheet.create({
|
|
342
|
+
sheetInner: {
|
|
343
|
+
width: '100%',
|
|
344
|
+
paddingHorizontal: (0, zkit_tools_1.wp)(16),
|
|
345
|
+
paddingTop: (0, zkit_tools_1.wp)(12),
|
|
346
|
+
},
|
|
347
|
+
header: {
|
|
348
|
+
minHeight: (0, zkit_tools_1.wp)(32),
|
|
349
|
+
alignItems: 'center',
|
|
350
|
+
justifyContent: 'center',
|
|
351
|
+
paddingHorizontal: (0, zkit_tools_1.wp)(12),
|
|
352
|
+
},
|
|
353
|
+
headerTitle: {
|
|
354
|
+
fontSize: (0, zkit_tools_1.sp)(16),
|
|
355
|
+
fontWeight: '600',
|
|
356
|
+
},
|
|
357
|
+
pickerArea: {
|
|
358
|
+
marginTop: (0, zkit_tools_1.wp)(4),
|
|
359
|
+
paddingVertical: WheelColumn_1.WHEEL_AREA_VERTICAL_INSET,
|
|
360
|
+
},
|
|
361
|
+
emptyState: {
|
|
362
|
+
minHeight: WheelColumn_1.WHEEL_AREA_HEIGHT + (0, zkit_tools_1.wp)(18),
|
|
363
|
+
alignItems: 'center',
|
|
364
|
+
justifyContent: 'center',
|
|
365
|
+
paddingHorizontal: (0, zkit_tools_1.wp)(24),
|
|
366
|
+
},
|
|
367
|
+
columnLabelsRow: {
|
|
368
|
+
flexDirection: 'row',
|
|
369
|
+
justifyContent: 'space-between',
|
|
370
|
+
marginBottom: (0, zkit_tools_1.wp)(6),
|
|
371
|
+
},
|
|
372
|
+
columnLabelItem: {
|
|
373
|
+
alignItems: 'center',
|
|
374
|
+
},
|
|
375
|
+
pickerWrapper: {
|
|
376
|
+
height: ITEM_HEIGHT * VISIBLE_ITEMS,
|
|
377
|
+
position: 'relative',
|
|
378
|
+
width: '100%',
|
|
379
|
+
overflow: 'visible',
|
|
380
|
+
},
|
|
381
|
+
highlightBar: {
|
|
382
|
+
position: 'absolute',
|
|
383
|
+
top: ITEM_HEIGHT * ((VISIBLE_ITEMS - 1) / 2),
|
|
384
|
+
left: -(0, zkit_tools_1.wp)(16),
|
|
385
|
+
right: -(0, zkit_tools_1.wp)(16),
|
|
386
|
+
height: ITEM_HEIGHT,
|
|
387
|
+
backgroundColor: WheelColumn_1.WHEEL_SELECTION_BACKGROUND_COLOR,
|
|
388
|
+
zIndex: 0,
|
|
389
|
+
},
|
|
390
|
+
topMask: {
|
|
391
|
+
position: 'absolute',
|
|
392
|
+
top: 0,
|
|
393
|
+
left: 0,
|
|
394
|
+
right: 0,
|
|
395
|
+
height: ITEM_HEIGHT * ((VISIBLE_ITEMS - 1) / 2),
|
|
396
|
+
zIndex: 2,
|
|
397
|
+
},
|
|
398
|
+
bottomMask: {
|
|
399
|
+
position: 'absolute',
|
|
400
|
+
bottom: 0,
|
|
401
|
+
left: 0,
|
|
402
|
+
right: 0,
|
|
403
|
+
height: ITEM_HEIGHT * ((VISIBLE_ITEMS - 1) / 2),
|
|
404
|
+
zIndex: 2,
|
|
405
|
+
},
|
|
406
|
+
columnsRow: {
|
|
407
|
+
flexDirection: 'row',
|
|
408
|
+
alignItems: 'stretch',
|
|
409
|
+
justifyContent: 'space-between',
|
|
410
|
+
zIndex: 1,
|
|
411
|
+
},
|
|
412
|
+
});
|