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.
Files changed (267) hide show
  1. package/README.md +267 -0
  2. package/dist/ComponentLibProvider.d.ts +15 -0
  3. package/dist/ComponentLibProvider.d.ts.map +1 -0
  4. package/dist/ComponentLibProvider.js +18 -0
  5. package/dist/assets/animations/spinner.json +1 -0
  6. package/dist/assets/icons/check.svg +4 -0
  7. package/dist/assets/icons/toast/error.webp +0 -0
  8. package/dist/assets/icons/toast/success.webp +0 -0
  9. package/dist/assets/icons/toast/warning.webp +0 -0
  10. package/dist/config.d.ts +16 -0
  11. package/dist/config.d.ts.map +1 -0
  12. package/dist/config.js +42 -0
  13. package/dist/i18n/I18nProvider.d.ts +11 -0
  14. package/dist/i18n/I18nProvider.d.ts.map +1 -0
  15. package/dist/i18n/I18nProvider.js +84 -0
  16. package/dist/i18n/locale.d.ts +7 -0
  17. package/dist/i18n/locale.d.ts.map +1 -0
  18. package/dist/i18n/locale.js +87 -0
  19. package/dist/i18n/locales/de.d.ts +51 -0
  20. package/dist/i18n/locales/de.d.ts.map +1 -0
  21. package/dist/i18n/locales/de.js +62 -0
  22. package/dist/i18n/locales/en-US.d.ts +51 -0
  23. package/dist/i18n/locales/en-US.d.ts.map +1 -0
  24. package/dist/i18n/locales/en-US.js +62 -0
  25. package/dist/i18n/locales/index.d.ts +9 -0
  26. package/dist/i18n/locales/index.d.ts.map +1 -0
  27. package/dist/i18n/locales/index.js +23 -0
  28. package/dist/i18n/locales/ja.d.ts +51 -0
  29. package/dist/i18n/locales/ja.d.ts.map +1 -0
  30. package/dist/i18n/locales/ja.js +62 -0
  31. package/dist/i18n/locales/zh-CN.d.ts +51 -0
  32. package/dist/i18n/locales/zh-CN.d.ts.map +1 -0
  33. package/dist/i18n/locales/zh-CN.js +62 -0
  34. package/dist/i18n/locales/zh-TW.d.ts +51 -0
  35. package/dist/i18n/locales/zh-TW.d.ts.map +1 -0
  36. package/dist/i18n/locales/zh-TW.js +62 -0
  37. package/dist/i18n/types.d.ts +11 -0
  38. package/dist/i18n/types.d.ts.map +1 -0
  39. package/dist/i18n/types.js +2 -0
  40. package/dist/i18n/useI18n.d.ts +2 -0
  41. package/dist/i18n/useI18n.d.ts.map +1 -0
  42. package/dist/i18n/useI18n.js +41 -0
  43. package/dist/index.d.ts +57 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +90 -0
  46. package/dist/services/ActionDialogService/ActionDialog.d.ts +4 -0
  47. package/dist/services/ActionDialogService/ActionDialog.d.ts.map +1 -0
  48. package/dist/services/ActionDialogService/ActionDialog.js +531 -0
  49. package/dist/services/ActionDialogService/index.d.ts +4 -0
  50. package/dist/services/ActionDialogService/index.d.ts.map +1 -0
  51. package/dist/services/ActionDialogService/index.js +8 -0
  52. package/dist/services/ActionDialogService/service.d.ts +7 -0
  53. package/dist/services/ActionDialogService/service.d.ts.map +1 -0
  54. package/dist/services/ActionDialogService/service.js +309 -0
  55. package/dist/services/ActionDialogService/shared.d.ts +17 -0
  56. package/dist/services/ActionDialogService/shared.d.ts.map +1 -0
  57. package/dist/services/ActionDialogService/shared.js +167 -0
  58. package/dist/services/ActionDialogService/types.d.ts +160 -0
  59. package/dist/services/ActionDialogService/types.d.ts.map +1 -0
  60. package/dist/services/ActionDialogService/types.js +2 -0
  61. package/dist/services/CardToastService/index.d.ts +115 -0
  62. package/dist/services/CardToastService/index.d.ts.map +1 -0
  63. package/dist/services/CardToastService/index.js +899 -0
  64. package/dist/services/ImagePreviewService/index.d.ts +179 -0
  65. package/dist/services/ImagePreviewService/index.d.ts.map +1 -0
  66. package/dist/services/ImagePreviewService/index.js +1383 -0
  67. package/dist/services/LoadingService/index.d.ts +146 -0
  68. package/dist/services/LoadingService/index.d.ts.map +1 -0
  69. package/dist/services/LoadingService/index.js +827 -0
  70. package/dist/services/PermissionPurposeDialogService/index.d.ts +99 -0
  71. package/dist/services/PermissionPurposeDialogService/index.d.ts.map +1 -0
  72. package/dist/services/PermissionPurposeDialogService/index.js +360 -0
  73. package/dist/services/PickerService/index.d.ts +128 -0
  74. package/dist/services/PickerService/index.d.ts.map +1 -0
  75. package/dist/services/PickerService/index.js +250 -0
  76. package/dist/theme/ThemeProvider.d.ts +15 -0
  77. package/dist/theme/ThemeProvider.d.ts.map +1 -0
  78. package/dist/theme/ThemeProvider.js +61 -0
  79. package/dist/theme/defaultTheme.d.ts +3 -0
  80. package/dist/theme/defaultTheme.d.ts.map +1 -0
  81. package/dist/theme/defaultTheme.js +28 -0
  82. package/dist/theme/mergeTheme.d.ts +3 -0
  83. package/dist/theme/mergeTheme.d.ts.map +1 -0
  84. package/dist/theme/mergeTheme.js +19 -0
  85. package/dist/theme/types.d.ts +17 -0
  86. package/dist/theme/types.d.ts.map +1 -0
  87. package/dist/theme/types.js +2 -0
  88. package/dist/theme/useTheme.d.ts +2 -0
  89. package/dist/theme/useTheme.d.ts.map +1 -0
  90. package/dist/theme/useTheme.js +46 -0
  91. package/dist/ui/Accordion/index.d.ts +99 -0
  92. package/dist/ui/Accordion/index.d.ts.map +1 -0
  93. package/dist/ui/Accordion/index.js +777 -0
  94. package/dist/ui/AddressCascader/index.d.ts +58 -0
  95. package/dist/ui/AddressCascader/index.d.ts.map +1 -0
  96. package/dist/ui/AddressCascader/index.js +710 -0
  97. package/dist/ui/BetweenTime/index.d.ts +82 -0
  98. package/dist/ui/BetweenTime/index.d.ts.map +1 -0
  99. package/dist/ui/BetweenTime/index.js +702 -0
  100. package/dist/ui/Button/index.d.ts +93 -0
  101. package/dist/ui/Button/index.d.ts.map +1 -0
  102. package/dist/ui/Button/index.js +832 -0
  103. package/dist/ui/Checkbox/index.d.ts +103 -0
  104. package/dist/ui/Checkbox/index.d.ts.map +1 -0
  105. package/dist/ui/Checkbox/index.js +694 -0
  106. package/dist/ui/DatePicker/index.d.ts +5 -0
  107. package/dist/ui/DatePicker/index.d.ts.map +1 -0
  108. package/dist/ui/DatePicker/index.js +157 -0
  109. package/dist/ui/DatePicker/types.d.ts +99 -0
  110. package/dist/ui/DatePicker/types.d.ts.map +1 -0
  111. package/dist/ui/DatePicker/types.js +2 -0
  112. package/dist/ui/DatePicker/utils.d.ts +32 -0
  113. package/dist/ui/DatePicker/utils.d.ts.map +1 -0
  114. package/dist/ui/DatePicker/utils.js +316 -0
  115. package/dist/ui/LinkedScroll/index.d.ts +78 -0
  116. package/dist/ui/LinkedScroll/index.d.ts.map +1 -0
  117. package/dist/ui/LinkedScroll/index.js +470 -0
  118. package/dist/ui/LoadingSpinner/index.d.ts +8 -0
  119. package/dist/ui/LoadingSpinner/index.d.ts.map +1 -0
  120. package/dist/ui/LoadingSpinner/index.js +122 -0
  121. package/dist/ui/Picker/actionBar.d.ts +14 -0
  122. package/dist/ui/Picker/actionBar.d.ts.map +1 -0
  123. package/dist/ui/Picker/actionBar.js +28 -0
  124. package/dist/ui/Picker/index.d.ts +5 -0
  125. package/dist/ui/Picker/index.d.ts.map +1 -0
  126. package/dist/ui/Picker/index.js +412 -0
  127. package/dist/ui/Picker/types.d.ts +80 -0
  128. package/dist/ui/Picker/types.d.ts.map +1 -0
  129. package/dist/ui/Picker/types.js +2 -0
  130. package/dist/ui/Picker/utils.d.ts +27 -0
  131. package/dist/ui/Picker/utils.d.ts.map +1 -0
  132. package/dist/ui/Picker/utils.js +182 -0
  133. package/dist/ui/Radio/index.d.ts +95 -0
  134. package/dist/ui/Radio/index.d.ts.map +1 -0
  135. package/dist/ui/Radio/index.js +633 -0
  136. package/dist/ui/Sheet/index.d.ts +12 -0
  137. package/dist/ui/Sheet/index.d.ts.map +1 -0
  138. package/dist/ui/Sheet/index.js +832 -0
  139. package/dist/ui/Sheet/nativeBottom.d.ts +52 -0
  140. package/dist/ui/Sheet/nativeBottom.d.ts.map +1 -0
  141. package/dist/ui/Sheet/nativeBottom.js +442 -0
  142. package/dist/ui/Sheet/nativeBottom.web.d.ts +18 -0
  143. package/dist/ui/Sheet/nativeBottom.web.d.ts.map +1 -0
  144. package/dist/ui/Sheet/nativeBottom.web.js +46 -0
  145. package/dist/ui/Sheet/slots.d.ts +5 -0
  146. package/dist/ui/Sheet/slots.d.ts.map +1 -0
  147. package/dist/ui/Sheet/slots.js +40 -0
  148. package/dist/ui/Sheet/types.d.ts +131 -0
  149. package/dist/ui/Sheet/types.d.ts.map +1 -0
  150. package/dist/ui/Sheet/types.js +2 -0
  151. package/dist/ui/SliderCaptcha/index.d.ts +57 -0
  152. package/dist/ui/SliderCaptcha/index.d.ts.map +1 -0
  153. package/dist/ui/SliderCaptcha/index.js +586 -0
  154. package/dist/ui/Switch/index.d.ts +72 -0
  155. package/dist/ui/Switch/index.d.ts.map +1 -0
  156. package/dist/ui/Switch/index.js +671 -0
  157. package/dist/ui/Text/index.d.ts +41 -0
  158. package/dist/ui/Text/index.d.ts.map +1 -0
  159. package/dist/ui/Text/index.js +325 -0
  160. package/dist/ui/TextInput/TextInputPrimitive.d.ts +8 -0
  161. package/dist/ui/TextInput/TextInputPrimitive.d.ts.map +1 -0
  162. package/dist/ui/TextInput/TextInputPrimitive.js +54 -0
  163. package/dist/ui/TextInput/index.d.ts +89 -0
  164. package/dist/ui/TextInput/index.d.ts.map +1 -0
  165. package/dist/ui/TextInput/index.js +545 -0
  166. package/dist/ui/WheelColumn/ZKitWheelPickerNativeComponent.d.ts +39 -0
  167. package/dist/ui/WheelColumn/ZKitWheelPickerNativeComponent.d.ts.map +1 -0
  168. package/dist/ui/WheelColumn/ZKitWheelPickerNativeComponent.js +60 -0
  169. package/dist/ui/WheelColumn/constants.d.ts +2 -0
  170. package/dist/ui/WheelColumn/constants.d.ts.map +1 -0
  171. package/dist/ui/WheelColumn/constants.js +4 -0
  172. package/dist/ui/WheelColumn/index.d.ts +59 -0
  173. package/dist/ui/WheelColumn/index.d.ts.map +1 -0
  174. package/dist/ui/WheelColumn/index.js +547 -0
  175. package/ios/ZKitWheelPicker.h +18 -0
  176. package/ios/ZKitWheelPicker.mm +230 -0
  177. package/ios/ZKitWheelPickerLabel.h +10 -0
  178. package/ios/ZKitWheelPickerLabel.mm +31 -0
  179. package/ios/ZKitWheelPickerManager.h +5 -0
  180. package/ios/ZKitWheelPickerManager.mm +53 -0
  181. package/package.json +75 -0
  182. package/react-native.config.js +10 -0
  183. package/src/ComponentLibProvider.tsx +56 -0
  184. package/src/assets/animations/spinner.json +1 -0
  185. package/src/assets/icons/check.svg +4 -0
  186. package/src/assets/icons/toast/error.webp +0 -0
  187. package/src/assets/icons/toast/success.webp +0 -0
  188. package/src/assets/icons/toast/warning.webp +0 -0
  189. package/src/config.ts +65 -0
  190. package/src/i18n/I18nProvider.tsx +69 -0
  191. package/src/i18n/locale.ts +108 -0
  192. package/src/i18n/locales/de.ts +67 -0
  193. package/src/i18n/locales/en-US.ts +67 -0
  194. package/src/i18n/locales/index.ts +19 -0
  195. package/src/i18n/locales/ja.ts +67 -0
  196. package/src/i18n/locales/zh-CN.ts +67 -0
  197. package/src/i18n/locales/zh-TW.ts +67 -0
  198. package/src/i18n/types.ts +21 -0
  199. package/src/i18n/useI18n.ts +7 -0
  200. package/src/index.ts +395 -0
  201. package/src/services/ActionDialogService/ActionDialog.tsx +756 -0
  202. package/src/services/ActionDialogService/README.md +146 -0
  203. package/src/services/ActionDialogService/index.tsx +39 -0
  204. package/src/services/ActionDialogService/service.tsx +355 -0
  205. package/src/services/ActionDialogService/shared.ts +204 -0
  206. package/src/services/ActionDialogService/types.ts +197 -0
  207. package/src/services/CardToastService/README.md +128 -0
  208. package/src/services/CardToastService/index.tsx +1284 -0
  209. package/src/services/ImagePreviewService/README.md +67 -0
  210. package/src/services/ImagePreviewService/index.tsx +2148 -0
  211. package/src/services/LoadingService/README.md +128 -0
  212. package/src/services/LoadingService/index.tsx +1113 -0
  213. package/src/services/PermissionPurposeDialogService/README.md +80 -0
  214. package/src/services/PermissionPurposeDialogService/index.tsx +449 -0
  215. package/src/services/PickerService/README.md +154 -0
  216. package/src/services/PickerService/index.tsx +410 -0
  217. package/src/theme/ThemeProvider.tsx +40 -0
  218. package/src/theme/defaultTheme.ts +30 -0
  219. package/src/theme/mergeTheme.ts +16 -0
  220. package/src/theme/types.ts +36 -0
  221. package/src/theme/useTheme.ts +10 -0
  222. package/src/types/svg.d.ts +9 -0
  223. package/src/types/vant-area-data.d.ts +19 -0
  224. package/src/ui/Accordion/README.md +67 -0
  225. package/src/ui/Accordion/index.tsx +1221 -0
  226. package/src/ui/AddressCascader/README.md +144 -0
  227. package/src/ui/AddressCascader/index.tsx +1084 -0
  228. package/src/ui/BetweenTime/README.md +490 -0
  229. package/src/ui/BetweenTime/index.tsx +1001 -0
  230. package/src/ui/Button/README.md +186 -0
  231. package/src/ui/Button/index.tsx +1356 -0
  232. package/src/ui/Checkbox/README.md +211 -0
  233. package/src/ui/Checkbox/index.tsx +1231 -0
  234. package/src/ui/DatePicker/README.md +117 -0
  235. package/src/ui/DatePicker/index.tsx +295 -0
  236. package/src/ui/DatePicker/types.ts +115 -0
  237. package/src/ui/DatePicker/utils.ts +405 -0
  238. package/src/ui/LinkedScroll/README.md +55 -0
  239. package/src/ui/LinkedScroll/index.tsx +809 -0
  240. package/src/ui/LoadingSpinner/index.tsx +104 -0
  241. package/src/ui/Picker/README.md +190 -0
  242. package/src/ui/Picker/actionBar.tsx +70 -0
  243. package/src/ui/Picker/index.tsx +694 -0
  244. package/src/ui/Picker/types.ts +94 -0
  245. package/src/ui/Picker/utils.ts +239 -0
  246. package/src/ui/Radio/README.md +207 -0
  247. package/src/ui/Radio/index.tsx +1117 -0
  248. package/src/ui/Sheet/README.md +82 -0
  249. package/src/ui/Sheet/index.tsx +1163 -0
  250. package/src/ui/Sheet/nativeBottom.tsx +683 -0
  251. package/src/ui/Sheet/nativeBottom.web.tsx +40 -0
  252. package/src/ui/Sheet/slots.tsx +75 -0
  253. package/src/ui/Sheet/types.ts +195 -0
  254. package/src/ui/SliderCaptcha/README.md +61 -0
  255. package/src/ui/SliderCaptcha/index.tsx +816 -0
  256. package/src/ui/Switch/README.md +143 -0
  257. package/src/ui/Switch/index.tsx +1092 -0
  258. package/src/ui/Text/README.md +157 -0
  259. package/src/ui/Text/index.tsx +450 -0
  260. package/src/ui/TextInput/README.md +197 -0
  261. package/src/ui/TextInput/TextInputPrimitive.tsx +44 -0
  262. package/src/ui/TextInput/index.tsx +942 -0
  263. package/src/ui/WheelColumn/README.md +104 -0
  264. package/src/ui/WheelColumn/ZKitWheelPickerNativeComponent.tsx +68 -0
  265. package/src/ui/WheelColumn/constants.ts +1 -0
  266. package/src/ui/WheelColumn/index.tsx +826 -0
  267. package/zkit-ui.podspec +19 -0
@@ -0,0 +1,1001 @@
1
+ import * as React from 'react';
2
+ import {
3
+ Platform,
4
+ Pressable,
5
+ StyleSheet,
6
+ useWindowDimensions,
7
+ View,
8
+ type LayoutChangeEvent,
9
+ } from 'react-native';
10
+ import { LinearGradient } from 'expo-linear-gradient';
11
+ import dayjs, { type Dayjs } from 'dayjs';
12
+ import customParseFormat from 'dayjs/plugin/customParseFormat';
13
+ import { useSafeAreaInsets } from 'react-native-safe-area-context';
14
+ import { sp, wp } from 'zkit-tools';
15
+ import { useI18n } from '../../i18n/useI18n';
16
+ import { useTheme } from '../../theme/useTheme';
17
+ import { Sheet, type SheetOpenChangeDetails } from '../Sheet';
18
+ import { Button } from '../Button';
19
+ import { PickerActionBar, getPickerActionBarBottomInset } from '../Picker/actionBar';
20
+ import { Text } from '../Text';
21
+ import {
22
+ WheelColumn,
23
+ WHEEL_AREA_HEIGHT,
24
+ WHEEL_AREA_VERTICAL_INSET,
25
+ WHEEL_ITEM_HEIGHT,
26
+ WHEEL_SELECTION_BACKGROUND_COLOR,
27
+ WHEEL_VISIBLE_ITEMS,
28
+ type WheelColumnHandle,
29
+ type WheelOption,
30
+ } from '../WheelColumn';
31
+
32
+ dayjs.extend(customParseFormat);
33
+
34
+ const ITEM_HEIGHT = WHEEL_ITEM_HEIGHT;
35
+ const VISIBLE_ITEMS = WHEEL_VISIBLE_ITEMS;
36
+
37
+ type ModelType = 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second';
38
+ type Side = 'start' | 'end';
39
+
40
+ type BetweenTimeConfirmPayload = {
41
+ value: string[];
42
+ };
43
+
44
+ export type BetweenTimeHandle = {
45
+ open: () => void;
46
+ close: () => void;
47
+ };
48
+
49
+ export type BetweenTimeProps = {
50
+ /**
51
+ * 当前时间区间。
52
+ * - 必须是“标准时间格式”字符串数组(长度 0 或 2)
53
+ * - 组件内部会基于 start/end 做边界校正,并保证前后顺序
54
+ */
55
+ value?: string[];
56
+ defaultValue?: string[];
57
+ onValueChange?: (next: string[]) => void;
58
+
59
+ open?: boolean;
60
+ defaultOpen?: boolean;
61
+ onOpenChange?: (next: boolean) => void;
62
+ onDismissComplete?: () => void;
63
+
64
+ /**
65
+ * 顶部标题。
66
+ */
67
+ title?: string;
68
+
69
+ /**
70
+ * 全局可选时间范围(建议提供标准时间格式)。
71
+ */
72
+ start?: string;
73
+ end?: string;
74
+
75
+ /**
76
+ * 展示精确到的级别(影响展示列数/输出格式)。
77
+ */
78
+ type?: ModelType;
79
+
80
+ /**
81
+ * 输入框展示使用的格式化模板。
82
+ */
83
+ format?: string;
84
+
85
+ /**
86
+ * 是否把 format 格式化后的值同步到 value。
87
+ * 注意:开启后必须保证 format 输出仍是可解析的标准时间格式,否则会抛错。
88
+ */
89
+ formatSyncValue?: boolean;
90
+
91
+ /**
92
+ * 单位名称(列头)。
93
+ */
94
+ cellUnits?: string[];
95
+
96
+ /**
97
+ * 快捷时间区间选择:
98
+ * - d/w/m/y/q:本日/本周/本月/本年/本季度
99
+ * - 数字字符串:最近 xx 天(例如 '7')
100
+ */
101
+ quickDate?: string[];
102
+
103
+ /**
104
+ * 是否懒加载弹层内容(避免复杂内容影响开启动画)。
105
+ */
106
+ lazyContent?: boolean;
107
+
108
+ /**
109
+ * 弹层高度(数字或可解析为数字的字符串)。
110
+ */
111
+ drawerSize?: string | number;
112
+
113
+ /**
114
+ * 禁用打开弹层。
115
+ */
116
+ disabled?: boolean;
117
+
118
+ /**
119
+ * 取消回调。
120
+ */
121
+ onCancel?: () => void;
122
+ /**
123
+ * 确认回调。
124
+ */
125
+ onConfirm?: (payload: BetweenTimeConfirmPayload) => void;
126
+
127
+ /**
128
+ * slot:默认触发打开选择器的子节点(React 里即 children)。
129
+ */
130
+ children?: React.ReactNode;
131
+ };
132
+
133
+ type DateBounds = { min?: Dayjs; max?: Dayjs };
134
+
135
+
136
+ const STANDARD_INPUT_FORMATS = [
137
+ 'YYYY',
138
+ 'YYYY-M',
139
+ 'YYYY-MM',
140
+ 'YYYY-M-D',
141
+ 'YYYY-MM-DD',
142
+ 'YYYY-MM-DDHH',
143
+ 'YYYY-MM-DD HH',
144
+ 'YYYY-MM-DDHH:mm',
145
+ 'YYYY-MM-DD HH:mm',
146
+ 'YYYY-MM-DDHH:mm:ss',
147
+ 'YYYY-MM-DD HH:mm:ss',
148
+ ];
149
+
150
+ function clampNumber(n: number, min: number, max: number) {
151
+ return Math.max(min, Math.min(max, n));
152
+ }
153
+
154
+ function toIntOrNull(v: string) {
155
+ const n = Number.parseInt(v, 10);
156
+ return Number.isFinite(n) ? n : null;
157
+ }
158
+
159
+ function parseStandardDateStrict(input?: string): Dayjs | undefined {
160
+ if (!input) return undefined;
161
+ const d = dayjs(input, STANDARD_INPUT_FORMATS, true);
162
+ if (!d.isValid()) {
163
+ throw new Error(`[zkit-ui][BetweenTime] Invalid date string: "${input}"`);
164
+ }
165
+ return d;
166
+ }
167
+
168
+ function formatByType(d: Dayjs, type: ModelType) {
169
+ switch (type) {
170
+ case 'year':
171
+ return d.format('YYYY');
172
+ case 'month':
173
+ return d.format('YYYY-MM');
174
+ case 'day':
175
+ return d.format('YYYY-MM-DD');
176
+ case 'hour':
177
+ return d.format('YYYY-MM-DDHH');
178
+ case 'minute':
179
+ return d.format('YYYY-MM-DDHH:mm');
180
+ case 'second':
181
+ return d.format('YYYY-MM-DDHH:mm:ss');
182
+ }
183
+ }
184
+
185
+ function normalizeDraftByType(d: Dayjs, type: ModelType) {
186
+ if (type === 'year') return d.month(0).date(1).hour(0).minute(0).second(0);
187
+ if (type === 'month') return d.date(1).hour(0).minute(0).second(0);
188
+ if (type === 'day') return d.hour(0).minute(0).second(0);
189
+ if (type === 'hour') return d.minute(0).second(0);
190
+ if (type === 'minute') return d.second(0);
191
+ return d;
192
+ }
193
+
194
+ function clampToBounds(d: Dayjs, bounds: DateBounds) {
195
+ if (bounds.min && d.isBefore(bounds.min)) return bounds.min;
196
+ if (bounds.max && d.isAfter(bounds.max)) return bounds.max;
197
+ return d;
198
+ }
199
+
200
+ function resolveInitialPair(modelValue: string[] | undefined, bounds: DateBounds, type: ModelType) {
201
+ const rawStart = Array.isArray(modelValue) ? modelValue[0] : undefined;
202
+ const rawEnd = Array.isArray(modelValue) ? modelValue[1] : undefined;
203
+ const min = bounds.min;
204
+ const max = bounds.max;
205
+
206
+ const now = dayjs();
207
+ let s = rawStart ? parseStandardDateStrict(rawStart) : undefined;
208
+ let e = rawEnd ? parseStandardDateStrict(rawEnd) : undefined;
209
+
210
+ if (!s || !e) {
211
+ const seed = clampToBounds(now, bounds);
212
+ s = s ?? seed;
213
+ e = e ?? seed;
214
+ }
215
+
216
+ s = normalizeDraftByType(clampToBounds(s, bounds), type);
217
+ e = normalizeDraftByType(clampToBounds(e, bounds), type);
218
+
219
+ if (s.isAfter(e)) {
220
+ const tmp = s;
221
+ s = e;
222
+ e = tmp;
223
+ }
224
+
225
+ if (min && max && min.isAfter(max)) {
226
+ throw new Error('[zkit-ui][BetweenTime] Invalid bounds: start is after end.');
227
+ }
228
+
229
+ return { start: s, end: e };
230
+ }
231
+
232
+ function ensureFormatSyncValueIsStandard(value: string) {
233
+ const d = dayjs(value, STANDARD_INPUT_FORMATS, true);
234
+ if (!d.isValid()) {
235
+ throw new Error(
236
+ `[zkit-ui][BetweenTime] formatSyncValue requires standard output, got "${value}".`
237
+ );
238
+ }
239
+ }
240
+
241
+ function getQuarterStart(d: Dayjs) {
242
+ const m = d.month(); // 0-11
243
+ const qStartMonth = Math.floor(m / 3) * 3;
244
+ return d.month(qStartMonth).date(1).hour(0).minute(0).second(0);
245
+ }
246
+
247
+ function getQuickRange(key: string, now: Dayjs): { start: Dayjs; end: Dayjs } | null {
248
+ if (key === 'd') {
249
+ const t = now.startOf('day');
250
+ return { start: t, end: t.endOf('day') };
251
+ }
252
+ if (key === 'w') {
253
+ const s = now.startOf('week').startOf('day');
254
+ const e = now.endOf('week').endOf('day');
255
+ return { start: s, end: e };
256
+ }
257
+ if (key === 'm') {
258
+ const s = now.startOf('month').startOf('day');
259
+ const e = now.endOf('month').endOf('day');
260
+ return { start: s, end: e };
261
+ }
262
+ if (key === 'y') {
263
+ const s = now.startOf('year').startOf('day');
264
+ const e = now.endOf('year').endOf('day');
265
+ return { start: s, end: e };
266
+ }
267
+ if (key === 'q') {
268
+ const s = getQuarterStart(now).startOf('day');
269
+ const e = s.add(3, 'month').subtract(1, 'second').endOf('day');
270
+ return { start: s, end: e };
271
+ }
272
+ const n = toIntOrNull(key);
273
+ if (n != null && n > 0) {
274
+ const e = now.endOf('day');
275
+ const s = now.subtract(n - 1, 'day').startOf('day');
276
+ return { start: s, end: e };
277
+ }
278
+ return null;
279
+ }
280
+
281
+
282
+ function getColumnsCount(type: ModelType) {
283
+ if (type === 'year') return 1;
284
+ if (type === 'month') return 2;
285
+ if (type === 'day') return 3;
286
+ if (type === 'hour') return 4;
287
+ if (type === 'minute') return 5;
288
+ return 6;
289
+ }
290
+
291
+ function ensureBoundsValid(bounds: DateBounds) {
292
+ if (bounds.min && bounds.max && bounds.min.isAfter(bounds.max)) {
293
+ throw new Error('[zkit-ui][BetweenTime] Invalid bounds: start is after end.');
294
+ }
295
+ }
296
+
297
+ // 缓存常用的选项数组,避免重复创建
298
+ const wheelOptionsCache = new Map<string, WheelOption[]>();
299
+
300
+ function buildWheelOptions(min: number, max: number, pad2 = false): WheelOption[] {
301
+ const cacheKey = `${min}-${max}-${pad2}`;
302
+ const cached = wheelOptionsCache.get(cacheKey);
303
+ if (cached) return cached;
304
+
305
+ const out: WheelOption[] = [];
306
+ for (let v = min; v <= max; v += 1) {
307
+ out.push({ value: v, label: pad2 ? String(v).padStart(2, '0') : String(v) });
308
+ }
309
+ wheelOptionsCache.set(cacheKey, out);
310
+ return out;
311
+ }
312
+
313
+ function resolveWheelData(d: Dayjs, bounds: DateBounds, type: ModelType) {
314
+ const count = getColumnsCount(type);
315
+ const min = bounds.min;
316
+ const max = bounds.max;
317
+
318
+ const minYear = min?.year() ?? 1970;
319
+ const maxYear = max?.year() ?? 2099;
320
+ const years = buildWheelOptions(minYear, maxYear);
321
+
322
+ const y = clampNumber(d.year(), minYear, maxYear);
323
+
324
+ const mMin = y === min?.year() ? (min.month() + 1) : 1;
325
+ const mMax = y === max?.year() ? (max.month() + 1) : 12;
326
+ const months = buildWheelOptions(mMin, mMax, true);
327
+
328
+ const month = clampNumber(d.month() + 1, mMin, mMax);
329
+ const base = dayjs(`${y}-${String(month).padStart(2, '0')}-01`);
330
+ const dim = base.daysInMonth();
331
+
332
+ const isMinYM = y === min?.year() && month === (min.month() + 1);
333
+ const isMaxYM = y === max?.year() && month === (max.month() + 1);
334
+ const dMin = isMinYM ? min.date() : 1;
335
+ const dMax = isMaxYM ? max.date() : dim;
336
+ const days = buildWheelOptions(dMin, dMax, true);
337
+
338
+ const day = clampNumber(d.date(), dMin, dMax);
339
+ const sameMinYMD =
340
+ min != null && y === min.year() && month === (min.month() + 1) && day === min.date();
341
+ const sameMaxYMD =
342
+ max != null && y === max.year() && month === (max.month() + 1) && day === max.date();
343
+ const hMin = sameMinYMD ? min.hour() : 0;
344
+ const hMax = sameMaxYMD ? max.hour() : 23;
345
+ const hours = buildWheelOptions(hMin, hMax, true);
346
+
347
+ const hour = clampNumber(d.hour(), hMin, hMax);
348
+ const sameMinYMDH = sameMinYMD && hour === min?.hour();
349
+ const sameMaxYMDH = sameMaxYMD && hour === max?.hour();
350
+ const minMin = sameMinYMDH ? min.minute() : 0;
351
+ const minMax = sameMaxYMDH ? max.minute() : 59;
352
+ const minutes = buildWheelOptions(minMin, minMax, true);
353
+
354
+ const minute = clampNumber(d.minute(), minMin, minMax);
355
+ const sameMinYMDHM = sameMinYMDH && minute === min?.minute();
356
+ const sameMaxYMDHM = sameMaxYMDH && minute === max?.minute();
357
+ const sMin = sameMinYMDHM ? min.second() : 0;
358
+ const sMax = sameMaxYMDHM ? max.second() : 59;
359
+ const seconds = buildWheelOptions(sMin, sMax, true);
360
+
361
+ const all = [years, months, days, hours, minutes, seconds].slice(0, count);
362
+ const indices = [
363
+ years.findIndex((it) => it.value === y),
364
+ months.findIndex((it) => it.value === month),
365
+ days.findIndex((it) => it.value === day),
366
+ hours.findIndex((it) => it.value === hour),
367
+ minutes.findIndex((it) => it.value === minute),
368
+ seconds.findIndex((it) => it.value === clampNumber(d.second(), sMin, sMax)),
369
+ ].slice(0, count);
370
+
371
+ return { columns: all, indices };
372
+ }
373
+
374
+ function applyColumnValue(d: Dayjs, columnIndex: number, value: number) {
375
+ if (columnIndex === 0) return d.year(value);
376
+ if (columnIndex === 1) return d.month(value - 1);
377
+ if (columnIndex === 2) return d.date(value);
378
+ if (columnIndex === 3) return d.hour(value);
379
+ if (columnIndex === 4) return d.minute(value);
380
+ return d.second(value);
381
+ }
382
+
383
+ function composeTrigger(children: React.ReactNode, onPress: () => void, disabled?: boolean) {
384
+ if (React.isValidElement(children)) {
385
+ const anyChild = children as any;
386
+ const prevOnPress = anyChild?.props?.onPress;
387
+ if (typeof prevOnPress === 'function') {
388
+ return React.cloneElement(children as any, {
389
+ onPress: (...args: any[]) => {
390
+ prevOnPress(...args);
391
+ onPress();
392
+ },
393
+ disabled: disabled || anyChild?.props?.disabled,
394
+ });
395
+ }
396
+ return React.cloneElement(children as any, {
397
+ onPress,
398
+ disabled: disabled || anyChild?.props?.disabled,
399
+ });
400
+ }
401
+ return (
402
+ <Pressable onPress={onPress} disabled={disabled}>
403
+ {children}
404
+ </Pressable>
405
+ );
406
+ }
407
+
408
+ export const BetweenTime = React.forwardRef<BetweenTimeHandle, BetweenTimeProps>(function BetweenTime({
409
+ title,
410
+ start,
411
+ end,
412
+ type = 'day',
413
+ format = 'YYYY-MM-DD',
414
+ formatSyncValue = false,
415
+ cellUnits,
416
+ quickDate,
417
+ lazyContent = true,
418
+ drawerSize,
419
+ disabled = false,
420
+ value: valueProp,
421
+ defaultValue,
422
+ onValueChange,
423
+ open: openProp,
424
+ defaultOpen = false,
425
+ onOpenChange,
426
+ onDismissComplete,
427
+ onCancel,
428
+ onConfirm,
429
+ children,
430
+ }: BetweenTimeProps, ref) {
431
+ const { t } = useI18n();
432
+ const theme = useTheme();
433
+ const { height: screenH, width: screenW } = useWindowDimensions();
434
+ const insets = useSafeAreaInsets();
435
+ const safeBottom = getPickerActionBarBottomInset(insets.bottom);
436
+
437
+ const bounds = React.useMemo<DateBounds>(() => {
438
+ const min = parseStandardDateStrict(start);
439
+ const max = parseStandardDateStrict(end);
440
+ const b = { min, max };
441
+ ensureBoundsValid(b);
442
+ return b;
443
+ }, [start, end]);
444
+
445
+ const [innerValue, setInnerValue] = React.useState<string[]>(defaultValue ?? []);
446
+ const isValueControlled = valueProp !== undefined;
447
+ const value = isValueControlled ? (valueProp as string[]) : innerValue;
448
+
449
+ const [innerOpen, setInnerOpen] = React.useState(defaultOpen);
450
+ const isOpenControlled = openProp !== undefined;
451
+ const visible = isOpenControlled ? !!openProp : innerOpen;
452
+ const [contentMounted, setContentMounted] = React.useState(!lazyContent);
453
+
454
+ const detents = React.useMemo<Array<'auto' | number>>(() => {
455
+ if (drawerSize == null) return ['auto'];
456
+ const n = typeof drawerSize === 'number' ? drawerSize : Number.parseFloat(drawerSize);
457
+ if (!Number.isFinite(n) || n <= 0) return ['auto'];
458
+ const fraction = clampNumber(n / screenH, 0.1, 0.92);
459
+ return [fraction];
460
+ }, [drawerSize, screenH]);
461
+
462
+ const [activeSide, setActiveSide] = React.useState<Side>('start');
463
+
464
+ const [{ draftStart, draftEnd }, setDraft] = React.useState(() => {
465
+ const pair = resolveInitialPair(value, bounds, type);
466
+ return { draftStart: pair.start, draftEnd: pair.end };
467
+ });
468
+
469
+ React.useEffect(() => {
470
+ const pair = resolveInitialPair(value, bounds, type);
471
+ setDraft({ draftStart: pair.start, draftEnd: pair.end });
472
+ }, [bounds, type, value?.[0], value?.[1]]);
473
+
474
+ React.useEffect(() => {
475
+ if (visible) {
476
+ const pair = resolveInitialPair(value, bounds, type);
477
+ setDraft({ draftStart: pair.start, draftEnd: pair.end });
478
+ if (lazyContent && !contentMounted) setContentMounted(true);
479
+ }
480
+ // 只希望在进入打开态时重置草稿,不跟随其他依赖重复触发。
481
+ // eslint-disable-next-line react-hooks/exhaustive-deps
482
+ }, [visible]);
483
+
484
+ const defaultCellUnits = React.useMemo(() => [
485
+ t('betweenTime.unit.year'),
486
+ t('betweenTime.unit.month'),
487
+ t('betweenTime.unit.day'),
488
+ t('betweenTime.unit.hour'),
489
+ t('betweenTime.unit.minute'),
490
+ t('betweenTime.unit.second'),
491
+ ], [t]);
492
+
493
+ const getQuickLabel = React.useCallback((key: string) => {
494
+ if (key === 'd') return t('betweenTime.quick.today');
495
+ if (key === 'w') return t('betweenTime.quick.thisWeek');
496
+ if (key === 'm') return t('betweenTime.quick.thisMonth');
497
+ if (key === 'y') return t('betweenTime.quick.thisYear');
498
+ if (key === 'q') return t('betweenTime.quick.thisQuarter');
499
+ const n = toIntOrNull(key);
500
+ if (n != null && n > 0) return t('betweenTime.quick.recentDays', { n });
501
+ return key;
502
+ }, [t]);
503
+
504
+ const setPickerOpen = React.useCallback((nextOpen: boolean) => {
505
+ onOpenChange?.(nextOpen);
506
+ if (!isOpenControlled) setInnerOpen(nextOpen);
507
+ }, [isOpenControlled, onOpenChange]);
508
+
509
+ const close = React.useCallback(() => {
510
+ setPickerOpen(false);
511
+ }, [setPickerOpen]);
512
+
513
+ const openPicker = React.useCallback(() => {
514
+ if (disabled) return;
515
+ if (!visible) {
516
+ setPickerOpen(true);
517
+ }
518
+
519
+ const pair = resolveInitialPair(value, bounds, type);
520
+ setDraft({ draftStart: pair.start, draftEnd: pair.end });
521
+
522
+ if (lazyContent && !contentMounted) {
523
+ setContentMounted(true);
524
+ }
525
+ }, [bounds, contentMounted, disabled, lazyContent, setPickerOpen, type, value, visible]);
526
+
527
+ React.useImperativeHandle(ref, () => ({
528
+ open: openPicker,
529
+ close,
530
+ }), [openPicker, close]);
531
+
532
+ const columnsCount = React.useMemo(() => getColumnsCount(type), [type]);
533
+ const wheelsRef = React.useRef<Array<WheelColumnHandle | null>>([]);
534
+ React.useEffect(() => {
535
+ wheelsRef.current.length = columnsCount;
536
+ }, [columnsCount]);
537
+ const resolvedCellUnits = cellUnits ?? defaultCellUnits;
538
+ const unitLabels = React.useMemo(() => resolvedCellUnits.slice(0, columnsCount), [resolvedCellUnits, columnsCount]);
539
+ const activeDraft = activeSide === 'start' ? draftStart : draftEnd;
540
+ const { columns, indices } = React.useMemo(
541
+ () => resolveWheelData(activeDraft, bounds, type),
542
+ [activeDraft, bounds, type]
543
+ );
544
+
545
+ const columnsLayoutRef = React.useRef({ width: screenW - wp(32) });
546
+ const onColumnsLayout = React.useCallback((e: LayoutChangeEvent) => {
547
+ columnsLayoutRef.current = { width: e.nativeEvent.layout.width };
548
+ }, []);
549
+ const columnWidth = React.useMemo(() => {
550
+ const w = columnsLayoutRef.current.width;
551
+ return w / Math.max(1, columnsCount);
552
+ }, [columnsCount, screenW]);
553
+
554
+ const setValue = React.useCallback(
555
+ (next: string[]) => {
556
+ onValueChange?.(next);
557
+ if (!isValueControlled) setInnerValue(next);
558
+ },
559
+ [isValueControlled, onValueChange]
560
+ );
561
+
562
+ const applyPairAndEmit = React.useCallback(
563
+ (nextStart: Dayjs, nextEnd: Dayjs) => {
564
+ const s = normalizeDraftByType(clampToBounds(nextStart, bounds), type);
565
+ const e = normalizeDraftByType(clampToBounds(nextEnd, bounds), type);
566
+ let a = s;
567
+ let b = e;
568
+ let nextActive = activeSide;
569
+ if (a.isAfter(b)) {
570
+ const tmp = a;
571
+ a = b;
572
+ b = tmp;
573
+ nextActive = activeSide === 'start' ? 'end' : 'start';
574
+ }
575
+ setDraft({ draftStart: a, draftEnd: b });
576
+ if (nextActive !== activeSide) setActiveSide(nextActive);
577
+
578
+ const rawStart = formatByType(a, type);
579
+ const rawEnd = formatByType(b, type);
580
+
581
+ let outStart = rawStart;
582
+ let outEnd = rawEnd;
583
+ if (formatSyncValue) {
584
+ outStart = a.format(format);
585
+ outEnd = b.format(format);
586
+ ensureFormatSyncValueIsStandard(outStart);
587
+ ensureFormatSyncValueIsStandard(outEnd);
588
+ }
589
+
590
+ const nextValue = outStart && outEnd ? [outStart, outEnd] : [];
591
+ setValue(nextValue);
592
+ },
593
+ [activeSide, bounds, format, formatSyncValue, setValue, type]
594
+ );
595
+
596
+ // iOS 原生 wheel 在减速尚未结束时,业务层未必已经拿到最新列值。
597
+ // 确认按钮这里会主动向每一列请求一次“以当前中心项为准”的即时结算,
598
+ // 然后再统一重建 start / end,避免出现“明明已经滚到新值,但确认后还是旧值”的错位。
599
+ const syncDraftFromWheels = React.useCallback(async () => {
600
+ let nextDraft = activeDraft;
601
+
602
+ for (let columnIndex = 0; columnIndex < columnsCount; columnIndex += 1) {
603
+ const opts = columns[columnIndex] ?? [];
604
+ if (!opts.length) break;
605
+
606
+ const wheel = wheelsRef.current[columnIndex];
607
+ const settledIndex =
608
+ Platform.OS === 'ios'
609
+ ? await wheel?.syncCurrentSelection()
610
+ : wheel?.settleToNearest(false);
611
+ const safeIndex = clampNumber(settledIndex ?? indices[columnIndex] ?? 0, 0, opts.length - 1);
612
+ const picked = opts[safeIndex];
613
+ if (!picked) continue;
614
+
615
+ nextDraft = applyColumnValue(nextDraft, columnIndex, picked.value as number);
616
+ }
617
+
618
+ nextDraft = normalizeDraftByType(clampToBounds(nextDraft, bounds), type);
619
+
620
+ const startCandidate = activeSide === 'start' ? nextDraft : draftStart;
621
+ const endCandidate = activeSide === 'start' ? draftEnd : nextDraft;
622
+ const nextStart = normalizeDraftByType(clampToBounds(startCandidate, bounds), type);
623
+ const nextEnd = normalizeDraftByType(clampToBounds(endCandidate, bounds), type);
624
+ const nextPair = nextStart.isAfter(nextEnd)
625
+ ? { start: nextEnd, end: nextStart }
626
+ : { start: nextStart, end: nextEnd };
627
+
628
+ applyPairAndEmit(nextPair.start, nextPair.end);
629
+ return nextPair;
630
+ }, [activeDraft, activeSide, applyPairAndEmit, bounds, columns, columnsCount, draftEnd, draftStart, indices, type]);
631
+
632
+ const handleWheelIndexChange = React.useCallback(
633
+ (columnIndex: number, nextIndex: number) => {
634
+ const opts = columns[columnIndex];
635
+ const picked = opts?.[nextIndex];
636
+ if (!picked) return;
637
+ const valueNum = picked.value as number;
638
+ let nextDraft = applyColumnValue(activeDraft, columnIndex, valueNum);
639
+ nextDraft = clampToBounds(nextDraft, bounds);
640
+ nextDraft = normalizeDraftByType(nextDraft, type);
641
+
642
+ if (activeSide === 'start') applyPairAndEmit(nextDraft, draftEnd);
643
+ else applyPairAndEmit(draftStart, nextDraft);
644
+ },
645
+ [activeDraft, activeSide, applyPairAndEmit, bounds, columns, draftEnd, draftStart, type]
646
+ );
647
+
648
+ const handleClear = React.useCallback(() => {
649
+ setValue([]);
650
+ }, [setValue]);
651
+
652
+ const handleCancel = React.useCallback(() => {
653
+ onCancel?.();
654
+ const pair = resolveInitialPair(value, bounds, type);
655
+ setDraft({ draftStart: pair.start, draftEnd: pair.end });
656
+ close();
657
+ }, [bounds, close, onCancel, type, value]);
658
+
659
+ const handleConfirm = React.useCallback(async () => {
660
+ const synced = await syncDraftFromWheels();
661
+ const next = [synced.start, synced.end];
662
+ const rawStart = formatByType(next[0], type);
663
+ const rawEnd = formatByType(next[1], type);
664
+ let outStart = rawStart;
665
+ let outEnd = rawEnd;
666
+ if (formatSyncValue) {
667
+ outStart = next[0].format(format);
668
+ outEnd = next[1].format(format);
669
+ ensureFormatSyncValueIsStandard(outStart);
670
+ ensureFormatSyncValueIsStandard(outEnd);
671
+ }
672
+ const nextValue = outStart && outEnd ? [outStart, outEnd] : [];
673
+ setValue(nextValue);
674
+ onConfirm?.({ value: nextValue });
675
+ close();
676
+ }, [close, format, formatSyncValue, onConfirm, setValue, syncDraftFromWheels, type]);
677
+
678
+ const handleQuickPick = React.useCallback(
679
+ (key: string) => {
680
+ const range = getQuickRange(key, dayjs());
681
+ if (!range) return;
682
+ applyPairAndEmit(range.start, range.end);
683
+ },
684
+ [applyPairAndEmit]
685
+ );
686
+
687
+ const triggerNode = React.useMemo(
688
+ () => children != null ? composeTrigger(children, openPicker, disabled) : null,
689
+ [children, disabled, openPicker]
690
+ );
691
+
692
+ const handleSheetOpenChange = React.useCallback((nextOpen: boolean, meta: SheetOpenChangeDetails) => {
693
+ if (!nextOpen && visible && meta.reason !== 'api') {
694
+ onCancel?.();
695
+ const pair = resolveInitialPair(value, bounds, type);
696
+ setDraft({ draftStart: pair.start, draftEnd: pair.end });
697
+ }
698
+ setPickerOpen(nextOpen);
699
+ }, [bounds, onCancel, setPickerOpen, type, value, visible]);
700
+
701
+ const handleSheetDismissComplete = React.useCallback(() => {
702
+ if (lazyContent) setContentMounted(false);
703
+ onDismissComplete?.();
704
+ }, [lazyContent, onDismissComplete]);
705
+
706
+ const sheetNode = (
707
+ <Sheet
708
+ placement="bottom"
709
+ open={visible}
710
+ onOpenChange={handleSheetOpenChange}
711
+ onCloseComplete={handleSheetDismissComplete}
712
+ detents={detents}
713
+ backgroundColor={theme.colors.surface}
714
+ handle={false}
715
+ draggable={false}
716
+ dismissible={!disabled}
717
+ nativeProps={{ insetAdjustment: 'never' }}
718
+ >
719
+ <View
720
+ style={[
721
+ styles.sheetInner,
722
+ {
723
+ backgroundColor: theme.colors.surface,
724
+ paddingBottom: safeBottom,
725
+ },
726
+ ]}
727
+ pointerEvents={disabled ? 'none' : 'auto'}
728
+ >
729
+ <View style={styles.header}>
730
+ <Text style={[styles.headerTitle, { color: theme.colors.onSurface }]} numberOfLines={1}>
731
+ {title ?? t('betweenTime.title')}
732
+ </Text>
733
+ <Button
734
+ variant="ghost"
735
+ onPress={handleClear}
736
+ disabled={disabled}
737
+ colors={{ text: theme.colors.muted }}
738
+ layout={{ minHeight: wp(32), paddingHorizontal: wp(8), textSize: sp(14) }}
739
+ >
740
+ {t('betweenTime.clear')}
741
+ </Button>
742
+ </View>
743
+
744
+ {Array.isArray(quickDate) && quickDate.length > 0 ? (
745
+ <View style={styles.quickRow}>
746
+ {quickDate.map((k) => (
747
+ <Pressable
748
+ key={k}
749
+ onPress={() => handleQuickPick(k)}
750
+ style={({ pressed }) => [
751
+ styles.quickPill,
752
+ {
753
+ borderColor: `${theme.colors.primary}22`,
754
+ backgroundColor: `${theme.colors.primary}14`,
755
+ },
756
+ pressed && { opacity: 0.8 },
757
+ ]}
758
+ disabled={disabled}
759
+ >
760
+ <Text style={[styles.quickText, { color: theme.colors.primary }]}>{getQuickLabel(k)}</Text>
761
+ </Pressable>
762
+ ))}
763
+ </View>
764
+ ) : null}
765
+
766
+ <View style={styles.rangeRow}>
767
+ <Pressable
768
+ onPress={() => setActiveSide('start')}
769
+ style={({ pressed }) => [
770
+ styles.rangePill,
771
+ activeSide === 'start'
772
+ ? { borderColor: theme.colors.primary, backgroundColor: '#FFFFFF' }
773
+ : { borderColor: theme.colors.border, backgroundColor: '#FFFFFF' },
774
+ pressed && { opacity: 0.85 },
775
+ ]}
776
+ >
777
+ <Text
778
+ style={[
779
+ styles.rangeText,
780
+ { color: activeSide === 'start' ? theme.colors.primary : theme.colors.muted },
781
+ ]}
782
+ numberOfLines={1}
783
+ >
784
+ {draftStart ? draftStart.format(format) : t('betweenTime.startTime')}
785
+ </Text>
786
+ </Pressable>
787
+
788
+ <Text style={[styles.toText, { color: theme.colors.muted }]}>{t('betweenTime.to')}</Text>
789
+
790
+ <Pressable
791
+ onPress={() => setActiveSide('end')}
792
+ style={({ pressed }) => [
793
+ styles.rangePill,
794
+ activeSide === 'end'
795
+ ? { borderColor: theme.colors.primary, backgroundColor: '#FFFFFF' }
796
+ : { borderColor: theme.colors.border, backgroundColor: '#FFFFFF' },
797
+ pressed && { opacity: 0.85 },
798
+ ]}
799
+ >
800
+ <Text
801
+ style={[
802
+ styles.rangeText,
803
+ { color: activeSide === 'end' ? theme.colors.primary : theme.colors.muted },
804
+ ]}
805
+ numberOfLines={1}
806
+ >
807
+ {draftEnd ? draftEnd.format(format) : t('betweenTime.endTime')}
808
+ </Text>
809
+ </Pressable>
810
+ </View>
811
+
812
+ {contentMounted ? (
813
+ <View style={styles.pickerArea}>
814
+ <View style={styles.unitRow}>
815
+ {unitLabels.map((u, idx) => (
816
+ <View key={`${u}-${idx}`} style={[styles.unitCell, { width: columnWidth }]}>
817
+ <Text style={[styles.unitText, { color: theme.colors.muted }]}>{u}</Text>
818
+ </View>
819
+ ))}
820
+ </View>
821
+
822
+ <View style={styles.pickerWrapper} onLayout={onColumnsLayout}>
823
+ {Platform.OS !== 'ios' && (
824
+ <View style={styles.highlightBar} pointerEvents="none" />
825
+ )}
826
+ <View style={styles.columnsRow}>
827
+ {columns.map((col, colIdx) => (
828
+ <WheelColumn
829
+ key={`col-${colIdx}-${columnsCount}`}
830
+ ref={(instance) => {
831
+ wheelsRef.current[colIdx] = instance;
832
+ }}
833
+ options={col}
834
+ value={col[Math.max(0, indices[colIdx] ?? 0)]?.value ?? null}
835
+ onChange={(payload) => handleWheelIndexChange(colIdx, payload.index)}
836
+ width={columnWidth}
837
+ disabled={disabled}
838
+ />
839
+ ))}
840
+ </View>
841
+ {Platform.OS !== 'ios' && (
842
+ <>
843
+ <View style={styles.topMask} pointerEvents="none">
844
+ <LinearGradient
845
+ colors={['#FFFFFF', 'rgba(255,255,255,0)']}
846
+ style={StyleSheet.absoluteFill}
847
+ />
848
+ </View>
849
+ <View style={styles.bottomMask} pointerEvents="none">
850
+ <LinearGradient
851
+ colors={['rgba(255,255,255,0)', '#FFFFFF']}
852
+ style={StyleSheet.absoluteFill}
853
+ />
854
+ </View>
855
+ </>
856
+ )}
857
+ </View>
858
+ </View>
859
+ ) : (
860
+ <View style={[styles.pickerArea, { height: WHEEL_AREA_HEIGHT + wp(26) }]} />
861
+ )}
862
+
863
+ <PickerActionBar
864
+ cancelText={t('betweenTime.cancel')}
865
+ confirmText={t('betweenTime.confirm')}
866
+ onCancel={handleCancel}
867
+ onConfirm={handleConfirm}
868
+ disabled={disabled}
869
+ style={styles.footer}
870
+ />
871
+ </View>
872
+ </Sheet>
873
+ );
874
+
875
+ return (
876
+ <>
877
+ {triggerNode}
878
+ {sheetNode}
879
+ </>
880
+ );
881
+ });
882
+
883
+ const styles = StyleSheet.create({
884
+ sheetInner: {
885
+ width: '100%',
886
+ paddingHorizontal: wp(16),
887
+ paddingTop: wp(14),
888
+ },
889
+ header: {
890
+ height: wp(44),
891
+ flexDirection: 'row',
892
+ alignItems: 'center',
893
+ justifyContent: 'space-between',
894
+ },
895
+ headerTitle: {
896
+ fontSize: sp(16),
897
+ fontWeight: '600',
898
+ },
899
+ quickRow: {
900
+ flexDirection: 'row',
901
+ flexWrap: 'wrap',
902
+ gap: wp(10),
903
+ paddingTop: wp(8),
904
+ paddingBottom: wp(12),
905
+ },
906
+ quickPill: {
907
+ height: wp(28),
908
+ paddingHorizontal: wp(12),
909
+ borderRadius: wp(14),
910
+ borderWidth: StyleSheet.hairlineWidth,
911
+ alignItems: 'center',
912
+ justifyContent: 'center',
913
+ },
914
+ quickText: {
915
+ fontSize: sp(12),
916
+ fontWeight: '600',
917
+ },
918
+ rangeRow: {
919
+ flexDirection: 'row',
920
+ alignItems: 'center',
921
+ justifyContent: 'space-between',
922
+ paddingTop: wp(4),
923
+ paddingBottom: wp(10),
924
+ },
925
+ rangePill: {
926
+ flex: 1,
927
+ height: wp(40),
928
+ borderRadius: wp(20),
929
+ borderWidth: wp(1.5),
930
+ alignItems: 'center',
931
+ justifyContent: 'center',
932
+ paddingHorizontal: wp(12),
933
+ },
934
+ rangeText: {
935
+ fontSize: sp(14),
936
+ fontWeight: '600',
937
+ },
938
+ toText: {
939
+ width: wp(28),
940
+ textAlign: 'center',
941
+ fontSize: sp(13),
942
+ fontWeight: '600',
943
+ },
944
+ pickerArea: {
945
+ paddingTop: wp(4),
946
+ paddingBottom: WHEEL_AREA_VERTICAL_INSET * 2,
947
+ },
948
+ unitRow: {
949
+ flexDirection: 'row',
950
+ justifyContent: 'space-between',
951
+ paddingBottom: wp(6),
952
+ },
953
+ unitCell: {
954
+ alignItems: 'center',
955
+ justifyContent: 'center',
956
+ },
957
+ unitText: {
958
+ fontSize: sp(12),
959
+ fontWeight: '600',
960
+ },
961
+ pickerWrapper: {
962
+ height: ITEM_HEIGHT * VISIBLE_ITEMS,
963
+ position: 'relative',
964
+ width: '100%',
965
+ overflow: 'visible',
966
+ },
967
+ highlightBar: {
968
+ position: 'absolute',
969
+ top: ITEM_HEIGHT * ((VISIBLE_ITEMS - 1) / 2),
970
+ left: -wp(16),
971
+ right: -wp(16),
972
+ height: ITEM_HEIGHT,
973
+ backgroundColor: WHEEL_SELECTION_BACKGROUND_COLOR,
974
+ zIndex: 0,
975
+ },
976
+ topMask: {
977
+ position: 'absolute',
978
+ top: 0,
979
+ left: 0,
980
+ right: 0,
981
+ height: ITEM_HEIGHT * ((VISIBLE_ITEMS - 1) / 2),
982
+ zIndex: 2,
983
+ },
984
+ bottomMask: {
985
+ position: 'absolute',
986
+ bottom: 0,
987
+ left: 0,
988
+ right: 0,
989
+ height: ITEM_HEIGHT * ((VISIBLE_ITEMS - 1) / 2),
990
+ zIndex: 2,
991
+ },
992
+ columnsRow: {
993
+ flexDirection: 'row',
994
+ alignItems: 'stretch',
995
+ justifyContent: 'space-between',
996
+ zIndex: 1,
997
+ },
998
+ footer: {
999
+ paddingTop: wp(12),
1000
+ },
1001
+ });