@tarojs/components-react 4.1.12-beta.37 → 4.1.12-beta.39

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.
@@ -11,16 +11,18 @@ 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
20
+ forwardedRef,
21
+ disableDefaultSize = false
21
22
  } = props,
22
- reset = __rest(props, ["className", "style", "src", "mode", "onError", "lazyLoad", "imgProps", "forwardedRef"]);
23
+ reset = __rest(props, ["className", "style", "src", "mode", "onError", "lazyLoad", "imgProps", "forwardedRef", "disableDefaultSize"]);
23
24
  const cls = classNames('taro-img', {
25
+ 'taro-img--with-default-host-size': !disableDefaultSize,
24
26
  'taro-img__widthfix': mode === 'widthFix'
25
27
  }, className);
26
28
  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}\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,WAA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A,GAAG,EAAEE,GAAG,IAAK/C,MAAM,CAACiC,OAAO,GAAGc,GAAK;AACnC1C,MAAAA,SAAS,EAAEY,MAAO;AAClBV,MAAAA,GAAG,EAAEA,GAAI;AACTgB,MAAAA,MAAM,EAAEH,WAAY;AACpBX,MAAAA,OAAO,EAAEA,OAAQ;MAAA,GACbE;KACJ;AACH,GACE,CAAC;AAEV;AAEA,YAAeqC,yBAAyB,CAAClD,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 /** 为 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,MAAM,GAAGE,WAAW,CAAC,GAAGC,QAAQ,CAAC,KAAK,CAAC;EACvC,MAAM;MACJC,SAAS;MACTC,KAAK;MACLC,GAAG;MACHC,IAAI;MACJC,OAAO;MACPC,QAAQ;MACRC,QAAQ;MACRC,YAAY;AACZC,MAAAA,kBAAkB,GAAG;AAEnB,KAAA,GAAAd,KAAK;IADJe,KAAK,GACNC,MAAA,CAAAhB,KAAK,EAXH,CA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,EAAEA,OAAQ;MAAA,GACbE;KACJ;AACH,GACE,CAAC;AAEV;AAEA,YAAesC,yBAAyB,CAACnD,KAAK,CAAC;;;;"}
@@ -12,6 +12,80 @@ const getIndicatorStyle = lineColor => {
12
12
  borderBottomColor: lineColor
13
13
  };
14
14
  };
15
+ // 大屏方案版本要求
16
+ const MIN_DESIGN_APP_VERSION = 16;
17
+ const MIN_APP_VERSION = '15.7.0';
18
+ // semver 版本比较
19
+ const isAppVersionAtLeast = (version, min) => {
20
+ var _a, _b;
21
+ if (!version || typeof version !== 'string') return false;
22
+ const parts = v => {
23
+ const m = String(v).trim().match(/^(\d+)(?:\.(\d+))?(?:\.(\d+))?/);
24
+ if (!m) return [];
25
+ return [parseInt(m[1], 10) || 0, parseInt(m[2] || '0', 10) || 0, parseInt(m[3] || '0', 10) || 0];
26
+ };
27
+ const a = parts(version);
28
+ const b = parts(min);
29
+ if (a.length === 0) return false;
30
+ if (b.length === 0) return true;
31
+ for (let i = 0; i < Math.max(a.length, b.length); i++) {
32
+ const da = (_a = a[i]) !== null && _a !== void 0 ? _a : 0;
33
+ const db = (_b = b[i]) !== null && _b !== void 0 ? _b : 0;
34
+ if (da > db) return true;
35
+ if (da < db) return false;
36
+ }
37
+ return true;
38
+ };
39
+ // 读取 JDMobileConfig,异常时返回 undefined
40
+ const tryGetMobileConfigSync = opt => {
41
+ var _a;
42
+ try {
43
+ const fn = (_a = Taro.JDMobileConfig) === null || _a === void 0 ? void 0 : _a.getMobileConfigSync;
44
+ if (typeof fn !== 'function') return undefined;
45
+ return fn(opt);
46
+ } catch (_b) {
47
+ return undefined;
48
+ }
49
+ };
50
+ // 判断是否启用测量值缩放适配(true=启用, false=使用系统侧缩放)
51
+ const resolveUseMeasuredScale = res => {
52
+ // H5/weapp 不参与大屏系数
53
+ if (process.env.TARO_ENV === 'h5' || process.env.TARO_ENV === 'weapp') {
54
+ return false;
55
+ }
56
+ // 条件1: designAppVersion < 16,不满足则使用系统侧缩放
57
+ const designAppVersionRaw = res.designAppVersion;
58
+ const designAppVersionMajor = designAppVersionRaw != null ? parseInt(String(designAppVersionRaw).trim(), 10) : Number.NaN;
59
+ if (!Number.isFinite(designAppVersionMajor) || designAppVersionMajor < MIN_DESIGN_APP_VERSION) {
60
+ return false;
61
+ }
62
+ // 条件2: appVersion < 15.7.0,不满足则使用系统侧缩放
63
+ if (!isAppVersionAtLeast(res.version, MIN_APP_VERSION)) {
64
+ return false;
65
+ }
66
+ // 条件3: 平台判断
67
+ const platform = String(res.platform || '').toLowerCase();
68
+ if (platform === 'harmony') {
69
+ return true;
70
+ }
71
+ if (platform === 'android') {
72
+ const raw = tryGetMobileConfigSync({
73
+ space: 'taro',
74
+ configName: 'config',
75
+ key: 'disableFixBoundingScaleRatio'
76
+ });
77
+ return raw !== 1 && raw !== '1';
78
+ }
79
+ if (platform === 'ios') {
80
+ const raw = tryGetMobileConfigSync({
81
+ space: 'Taro',
82
+ configName: 'excutor',
83
+ key: 'disableBoundingScaleRatio'
84
+ });
85
+ return raw !== 1 && raw !== '1';
86
+ }
87
+ return false;
88
+ };
15
89
  // 辅助函数:计算 lengthScaleRatio
16
90
  const calculateLengthScaleRatio = res => {
17
91
  let lengthScaleRatio = res === null || res === void 0 ? void 0 : res.lengthScaleRatio;
@@ -50,6 +124,29 @@ const setTargetScrollTopWithScale = function (setTargetScrollTop, baseValue, ran
50
124
  setTargetScrollTop(finalValue);
51
125
  }
52
126
  };
127
+ // 根据 scrollTop 计算选中索引
128
+ // 系统侧缩放模式:scrollHeight 已被系统缩放,直接相除即可
129
+ // 自行缩放模式:需要除以 ratio 换算(harmony 特殊处理,ratio 已内嵌在 itemHeight 中)
130
+ const getSelectedIndex = function (scrollTop, itemHeight) {
131
+ let lengthScaleRatio = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
132
+ let useMeasuredScale = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
133
+ if (!useMeasuredScale || process.env.TARO_PLATFORM === 'harmony') {
134
+ return Math.round(scrollTop / itemHeight);
135
+ }
136
+ return Math.round(scrollTop / lengthScaleRatio / itemHeight);
137
+ };
138
+ // 计算单项高度(返回设计稿值)
139
+ const calculateItemHeight = function (scrollView, lengthScaleRatio) {
140
+ let useMeasuredScale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
141
+ if (process.env.TARO_PLATFORM === 'harmony') {
142
+ return useMeasuredScale ? PICKER_LINE_HEIGHT * lengthScaleRatio : PICKER_LINE_HEIGHT;
143
+ }
144
+ if (scrollView && (scrollView === null || scrollView === void 0 ? void 0 : scrollView.scrollHeight)) {
145
+ return useMeasuredScale ? scrollView.scrollHeight / lengthScaleRatio / scrollView.childNodes.length : scrollView.scrollHeight / scrollView.childNodes.length;
146
+ }
147
+ console.warn('Height measurement anomaly');
148
+ return PICKER_LINE_HEIGHT;
149
+ };
53
150
  function PickerGroupBasic(props) {
54
151
  const {
55
152
  range = [],
@@ -70,35 +167,25 @@ function PickerGroupBasic(props) {
70
167
  // 触摸状态用于优化用户体验
71
168
  const [isTouching, setIsTouching] = React.useState(false);
72
169
  const lengthScaleRatioRef = React.useRef(1);
170
+ const useMeasuredScaleRef = React.useRef(false);
73
171
  const itemHeightRef = React.useRef(PICKER_LINE_HEIGHT);
74
- // 初始化时计算 lengthScaleRatio
172
+ // 初始化时计算 lengthScaleRatio 并判定缩放模式
75
173
  React.useEffect(() => {
76
174
  Taro.getSystemInfo({
77
175
  success: res => {
78
176
  lengthScaleRatioRef.current = calculateLengthScaleRatio(res);
177
+ useMeasuredScaleRef.current = resolveUseMeasuredScale(res);
178
+ itemHeightRef.current = calculateItemHeight(scrollViewRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
79
179
  },
80
180
  fail: () => {
81
- // 失败时使用默认值 1
82
181
  lengthScaleRatioRef.current = 1;
182
+ useMeasuredScaleRef.current = false;
83
183
  }
84
184
  });
85
185
  }, []);
86
186
  React.useEffect(() => {
87
- var _a;
88
- if (process.env.TARO_PLATFORM === 'harmony') {
89
- itemHeightRef.current = PICKER_LINE_HEIGHT * lengthScaleRatioRef.current;
90
- } else {
91
- if (scrollViewRef.current && ((_a = scrollViewRef.current) === null || _a === void 0 ? void 0 : _a.scrollHeight)) {
92
- itemHeightRef.current = scrollViewRef.current.scrollHeight / scrollViewRef.current.childNodes.length;
93
- } else {
94
- console.warn('Height measurement anomaly');
95
- }
96
- }
187
+ itemHeightRef.current = calculateItemHeight(scrollViewRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
97
188
  }, [range.length]); // 只在range长度变化时重新计算
98
- // 获取选中的索引
99
- const getSelectedIndex = scrollTop => {
100
- return Math.round(scrollTop / itemHeightRef.current);
101
- };
102
189
  // 当selectedIndex变化时,调整滚动位置
103
190
  React.useEffect(() => {
104
191
  if (scrollViewRef.current && range.length > 0 && !isTouching) {
@@ -120,7 +207,7 @@ function PickerGroupBasic(props) {
120
207
  isCenterTimerId.current = setTimeout(() => {
121
208
  if (!scrollViewRef.current) return;
122
209
  const scrollTop = scrollViewRef.current.scrollTop;
123
- const newIndex = getSelectedIndex(scrollTop);
210
+ const newIndex = getSelectedIndex(scrollTop, itemHeightRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
124
211
  setIsTouching(false);
125
212
  const baseValue = newIndex * itemHeightRef.current;
126
213
  const randomOffset = Math.random() * 0.001; // 随机数为了在一个项内滚动时强制刷新
@@ -141,7 +228,7 @@ function PickerGroupBasic(props) {
141
228
  isCenterTimerId.current = null;
142
229
  }
143
230
  const scrollTop = scrollViewRef.current.scrollTop;
144
- const newIndex = getSelectedIndex(scrollTop);
231
+ const newIndex = getSelectedIndex(scrollTop, itemHeightRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
145
232
  if (newIndex !== currentIndex) {
146
233
  setCurrentIndex(newIndex);
147
234
  }
@@ -214,34 +301,25 @@ function PickerGroupTime(props) {
214
301
  const [currentIndex, setCurrentIndex] = React.useState(selectedIndex);
215
302
  const [isTouching, setIsTouching] = React.useState(false);
216
303
  const lengthScaleRatioRef = React.useRef(1);
304
+ const useMeasuredScaleRef = React.useRef(false);
217
305
  const itemHeightRef = React.useRef(PICKER_LINE_HEIGHT);
218
- // 初始化时计算 lengthScaleRatio
306
+ // 初始化时计算 lengthScaleRatio 并判定缩放模式
219
307
  React.useEffect(() => {
220
308
  Taro.getSystemInfo({
221
309
  success: res => {
222
310
  lengthScaleRatioRef.current = calculateLengthScaleRatio(res);
311
+ useMeasuredScaleRef.current = resolveUseMeasuredScale(res);
312
+ itemHeightRef.current = calculateItemHeight(scrollViewRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
223
313
  },
224
314
  fail: () => {
225
- // 失败时使用默认值 1
226
315
  lengthScaleRatioRef.current = 1;
316
+ useMeasuredScaleRef.current = false;
227
317
  }
228
318
  });
229
319
  }, []);
230
320
  React.useEffect(() => {
231
- var _a;
232
- if (process.env.TARO_PLATFORM === 'harmony') {
233
- itemHeightRef.current = PICKER_LINE_HEIGHT * lengthScaleRatioRef.current;
234
- } else {
235
- if (scrollViewRef.current && ((_a = scrollViewRef.current) === null || _a === void 0 ? void 0 : _a.scrollHeight)) {
236
- itemHeightRef.current = scrollViewRef.current.scrollHeight / scrollViewRef.current.childNodes.length;
237
- } else {
238
- console.warn('Height measurement anomaly');
239
- }
240
- }
321
+ itemHeightRef.current = calculateItemHeight(scrollViewRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
241
322
  }, [range.length]); // 只在range长度变化时重新计算
242
- const getSelectedIndex = scrollTop => {
243
- return Math.round(scrollTop / itemHeightRef.current);
244
- };
245
323
  // 当selectedIndex变化时,调整滚动位置
246
324
  React.useEffect(() => {
247
325
  if (scrollViewRef.current && range.length > 0 && !isTouching) {
@@ -263,7 +341,7 @@ function PickerGroupTime(props) {
263
341
  isCenterTimerId.current = setTimeout(() => {
264
342
  if (!scrollViewRef.current) return;
265
343
  const scrollTop = scrollViewRef.current.scrollTop;
266
- const newIndex = getSelectedIndex(scrollTop);
344
+ const newIndex = getSelectedIndex(scrollTop, itemHeightRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
267
345
  setIsTouching(false);
268
346
  // 调用updateIndex执行限位逻辑,获取是否触发了限位
269
347
  const isLimited = Boolean(updateIndex(newIndex, columnId, true));
@@ -284,7 +362,7 @@ function PickerGroupTime(props) {
284
362
  isCenterTimerId.current = null;
285
363
  }
286
364
  const scrollTop = scrollViewRef.current.scrollTop;
287
- const newIndex = getSelectedIndex(scrollTop);
365
+ const newIndex = getSelectedIndex(scrollTop, itemHeightRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
288
366
  if (newIndex !== currentIndex) {
289
367
  setCurrentIndex(newIndex);
290
368
  }
@@ -355,34 +433,25 @@ function PickerGroupDate(props) {
355
433
  const [currentIndex, setCurrentIndex] = React.useState(selectedIndex);
356
434
  const [isTouching, setIsTouching] = React.useState(false);
357
435
  const lengthScaleRatioRef = React.useRef(1);
436
+ const useMeasuredScaleRef = React.useRef(false);
358
437
  const itemHeightRef = React.useRef(PICKER_LINE_HEIGHT);
359
- // 初始化时计算 lengthScaleRatio
438
+ // 初始化时计算 lengthScaleRatio 并判定缩放模式
360
439
  React.useEffect(() => {
361
440
  Taro.getSystemInfo({
362
441
  success: res => {
363
442
  lengthScaleRatioRef.current = calculateLengthScaleRatio(res);
443
+ useMeasuredScaleRef.current = resolveUseMeasuredScale(res);
444
+ itemHeightRef.current = calculateItemHeight(scrollViewRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
364
445
  },
365
446
  fail: () => {
366
- // 失败时使用默认值 1
367
447
  lengthScaleRatioRef.current = 1;
448
+ useMeasuredScaleRef.current = false;
368
449
  }
369
450
  });
370
451
  }, []);
371
452
  React.useEffect(() => {
372
- var _a;
373
- if (process.env.TARO_PLATFORM === 'harmony') {
374
- itemHeightRef.current = PICKER_LINE_HEIGHT * lengthScaleRatioRef.current;
375
- } else {
376
- if (scrollViewRef.current && ((_a = scrollViewRef.current) === null || _a === void 0 ? void 0 : _a.scrollHeight)) {
377
- itemHeightRef.current = scrollViewRef.current.scrollHeight / scrollViewRef.current.childNodes.length;
378
- } else {
379
- console.warn('Height measurement anomaly');
380
- }
381
- }
453
+ itemHeightRef.current = calculateItemHeight(scrollViewRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
382
454
  }, [range.length]); // 只在range长度变化时重新计算
383
- const getSelectedIndex = scrollTop => {
384
- return Math.round(scrollTop / itemHeightRef.current);
385
- };
386
455
  // 当selectedIndex变化时,调整滚动位置
387
456
  React.useEffect(() => {
388
457
  if (scrollViewRef.current && range.length > 0 && !isTouching) {
@@ -404,7 +473,7 @@ function PickerGroupDate(props) {
404
473
  isCenterTimerId.current = setTimeout(() => {
405
474
  if (!scrollViewRef.current) return;
406
475
  const scrollTop = scrollViewRef.current.scrollTop;
407
- const newIndex = getSelectedIndex(scrollTop);
476
+ const newIndex = getSelectedIndex(scrollTop, itemHeightRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
408
477
  setIsTouching(false);
409
478
  const baseValue = newIndex * itemHeightRef.current;
410
479
  const randomOffset = Math.random() * 0.001; // 随机数为了在一个项内滚动时强制刷新
@@ -427,7 +496,7 @@ function PickerGroupDate(props) {
427
496
  isCenterTimerId.current = null;
428
497
  }
429
498
  const scrollTop = scrollViewRef.current.scrollTop;
430
- const newIndex = getSelectedIndex(scrollTop);
499
+ const newIndex = getSelectedIndex(scrollTop, itemHeightRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
431
500
  if (newIndex !== currentIndex) {
432
501
  setCurrentIndex(newIndex);
433
502
  }
@@ -498,40 +567,31 @@ function PickerGroupRegion(props) {
498
567
  const [currentIndex, setCurrentIndex] = React.useState(selectedIndex);
499
568
  const [isTouching, setIsTouching] = React.useState(false);
500
569
  const lengthScaleRatioRef = React.useRef(1);
570
+ const useMeasuredScaleRef = React.useRef(false);
501
571
  const itemHeightRef = React.useRef(PICKER_LINE_HEIGHT);
502
572
  const isUserBeginScrollRef = React.useRef(false);
503
- // 初始化时计算 lengthScaleRatio
573
+ // 初始化时计算 lengthScaleRatio 并判定缩放模式
504
574
  React.useEffect(() => {
505
575
  Taro.getSystemInfo({
506
576
  success: res => {
507
577
  lengthScaleRatioRef.current = calculateLengthScaleRatio(res);
578
+ useMeasuredScaleRef.current = resolveUseMeasuredScale(res);
579
+ itemHeightRef.current = calculateItemHeight(scrollViewRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
508
580
  },
509
581
  fail: () => {
510
- // 失败时使用默认值 1
511
582
  lengthScaleRatioRef.current = 1;
583
+ useMeasuredScaleRef.current = false;
512
584
  }
513
585
  });
514
586
  }, []);
515
587
  React.useEffect(() => {
516
- var _a;
517
- if (process.env.TARO_PLATFORM === 'harmony') {
518
- itemHeightRef.current = PICKER_LINE_HEIGHT * lengthScaleRatioRef.current;
519
- } else {
520
- if (scrollViewRef.current && ((_a = scrollViewRef.current) === null || _a === void 0 ? void 0 : _a.scrollHeight)) {
521
- itemHeightRef.current = scrollViewRef.current.scrollHeight / scrollViewRef.current.childNodes.length;
522
- } else {
523
- console.warn('Height measurement anomaly');
524
- }
525
- }
588
+ itemHeightRef.current = calculateItemHeight(scrollViewRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
526
589
  }, [range.length]); // 只在range长度变化时重新计算
527
- const getSelectedIndex = scrollTop => {
528
- return Math.round(scrollTop / itemHeightRef.current);
529
- };
530
590
  // 当selectedIndex变化时,调整滚动位置
531
591
  React.useEffect(() => {
532
592
  if (scrollViewRef.current && range.length > 0 && !isTouching) {
533
593
  const baseValue = selectedIndex * itemHeightRef.current;
534
- setTargetScrollTopWithScale(setTargetScrollTop, baseValue);
594
+ setTargetScrollTopWithScale(setTargetScrollTop, baseValue, undefined, lengthScaleRatioRef.current);
535
595
  setCurrentIndex(selectedIndex);
536
596
  }
537
597
  }, [selectedIndex, range]);
@@ -547,7 +607,7 @@ function PickerGroupRegion(props) {
547
607
  isCenterTimerId.current = setTimeout(() => {
548
608
  if (!scrollViewRef.current) return;
549
609
  const scrollTop = scrollViewRef.current.scrollTop;
550
- const newIndex = getSelectedIndex(scrollTop);
610
+ const newIndex = getSelectedIndex(scrollTop, itemHeightRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
551
611
  setIsTouching(false);
552
612
  const baseValue = newIndex * itemHeightRef.current;
553
613
  const randomOffset = Math.random() * 0.001; // 随机数为了在一个项内滚动时强制刷新
@@ -563,7 +623,7 @@ function PickerGroupRegion(props) {
563
623
  isCenterTimerId.current = null;
564
624
  }
565
625
  const scrollTop = scrollViewRef.current.scrollTop;
566
- const newIndex = getSelectedIndex(scrollTop);
626
+ const newIndex = getSelectedIndex(scrollTop, itemHeightRef.current, lengthScaleRatioRef.current, useMeasuredScaleRef.current);
567
627
  if (newIndex !== currentIndex) {
568
628
  setCurrentIndex(newIndex);
569
629
  }