@tarojs/components-react 4.2.1-beta.2 → 4.2.1

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 (77) hide show
  1. package/dist/components/image/index.js +3 -5
  2. package/dist/components/image/index.js.map +1 -1
  3. package/dist/components/picker/index.js +38 -110
  4. package/dist/components/picker/index.js.map +1 -1
  5. package/dist/components/picker/picker-group.js +127 -477
  6. package/dist/components/picker/picker-group.js.map +1 -1
  7. package/dist/components/refresher/index.js +5 -5
  8. package/dist/components/refresher/index.js.map +1 -1
  9. package/dist/components/scroll-view/index.js +36 -80
  10. package/dist/components/scroll-view/index.js.map +1 -1
  11. package/dist/index.css +1 -1
  12. package/dist/index.js +2 -6
  13. package/dist/index.js.map +1 -1
  14. package/dist/original/components/image/index.js +3 -5
  15. package/dist/original/components/image/index.js.map +1 -1
  16. package/dist/original/components/image/style/index.scss +1 -5
  17. package/dist/original/components/picker/index.js +38 -110
  18. package/dist/original/components/picker/index.js.map +1 -1
  19. package/dist/original/components/picker/picker-group.js +127 -477
  20. package/dist/original/components/picker/picker-group.js.map +1 -1
  21. package/dist/original/components/picker/style/index.scss +8 -9
  22. package/dist/original/components/refresher/index.js +5 -5
  23. package/dist/original/components/refresher/index.js.map +1 -1
  24. package/dist/original/components/scroll-view/index.js +36 -80
  25. package/dist/original/components/scroll-view/index.js.map +1 -1
  26. package/dist/original/index.js +2 -6
  27. package/dist/original/index.js.map +1 -1
  28. package/dist/solid/components/image/index.js +3 -5
  29. package/dist/solid/components/image/index.js.map +1 -1
  30. package/dist/solid/components/picker/index.js +45 -121
  31. package/dist/solid/components/picker/index.js.map +1 -1
  32. package/dist/solid/components/picker/picker-group.js +151 -500
  33. package/dist/solid/components/picker/picker-group.js.map +1 -1
  34. package/dist/solid/components/refresher/index.js +5 -5
  35. package/dist/solid/components/refresher/index.js.map +1 -1
  36. package/dist/solid/components/scroll-view/index.js +40 -84
  37. package/dist/solid/components/scroll-view/index.js.map +1 -1
  38. package/dist/solid/index.css +1 -1
  39. package/dist/solid/index.js +1 -1
  40. package/package.json +6 -8
  41. package/dist/components/map/MapContext.js +0 -628
  42. package/dist/components/map/MapContext.js.map +0 -1
  43. package/dist/components/map/MapCustomCallout.js +0 -91
  44. package/dist/components/map/MapCustomCallout.js.map +0 -1
  45. package/dist/components/map/common.js +0 -4
  46. package/dist/components/map/common.js.map +0 -1
  47. package/dist/components/map/createMapContext.js +0 -34
  48. package/dist/components/map/createMapContext.js.map +0 -1
  49. package/dist/components/map/handler.js +0 -50
  50. package/dist/components/map/handler.js.map +0 -1
  51. package/dist/components/map/index.js +0 -329
  52. package/dist/components/map/index.js.map +0 -1
  53. package/dist/components/switch/index.js +0 -125
  54. package/dist/components/switch/index.js.map +0 -1
  55. package/dist/components/switch/style/index.scss.js +0 -4
  56. package/dist/components/switch/style/index.scss.js.map +0 -1
  57. package/dist/contexts/ScrollElementContext.js +0 -6
  58. package/dist/contexts/ScrollElementContext.js.map +0 -1
  59. package/dist/original/components/map/MapContext.js +0 -628
  60. package/dist/original/components/map/MapContext.js.map +0 -1
  61. package/dist/original/components/map/MapCustomCallout.js +0 -91
  62. package/dist/original/components/map/MapCustomCallout.js.map +0 -1
  63. package/dist/original/components/map/common.js +0 -4
  64. package/dist/original/components/map/common.js.map +0 -1
  65. package/dist/original/components/map/createMapContext.js +0 -34
  66. package/dist/original/components/map/createMapContext.js.map +0 -1
  67. package/dist/original/components/map/handler.js +0 -50
  68. package/dist/original/components/map/handler.js.map +0 -1
  69. package/dist/original/components/map/index.js +0 -329
  70. package/dist/original/components/map/index.js.map +0 -1
  71. package/dist/original/components/switch/index.js +0 -125
  72. package/dist/original/components/switch/index.js.map +0 -1
  73. package/dist/original/components/switch/style/index.scss +0 -35
  74. package/dist/original/contexts/ScrollElementContext.js +0 -6
  75. package/dist/original/contexts/ScrollElementContext.js.map +0 -1
  76. package/dist/solid/contexts/ScrollElementContext.js +0 -6
  77. package/dist/solid/contexts/ScrollElementContext.js.map +0 -1
@@ -11,18 +11,16 @@ function Image(props) {
11
11
  const [, setIsLoaded] = useState(false);
12
12
  const {
13
13
  className,
14
- style,
14
+ style = {},
15
15
  src,
16
16
  mode,
17
17
  onError,
18
18
  lazyLoad,
19
19
  imgProps,
20
- forwardedRef,
21
- disableDefaultSize = false
20
+ forwardedRef
22
21
  } = props,
23
- reset = __rest(props, ["className", "style", "src", "mode", "onError", "lazyLoad", "imgProps", "forwardedRef", "disableDefaultSize"]);
22
+ reset = __rest(props, ["className", "style", "src", "mode", "onError", "lazyLoad", "imgProps", "forwardedRef"]);
24
23
  const cls = classNames('taro-img', {
25
- 'taro-img--with-default-host-size': !disableDefaultSize,
26
24
  'taro-img__widthfix': mode === 'widthFix'
27
25
  }, className);
28
26
  const imgCls = classNames('taro-img__mode-' + (mode || 'scaleToFill').toLowerCase().replace(/\s/g, ''));
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/components/image/index.tsx"],"sourcesContent":["import './style/index.scss'\n\nimport classNames from 'classnames'\n\nimport { createForwardRefComponent } from '../../utils'\nimport { useCallback, useEffect, useRef, useState } from '../../utils/hooks'\n\nimport type React from 'react'\n\ninterface IProps extends React.HTMLAttributes<HTMLDivElement> {\n src: string\n mode: string\n onError: () => void\n onLoad: (e) => void\n lazyLoad?: boolean\n imgProps?: Record<string, any>\n forwardedRef?: React.MutableRefObject<HTMLDivElement>\n /** 为 true 时不挂载默认占位尺寸(320×240),由业务 style/class 决定容器大小 */\n disableDefaultSize?: boolean\n}\n\nfunction Image (props: IProps) {\n const imgRef = useRef<HTMLImageElement | null>(null)\n const observer = useRef<Partial<IntersectionObserver>>({})\n const [, setIsLoaded] = useState(false)\n const {\n className,\n style,\n src,\n mode,\n onError,\n lazyLoad,\n imgProps,\n forwardedRef,\n disableDefaultSize = false,\n ...reset\n } = props\n\n const cls = classNames(\n 'taro-img',\n {\n 'taro-img--with-default-host-size': !disableDefaultSize,\n 'taro-img__widthfix': mode === 'widthFix'\n },\n className\n )\n const imgCls = classNames(\n 'taro-img__mode-' +\n (mode || 'scaleToFill').toLowerCase().replace(/\\s/g, '')\n )\n\n const imageOnLoad = useCallback((e) => {\n const { onLoad } = props\n Object.defineProperty(e, 'detail', {\n enumerable: true,\n writable: true,\n value: {\n width: e.target.width,\n height: e.target.height\n }\n })\n\n onLoad && onLoad(e)\n }, [props])\n\n useEffect(() => {\n if (lazyLoad) {\n observer.current = new IntersectionObserver(\n entries => {\n // 异步 api 关系\n if (entries[entries.length - 1].isIntersecting) {\n setIsLoaded(true)\n // findDOMNode(this).children[0].src = src\n imgRef.current!.src = src\n }\n },\n {\n rootMargin: '300px 0px'\n }\n )\n observer.current.observe?.(imgRef.current!)\n }\n\n return () => {\n observer.current?.disconnect?.()\n }\n }, [lazyLoad, src])\n\n return (\n <div className={cls} style={style} ref={forwardedRef} {...reset}>\n {lazyLoad ? (\n <img\n ref={img => (imgRef.current = img)}\n className={imgCls}\n data-src={src}\n onLoad={imageOnLoad}\n onError={onError}\n {...imgProps}\n />\n ) : (\n <img\n ref={img => (imgRef.current = img)}\n className={imgCls}\n src={src}\n onLoad={imageOnLoad}\n onError={onError}\n {...imgProps}\n />\n )}\n </div>\n )\n}\n\nexport default createForwardRefComponent(Image)\n"],"names":["Image","props","imgRef","useRef","observer","setIsLoaded","useState","className","style","src","mode","onError","lazyLoad","imgProps","forwardedRef","disableDefaultSize","reset","__rest","cls","classNames","imgCls","toLowerCase","replace","imageOnLoad","useCallback","e","onLoad","Object","defineProperty","enumerable","writable","value","width","target","height","useEffect","current","IntersectionObserver","entries","length","isIntersecting","rootMargin","_b","_a","observe","call","disconnect","_jsx","ref","children","img","createForwardRefComponent"],"mappings":";;;;;;;AAqBA,SAASA,KAAKA,CAAEC,KAAa,EAAA;AAC3B,EAAA,MAAMC,MAAM,GAAGC,MAAM,CAA0B,IAAI,CAAC;AACpD,EAAA,MAAMC,QAAQ,GAAGD,MAAM,CAAgC,EAAE,CAAC;AAC1D,EAAA,MA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EAAEA,OAAQ;MAAA,GACbE;KAAS,CACb,gBAEFkC,GAAA,CAAA,KAAA,EAAA;AACEC,MAAAA,GAAG,EAAEE,GAAG,IAAKhD,MAAM,CAACkC,OAAO,GAAGc,GAAK;AACnC3C,MAAAA,SAAS,EAAEa,MAAO;AAClBX,MAAAA,GAAG,EAAEA,GAAI;AACTiB,MAAAA,MAAM,EAAEH,WAAY;AACpBZ,MAAAA,OAAO,EAAEA,OAAQ;MAAA,GACbE;KACJ;AACH,GACE,CAAC;AAEV;AAEA,YAAesC,yBAAyB,CAACnD,KAAK,CAAC;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/components/image/index.tsx"],"sourcesContent":["import './style/index.scss'\n\nimport classNames from 'classnames'\n\nimport { createForwardRefComponent } from '../../utils'\nimport { useCallback, useEffect, useRef, useState } from '../../utils/hooks'\n\nimport type React from 'react'\n\ninterface IProps extends React.HTMLAttributes<HTMLDivElement> {\n src: string\n mode: string\n onError: () => void\n onLoad: (e) => void\n lazyLoad?: boolean\n imgProps?: Record<string, any>\n forwardedRef?: React.MutableRefObject<HTMLDivElement>\n}\n\nfunction Image (props: IProps) {\n const imgRef = useRef<HTMLImageElement | null>(null)\n const observer = useRef<Partial<IntersectionObserver>>({})\n const [, setIsLoaded] = useState(false)\n const {\n className,\n style = {},\n src,\n mode,\n onError,\n lazyLoad,\n imgProps,\n forwardedRef,\n ...reset\n } = props\n\n const cls = classNames(\n 'taro-img',\n {\n 'taro-img__widthfix': mode === 'widthFix'\n },\n className\n )\n const imgCls = classNames(\n 'taro-img__mode-' +\n (mode || 'scaleToFill').toLowerCase().replace(/\\s/g, '')\n )\n\n const imageOnLoad = useCallback((e) => {\n const { onLoad } = props\n Object.defineProperty(e, 'detail', {\n enumerable: true,\n writable: true,\n value: {\n width: e.target.width,\n height: e.target.height\n }\n })\n\n onLoad && onLoad(e)\n }, [props])\n\n useEffect(() => {\n if (lazyLoad) {\n observer.current = new IntersectionObserver(\n entries => {\n // 异步 api 关系\n if (entries[entries.length - 1].isIntersecting) {\n setIsLoaded(true)\n // findDOMNode(this).children[0].src = src\n imgRef.current!.src = src\n }\n },\n {\n rootMargin: '300px 0px'\n }\n )\n observer.current.observe?.(imgRef.current!)\n }\n\n return () => {\n observer.current?.disconnect?.()\n }\n }, [lazyLoad, src])\n\n return (\n <div className={cls} style={style} ref={forwardedRef} {...reset}>\n {lazyLoad ? (\n <img\n ref={img => (imgRef.current = img)}\n className={imgCls}\n data-src={src}\n onLoad={imageOnLoad}\n onError={onError}\n {...imgProps}\n />\n ) : (\n <img\n ref={img => (imgRef.current = img)}\n className={imgCls}\n src={src}\n onLoad={imageOnLoad}\n onError={onError}\n {...imgProps}\n />\n )}\n </div>\n )\n}\n\nexport default createForwardRefComponent(Image)\n"],"names":["Image","props","imgRef","useRef","observer","setIsLoaded","useState","className","style","src","mode","onError","lazyLoad","imgProps","forwardedRef","reset","__rest","cls","classNames","imgCls","toLowerCase","replace","imageOnLoad","useCallback","e","onLoad","Object","defineProperty","enumerable","writable","value","width","target","height","useEffect","current","IntersectionObserver","entries","length","isIntersecting","rootMargin","_b","_a","observe","call","disconnect","_jsx","ref","children","img","createForwardRefComponent"],"mappings":";;;;;;;AAmBA,SAASA,KAAKA,CAAEC,KAAa,EAAA;AAC3B,EAAA,MAAMC,MAAM,GAAGC,MAAM,CAA0B,IAAI,CAAC;AACpD,EAAA,MAAMC,QAAQ,GAAGD,MAAM,CAAgC,EAAE,CAAC;AAC1D,EAAA,MAAM,GAAGE,WAAW,CAAC,GAAGC,QAAQ,CAAC,KAAK,CAAC;EACvC,MAAM;MACJC,SAAS;MACTC,KAAK,GAAG,EAAE;MACVC,GAAG;MACHC,IAAI;MACJC,OAAO;MACPC,QAAQ;MACRC,QAAQ;AACRC,MAAAA;AAAY,KAAA,GAEVb,KAAK;IADJc,KAAK,GAAAC,MAAA,CACNf,KAAK,EAVH,CAUL,WAAA,EAAA,OAAA,EAAA,KAAA,EAAA,MAAA,EAAA,SAAA,EAA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 +1,6 @@
1
1
  import { __rest } from 'tslib';
2
2
  import './style/index.scss.js';
3
3
  import { View } from '@tarojs/components';
4
- import Taro from '@tarojs/taro';
5
4
  import classNames from 'classnames';
6
5
  import React__default from 'react';
7
6
  import { verifyValue, verifyTime, hoursRange, minutesRange, verifyDate, getYearRange, getMonthRange, getDayRange, compareTime, omit } from '../../utils/index.js';
@@ -128,13 +127,12 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
128
127
  children,
129
128
  formType,
130
129
  lang,
131
- theme = 'light',
132
- enableClickItemScroll = true
130
+ theme = 'light'
133
131
  } = props,
134
- restProps = __rest(props, ["mode", "disabled", "range", "rangeKey", "value", "start", "end", "fields", "headerText", "level", "regionData", "textProps", "colors", "onChange", "onColumnChange", "onCancel", "children", "formType", "lang", "theme", "enableClickItemScroll"]);
132
+ restProps = __rest(props, ["mode", "disabled", "range", "rangeKey", "value", "start", "end", "fields", "headerText", "level", "regionData", "textProps", "colors", "onChange", "onColumnChange", "onCancel", "children", "formType", "lang", "theme"]);
135
133
  const indexRef = React__default.useRef([]);
136
134
  const pickerDateRef = React__default.useRef();
137
- // region:首次用户滚动初始化完成前不入库
135
+ // 记录是否是用户滚动
138
136
  const isInitializationCompletedRef = React__default.useRef(false);
139
137
  const [state, setState] = React__default.useState({
140
138
  pickerValue: value || EMPTY_ARRAY,
@@ -143,45 +141,14 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
143
141
  hidden: true,
144
142
  fadeOut: false,
145
143
  isWillLoadCalled: false,
146
- a11yTimeLimitColumnId: null,
147
- a11yTimeLimitNonce: 0
144
+ timestamp: 0 // 用以部分模式下强制刷新组件的的时间戳,多用于反复限位
148
145
  });
149
- // 安全区域底部距离
150
- const [safeAreaBottom, setSafeAreaBottom] = React__default.useState(0);
151
146
  // 在组件内部
152
147
  const [columnsCount, setColumnsCount] = React__default.useState(() => getRegionColumnsCount(level));
153
148
  // 只在level变化时更新列数
154
149
  React__default.useEffect(() => {
155
150
  setColumnsCount(getRegionColumnsCount(level));
156
151
  }, [level]);
157
- // 更新安全区域
158
- const updateSafeArea = React__default.useCallback(() => {
159
- try {
160
- const systemInfo = Taro.getSystemInfoSync();
161
- const {
162
- safeArea,
163
- windowHeight
164
- } = systemInfo;
165
- if (safeArea && windowHeight) {
166
- const lengthScaleRatio = systemInfo.lengthScaleRatio || 1;
167
- const bottom = (windowHeight - safeArea.bottom) / lengthScaleRatio;
168
- setSafeAreaBottom(Math.max(0, bottom));
169
- }
170
- } catch (e) {
171
- // H5 环境或其他异常情况,不设置安全区域
172
- setSafeAreaBottom(0);
173
- }
174
- }, []);
175
- // 初始化安全区域
176
- React__default.useEffect(() => {
177
- updateSafeArea();
178
- }, [updateSafeArea]);
179
- // 监听窗口变化(导航方式切换等)
180
- React__default.useEffect(() => {
181
- const handleResize = () => updateSafeArea();
182
- window.addEventListener('resize', handleResize);
183
- return () => window.removeEventListener('resize', handleResize);
184
- }, [updateSafeArea]);
185
152
  // 获取当前索引数组
186
153
  const getIndices = React__default.useCallback(() => {
187
154
  return indexRef.current;
@@ -232,36 +199,25 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
232
199
  const monthRange = getMonthRange(_start, _end, currentYear);
233
200
  const dayRange = getDayRange(_start, _end, currentYear, currentMonth);
234
201
  indexRef.current = [yearRange.indexOf(currentYear), monthRange.indexOf(currentMonth), dayRange.indexOf(currentDay)];
235
- // props 同步时始终刷新 _updateValue,避免取消后再开时日列草稿与索引不一致
236
- pickerDateRef.current = {
237
- _value,
238
- _start,
239
- _end,
240
- _updateValue: [currentYear, currentMonth, currentDay]
241
- };
202
+ if (!pickerDateRef.current || pickerDateRef.current._value.getTime() !== _value.getTime() || pickerDateRef.current._start.getTime() !== _start.getTime() || pickerDateRef.current._end.getTime() !== _end.getTime()) {
203
+ pickerDateRef.current = {
204
+ _value,
205
+ _start,
206
+ _end,
207
+ _updateValue: [currentYear, currentMonth, currentDay]
208
+ };
209
+ }
242
210
  } else if (mode === 'region') {
243
211
  // region 模式处理 - 验证数据
244
212
  if (!regionData) {
245
213
  console.error('Picker: regionData is required for region mode');
246
- indexRef.current = Array.from({
247
- length: columnsCount
248
- }, () => 0);
249
- setState(prev => Object.assign(Object.assign({}, prev), {
250
- selectedIndices: [...indexRef.current],
251
- pickerValue: value || EMPTY_ARRAY
252
- }));
214
+ indexRef.current = [0];
253
215
  return;
254
216
  }
255
217
  const validation = validateRegionData(regionData, 'Picker');
256
218
  if (!validation.valid) {
257
219
  console.error(validation.error);
258
- indexRef.current = Array.from({
259
- length: columnsCount
260
- }, () => 0);
261
- setState(prev => Object.assign(Object.assign({}, prev), {
262
- selectedIndices: [...indexRef.current],
263
- pickerValue: value || EMPTY_ARRAY
264
- }));
220
+ indexRef.current = [0];
265
221
  return;
266
222
  }
267
223
  // 获取列数
@@ -308,16 +264,16 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
308
264
  handleProps();
309
265
  }
310
266
  }, [handleProps, state.isWillLoadCalled, JSON.stringify(value)]);
311
- // 打开时按 props 重算索引,避免未确认的滑动与 indexRef 残留导致再开抖动
267
+ // 显示 Picker
312
268
  const showPicker = React__default.useCallback(() => {
313
269
  if (disabled) return;
314
270
  isInitializationCompletedRef.current = false;
315
- handleProps();
271
+ const newIndices = getIndices();
316
272
  setState(prev => Object.assign(Object.assign({}, prev), {
317
- hidden: false,
318
- a11yTimeLimitColumnId: null
273
+ selectedIndices: newIndices,
274
+ hidden: false
319
275
  }));
320
- }, [disabled, handleProps]);
276
+ }, [disabled, getIndices]);
321
277
  // 隐藏 Picker
322
278
  const hidePicker = React__default.useCallback(() => {
323
279
  isInitializationCompletedRef.current = false;
@@ -392,11 +348,11 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
392
348
  finalIndices = [...newIndices];
393
349
  hasLimited = true;
394
350
  }
351
+ // 触发限位,更新状态,其它状态不用主动触发滚动
395
352
  if (hasLimited) {
396
353
  setState(prev => Object.assign(Object.assign({}, prev), {
397
354
  selectedIndices: finalIndices,
398
- a11yTimeLimitColumnId: columnId,
399
- a11yTimeLimitNonce: prev.a11yTimeLimitNonce + 1
355
+ timestamp: Date.now()
400
356
  }));
401
357
  } else {
402
358
  setState(prev => Object.assign(Object.assign({}, prev), {
@@ -629,17 +585,11 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
629
585
  }
630
586
  });
631
587
  }, [onColumnChange]);
632
- const consumeTimeA11yLimitFocus = React__default.useCallback(() => {
633
- setState(prev => Object.assign(Object.assign({}, prev), {
634
- a11yTimeLimitColumnId: null
635
- }));
636
- }, []);
637
- // 取消时按 props 回同步索引,避免与 value 脱节
588
+ // 处理取消
638
589
  const handleCancel = React__default.useCallback(() => {
639
- handleProps();
640
590
  hidePicker();
641
591
  onCancel === null || onCancel === void 0 ? void 0 : onCancel();
642
- }, [handleProps, hidePicker, onCancel]);
592
+ }, [hidePicker, onCancel]);
643
593
  // 渲染选择器组
644
594
  const renderPickerGroup = React__default.useMemo(() => {
645
595
  switch (mode) {
@@ -653,16 +603,11 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
653
603
  columnId: String(index),
654
604
  selectedIndex: state.selectedIndices[index] // 传递对应列的selectedIndex
655
605
  ,
656
- colors: colors,
657
- enableClickItemScroll: enableClickItemScroll
606
+ colors: colors
658
607
  }, index));
659
608
  }
660
609
  case 'time':
661
610
  {
662
- const timeA11yLimitFocus = state.a11yTimeLimitColumnId != null ? {
663
- nonce: state.a11yTimeLimitNonce,
664
- columnId: state.a11yTimeLimitColumnId
665
- } : null;
666
611
  return [/*#__PURE__*/jsx(PickerGroup, {
667
612
  mode: "time",
668
613
  range: hoursRange,
@@ -670,24 +615,16 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
670
615
  columnId: "0",
671
616
  selectedIndex: state.selectedIndices[0] // 传递小时列的selectedIndex
672
617
  ,
673
- colors: colors,
674
- timeA11yLimitFocus: timeA11yLimitFocus,
675
- onTimeA11yLimitFocusConsumed: consumeTimeA11yLimitFocus,
676
- timeA11yLimitEventNonce: state.a11yTimeLimitNonce,
677
- enableClickItemScroll: enableClickItemScroll
678
- }, "hour"), /*#__PURE__*/jsx(PickerGroup, {
618
+ colors: colors
619
+ }, `hour-${state.timestamp}`), /*#__PURE__*/jsx(PickerGroup, {
679
620
  mode: "time",
680
621
  range: minutesRange,
681
622
  updateIndex: updateIndex,
682
623
  columnId: "1",
683
624
  selectedIndex: state.selectedIndices[1] // 传递分钟列的selectedIndex
684
625
  ,
685
- colors: colors,
686
- timeA11yLimitFocus: timeA11yLimitFocus,
687
- onTimeA11yLimitFocusConsumed: consumeTimeA11yLimitFocus,
688
- timeA11yLimitEventNonce: state.a11yTimeLimitNonce,
689
- enableClickItemScroll: enableClickItemScroll
690
- }, "minute")];
626
+ colors: colors
627
+ }, `minute-${state.timestamp}`)];
691
628
  }
692
629
  case 'date':
693
630
  {
@@ -712,8 +649,7 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
712
649
  columnId: "0",
713
650
  selectedIndex: state.selectedIndices[0] // 传递年份列的selectedIndex
714
651
  ,
715
- colors: colors,
716
- enableClickItemScroll: enableClickItemScroll
652
+ colors: colors
717
653
  }, `year`)];
718
654
  if (fields === 'month' || fields === 'day') {
719
655
  renderView.push(/*#__PURE__*/jsx(PickerGroup, {
@@ -724,8 +660,7 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
724
660
  columnId: "1",
725
661
  selectedIndex: state.selectedIndices[1] // 传递月份列的selectedIndex
726
662
  ,
727
- colors: colors,
728
- enableClickItemScroll: enableClickItemScroll
663
+ colors: colors
729
664
  }, `month`));
730
665
  }
731
666
  if (fields === 'day') {
@@ -737,8 +672,7 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
737
672
  columnId: "2",
738
673
  selectedIndex: state.selectedIndices[2] // 传递日期列的selectedIndex
739
674
  ,
740
- colors: colors,
741
- enableClickItemScroll: enableClickItemScroll
675
+ colors: colors
742
676
  }, `day`));
743
677
  }
744
678
  return renderView;
@@ -773,8 +707,7 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
773
707
  updateIndex: updateIndex,
774
708
  columnId: String(i),
775
709
  selectedIndex: state.selectedIndices[i],
776
- colors: colors,
777
- enableClickItemScroll: enableClickItemScroll
710
+ colors: colors
778
711
  }, `region-${i}`));
779
712
  }
780
713
  return columns;
@@ -787,11 +720,10 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
787
720
  columnId: "0",
788
721
  selectedIndex: state.selectedIndices[0] // 传递selector模式的selectedIndex
789
722
  ,
790
- colors: colors,
791
- enableClickItemScroll: enableClickItemScroll
723
+ colors: colors
792
724
  });
793
725
  }
794
- }, [mode, range, rangeKey, fields, updateIndex, updateDay, handleColumnChange, pickerDateRef.current, level, regionData, state.selectedIndices, state.a11yTimeLimitColumnId, state.a11yTimeLimitNonce, consumeTimeA11yLimitFocus, columnsCount, lang, colors, enableClickItemScroll]);
726
+ }, [mode, range, rangeKey, fields, updateIndex, updateDay, handleColumnChange, pickerDateRef.current, level, regionData, state.selectedIndices, columnsCount, lang, colors]);
795
727
  // 动画类名控制逻辑
796
728
  const clsMask = classNames('taro-picker__mask-overlay', 'taro-picker__animate-fade-in', {
797
729
  'taro-picker__animate-fade-out': state.fadeOut
@@ -805,9 +737,6 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
805
737
  const titleStyle = colors.titleColor ? {
806
738
  color: colors.titleColor
807
739
  } : null;
808
- const maskOverlayStyle = colors.maskColor ? {
809
- backgroundColor: colors.maskColor
810
- } : undefined;
811
740
  // 暴露方法给外部
812
741
  React__default.useImperativeHandle(ref, () => ({
813
742
  showPicker,
@@ -826,16 +755,15 @@ const Picker = /*#__PURE__*/React__default.forwardRef((props, ref) => {
826
755
  onClick: showPicker,
827
756
  children: children
828
757
  }), !state.hidden && /*#__PURE__*/jsxs(View, {
829
- className: classNames('taro-picker__overlay', `taro-picker__overlay--theme-${theme}`),
758
+ className: "taro-picker__overlay",
830
759
  children: [/*#__PURE__*/jsx(View, {
831
760
  className: clsMask,
832
- style: maskOverlayStyle,
833
761
  onClick: handleCancel
834
762
  }), /*#__PURE__*/jsxs(View, {
835
763
  className: clsSlider,
836
- style: Object.assign(Object.assign({}, backgroundStyle), {
837
- paddingBottom: safeAreaBottom ? `${safeAreaBottom}px` : undefined
838
- }),
764
+ ...(backgroundStyle ? {
765
+ style: backgroundStyle
766
+ } : {}),
839
767
  children: [/*#__PURE__*/jsxs(View, {
840
768
  className: "taro-picker__hd",
841
769
  ...(backgroundStyle ? {