@tarojs/components-advanced 4.1.12-beta.0 → 4.1.12-beta.10

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 (72) hide show
  1. package/dist/components/index.js +2 -0
  2. package/dist/components/index.js.map +1 -1
  3. package/dist/components/list/NoMore.d.ts +30 -0
  4. package/dist/components/list/NoMore.js +10 -0
  5. package/dist/components/list/NoMore.js.map +1 -0
  6. package/dist/components/list/hooks/useItemSizeCache.d.ts +13 -0
  7. package/dist/components/list/hooks/useItemSizeCache.js +40 -0
  8. package/dist/components/list/hooks/useItemSizeCache.js.map +1 -0
  9. package/dist/components/list/hooks/useListNestedScroll.d.ts +18 -0
  10. package/dist/components/list/hooks/useListNestedScroll.js +61 -0
  11. package/dist/components/list/hooks/useListNestedScroll.js.map +1 -0
  12. package/dist/components/list/hooks/useListScrollElementAttach.d.ts +21 -0
  13. package/dist/components/list/hooks/useListScrollElementAttach.js +86 -0
  14. package/dist/components/list/hooks/useListScrollElementAttach.js.map +1 -0
  15. package/dist/components/list/hooks/useListScrollElementAttachWeapp.d.ts +27 -0
  16. package/dist/components/list/hooks/useListScrollElementAttachWeapp.js +154 -0
  17. package/dist/components/list/hooks/useListScrollElementAttachWeapp.js.map +1 -0
  18. package/dist/components/list/hooks/useMeasureStartOffset.d.ts +12 -0
  19. package/dist/components/list/hooks/useMeasureStartOffset.js +84 -0
  20. package/dist/components/list/hooks/useMeasureStartOffset.js.map +1 -0
  21. package/dist/components/list/hooks/useMeasureStartOffsetWeapp.d.ts +13 -0
  22. package/dist/components/list/hooks/useMeasureStartOffsetWeapp.js +85 -0
  23. package/dist/components/list/hooks/useMeasureStartOffsetWeapp.js.map +1 -0
  24. package/dist/components/list/hooks/useRefresher.d.ts +74 -0
  25. package/dist/components/list/hooks/useRefresher.js +503 -0
  26. package/dist/components/list/hooks/useRefresher.js.map +1 -0
  27. package/dist/components/list/hooks/useResizeObserver.d.ts +26 -0
  28. package/dist/components/list/hooks/useResizeObserver.js +152 -0
  29. package/dist/components/list/hooks/useResizeObserver.js.map +1 -0
  30. package/dist/components/list/hooks/useScrollCorrection.d.ts +19 -0
  31. package/dist/components/list/hooks/useScrollCorrection.js +73 -0
  32. package/dist/components/list/hooks/useScrollCorrection.js.map +1 -0
  33. package/dist/components/list/hooks/useScrollParentAutoFind.d.ts +20 -0
  34. package/dist/components/list/hooks/useScrollParentAutoFind.js +81 -0
  35. package/dist/components/list/hooks/useScrollParentAutoFind.js.map +1 -0
  36. package/dist/components/list/index.d.ts +59 -3
  37. package/dist/components/list/index.js +997 -119
  38. package/dist/components/list/index.js.map +1 -1
  39. package/dist/components/list/utils.d.ts +16 -0
  40. package/dist/components/list/utils.js +19 -0
  41. package/dist/components/list/utils.js.map +1 -0
  42. package/dist/components/virtual-list/vue/list.d.ts +12 -12
  43. package/dist/components/virtual-waterfall/vue/waterfall.d.ts +11 -11
  44. package/dist/components/water-flow/flow-item.js +6 -4
  45. package/dist/components/water-flow/flow-item.js.map +1 -1
  46. package/dist/components/water-flow/flow-section.js +1 -1
  47. package/dist/components/water-flow/flow-section.js.map +1 -1
  48. package/dist/components/water-flow/interface.d.ts +14 -2
  49. package/dist/components/water-flow/root.d.ts +16 -2
  50. package/dist/components/water-flow/root.js +70 -28
  51. package/dist/components/water-flow/root.js.map +1 -1
  52. package/dist/components/water-flow/section.d.ts +1 -1
  53. package/dist/components/water-flow/section.js +12 -4
  54. package/dist/components/water-flow/section.js.map +1 -1
  55. package/dist/components/water-flow/utils.d.ts +4 -0
  56. package/dist/components/water-flow/utils.js +5 -1
  57. package/dist/components/water-flow/utils.js.map +1 -1
  58. package/dist/components/water-flow/water-flow.d.ts +1 -1
  59. package/dist/components/water-flow/water-flow.js +248 -27
  60. package/dist/components/water-flow/water-flow.js.map +1 -1
  61. package/dist/index.js +3 -0
  62. package/dist/index.js.map +1 -1
  63. package/dist/utils/index.d.ts +1 -0
  64. package/dist/utils/index.js +1 -0
  65. package/dist/utils/index.js.map +1 -1
  66. package/dist/utils/scrollElementContext.d.ts +15 -0
  67. package/dist/utils/scrollElementContext.js +14 -0
  68. package/dist/utils/scrollElementContext.js.map +1 -0
  69. package/dist/utils/scrollParent.d.ts +33 -0
  70. package/dist/utils/scrollParent.js +88 -0
  71. package/dist/utils/scrollParent.js.map +1 -0
  72. package/package.json +9 -8
@@ -1,11 +1,23 @@
1
- import { jsx, jsxs } from 'react/jsx-runtime';
1
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
2
  import { View, ScrollView } from '@tarojs/components';
3
+ import Taro from '@tarojs/taro';
3
4
  import React from 'react';
5
+ import '../../utils/index.js';
6
+ import { ScrollElementContextOrFallback } from '../../utils/scrollElementContext.js';
7
+ import { useItemSizeCache } from './hooks/useItemSizeCache.js';
8
+ import { useListNestedScroll } from './hooks/useListNestedScroll.js';
9
+ import { useListScrollElementAttach } from './hooks/useListScrollElementAttach.js';
10
+ import { useListScrollElementAttachWeapp } from './hooks/useListScrollElementAttachWeapp.js';
11
+ import { useRefresher, DEFAULT_REFRESHER_HEIGHT } from './hooks/useRefresher.js';
12
+ import { useResizeObserver } from './hooks/useResizeObserver.js';
13
+ import { useScrollCorrection } from './hooks/useScrollCorrection.js';
4
14
  import { ListItem } from './ListItem.js';
15
+ import { NoMore } from './NoMore.js';
5
16
  import { StickyHeader } from './StickyHeader.js';
6
17
  import { StickySection } from './StickySection.js';
18
+ import { isWeapp, isH5, supportsNativeRefresher } from './utils.js';
19
+ import { getScrollViewContextNode } from '../../utils/dom.js';
7
20
 
8
- // 工具:累加数组
9
21
  function accumulate(arr) {
10
22
  const result = [0];
11
23
  for (let i = 0; i < arr.length; i++) {
@@ -13,46 +25,286 @@ function accumulate(arr) {
13
25
  }
14
26
  return result;
15
27
  }
16
- // 检测抖动
17
28
  function isShaking(diffList) {
18
29
  if (diffList.length < 3)
19
30
  return false;
20
- // 检查是否有连续的正负交替
21
31
  const signs = diffList.map(diff => Math.sign(diff));
22
32
  let alternations = 0;
23
33
  for (let i = 1; i < signs.length; i++) {
24
- if (signs[i] !== 0 && signs[i] !== signs[i - 1]) {
34
+ if (signs[i] !== 0 && signs[i] !== signs[i - 1])
25
35
  alternations++;
26
- }
27
36
  }
28
- // 如果交替次数过多,认为是抖动
29
37
  return alternations >= 2;
30
38
  }
31
- const List = (props) => {
32
- const isH5 = process.env.TARO_ENV === 'h5';
33
- const { stickyHeader = false, space = 0, height = 400, width = '100%', showScrollbar = true, scrollTop: controlledScrollTop, scrollX = false, scrollY = true, onScroll, onScrollToUpper, onScrollToLower, upperThreshold = 0, lowerThreshold = 0, cacheCount = 2, style, children, } = props;
39
+ // 小程序端:判断 item 是否应该执行 SelectorQuery 测量(仅检查是否已测量过)
40
+ // SelectorQuery 是只读查询,不会触发 setData,滚动期间执行是安全的
41
+ function shouldMeasureWeappItem(index, measuredSet) {
42
+ return !measuredSet.has(index);
43
+ }
44
+ // 小程序端暂不外抛 onItemSizeChange,避免父层重渲染导致 List remount 引发回顶或空白
45
+ function weappDeferItemSizeChange(_index, _size, _onItemSizeChange) { }
46
+ /** 从 scroll 选项解析目标偏移量 */
47
+ function resolveScrollTargetOffset(options, isHorizontal) {
48
+ const opts = options !== null && options !== void 0 ? options : {};
49
+ const top = typeof opts.top === 'number' ? opts.top : undefined;
50
+ const left = typeof opts.left === 'number' ? opts.left : undefined;
51
+ let result = 0;
52
+ if (isHorizontal) {
53
+ if (typeof left === 'number')
54
+ result = left;
55
+ else if (typeof top === 'number')
56
+ result = top;
57
+ }
58
+ else {
59
+ if (typeof top === 'number')
60
+ result = top;
61
+ else if (typeof left === 'number')
62
+ result = left;
63
+ }
64
+ return Number.isFinite(result) ? result : 0;
65
+ }
66
+ // eslint-disable-next-line complexity -- List 多端/多模式逻辑集中,已抽离 useListNestedScroll、useListScrollElementAttach、resolveScrollTargetOffset 等
67
+ const InnerList = (props, ref) => {
68
+ var _a, _b, _c;
69
+ const { stickyHeader = false, space = 0, height = 400, width = '100%', showScrollbar = true, scrollTop: controlledScrollTop, scrollX = false, scrollY = true, onScroll, onScrollToUpper, onScrollToLower, onScrollStart, onScrollEnd, upperThreshold = 50, lowerThreshold = 50, cacheCount = 2, cacheExtent, enableBackToTop, className, style, children, nestedScroll, scrollElement, scrollRef: scrollRefProp, } = props;
34
70
  const isHorizontal = scrollX === true;
71
+ const listType = nestedScroll === true ? 'nested' : 'default';
72
+ const { effectiveScrollElement, effectiveStartOffset, effectiveStartOffsetRef, useScrollElementMode, needAutoFind, autoFindStatus, contentWrapperRef, contentId, } = useListNestedScroll(listType, scrollElement, undefined, isHorizontal);
35
73
  const DEFAULT_ITEM_WIDTH = 120;
36
74
  const DEFAULT_ITEM_HEIGHT = 40;
37
75
  // 滚动状态管理
38
76
  const containerRef = React.useRef(null);
77
+ // 生成唯一 List ID(用于小程序 ResizeObserver)
78
+ const listId = React.useMemo(() => `list-${Math.random().toString(36).slice(2, 11)}`, []);
39
79
  // 渲染偏移量 - 用于计算应该渲染哪些元素
40
80
  const [renderOffset, setRenderOffset] = React.useState(controlledScrollTop !== null && controlledScrollTop !== void 0 ? controlledScrollTop : 0);
41
- // 滚动视图偏移量 - 只在滚动结束或明确请求时更新到ScrollView
81
+ // 程序性滚动用的目标偏移;用户滑动期间不更新,避免与原生滚动冲突
42
82
  const [scrollViewOffset, setScrollViewOffset] = React.useState(controlledScrollTop !== null && controlledScrollTop !== void 0 ? controlledScrollTop : 0);
43
- const [containerLength] = React.useState(typeof (isHorizontal ? width : height) === 'number' ? (isHorizontal ? width : height) : 400);
83
+ // 用户正在滑动时不再向 ScrollView scrollTop,让滚动完全由原生接管
84
+ const [isUserScrolling, setIsUserScrolling] = React.useState(false);
85
+ // isUserScrolling 的 ref 镜像,供异步上下文读取最新值
86
+ const isUserScrollingRef = React.useRef(false);
87
+ const initialContainerLength = typeof (isHorizontal ? width : height) === 'number' ? (isHorizontal ? width : height) : 400;
88
+ const [containerLength, setContainerLength] = React.useState(initialContainerLength);
89
+ // 用容器实际尺寸更新视口长度,避免 props 与 CSS 不一致导致底部空白
90
+ React.useEffect(() => {
91
+ const el = containerRef.current;
92
+ if (!el || typeof ResizeObserver === 'undefined')
93
+ return;
94
+ const ro = new ResizeObserver((entries) => {
95
+ for (const entry of entries) {
96
+ const { contentRect } = entry;
97
+ const measured = isHorizontal ? contentRect.width : contentRect.height;
98
+ if (measured > 0)
99
+ setContainerLength(measured);
100
+ }
101
+ });
102
+ ro.observe(el);
103
+ return () => ro.disconnect();
104
+ }, [isHorizontal]);
44
105
  // 滚动追踪相关refs
45
106
  const isScrollingRef = React.useRef(false);
46
107
  const lastScrollTopRef = React.useRef(controlledScrollTop !== null && controlledScrollTop !== void 0 ? controlledScrollTop : 0);
47
108
  const scrollDiffListRef = React.useRef([0, 0, 0]);
48
109
  const scrollTimeoutRef = React.useRef(null);
49
- // 解析分组结构,只支持 StickySection 和 ListItem 作为直接子组件
110
+ // H5:仅程序性滚动时写回 DOM scrollTop,用户滑动结束后不写回避免卡顿
111
+ const programmaticScrollRef = React.useRef(false);
112
+ // 小程序端程序性滚动冷却期:handleScroll 只更新 renderOffset,避免 scrollIntoView 后被原生回调拉回
113
+ const programmaticCooldownRef = React.useRef(false);
114
+ const programmaticCooldownTimerRef = React.useRef(null);
115
+ const scrollViewOffsetRef = React.useRef(0);
116
+ // 处理渲染偏移量更新。
117
+ // syncToScrollView=true:程序性滚动,立即同步 scrollViewOffset。
118
+ // syncToScrollView=false:用户滑动,仅更新 renderOffset。weapp 采用 recycle-view 策略:不把用户滑动位置同步到 scrollViewOffset,避免「传滞后值拉回」和「从有到无归顶」。
119
+ const updateRenderOffset = React.useCallback((newOffset, syncToScrollView, source) => {
120
+ lastScrollTopRef.current = newOffset;
121
+ isScrollingRef.current = true;
122
+ if (scrollTimeoutRef.current) {
123
+ clearTimeout(scrollTimeoutRef.current);
124
+ }
125
+ setRenderOffset(newOffset); // 始终更新虚拟列表用到的偏移
126
+ if (syncToScrollView) {
127
+ isUserScrollingRef.current = false;
128
+ setIsUserScrolling(false);
129
+ // 小程序:target===sv 时 ScrollView 认为无变化不滚动→白屏;imperative/scrollIntoView 时先传中间值再 RAF 传 target 强制触发
130
+ // target=0 用 +0.01;target>0 用 -0.01(统一 +0.01 到底部会被 clamp 成同值无效)
131
+ const same = isWeapp && Math.abs(scrollViewOffsetRef.current - newOffset) < 1;
132
+ const needForce = same && (source === 'imperative' || source === 'scrollIntoView');
133
+ if (needForce) {
134
+ const intermediate = newOffset > 0 ? newOffset - 0.01 : 0.01;
135
+ setScrollViewOffset(intermediate);
136
+ requestAnimationFrame(() => {
137
+ setScrollViewOffset(newOffset);
138
+ });
139
+ }
140
+ else {
141
+ setScrollViewOffset(newOffset);
142
+ }
143
+ programmaticScrollRef.current = true;
144
+ if (isWeapp) {
145
+ programmaticCooldownRef.current = true;
146
+ if (programmaticCooldownTimerRef.current) {
147
+ clearTimeout(programmaticCooldownTimerRef.current);
148
+ }
149
+ programmaticCooldownTimerRef.current = setTimeout(() => {
150
+ programmaticCooldownRef.current = false;
151
+ }, 500);
152
+ }
153
+ }
154
+ else {
155
+ isUserScrollingRef.current = true;
156
+ setIsUserScrolling(true);
157
+ }
158
+ scrollTimeoutRef.current = setTimeout(() => {
159
+ isScrollingRef.current = false;
160
+ if (!syncToScrollView) {
161
+ isUserScrollingRef.current = false;
162
+ setIsUserScrolling(false);
163
+ // weapp recycle-view 策略:用户滑动结束后不同步 scrollViewOffset,保持 pass 的值不变,避免 从有到无 归顶
164
+ if (!isWeapp) {
165
+ setScrollViewOffset(lastScrollTopRef.current);
166
+ }
167
+ }
168
+ }, isWeapp ? 200 : 150);
169
+ }, []);
170
+ // 暴露给外部的实例方法:通过 ref.scroll({ top / left }) 进行程序性滚动
171
+ React.useImperativeHandle(ref, () => ({
172
+ scroll(options) {
173
+ const targetOffset = resolveScrollTargetOffset(options, isHorizontal);
174
+ const el = effectiveScrollElement === null || effectiveScrollElement === void 0 ? void 0 : effectiveScrollElement.current;
175
+ if (el && isH5) {
176
+ const scrollTarget = targetOffset + effectiveStartOffset;
177
+ if (isHorizontal) {
178
+ el.scrollTo({ left: scrollTarget });
179
+ }
180
+ else {
181
+ el.scrollTo({ top: scrollTarget });
182
+ }
183
+ updateRenderOffset(targetOffset, false, 'scrollElement');
184
+ }
185
+ else if (el && isWeapp && useScrollElementMode) {
186
+ // 小程序 scrollElement 模式:需通过 getScrollViewContextNode + node.scrollTo 真正滚动外部 scroll-view
187
+ // updateRenderOffset 必须在 scrollTo 之后调用,否则 getScrollViewContextNode 异步期间会先更新 renderOffset 导致闪一下
188
+ const startOff = effectiveStartOffsetRef.current;
189
+ const scrollTarget = targetOffset + startOff;
190
+ const scrollViewId = el.id || `_ls_${listId}`;
191
+ if (!el.id)
192
+ el.id = scrollViewId;
193
+ getScrollViewContextNode(`#${scrollViewId}`).then((node) => {
194
+ var _a, _b;
195
+ if (isHorizontal) {
196
+ (_a = node === null || node === void 0 ? void 0 : node.scrollTo) === null || _a === void 0 ? void 0 : _a.call(node, { left: scrollTarget, animated: false });
197
+ }
198
+ else {
199
+ (_b = node === null || node === void 0 ? void 0 : node.scrollTo) === null || _b === void 0 ? void 0 : _b.call(node, { top: scrollTarget, animated: false });
200
+ }
201
+ updateRenderOffset(targetOffset, true, 'imperative');
202
+ });
203
+ }
204
+ else {
205
+ updateRenderOffset(targetOffset, true, 'imperative');
206
+ }
207
+ },
208
+ }), [scrollX, effectiveScrollElement, effectiveStartOffset, effectiveStartOffsetRef, isH5, isWeapp, isHorizontal, listId, useScrollElementMode, updateRenderOffset]);
209
+ // 提取 Refresher 配置(List 属性为 base,Refresher 子组件覆盖)
210
+ const refresherConfig = React.useMemo(() => {
211
+ const listRefresherEnabled = props.refresherEnabled !== false && (props.refresherEnabled === true || props.onRefresherRefresh != null);
212
+ const baseFromList = listRefresherEnabled
213
+ ? {
214
+ refresherEnabled: props.refresherEnabled,
215
+ refresherThreshold: props.refresherThreshold,
216
+ refresherDefaultStyle: props.refresherDefaultStyle,
217
+ refresherBackground: props.refresherBackground,
218
+ refresherTriggered: props.refresherTriggered,
219
+ onRefresherPulling: props.onRefresherPulling,
220
+ onRefresherRefresh: props.onRefresherRefresh,
221
+ onRefresherRestore: props.onRefresherRestore,
222
+ onRefresherAbort: props.onRefresherAbort,
223
+ onRefresherWillRefresh: props.onRefresherWillRefresh,
224
+ onRefresherStatusChange: props.onRefresherStatusChange,
225
+ }
226
+ : null;
227
+ const isRefresherComponent = (child) => {
228
+ const type = child.type;
229
+ return (type === null || type === void 0 ? void 0 : type.displayName) === 'Refresher' || (type === null || type === void 0 ? void 0 : type.name) === 'Refresher';
230
+ };
231
+ let refresherChildProps = null;
232
+ let refresherCount = 0;
233
+ React.Children.forEach(children, (child) => {
234
+ if (React.isValidElement(child) && isRefresherComponent(child)) {
235
+ refresherCount++;
236
+ if (refresherCount > 1) {
237
+ return;
238
+ }
239
+ refresherChildProps = child.props;
240
+ }
241
+ });
242
+ if (refresherChildProps != null) {
243
+ const base = baseFromList !== null && baseFromList !== void 0 ? baseFromList : {};
244
+ // Refresher 子组件的配置覆盖 List 的配置
245
+ return Object.assign(Object.assign({}, base), refresherChildProps);
246
+ }
247
+ return baseFromList;
248
+ }, [
249
+ children,
250
+ props.refresherEnabled,
251
+ props.refresherThreshold,
252
+ props.refresherDefaultStyle,
253
+ props.refresherBackground,
254
+ props.refresherTriggered,
255
+ props.onRefresherPulling,
256
+ props.onRefresherRefresh,
257
+ props.onRefresherRestore,
258
+ props.onRefresherAbort,
259
+ props.onRefresherWillRefresh,
260
+ props.onRefresherStatusChange,
261
+ ]);
262
+ // 提取 NoMore 配置
263
+ const noMoreConfig = React.useMemo(() => {
264
+ var _a;
265
+ let config = null;
266
+ let noMoreCount = 0;
267
+ // 从子组件中提取 NoMore
268
+ React.Children.forEach(children, (child) => {
269
+ if (React.isValidElement(child) && child.type === NoMore) {
270
+ noMoreCount++;
271
+ if (noMoreCount > 1) {
272
+ return;
273
+ }
274
+ const childProps = child.props;
275
+ config = Object.assign(Object.assign({}, childProps), { visible: childProps.visible !== false });
276
+ }
277
+ });
278
+ // Props 方式转换为配置(优先级低于子组件)
279
+ if (props.showNoMore && !config) {
280
+ config = {
281
+ visible: true,
282
+ text: props.noMoreText,
283
+ style: props.noMoreStyle,
284
+ children: (_a = props.renderNoMore) === null || _a === void 0 ? void 0 : _a.call(props)
285
+ };
286
+ }
287
+ return config;
288
+ }, [children, props.showNoMore, props.noMoreText, props.noMoreStyle, props.renderNoMore]);
289
+ // Refresher 平台适配:H5 用 addImperativeTouchListeners
290
+ const { scrollViewRefresherProps, scrollViewRefresherHandlers, h5RefresherProps, addImperativeTouchListeners, renderRefresherContent, } = useRefresher(refresherConfig, isH5 && refresherConfig && !supportsNativeRefresher ? 0 : renderOffset, useScrollElementMode
291
+ ? (ev) => { var _a, _b; return (_b = (ev.target != null && ((_a = contentWrapperRef.current) === null || _a === void 0 ? void 0 : _a.contains(ev.target)))) !== null && _b !== void 0 ? _b : false; }
292
+ : undefined);
293
+ const refresherTeardownRef = React.useRef(null);
294
+ const addImperativeTouchListenersRef = React.useRef(addImperativeTouchListeners);
295
+ addImperativeTouchListenersRef.current = addImperativeTouchListeners;
296
+ React.useEffect(() => () => {
297
+ if (refresherTeardownRef.current)
298
+ refresherTeardownRef.current();
299
+ }, []);
300
+ // H5 下拉刷新顶栏高度(默认 50px,来自 useRefresher)
301
+ const refresherHeightForH5 = (isH5 && refresherConfig && !supportsNativeRefresher && refresherConfig.refresherEnabled !== false) ? DEFAULT_REFRESHER_HEIGHT : 0;
302
+ // 解析分组结构:StickySection、ListItem 为直接子组件,过滤 Refresher/NoMore
50
303
  const sections = React.useMemo(() => {
51
304
  const result = [];
52
305
  const defaultItems = [];
53
306
  React.Children.forEach(children, (child, idx) => {
54
307
  if (React.isValidElement(child) && child.type === StickySection) {
55
- // 分组模式
56
308
  const sectionProps = child.props;
57
309
  let header = null;
58
310
  const items = [];
@@ -65,7 +317,6 @@ const List = (props) => {
65
317
  result.push({ header, items, key: child.key || String(idx) });
66
318
  }
67
319
  else if (React.isValidElement(child) && child.type === ListItem) {
68
- // 普通 ListItem
69
320
  defaultItems.push(child);
70
321
  }
71
322
  });
@@ -74,8 +325,122 @@ const List = (props) => {
74
325
  }
75
326
  return result;
76
327
  }, [children]);
77
- // 工具:获取 header 尺寸,确保所有 header 相关逻辑一致
78
- const getHeaderSize = () => {
328
+ // 动态尺寸管理
329
+ const defaultEstimatedSize = isHorizontal ? DEFAULT_ITEM_WIDTH : DEFAULT_ITEM_HEIGHT;
330
+ const estimatedSize = (_a = props.estimatedItemSize) !== null && _a !== void 0 ? _a : defaultEstimatedSize;
331
+ // 计算总 item 数量(跨所有 section)
332
+ const totalItemCount = React.useMemo(() => {
333
+ return sections.reduce((sum, section) => sum + section.items.length, 0);
334
+ }, [sections]);
335
+ // 存储元素引用(用于 ResizeObserver)
336
+ const itemRefsRef = React.useRef(new Map());
337
+ // 存储 header 元素引用(用于 ResizeObserver)
338
+ const headerRefsRef = React.useRef(new Map());
339
+ // 小程序端:已完成 SelectorQuery 测量的 item 索引集,避免 refCallback 重复触发测量导致无限循环
340
+ const weappMeasuredItemsRef = React.useRef(new Set());
341
+ // 动态尺寸缓存更新版本:setItemSize 后递增,用于驱动 sectionOffsets/totalLength 与 item 定位重算
342
+ const [sizeCacheVersion, setSizeCacheVersion] = React.useState(0);
343
+ const sizeCacheRafRef = React.useRef(null);
344
+ // 小程序端:测量触发 re-render 时,reflow 帧传 eff 并同步 scrollViewOffset,避免下一帧传 0 导致跳变
345
+ const measureScrollProtectRef = React.useRef(false);
346
+ // 动态尺寸缓存
347
+ const sizeCache = useItemSizeCache({
348
+ isHorizontal,
349
+ estimatedItemSize: estimatedSize,
350
+ itemCount: totalItemCount
351
+ });
352
+ // header 动态尺寸缓存(sectionIndex -> size)
353
+ const headerSizeCacheRef = React.useRef(new Map());
354
+ // 滚动修正的可见起始索引
355
+ const visibleStartIndexRef = React.useRef(0);
356
+ // ScrollTop 修正(仅 H5):动高时尺寸变化自动修正 scrollTop
357
+ const scrollCorrectionEnabled = !isWeapp && props.useResizeObserver === true;
358
+ const scrollCorrection = useScrollCorrection({
359
+ enabled: scrollCorrectionEnabled,
360
+ visibleStartIndexRef,
361
+ setScrollOffset: (offsetOrUpdater) => {
362
+ const newOffset = typeof offsetOrUpdater === 'function'
363
+ ? offsetOrUpdater(renderOffset)
364
+ : offsetOrUpdater;
365
+ updateRenderOffset(newOffset, true, 'scrollCorrection'); // 程序性修正需同步到 ScrollView
366
+ }
367
+ });
368
+ const scrollCorrectionRef = React.useRef(scrollCorrection);
369
+ scrollCorrectionRef.current = scrollCorrection;
370
+ const onScrollRef = React.useRef(onScroll);
371
+ onScrollRef.current = onScroll;
372
+ const onScrollToUpperRef = React.useRef(onScrollToUpper);
373
+ onScrollToUpperRef.current = onScrollToUpper;
374
+ const onScrollToLowerRef = React.useRef(onScrollToLower);
375
+ onScrollToLowerRef.current = onScrollToLower;
376
+ const thresholdRef = React.useRef({ upper: upperThreshold, lower: lowerThreshold });
377
+ thresholdRef.current = { upper: upperThreshold, lower: lowerThreshold };
378
+ // 小程序 + 动高(virtual-list 风格):测量变化后同帧重排,不做程序性 scrollTop 回拉
379
+ const scheduleWeappDynamicReflow = React.useCallback(() => {
380
+ if (!isWeapp || props.useResizeObserver !== true)
381
+ return;
382
+ if (sizeCacheRafRef.current != null)
383
+ return;
384
+ sizeCacheRafRef.current = requestAnimationFrame(() => {
385
+ sizeCacheRafRef.current = null;
386
+ measureScrollProtectRef.current = true;
387
+ setSizeCacheVersion((v) => v + 1);
388
+ });
389
+ }, [isWeapp, props.useResizeObserver]);
390
+ // ResizeObserver(当启用动态测量时)
391
+ const resizeObserver = useResizeObserver({
392
+ enabled: props.useResizeObserver === true,
393
+ isHorizontal,
394
+ listId,
395
+ onResize: (index, size) => {
396
+ var _a;
397
+ const oldSize = sizeCache.getItemSize(index);
398
+ sizeCache.setItemSize(index, size);
399
+ if (Math.abs(oldSize - size) >= 1) {
400
+ if (isWeapp && props.useResizeObserver === true) {
401
+ scheduleWeappDynamicReflow();
402
+ }
403
+ else if (sizeCacheRafRef.current == null) {
404
+ sizeCacheRafRef.current = requestAnimationFrame(() => {
405
+ sizeCacheRafRef.current = null;
406
+ setSizeCacheVersion((v) => v + 1);
407
+ });
408
+ }
409
+ }
410
+ // 触发 ScrollTop 修正
411
+ scrollCorrection.recordSizeChange(index, oldSize, size);
412
+ // 小程序:延迟 onItemSizeChange,避免父组件重渲染导致 List remount
413
+ // H5:直接回调
414
+ if (isWeapp) {
415
+ weappDeferItemSizeChange(index, size, props.onItemSizeChange);
416
+ }
417
+ else {
418
+ (_a = props.onItemSizeChange) === null || _a === void 0 ? void 0 : _a.call(props, index, size);
419
+ }
420
+ }
421
+ });
422
+ // 嵌套滚动:内层高度变化上报
423
+ const handleReportNestedHeightChange = React.useCallback((height, index) => {
424
+ if (height <= 0)
425
+ return;
426
+ const estimatedHeader = estimatedSize * 0.5;
427
+ const fullHeight = height + estimatedHeader;
428
+ const oldSize = sizeCache.getItemSize(index);
429
+ if (Math.abs(oldSize - fullHeight) < 1)
430
+ return;
431
+ sizeCache.setItemSize(index, fullHeight);
432
+ scrollCorrection.recordSizeChange(index, oldSize, fullHeight);
433
+ if (isWeapp && props.useResizeObserver === true) {
434
+ scheduleWeappDynamicReflow();
435
+ }
436
+ else if (sizeCacheRafRef.current == null) {
437
+ sizeCacheRafRef.current = requestAnimationFrame(() => {
438
+ sizeCacheRafRef.current = null;
439
+ setSizeCacheVersion((v) => v + 1);
440
+ });
441
+ }
442
+ }, [sizeCache, scrollCorrection, estimatedSize, isWeapp, props.useResizeObserver, scheduleWeappDynamicReflow]);
443
+ const getDefaultHeaderSize = () => {
79
444
  if (isHorizontal) {
80
445
  if (typeof props.headerWidth === 'number')
81
446
  return props.headerWidth;
@@ -99,8 +464,19 @@ const List = (props) => {
99
464
  return DEFAULT_ITEM_HEIGHT;
100
465
  }
101
466
  };
102
- // 工具:获取 item 尺寸,支持函数/props/默认值
103
- const getItemSize = (index) => {
467
+ // 获取 header 尺寸(支持动态测量)
468
+ const getHeaderSize = React.useCallback((sectionIndex) => {
469
+ if (props.useResizeObserver === true) {
470
+ const cached = headerSizeCacheRef.current.get(sectionIndex);
471
+ if (cached != null && cached > 0)
472
+ return cached;
473
+ }
474
+ return getDefaultHeaderSize();
475
+ }, [props.useResizeObserver, props.headerHeight, props.headerWidth, props.itemHeight, props.itemWidth, props.itemSize, props.itemData, isHorizontal]);
476
+ const getItemSize = React.useCallback((index) => {
477
+ if (props.useResizeObserver === true) {
478
+ return sizeCache.getItemSize(index);
479
+ }
104
480
  if (isHorizontal) {
105
481
  if (typeof props.itemWidth === 'number')
106
482
  return props.itemWidth;
@@ -119,20 +495,22 @@ const List = (props) => {
119
495
  return props.itemSize(index, props.itemData) || DEFAULT_ITEM_HEIGHT;
120
496
  return DEFAULT_ITEM_HEIGHT;
121
497
  }
122
- };
123
- // 计算分组累积高度/宽度
498
+ }, [props.useResizeObserver, props.itemWidth, props.itemHeight, props.itemSize, props.itemData, isHorizontal, sizeCache]);
499
+ // 分组累积高度/宽度,sizeCacheVersion 变化时重算
124
500
  const sectionOffsets = React.useMemo(() => {
125
501
  const offsets = [0];
126
- sections.forEach((section) => {
127
- const headerSize = getHeaderSize();
128
- const itemSizes = section.items.map((_, i) => getItemSize(i));
502
+ let globalItemIndex = 0;
503
+ sections.forEach((section, sectionIdx) => {
504
+ const headerSize = getHeaderSize(sectionIdx);
505
+ const itemSizes = section.items.map((_, localIdx) => getItemSize(globalItemIndex + localIdx));
129
506
  const groupSize = (section.header ? headerSize : 0) +
130
507
  itemSizes.reduce((a, b) => a + b, 0) +
131
508
  Math.max(0, section.items.length) * space;
132
509
  offsets.push(offsets[offsets.length - 1] + groupSize);
510
+ globalItemIndex += section.items.length;
133
511
  });
134
512
  return offsets;
135
- }, [sections, space, isHorizontal, props.headerHeight, props.headerWidth, props.itemHeight, props.itemWidth, props.itemSize, props.itemData]);
513
+ }, [sections, space, isHorizontal, props.headerHeight, props.headerWidth, props.itemHeight, props.itemWidth, props.itemSize, props.itemData, getItemSize, getHeaderSize, sizeCacheVersion]);
136
514
  // 外层虚拟滚动:可见分组
137
515
  const [startSection, endSection] = React.useMemo(() => {
138
516
  let start = 0;
@@ -151,119 +529,326 @@ const List = (props) => {
151
529
  }
152
530
  return [start, end];
153
531
  }, [renderOffset, containerLength, sectionOffsets, sections.length, cacheCount]);
154
- // 触顶/触底事件
155
- React.useEffect(() => {
156
- if (onScrollToUpper && renderOffset <= (upperThreshold > 0 ? sectionOffsets[upperThreshold] : 0)) {
157
- onScrollToUpper();
158
- }
159
- if (onScrollToLower && renderOffset + containerLength >= sectionOffsets[sectionOffsets.length - 1] - (lowerThreshold > 0 ? sectionOffsets[sectionOffsets.length - 1] - sectionOffsets[sections.length - lowerThreshold] : 0)) {
160
- onScrollToLower();
161
- }
162
- }, [renderOffset, containerLength, sectionOffsets, sections.length, upperThreshold, lowerThreshold, onScrollToUpper, onScrollToLower]);
163
- // 处理渲染偏移量更新
164
- const updateRenderOffset = React.useCallback((newOffset) => {
165
- lastScrollTopRef.current = newOffset;
166
- isScrollingRef.current = true;
167
- if (scrollTimeoutRef.current) {
168
- clearTimeout(scrollTimeoutRef.current);
169
- }
170
- setRenderOffset(newOffset); // 立即更新渲染偏移量
171
- // 平台适配:微信小程序使用延时,其他平台立即更新
172
- const isWeapp = process.env.TARO_ENV === 'weapp';
173
- if (isWeapp) {
174
- // 微信小程序:使用延时避免抖动
175
- scrollTimeoutRef.current = setTimeout(() => {
176
- isScrollingRef.current = false;
177
- setScrollViewOffset(newOffset); // 滚动结束后,同步滚动视图偏移量
178
- }, 200);
532
+ // 视口内可见 item 的全局索引范围(供 onScrollIndex)
533
+ const [visibleStartItem, visibleEndItem] = React.useMemo(() => {
534
+ const viewportTop = renderOffset;
535
+ const viewportBottom = renderOffset + containerLength;
536
+ let firstVisible = -1;
537
+ let lastVisible = -1;
538
+ let globalIndex = 0;
539
+ for (let s = 0; s < sections.length; s++) {
540
+ const section = sections[s];
541
+ const headerSize = getHeaderSize(s);
542
+ const sectionStart = sectionOffsets[s] + (section.header ? headerSize : 0);
543
+ let itemTop = sectionStart;
544
+ for (let i = 0; i < section.items.length; i++) {
545
+ const itemSize = getItemSize(globalIndex);
546
+ const itemBottom = itemTop + itemSize;
547
+ // 判断 item 本身(不含 space)是否与视口相交
548
+ if (itemBottom > viewportTop && itemTop < viewportBottom) {
549
+ if (firstVisible < 0)
550
+ firstVisible = globalIndex;
551
+ lastVisible = globalIndex;
552
+ }
553
+ // 下一个 item 的起始位置 = 当前 item 结束 + space
554
+ itemTop = itemBottom + space;
555
+ globalIndex++;
556
+ }
179
557
  }
180
- else {
181
- // 其他平台:立即更新以获得更好的响应性
182
- setScrollViewOffset(newOffset); // 立即更新滚动视图偏移量
183
- scrollTimeoutRef.current = setTimeout(() => {
184
- isScrollingRef.current = false;
185
- }, 200);
558
+ if (firstVisible < 0 || lastVisible < 0)
559
+ return [0, 0];
560
+ return [firstVisible, lastVisible];
561
+ }, [renderOffset, containerLength, sections, sectionOffsets, getHeaderSize, getItemSize, space]);
562
+ const lastVisibleRangeRef = React.useRef({ start: -1, end: -1 });
563
+ React.useEffect(() => {
564
+ if (props.onScrollIndex) {
565
+ if (lastVisibleRangeRef.current.start !== visibleStartItem ||
566
+ lastVisibleRangeRef.current.end !== visibleEndItem) {
567
+ lastVisibleRangeRef.current = { start: visibleStartItem, end: visibleEndItem };
568
+ props.onScrollIndex(visibleStartItem, visibleEndItem);
569
+ }
186
570
  }
187
- }, []);
188
- // 智能滚动处理函数
571
+ }, [visibleStartItem, visibleEndItem, props.onScrollIndex]);
189
572
  const handleScroll = React.useCallback((e) => {
190
- // 兼容Stencil版本和React版本的事件结构
191
573
  let newOffset;
192
574
  if (e.detail) {
193
- // React版本的事件结构
194
575
  newOffset = isHorizontal ? e.detail.scrollLeft : e.detail.scrollTop;
195
576
  }
196
577
  else {
197
- // Stencil版本的事件结构
198
578
  newOffset = isHorizontal ? e.scrollLeft : e.scrollTop;
199
579
  }
200
- const diff = newOffset - lastScrollTopRef.current;
580
+ const effectiveOffset = newOffset;
581
+ const diff = effectiveOffset - lastScrollTopRef.current;
201
582
  scrollDiffListRef.current.shift();
202
583
  scrollDiffListRef.current.push(diff);
203
- // 只保留抖动检测,移除方向检测
204
- if (isScrollingRef.current && isShaking(scrollDiffListRef.current)) {
584
+ const shaking = isScrollingRef.current && isShaking(scrollDiffListRef.current);
585
+ if (shaking)
586
+ return;
587
+ if (programmaticCooldownRef.current) {
588
+ lastScrollTopRef.current = effectiveOffset;
589
+ setRenderOffset(effectiveOffset);
590
+ onScroll === null || onScroll === void 0 ? void 0 : onScroll({
591
+ scrollTop: isHorizontal ? 0 : newOffset,
592
+ scrollLeft: isHorizontal ? newOffset : 0
593
+ });
205
594
  return;
206
595
  }
207
- updateRenderOffset(newOffset); // 直接更新渲染偏移量
596
+ scrollCorrection.markUserScrolling();
597
+ updateRenderOffset(effectiveOffset, false, 'onScroll');
208
598
  onScroll === null || onScroll === void 0 ? void 0 : onScroll({
209
599
  scrollTop: isHorizontal ? 0 : newOffset,
210
600
  scrollLeft: isHorizontal ? newOffset : 0
211
601
  });
212
- }, [isHorizontal, onScroll, updateRenderOffset, containerLength]);
213
- // 初始化后的延迟同步 - 确保ScrollView正确设置初始位置
602
+ }, [isHorizontal, onScroll, updateRenderOffset, scrollCorrection, props.useResizeObserver]);
603
+ // 小程序:onScrollEnd 优先结束 isUserScrolling,timeout 兜底
604
+ const handleNativeScrollEnd = React.useCallback(() => {
605
+ if (isWeapp) {
606
+ if (scrollTimeoutRef.current) {
607
+ clearTimeout(scrollTimeoutRef.current);
608
+ scrollTimeoutRef.current = null;
609
+ }
610
+ if (isUserScrollingRef.current) {
611
+ isScrollingRef.current = false;
612
+ isUserScrollingRef.current = false;
613
+ setIsUserScrolling(false);
614
+ }
615
+ }
616
+ onScrollEnd === null || onScrollEnd === void 0 ? void 0 : onScrollEnd();
617
+ }, [isWeapp, onScrollEnd]);
618
+ // 暴露 scrollRef 给父组件,供内层 List/WaterFlow 传入 scrollElement
619
+ React.useLayoutEffect(() => {
620
+ if (!scrollRefProp)
621
+ return;
622
+ const el = useScrollElementMode ? effectiveScrollElement === null || effectiveScrollElement === void 0 ? void 0 : effectiveScrollElement.current : containerRef.current;
623
+ if (el) {
624
+ scrollRefProp.current = el;
625
+ }
626
+ }, [scrollRefProp, useScrollElementMode, effectiveScrollElement]);
627
+ // controlledScrollTop 变化时同步到 ScrollView
214
628
  React.useEffect(() => {
215
629
  if (typeof controlledScrollTop === 'number') {
216
- setScrollViewOffset(controlledScrollTop);
630
+ const sv = scrollViewOffsetRef.current;
631
+ const same = isWeapp && Math.abs(sv - controlledScrollTop) < 1;
632
+ if (same) {
633
+ const intermediate = controlledScrollTop > 0 ? controlledScrollTop - 0.01 : 0.01;
634
+ setRenderOffset(intermediate);
635
+ setScrollViewOffset(intermediate);
636
+ requestAnimationFrame(() => {
637
+ setRenderOffset(controlledScrollTop);
638
+ setScrollViewOffset(controlledScrollTop);
639
+ });
640
+ }
641
+ else {
642
+ setRenderOffset(controlledScrollTop);
643
+ setScrollViewOffset(controlledScrollTop);
644
+ }
217
645
  lastScrollTopRef.current = controlledScrollTop;
646
+ programmaticScrollRef.current = true;
218
647
  }
219
648
  }, [controlledScrollTop]);
220
- // 清理定时器
649
+ // 清理定时器、ResizeObserver 与尺寸缓存 RAF(仅在卸载时执行)
221
650
  React.useEffect(() => {
222
651
  return () => {
223
652
  if (scrollTimeoutRef.current) {
224
653
  clearTimeout(scrollTimeoutRef.current);
225
654
  }
655
+ // 小程序端冷却期定时器清理
656
+ if (isWeapp && programmaticCooldownTimerRef.current) {
657
+ clearTimeout(programmaticCooldownTimerRef.current);
658
+ }
659
+ if (sizeCacheRafRef.current != null) {
660
+ cancelAnimationFrame(sizeCacheRafRef.current);
661
+ sizeCacheRafRef.current = null;
662
+ }
663
+ resizeObserver.disconnect();
664
+ scrollCorrection.clearQueue();
226
665
  };
227
666
  }, []);
228
- // 容器样式
229
- const containerStyle = Object.assign({ position: 'relative', boxSizing: 'border-box', height: isHorizontal ? width : height, width: isHorizontal ? height : width }, style);
230
- // 修改ScrollView组件的props,添加data-testid属性
667
+ // scrollIntoView:仅当 scrollIntoView 变化时执行一次跳动,统一转换为 scrollTop 路径(updateRenderOffset)。
668
+ const lastScrollIntoViewRef = React.useRef(null);
669
+ React.useEffect(() => {
670
+ const targetId = props.scrollIntoView;
671
+ if (!targetId) {
672
+ lastScrollIntoViewRef.current = null;
673
+ return;
674
+ }
675
+ if (lastScrollIntoViewRef.current === targetId)
676
+ return;
677
+ lastScrollIntoViewRef.current = targetId;
678
+ let targetIndex = -1;
679
+ if (targetId.startsWith('list-item-')) {
680
+ targetIndex = parseInt(targetId.replace('list-item-', ''), 10);
681
+ }
682
+ if (targetIndex >= 0 && targetIndex < totalItemCount) {
683
+ let targetOffset = 0;
684
+ let currentGlobalIndex = 0;
685
+ for (let s = 0; s < sections.length; s++) {
686
+ const section = sections[s];
687
+ const headerSize = section.header ? getHeaderSize(s) : 0;
688
+ if (currentGlobalIndex + section.items.length > targetIndex) {
689
+ targetOffset += headerSize;
690
+ for (let i = 0; i < targetIndex - currentGlobalIndex; i++) {
691
+ targetOffset += getItemSize(currentGlobalIndex + i) + space;
692
+ }
693
+ break;
694
+ }
695
+ else {
696
+ targetOffset += headerSize;
697
+ for (let i = 0; i < section.items.length; i++) {
698
+ targetOffset += getItemSize(currentGlobalIndex + i) + space;
699
+ }
700
+ currentGlobalIndex += section.items.length;
701
+ }
702
+ }
703
+ const el = effectiveScrollElement === null || effectiveScrollElement === void 0 ? void 0 : effectiveScrollElement.current;
704
+ if (useScrollElementMode && el) {
705
+ const scrollTarget = targetOffset + (isWeapp ? effectiveStartOffsetRef.current : effectiveStartOffset);
706
+ if (isH5) {
707
+ if (isHorizontal) {
708
+ el.scrollTo({ left: scrollTarget });
709
+ }
710
+ else {
711
+ el.scrollTo({ top: scrollTarget });
712
+ }
713
+ updateRenderOffset(targetOffset, true, 'scrollIntoView');
714
+ }
715
+ else if (isWeapp) {
716
+ const scrollViewId = el.id || `_ls_${listId}`;
717
+ if (!el.id)
718
+ el.id = scrollViewId;
719
+ getScrollViewContextNode(`#${scrollViewId}`).then((node) => {
720
+ var _a, _b;
721
+ if (isHorizontal) {
722
+ (_a = node === null || node === void 0 ? void 0 : node.scrollTo) === null || _a === void 0 ? void 0 : _a.call(node, { left: scrollTarget, animated: false });
723
+ }
724
+ else {
725
+ (_b = node === null || node === void 0 ? void 0 : node.scrollTo) === null || _b === void 0 ? void 0 : _b.call(node, { top: scrollTarget, animated: false });
726
+ }
727
+ updateRenderOffset(targetOffset, true, 'scrollIntoView');
728
+ });
729
+ }
730
+ else {
731
+ updateRenderOffset(targetOffset, true, 'scrollIntoView');
732
+ }
733
+ }
734
+ else {
735
+ updateRenderOffset(targetOffset, true, 'scrollIntoView');
736
+ }
737
+ }
738
+ }, [props.scrollIntoView, totalItemCount, sections, getHeaderSize, getItemSize, space, updateRenderOffset, useScrollElementMode, effectiveScrollElement, effectiveStartOffset, effectiveStartOffsetRef, isH5, isWeapp, isHorizontal, listId]);
739
+ // 容器样式;H5 刷新中禁止滚动
740
+ const containerStyle = Object.assign(Object.assign({ position: 'relative', boxSizing: 'border-box', height,
741
+ width }, style), (isH5 && refresherConfig && !supportsNativeRefresher && h5RefresherProps.isRefreshing
742
+ ? { overflow: 'hidden' }
743
+ : {}));
231
744
  // ScrollView 属性
232
- const scrollViewProps = {
233
- scrollY: !scrollX && scrollY,
234
- scrollX: scrollX,
235
- style: containerStyle,
236
- enhanced: true,
237
- showScrollbar: showScrollbar,
238
- onScroll: handleScroll,
239
- onScrollToUpper,
745
+ const scrollViewProps = Object.assign(Object.assign(Object.assign(Object.assign({ scrollY: !scrollX && scrollY, scrollX, style: containerStyle, className, enhanced: true, showScrollbar,
746
+ upperThreshold,
747
+ lowerThreshold, scrollWithAnimation: false, onScroll: handleScroll, onScrollToUpper,
240
748
  onScrollToLower,
241
- 'data-testid': 'taro-list-container'
242
- };
243
- // 设置ScrollView的滚动位置 - 同时兼容React版本和Stencil版本
244
- if (isHorizontal) {
245
- scrollViewProps.scrollLeft = scrollViewOffset; // React版本
246
- scrollViewProps.mpScrollLeft = scrollViewOffset; // Stencil版本
749
+ onScrollStart, onScrollEnd: handleNativeScrollEnd, enableBackToTop }, (isWeapp ? { scrollAnchoring: true } : {})), (typeof cacheExtent === 'number' ? { cacheExtent } : {})), scrollViewRefresherProps), scrollViewRefresherHandlers);
750
+ // H5 对齐小程序:refresherTriggered=true 时顶部立即显示加载指示器,滚到顶部并锁定滚动直至设为 false
751
+ React.useEffect(() => {
752
+ if (!isH5 || !refresherConfig || supportsNativeRefresher || !h5RefresherProps.isRefreshing)
753
+ return;
754
+ updateRenderOffset(0, true, 'refresher');
755
+ }, [h5RefresherProps.isRefreshing, isH5, refresherConfig, supportsNativeRefresher, updateRenderOffset]);
756
+ // H5 下拉刷新:ref 存 addImperativeTouchListeners,避免 config 变化导致 effect 循环
757
+ React.useLayoutEffect(() => {
758
+ const attach = addImperativeTouchListenersRef.current;
759
+ if (!attach)
760
+ return;
761
+ let teardown = null;
762
+ const tryAttach = () => {
763
+ const el = useScrollElementMode ? effectiveScrollElement === null || effectiveScrollElement === void 0 ? void 0 : effectiveScrollElement.current : containerRef.current;
764
+ if (el && !refresherTeardownRef.current) {
765
+ teardown = attach(el);
766
+ refresherTeardownRef.current = teardown;
767
+ }
768
+ };
769
+ tryAttach();
770
+ const rafId = requestAnimationFrame(tryAttach);
771
+ return () => {
772
+ cancelAnimationFrame(rafId);
773
+ if (teardown) {
774
+ teardown();
775
+ }
776
+ refresherTeardownRef.current = null;
777
+ };
778
+ }, [useScrollElementMode, effectiveScrollElement]);
779
+ scrollViewOffsetRef.current = scrollViewOffset;
780
+ // scrollTop:weapp 传 scrollViewOffset(reflow 帧传 eff 防跳变);H5 仅非用户滑动时传
781
+ if (isWeapp) {
782
+ if (measureScrollProtectRef.current) {
783
+ measureScrollProtectRef.current = false;
784
+ const eff = lastScrollTopRef.current;
785
+ setScrollViewOffset(eff);
786
+ if (isHorizontal) {
787
+ scrollViewProps.scrollLeft = eff;
788
+ }
789
+ else {
790
+ scrollViewProps.scrollTop = eff;
791
+ }
792
+ programmaticScrollRef.current = false;
793
+ }
794
+ else {
795
+ const sv = scrollViewOffset;
796
+ if (isHorizontal) {
797
+ scrollViewProps.scrollLeft = sv;
798
+ }
799
+ else {
800
+ scrollViewProps.scrollTop = sv;
801
+ }
802
+ programmaticScrollRef.current = false;
803
+ }
247
804
  }
248
805
  else {
249
- scrollViewProps.scrollTop = scrollViewOffset; // React版本
250
- scrollViewProps.mpScrollTop = scrollViewOffset; // Stencil版本
251
- }
252
- // H5上额外使用DOM直接操作确保滚动位置正确
253
- if (isH5) {
254
- React.useEffect(() => {
255
- if (containerRef.current && typeof scrollViewOffset === 'number') {
256
- if (isHorizontal) {
257
- containerRef.current.scrollLeft = scrollViewOffset;
258
- }
259
- else {
260
- containerRef.current.scrollTop = scrollViewOffset;
261
- }
806
+ // H5:非用户滑动时传
807
+ if (!isUserScrolling) {
808
+ if (isHorizontal) {
809
+ scrollViewProps.scrollLeft = scrollViewOffset;
262
810
  }
263
- }, [scrollViewOffset, isHorizontal]);
811
+ else {
812
+ scrollViewProps.scrollTop = scrollViewOffset;
813
+ }
814
+ }
264
815
  }
265
- // 总高度/宽度
266
- const totalLength = sectionOffsets[sectionOffsets.length - 1];
816
+ // H5:程序性滚动时写回 DOM scrollTop
817
+ React.useEffect(() => {
818
+ if (!isH5)
819
+ return;
820
+ if (isUserScrolling || !containerRef.current || typeof scrollViewOffset !== 'number')
821
+ return;
822
+ if (!programmaticScrollRef.current)
823
+ return;
824
+ const scrollValue = scrollViewOffset;
825
+ if (isHorizontal) {
826
+ containerRef.current.scrollLeft = scrollValue;
827
+ }
828
+ else {
829
+ containerRef.current.scrollTop = scrollValue;
830
+ }
831
+ programmaticScrollRef.current = false;
832
+ }, [isH5, scrollViewOffset, isHorizontal, isUserScrolling]);
833
+ // 总高度/宽度(含 NoMore)
834
+ const noMoreHeight = (noMoreConfig === null || noMoreConfig === void 0 ? void 0 : noMoreConfig.visible) ? (noMoreConfig.height || 60) : 0;
835
+ const listContentLength = sectionOffsets[sectionOffsets.length - 1] + noMoreHeight;
836
+ const totalLength = listContentLength;
837
+ // scrollElement 模式下 onScrollToLower 需用内层内容高度判断,供 scroll handler 读取
838
+ const listContentLengthRef = React.useRef(0);
839
+ listContentLengthRef.current = listContentLength;
840
+ const scrollAttachRefsRef = React.useRef(null);
841
+ scrollAttachRefsRef.current = {
842
+ scrollCorrection: scrollCorrectionRef.current,
843
+ onScroll: onScrollRef.current,
844
+ onScrollToUpper: onScrollToUpperRef.current,
845
+ onScrollToLower: onScrollToLowerRef.current,
846
+ threshold: thresholdRef.current,
847
+ listContentLength: listContentLengthRef.current,
848
+ };
849
+ useListScrollElementAttach(useScrollElementMode && isH5, effectiveScrollElement, effectiveStartOffset, isHorizontal, setContainerLength, updateRenderOffset, scrollRefProp, scrollAttachRefsRef);
850
+ useListScrollElementAttachWeapp(useScrollElementMode && isWeapp, effectiveScrollElement, effectiveStartOffsetRef, effectiveStartOffset, isHorizontal, setContainerLength, updateRenderOffset, scrollRefProp, scrollAttachRefsRef, initialContainerLength // 兜底:measure 未完成或失败时供 onScrollToUpper/Lower 及 containerLengthRef 使用
851
+ );
267
852
  // 吸顶/吸左 header
268
853
  const stickyHeaderNode = React.useMemo(() => {
269
854
  if (!stickyHeader)
@@ -272,9 +857,18 @@ const List = (props) => {
272
857
  if (sectionOffsets[i] <= renderOffset && renderOffset < sectionOffsets[i + 1]) {
273
858
  const section = sections[i];
274
859
  if (section.header) {
275
- const headerSize = getHeaderSize();
276
- // 内联样式替代className
277
- const stickyHeaderStyle = Object.assign({ position: 'sticky', top: 0, left: 0, zIndex: 100, background: '#fff', boxSizing: 'border-box', minHeight: '20px', overflow: 'hidden', lineHeight: 1 }, (isHorizontal ? { width: headerSize } : { height: headerSize }));
860
+ // 吸顶 header 不设固定 height/width,由内容撑开,避免「外部 60px 容器 + 实际内容 40+px」导致 header 内空白
861
+ const stickyHeaderStyle = {
862
+ position: 'sticky',
863
+ top: 0,
864
+ left: 0,
865
+ zIndex: 100,
866
+ background: '#fff',
867
+ boxSizing: 'border-box',
868
+ minHeight: 20,
869
+ overflow: 'hidden',
870
+ lineHeight: 1
871
+ };
278
872
  return (jsx(View, { style: stickyHeaderStyle, children: section.header }));
279
873
  }
280
874
  }
@@ -285,20 +879,105 @@ const List = (props) => {
285
879
  const renderSections = () => {
286
880
  const nodes = [];
287
881
  let offset = sectionOffsets[startSection];
882
+ let globalItemIndex = 0; // 全局 item 索引(跨 section)
883
+ // 计算起始 section 之前的所有 item 数量
884
+ for (let s = 0; s < startSection; s++) {
885
+ globalItemIndex += sections[s].items.length;
886
+ }
288
887
  for (let s = startSection; s <= endSection; s++) {
289
888
  const section = sections[s];
290
- const headerSize = getHeaderSize();
291
- const itemSizes = section.items.map((_, i) => getItemSize(i));
889
+ const headerSize = getHeaderSize(s);
890
+ const itemSizes = section.items.map((_, i) => getItemSize(globalItemIndex + i));
292
891
  // header
293
892
  if (section.header) {
294
- // 内联样式替代className
893
+ const sectionIndex = s;
894
+ // 动态测量时外层定位容器不设固定高度,由内层撑开
295
895
  const sectionHeaderStyle = Object.assign({ position: 'absolute', zIndex: 2, boxSizing: 'border-box', width: '100%', minHeight: '20px', overflow: 'hidden', lineHeight: 1 }, (isHorizontal
296
- ? { top: 0, height: '100%', left: offset, width: headerSize }
297
- : { top: offset, height: headerSize }));
298
- nodes.push(React.createElement(View, {
299
- key: section.key + '-header',
300
- style: sectionHeaderStyle,
301
- }, section.header));
896
+ ? { top: 0, height: '100%', left: offset, width: props.useResizeObserver ? undefined : headerSize }
897
+ : { top: offset, height: props.useResizeObserver ? undefined : headerSize }));
898
+ // header ref 回调(用于 ResizeObserver 测量)
899
+ const headerRefCallback = props.useResizeObserver ? (el) => {
900
+ if (el) {
901
+ headerRefsRef.current.set(sectionIndex, el);
902
+ resizeObserver.observe(el, -sectionIndex - 1); // 用负数索引区分 header 和 item
903
+ const measureAndUpdateHeader = (measured) => {
904
+ var _a;
905
+ if (measured > 0) {
906
+ const oldSize = (_a = headerSizeCacheRef.current.get(sectionIndex)) !== null && _a !== void 0 ? _a : getDefaultHeaderSize();
907
+ if (Math.abs(oldSize - measured) >= 1) {
908
+ headerSizeCacheRef.current.set(sectionIndex, measured);
909
+ if (isWeapp && props.useResizeObserver === true) {
910
+ scheduleWeappDynamicReflow();
911
+ }
912
+ else if (sizeCacheRafRef.current == null) {
913
+ sizeCacheRafRef.current = requestAnimationFrame(() => {
914
+ sizeCacheRafRef.current = null;
915
+ setSizeCacheVersion((v) => v + 1);
916
+ });
917
+ }
918
+ }
919
+ }
920
+ };
921
+ if (isH5) {
922
+ requestAnimationFrame(() => {
923
+ if (!headerRefsRef.current.has(sectionIndex))
924
+ return;
925
+ const rect = el.getBoundingClientRect();
926
+ measureAndUpdateHeader(isHorizontal ? rect.width : rect.height);
927
+ });
928
+ }
929
+ else if (isWeapp) {
930
+ Taro.nextTick(() => {
931
+ if (!headerRefsRef.current.has(sectionIndex))
932
+ return;
933
+ Taro.createSelectorQuery()
934
+ .select(`#${listId}-list-header-inner-${sectionIndex}`)
935
+ .boundingClientRect((rect) => {
936
+ if (rect) {
937
+ measureAndUpdateHeader(isHorizontal ? rect.width : rect.height);
938
+ }
939
+ })
940
+ .exec();
941
+ });
942
+ }
943
+ }
944
+ else {
945
+ const oldEl = headerRefsRef.current.get(sectionIndex);
946
+ if (oldEl) {
947
+ resizeObserver.unobserve(oldEl);
948
+ headerRefsRef.current.delete(sectionIndex);
949
+ }
950
+ }
951
+ } : undefined;
952
+ // 动态尺寸时:外层定位,内层撑开以便测量
953
+ const headerContentStyle = props.useResizeObserver
954
+ ? (isHorizontal
955
+ // weapp 下 max-content 兼容性不稳定,改用 inline-flex 收缩包裹以测得真实宽度
956
+ ? (isWeapp
957
+ ? { boxSizing: 'border-box', display: 'inline-flex', height: '100%' }
958
+ : { boxSizing: 'border-box', width: 'max-content', height: '100%' })
959
+ : { boxSizing: 'border-box', width: '100%' })
960
+ : {};
961
+ if (props.useResizeObserver) {
962
+ const headerInnerProps = {
963
+ ref: headerRefCallback,
964
+ style: headerContentStyle,
965
+ 'data-index': String(-sectionIndex - 1), // 用于 unobserve 获取 index;与 observe(el, -sectionIndex-1) 对应
966
+ };
967
+ if (isWeapp) {
968
+ headerInnerProps.id = `${listId}-list-header-inner-${sectionIndex}`;
969
+ }
970
+ nodes.push(React.createElement(View, {
971
+ key: section.key + '-header',
972
+ style: sectionHeaderStyle,
973
+ }, React.createElement(View, headerInnerProps, section.header)));
974
+ }
975
+ else {
976
+ nodes.push(React.createElement(View, {
977
+ key: section.key + '-header',
978
+ style: sectionHeaderStyle,
979
+ }, section.header));
980
+ }
302
981
  offset += headerSize;
303
982
  }
304
983
  // item offsets
@@ -318,9 +997,17 @@ const List = (props) => {
318
997
  break;
319
998
  }
320
999
  }
1000
+ // 更新可见起始索引(用于 ScrollCorrection)
1001
+ if (s === startSection && startItem === 0) {
1002
+ visibleStartIndexRef.current = globalItemIndex;
1003
+ }
1004
+ else if (s === startSection) {
1005
+ visibleStartIndexRef.current = globalItemIndex + startItem;
1006
+ }
321
1007
  // 渲染可见item
322
1008
  for (let i = startItem; i <= endItem; i++) {
323
- // 内联样式替代className
1009
+ const currentGlobalIndex = globalItemIndex + i;
1010
+ const itemId = `list-item-${currentGlobalIndex}`;
324
1011
  const sectionItemStyle = Object.assign({ position: 'absolute', zIndex: 1, boxSizing: 'border-box', width: '100%', minHeight: '20px', overflow: 'hidden', lineHeight: 1 }, (isHorizontal
325
1012
  ? {
326
1013
  top: 0,
@@ -334,17 +1021,208 @@ const List = (props) => {
334
1021
  height: itemSizes[i],
335
1022
  marginBottom: space
336
1023
  }));
337
- nodes.push(React.createElement(View, {
1024
+ // ResizeObserver:绑定内层内容容器测量真实尺寸,尺寸变化时才 bump 版本
1025
+ const refCallback = (el) => {
1026
+ if (el) {
1027
+ const capturedIndex = currentGlobalIndex;
1028
+ itemRefsRef.current.set(capturedIndex, el);
1029
+ resizeObserver.observe(el, capturedIndex);
1030
+ // H5:使用 getBoundingClientRect 进行 fallback 测量
1031
+ // 小程序:使用 SelectorQuery 进行 fallback 测量(小程序没有 getBoundingClientRect)
1032
+ const measureAndUpdate = (measured) => {
1033
+ var _a;
1034
+ if (measured > 0) {
1035
+ const oldSize = sizeCache.getItemSize(capturedIndex);
1036
+ if (Math.abs(oldSize - measured) < 1)
1037
+ return;
1038
+ sizeCache.setItemSize(capturedIndex, measured);
1039
+ scrollCorrection.recordSizeChange(capturedIndex, oldSize, measured);
1040
+ if (isWeapp && props.useResizeObserver === true) {
1041
+ scheduleWeappDynamicReflow();
1042
+ }
1043
+ else if (sizeCacheRafRef.current == null) {
1044
+ sizeCacheRafRef.current = requestAnimationFrame(() => {
1045
+ sizeCacheRafRef.current = null;
1046
+ setSizeCacheVersion((v) => v + 1);
1047
+ });
1048
+ }
1049
+ // 小程序:延迟 onItemSizeChange,避免父组件重渲染导致 List remount
1050
+ if (isWeapp) {
1051
+ weappDeferItemSizeChange(capturedIndex, measured, props.onItemSizeChange);
1052
+ }
1053
+ else {
1054
+ (_a = props.onItemSizeChange) === null || _a === void 0 ? void 0 : _a.call(props, capturedIndex, measured);
1055
+ }
1056
+ }
1057
+ };
1058
+ if (isH5) {
1059
+ requestAnimationFrame(() => {
1060
+ if (!itemRefsRef.current.has(capturedIndex))
1061
+ return;
1062
+ const rect = el.getBoundingClientRect();
1063
+ measureAndUpdate(isHorizontal ? rect.width : rect.height);
1064
+ });
1065
+ }
1066
+ else if (isWeapp) {
1067
+ // 小程序端:使用 SelectorQuery 测量内层内容容器的实际尺寸
1068
+ // 注意:必须选 inner 容器(无固定高度,由内容撑开),不能选 outer(有虚拟列表设置的固定高度)
1069
+ // 已测量过的 item 跳过,避免 refCallback 重复触发导致无限循环
1070
+ // 滚动期间跳过 SelectorQuery(不加入 weappMeasuredItemsRef),避免异步查询干扰 scroll-view
1071
+ // SelectorQuery 是只读查询,滚动期间执行安全
1072
+ if (shouldMeasureWeappItem(capturedIndex, weappMeasuredItemsRef.current)) {
1073
+ weappMeasuredItemsRef.current.add(capturedIndex);
1074
+ // 使用 Taro.nextTick 代替 setTimeout(50):等待下一帧渲染完成后再测量
1075
+ // 比固定延时更快(减少"预估→实测"闪烁)且更可靠(保证 DOM 已更新)
1076
+ Taro.nextTick(() => {
1077
+ if (!itemRefsRef.current.has(capturedIndex))
1078
+ return;
1079
+ Taro.createSelectorQuery()
1080
+ // 页面上可能同时存在多个 List,inner id 必须带 listId 前缀避免跨列表误命中
1081
+ .select(`#${listId}-list-item-inner-${capturedIndex}`)
1082
+ .boundingClientRect((rect) => {
1083
+ if (rect) {
1084
+ measureAndUpdate(isHorizontal ? rect.width : rect.height);
1085
+ }
1086
+ })
1087
+ .exec();
1088
+ });
1089
+ }
1090
+ }
1091
+ }
1092
+ else {
1093
+ const oldEl = itemRefsRef.current.get(currentGlobalIndex);
1094
+ if (oldEl) {
1095
+ resizeObserver.unobserve(oldEl);
1096
+ itemRefsRef.current.delete(currentGlobalIndex);
1097
+ }
1098
+ }
1099
+ };
1100
+ // 动态尺寸时:外层负责定位,内层由内容撑开以便测量真实尺寸。
1101
+ // 纵向:内层 width:100% 无 height,由内容撑开,测到的是内容高度。
1102
+ // 横向:width:max-content + height:100%:
1103
+ // - width:max-content 便于测量真实宽度;
1104
+ // - height:100% 让测量层与外层 slot 条带高度一致,避免「外层条带 180px、内层 wrapper 只有内容高度」导致的内外高度差。
1105
+ const contentWrapperStyle = props.useResizeObserver
1106
+ ? (isHorizontal
1107
+ // weapp 下 max-content 兼容性不稳定,改用 inline-flex 收缩包裹以测得真实宽度
1108
+ ? (isWeapp
1109
+ ? { boxSizing: 'border-box', display: 'inline-flex', height: '100%' }
1110
+ : { boxSizing: 'border-box', width: 'max-content', height: '100%' })
1111
+ : { boxSizing: 'border-box', width: '100%' })
1112
+ : {};
1113
+ const outerItemProps = {
338
1114
  key: section.key + '-item-' + i,
1115
+ id: itemId,
339
1116
  style: sectionItemStyle,
340
- }, section.items[i]));
1117
+ };
1118
+ if (props.useResizeObserver) {
1119
+ const innerProps = {
1120
+ ref: refCallback,
1121
+ style: contentWrapperStyle,
1122
+ };
1123
+ // 小程序端需要 id 用于 SelectorQuery 测量内容真实尺寸;H5 端不需要(用 getBoundingClientRect)
1124
+ if (isWeapp) {
1125
+ // 页面内多 List 并存时避免 id 冲突(例如 demo 同页含多个 List)
1126
+ innerProps.id = `${listId}-list-item-inner-${currentGlobalIndex}`;
1127
+ }
1128
+ innerProps['data-index'] = String(currentGlobalIndex);
1129
+ const itemNode = React.createElement(View, outerItemProps, React.createElement(View, innerProps, section.items[i]));
1130
+ // 任务 4.1:当 List 暴露 scrollRef 时,为每个 item 提供 Context,供内层 WaterFlow 使用
1131
+ const itemWithContext = scrollRefProp && !useScrollElementMode
1132
+ ? React.createElement(ScrollElementContextOrFallback.Provider, {
1133
+ key: outerItemProps.key,
1134
+ value: {
1135
+ scrollRef: scrollRefProp,
1136
+ containerHeight: containerLength,
1137
+ startOffset: offset + itemOffsets[i],
1138
+ reportNestedHeightChange: props.useResizeObserver
1139
+ ? (h) => handleReportNestedHeightChange(h, currentGlobalIndex)
1140
+ : undefined,
1141
+ },
1142
+ }, itemNode)
1143
+ : itemNode;
1144
+ nodes.push(itemWithContext);
1145
+ }
1146
+ else {
1147
+ const itemNode = React.createElement(View, outerItemProps, section.items[i]);
1148
+ const itemWithContext = scrollRefProp && !useScrollElementMode
1149
+ ? React.createElement(ScrollElementContextOrFallback.Provider, {
1150
+ key: outerItemProps.key,
1151
+ value: {
1152
+ scrollRef: scrollRefProp,
1153
+ containerHeight: containerLength,
1154
+ startOffset: offset + itemOffsets[i],
1155
+ reportNestedHeightChange: props.useResizeObserver
1156
+ ? (h) => handleReportNestedHeightChange(h, currentGlobalIndex)
1157
+ : undefined,
1158
+ },
1159
+ }, itemNode)
1160
+ : itemNode;
1161
+ nodes.push(itemWithContext);
1162
+ }
341
1163
  }
1164
+ globalItemIndex += section.items.length;
342
1165
  offset += itemOffsets[itemOffsets.length - 1];
343
1166
  }
344
1167
  return nodes;
345
1168
  };
346
- return (jsx(ScrollView, Object.assign({ ref: containerRef }, scrollViewProps, { children: jsxs(View, { style: isHorizontal ? { width: totalLength, position: 'relative', height: '100%' } : { height: totalLength, position: 'relative', width: '100%' }, children: [stickyHeaderNode, renderSections()] }) })));
1169
+ // 渲染 NoMore 内容
1170
+ const renderNoMoreContent = () => {
1171
+ if (!noMoreConfig || !noMoreConfig.visible)
1172
+ return null;
1173
+ const noMoreHeightValue = noMoreConfig.height || 60;
1174
+ const listContentEnd = sectionOffsets[sectionOffsets.length - 1];
1175
+ const defaultStyle = Object.assign(Object.assign(Object.assign({ position: 'absolute' }, (isHorizontal
1176
+ ? { left: listContentEnd, top: 0, width: noMoreHeightValue, height: '100%' }
1177
+ : { top: listContentEnd, left: 0, width: '100%', height: noMoreHeightValue })), { display: 'flex', alignItems: 'center', justifyContent: 'center', textAlign: 'center', color: '#999', fontSize: '14px', boxSizing: 'border-box' }), noMoreConfig.style);
1178
+ return (jsx(View, { style: defaultStyle, children: noMoreConfig.children || noMoreConfig.text || '没有更多了' }));
1179
+ };
1180
+ // 空列表场景:仅显示 NoMore
1181
+ if (sections.length === 0 && (noMoreConfig === null || noMoreConfig === void 0 ? void 0 : noMoreConfig.visible)) {
1182
+ return (jsx(ScrollView, Object.assign({ ref: containerRef }, scrollViewProps, { children: jsx(View, { style: Object.assign({ minHeight: containerLength, display: 'flex', alignItems: 'center', justifyContent: 'center' }, containerStyle), children: renderNoMoreContent() }) })));
1183
+ }
1184
+ // 可滚区域总尺寸
1185
+ // H5 refresher 用负 translateY 隐藏,有上方混排时可能延伸到 sibling 区域;overflow:hidden 裁剪避免重叠
1186
+ const needsRefresherClip = refresherHeightForH5 > 0;
1187
+ const contentWrapperStyle = isHorizontal
1188
+ ? Object.assign({ width: totalLength, position: 'relative', height: '100%' }, (needsRefresherClip && { overflow: 'hidden' })) : Object.assign({ height: totalLength, position: 'relative', width: '100%' }, (needsRefresherClip && { overflow: 'hidden' }));
1189
+ const listWrapperStyle = isHorizontal
1190
+ ? { width: listContentLength, position: 'relative', height: '100%' }
1191
+ : { height: listContentLength, position: 'relative', width: '100%' };
1192
+ const pullTranslate = refresherHeightForH5 > 0 && h5RefresherProps.pullDistance !== 0
1193
+ ? { transform: `translateY(${h5RefresherProps.pullDistance}px)` }
1194
+ : {};
1195
+ const h5RefresherTranslateY = -refresherHeightForH5 + h5RefresherProps.pullDistance;
1196
+ // 内容区域渲染
1197
+ const renderContentArea = () => {
1198
+ var _a, _b;
1199
+ return (jsx(View, { style: contentWrapperStyle, children: refresherHeightForH5 > 0 ? (jsxs(Fragment, { children: [jsx(View, { style: {
1200
+ position: 'absolute',
1201
+ top: 0,
1202
+ left: 0,
1203
+ right: 0,
1204
+ height: refresherHeightForH5,
1205
+ zIndex: 0,
1206
+ transform: `translateY(${h5RefresherTranslateY}px)`,
1207
+ }, children: renderRefresherContent() }), jsxs(View, { style: Object.assign(Object.assign(Object.assign({}, listWrapperStyle), pullTranslate), { zIndex: 1, background: (_b = (_a = style === null || style === void 0 ? void 0 : style.background) !== null && _a !== void 0 ? _a : style === null || style === void 0 ? void 0 : style.backgroundColor) !== null && _b !== void 0 ? _b : '#fff' }), children: [stickyHeaderNode, renderSections(), renderNoMoreContent()] })] })) : (jsxs(Fragment, { children: [!supportsNativeRefresher && renderRefresherContent(), stickyHeaderNode, renderSections(), renderNoMoreContent()] })) }));
1208
+ };
1209
+ // useScrollElementMode 或 needAutoFind&&pending:渲染 View 以便监听外部滚动或 probe 阶段查找滚动父节点
1210
+ const renderView = useScrollElementMode || (!!needAutoFind && autoFindStatus === 'pending');
1211
+ if (renderView) {
1212
+ // 任务 2.4:恢复 refresher DOM 结构(refresher 层 + listWrapperStyle)
1213
+ return (jsx(View, { ref: contentWrapperRef, id: contentId, style: contentWrapperStyle, children: refresherHeightForH5 > 0 ? (jsxs(Fragment, { children: [jsx(View, { style: {
1214
+ position: 'absolute',
1215
+ top: 0,
1216
+ left: 0,
1217
+ right: 0,
1218
+ height: refresherHeightForH5,
1219
+ zIndex: 0,
1220
+ transform: `translateY(${h5RefresherTranslateY}px)`,
1221
+ }, children: renderRefresherContent() }), jsxs(View, { style: Object.assign(Object.assign(Object.assign({}, listWrapperStyle), pullTranslate), { zIndex: 1, background: (_c = (_b = style === null || style === void 0 ? void 0 : style.background) !== null && _b !== void 0 ? _b : style === null || style === void 0 ? void 0 : style.backgroundColor) !== null && _c !== void 0 ? _c : '#fff' }), children: [stickyHeaderNode, renderSections(), renderNoMoreContent()] })] })) : (jsxs(Fragment, { children: [stickyHeaderNode, renderSections(), renderNoMoreContent()] })) }));
1222
+ }
1223
+ return (jsxs(ScrollView, Object.assign({ ref: containerRef }, scrollViewProps, { id: listId, children: [supportsNativeRefresher && renderRefresherContent(), renderContentArea()] })));
347
1224
  };
1225
+ const List = React.forwardRef(InnerList);
348
1226
 
349
- export { List, ListItem, StickyHeader, StickySection, accumulate, List as default, isShaking };
1227
+ export { List, ListItem, ScrollElementContextOrFallback as ListScrollElementContext, NoMore, StickyHeader, StickySection, accumulate, List as default, isShaking };
350
1228
  //# sourceMappingURL=index.js.map