@tarojs/components-advanced 4.0.8-beta.0 → 4.0.8-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +8 -0
- package/dist/components/index.js.map +1 -1
- package/dist/components/list/ListItem.d.ts +9 -0
- package/dist/components/list/ListItem.js +9 -0
- package/dist/components/list/ListItem.js.map +1 -0
- package/dist/components/list/StickyHeader.d.ts +9 -0
- package/dist/components/list/StickyHeader.js +9 -0
- package/dist/components/list/StickyHeader.js.map +1 -0
- package/dist/components/list/StickySection.d.ts +9 -0
- package/dist/components/list/StickySection.js +9 -0
- package/dist/components/list/StickySection.js.map +1 -0
- package/dist/components/list/index.d.ts +37 -0
- package/dist/components/list/index.js +350 -0
- package/dist/components/list/index.js.map +1 -0
- package/dist/components/virtual-list/dom-helpers.js.map +1 -1
- package/dist/components/virtual-list/index.d.ts +5 -5
- package/dist/components/virtual-list/index.js.map +1 -1
- package/dist/components/virtual-list/list-set.js.map +1 -1
- package/dist/components/virtual-list/preset.d.ts +0 -1
- package/dist/components/virtual-list/preset.js.map +1 -1
- package/dist/components/virtual-list/react/index.js.map +1 -1
- package/dist/components/virtual-list/react/list.js.map +1 -1
- package/dist/components/virtual-list/react/validate.js.map +1 -1
- package/dist/components/virtual-list/react/wrapper.js.map +1 -1
- package/dist/components/virtual-list/utils.js.map +1 -1
- package/dist/components/virtual-list/vue/index.js.map +1 -1
- package/dist/components/virtual-list/vue/list.d.ts +13 -13
- package/dist/components/virtual-list/vue/list.js +3 -3
- package/dist/components/virtual-list/vue/list.js.map +1 -1
- package/dist/components/virtual-waterfall/index.js.map +1 -1
- package/dist/components/virtual-waterfall/list-map.js.map +1 -1
- package/dist/components/virtual-waterfall/preset.d.ts +0 -1
- package/dist/components/virtual-waterfall/preset.js.map +1 -1
- package/dist/components/virtual-waterfall/react/index.js.map +1 -1
- package/dist/components/virtual-waterfall/react/waterfall.js.map +1 -1
- package/dist/components/virtual-waterfall/react/wrapper.js +7 -5
- package/dist/components/virtual-waterfall/react/wrapper.js.map +1 -1
- package/dist/components/virtual-waterfall/vue/index.js.map +1 -1
- package/dist/components/virtual-waterfall/vue/waterfall.d.ts +11 -11
- package/dist/components/virtual-waterfall/vue/waterfall.js +3 -3
- package/dist/components/virtual-waterfall/vue/waterfall.js.map +1 -1
- package/dist/components/water-flow/flow-item.d.ts +11 -0
- package/dist/components/water-flow/flow-item.js +70 -0
- package/dist/components/water-flow/flow-item.js.map +1 -0
- package/dist/components/water-flow/flow-section.d.ts +7 -0
- package/dist/components/water-flow/flow-section.js +66 -0
- package/dist/components/water-flow/flow-section.js.map +1 -0
- package/dist/components/water-flow/index.d.ts +4 -0
- package/dist/components/water-flow/index.js +4 -0
- package/dist/components/water-flow/index.js.map +1 -0
- package/dist/components/water-flow/interface.d.ts +54 -0
- package/dist/components/water-flow/node.d.ts +63 -0
- package/dist/components/water-flow/node.js +99 -0
- package/dist/components/water-flow/node.js.map +1 -0
- package/dist/components/water-flow/root.d.ts +144 -0
- package/dist/components/water-flow/root.js +383 -0
- package/dist/components/water-flow/root.js.map +1 -0
- package/dist/components/water-flow/section.d.ts +112 -0
- package/dist/components/water-flow/section.js +233 -0
- package/dist/components/water-flow/section.js.map +1 -0
- package/dist/components/water-flow/stateful-event-bus.d.ts +33 -0
- package/dist/components/water-flow/stateful-event-bus.js +70 -0
- package/dist/components/water-flow/stateful-event-bus.js.map +1 -0
- package/dist/components/water-flow/use-memoized-fn.d.ts +4 -0
- package/dist/components/water-flow/use-memoized-fn.js +16 -0
- package/dist/components/water-flow/use-memoized-fn.js.map +1 -0
- package/dist/components/water-flow/use-observed-attr.d.ts +2 -0
- package/dist/components/water-flow/use-observed-attr.js +20 -0
- package/dist/components/water-flow/use-observed-attr.js.map +1 -0
- package/dist/components/water-flow/use-unmount.d.ts +1 -0
- package/dist/components/water-flow/utils.d.ts +30 -0
- package/dist/components/water-flow/utils.js +45 -0
- package/dist/components/water-flow/utils.js.map +1 -0
- package/dist/components/water-flow/water-flow.d.ts +4 -0
- package/dist/components/water-flow/water-flow.js +159 -0
- package/dist/components/water-flow/water-flow.js.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/convert.js.map +1 -1
- package/dist/utils/dom.js.map +1 -1
- package/dist/utils/helper.js.map +1 -1
- package/dist/utils/lodash.js.map +1 -1
- package/dist/utils/math.js.map +1 -1
- package/dist/utils/timer.js.map +1 -1
- package/dist/utils/vue-render.js.map +1 -1
- package/package.json +10 -12
package/dist/components/index.js
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
export { List, accumulate, isShaking } from './list/index.js';
|
|
1
2
|
export { VirtualList } from './virtual-list/index.js';
|
|
2
3
|
export { VirtualWaterfall } from './virtual-waterfall/index.js';
|
|
4
|
+
import './water-flow/index.js';
|
|
5
|
+
export { ListItem } from './list/ListItem.js';
|
|
6
|
+
export { StickyHeader } from './list/StickyHeader.js';
|
|
7
|
+
export { StickySection } from './list/StickySection.js';
|
|
8
|
+
export { FlowItem, useFlowItemPositioner } from './water-flow/flow-item.js';
|
|
9
|
+
export { FlowSection } from './water-flow/flow-section.js';
|
|
10
|
+
export { WaterFlow } from './water-flow/water-flow.js';
|
|
3
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { View } from '@tarojs/components';
|
|
3
|
+
|
|
4
|
+
const ListItem = ({ children, className, style }) => {
|
|
5
|
+
return jsx(View, { className: className, style: style, children: children });
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export { ListItem, ListItem as default };
|
|
9
|
+
//# sourceMappingURL=ListItem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ListItem.js","sources":["../../../src/components/list/ListItem.tsx"],"sourcesContent":["import { View } from '@tarojs/components'\nimport React from 'react'\n\nexport interface ListItemProps {\n children: React.ReactNode\n className?: string\n style?: React.CSSProperties\n}\n\nconst ListItem: React.FC<ListItemProps> = ({ children, className, style }) => {\n return <View className={className} style={style}>{children}</View>\n}\n\nexport { ListItem }\nexport default ListItem\n"],"names":["_jsx"],"mappings":";;;AASM,MAAA,QAAQ,GAA4B,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,KAAI;AAC3E,IAAA,OAAOA,GAAC,CAAA,IAAI,EAAC,EAAA,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAG,QAAA,EAAA,QAAQ,GAAQ;AACpE;;;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface StickyHeaderProps {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
className?: string;
|
|
5
|
+
style?: React.CSSProperties;
|
|
6
|
+
}
|
|
7
|
+
declare const StickyHeader: React.FC<StickyHeaderProps>;
|
|
8
|
+
export { StickyHeader };
|
|
9
|
+
export default StickyHeader;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { View } from '@tarojs/components';
|
|
3
|
+
|
|
4
|
+
const StickyHeader = ({ children, className, style }) => {
|
|
5
|
+
return jsx(View, { className: className, style: style, children: children });
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export { StickyHeader, StickyHeader as default };
|
|
9
|
+
//# sourceMappingURL=StickyHeader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StickyHeader.js","sources":["../../../src/components/list/StickyHeader.tsx"],"sourcesContent":["import { View } from '@tarojs/components'\nimport React from 'react'\n\nexport interface StickyHeaderProps {\n children: React.ReactNode\n className?: string\n style?: React.CSSProperties\n}\n\nconst StickyHeader: React.FC<StickyHeaderProps> = ({ children, className, style }) => {\n return <View className={className} style={style}>{children}</View>\n}\n\nexport { StickyHeader }\nexport default StickyHeader\n"],"names":["_jsx"],"mappings":";;;AASM,MAAA,YAAY,GAAgC,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,KAAI;AACnF,IAAA,OAAOA,GAAC,CAAA,IAAI,EAAC,EAAA,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAG,QAAA,EAAA,QAAQ,GAAQ;AACpE;;;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface StickySectionProps {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
className?: string;
|
|
5
|
+
style?: React.CSSProperties;
|
|
6
|
+
}
|
|
7
|
+
declare const StickySection: React.FC<StickySectionProps>;
|
|
8
|
+
export { StickySection };
|
|
9
|
+
export default StickySection;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { View } from '@tarojs/components';
|
|
3
|
+
|
|
4
|
+
const StickySection = ({ children, className, style }) => {
|
|
5
|
+
return jsx(View, { className: className, style: style, children: children });
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export { StickySection, StickySection as default };
|
|
9
|
+
//# sourceMappingURL=StickySection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StickySection.js","sources":["../../../src/components/list/StickySection.tsx"],"sourcesContent":["import { View } from '@tarojs/components'\nimport React from 'react'\n\nexport interface StickySectionProps {\n children: React.ReactNode\n className?: string\n style?: React.CSSProperties\n}\n\nconst StickySection: React.FC<StickySectionProps> = ({ children, className, style }) => {\n return <View className={className} style={style}>{children}</View>\n}\n\nexport { StickySection }\nexport default StickySection\n"],"names":["_jsx"],"mappings":";;;AASM,MAAA,aAAa,GAAiC,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,KAAI;AACrF,IAAA,OAAOA,GAAC,CAAA,IAAI,EAAC,EAAA,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAG,QAAA,EAAA,QAAQ,GAAQ;AACpE;;;;"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import ListItem from './ListItem';
|
|
3
|
+
import StickyHeader from './StickyHeader';
|
|
4
|
+
import StickySection from './StickySection';
|
|
5
|
+
export interface ListProps {
|
|
6
|
+
showScrollbar?: boolean;
|
|
7
|
+
scrollTop?: number;
|
|
8
|
+
onScroll?: (e: {
|
|
9
|
+
scrollTop: number;
|
|
10
|
+
scrollLeft: number;
|
|
11
|
+
}) => void;
|
|
12
|
+
onScrollToUpper?: () => void;
|
|
13
|
+
onScrollToLower?: () => void;
|
|
14
|
+
upperThresholdCount?: number;
|
|
15
|
+
lowerThresholdCount?: number;
|
|
16
|
+
cacheCount?: number;
|
|
17
|
+
stickyHeader?: boolean;
|
|
18
|
+
space?: number;
|
|
19
|
+
item?: React.ComponentType<any>;
|
|
20
|
+
itemCount?: number;
|
|
21
|
+
itemData?: any[];
|
|
22
|
+
itemSize?: number | ((index: number, data?: any[]) => number);
|
|
23
|
+
height?: number | string;
|
|
24
|
+
width?: number | string;
|
|
25
|
+
layout?: 'vertical' | 'horizontal';
|
|
26
|
+
style?: React.CSSProperties;
|
|
27
|
+
children?: React.ReactNode;
|
|
28
|
+
headerHeight?: number;
|
|
29
|
+
headerWidth?: number;
|
|
30
|
+
itemHeight?: number;
|
|
31
|
+
itemWidth?: number;
|
|
32
|
+
}
|
|
33
|
+
export declare function accumulate(arr: number[]): number[];
|
|
34
|
+
export declare function isShaking(diffList: number[]): boolean;
|
|
35
|
+
declare const List: React.FC<ListProps>;
|
|
36
|
+
export { List, ListItem, StickyHeader, StickySection };
|
|
37
|
+
export default List;
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import { View, ScrollView } from '@tarojs/components';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { ListItem } from './ListItem.js';
|
|
5
|
+
import { StickyHeader } from './StickyHeader.js';
|
|
6
|
+
import { StickySection } from './StickySection.js';
|
|
7
|
+
|
|
8
|
+
// 工具:累加数组
|
|
9
|
+
function accumulate(arr) {
|
|
10
|
+
const result = [0];
|
|
11
|
+
for (let i = 0; i < arr.length; i++) {
|
|
12
|
+
result[i + 1] = result[i] + arr[i];
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
// 检测抖动
|
|
17
|
+
function isShaking(diffList) {
|
|
18
|
+
if (diffList.length < 3)
|
|
19
|
+
return false;
|
|
20
|
+
// 检查是否有连续的正负交替
|
|
21
|
+
const signs = diffList.map(diff => Math.sign(diff));
|
|
22
|
+
let alternations = 0;
|
|
23
|
+
for (let i = 1; i < signs.length; i++) {
|
|
24
|
+
if (signs[i] !== 0 && signs[i] !== signs[i - 1]) {
|
|
25
|
+
alternations++;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// 如果交替次数过多,认为是抖动
|
|
29
|
+
return alternations >= 2;
|
|
30
|
+
}
|
|
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, onScroll, onScrollToUpper, onScrollToLower, upperThresholdCount = 0, lowerThresholdCount = 0, cacheCount = 2, style, children, layout = 'vertical' } = props;
|
|
34
|
+
const isHorizontal = layout === 'horizontal';
|
|
35
|
+
const DEFAULT_ITEM_WIDTH = 120;
|
|
36
|
+
const DEFAULT_ITEM_HEIGHT = 40;
|
|
37
|
+
// 滚动状态管理
|
|
38
|
+
const containerRef = React.useRef(null);
|
|
39
|
+
// 渲染偏移量 - 用于计算应该渲染哪些元素
|
|
40
|
+
const [renderOffset, setRenderOffset] = React.useState(controlledScrollTop !== null && controlledScrollTop !== void 0 ? controlledScrollTop : 0);
|
|
41
|
+
// 滚动视图偏移量 - 只在滚动结束或明确请求时更新到ScrollView
|
|
42
|
+
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);
|
|
44
|
+
// 滚动追踪相关refs
|
|
45
|
+
const isScrollingRef = React.useRef(false);
|
|
46
|
+
const lastScrollTopRef = React.useRef(controlledScrollTop !== null && controlledScrollTop !== void 0 ? controlledScrollTop : 0);
|
|
47
|
+
const scrollDiffListRef = React.useRef([0, 0, 0]);
|
|
48
|
+
const scrollTimeoutRef = React.useRef(null);
|
|
49
|
+
// 解析分组结构,只支持 StickySection 和 ListItem 作为直接子组件
|
|
50
|
+
const sections = React.useMemo(() => {
|
|
51
|
+
const result = [];
|
|
52
|
+
const defaultItems = [];
|
|
53
|
+
React.Children.forEach(children, (child, idx) => {
|
|
54
|
+
if (React.isValidElement(child) && child.type === StickySection) {
|
|
55
|
+
// 分组模式
|
|
56
|
+
const sectionProps = child.props;
|
|
57
|
+
let header = null;
|
|
58
|
+
const items = [];
|
|
59
|
+
React.Children.forEach(sectionProps.children, (subChild) => {
|
|
60
|
+
if (React.isValidElement(subChild) && subChild.type === StickyHeader)
|
|
61
|
+
header = subChild;
|
|
62
|
+
else if (React.isValidElement(subChild) && subChild.type === ListItem)
|
|
63
|
+
items.push(subChild);
|
|
64
|
+
});
|
|
65
|
+
result.push({ header, items, key: child.key || String(idx) });
|
|
66
|
+
}
|
|
67
|
+
else if (React.isValidElement(child) && child.type === ListItem) {
|
|
68
|
+
// 普通 ListItem
|
|
69
|
+
defaultItems.push(child);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
if (defaultItems.length > 0) {
|
|
73
|
+
result.push({ header: null, items: defaultItems, key: 'default' });
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
}, [children]);
|
|
77
|
+
// 工具:获取 header 尺寸,确保所有 header 相关逻辑一致
|
|
78
|
+
const getHeaderSize = () => {
|
|
79
|
+
if (isHorizontal) {
|
|
80
|
+
if (typeof props.headerWidth === 'number')
|
|
81
|
+
return props.headerWidth;
|
|
82
|
+
if (typeof props.itemWidth === 'number')
|
|
83
|
+
return props.itemWidth;
|
|
84
|
+
if (typeof props.itemSize === 'number')
|
|
85
|
+
return props.itemSize;
|
|
86
|
+
if (typeof props.itemSize === 'function')
|
|
87
|
+
return props.itemSize(0, props.itemData) || DEFAULT_ITEM_WIDTH;
|
|
88
|
+
return DEFAULT_ITEM_WIDTH;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
if (typeof props.headerHeight === 'number')
|
|
92
|
+
return props.headerHeight;
|
|
93
|
+
if (typeof props.itemHeight === 'number')
|
|
94
|
+
return props.itemHeight;
|
|
95
|
+
if (typeof props.itemSize === 'number')
|
|
96
|
+
return props.itemSize;
|
|
97
|
+
if (typeof props.itemSize === 'function')
|
|
98
|
+
return props.itemSize(0, props.itemData) || DEFAULT_ITEM_HEIGHT;
|
|
99
|
+
return DEFAULT_ITEM_HEIGHT;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
// 工具:获取 item 尺寸,支持函数/props/默认值
|
|
103
|
+
const getItemSize = (index) => {
|
|
104
|
+
if (isHorizontal) {
|
|
105
|
+
if (typeof props.itemWidth === 'number')
|
|
106
|
+
return props.itemWidth;
|
|
107
|
+
if (typeof props.itemSize === 'number')
|
|
108
|
+
return props.itemSize;
|
|
109
|
+
if (typeof props.itemSize === 'function')
|
|
110
|
+
return props.itemSize(index, props.itemData) || DEFAULT_ITEM_WIDTH;
|
|
111
|
+
return DEFAULT_ITEM_WIDTH;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
if (typeof props.itemHeight === 'number')
|
|
115
|
+
return props.itemHeight;
|
|
116
|
+
if (typeof props.itemSize === 'number')
|
|
117
|
+
return props.itemSize;
|
|
118
|
+
if (typeof props.itemSize === 'function')
|
|
119
|
+
return props.itemSize(index, props.itemData) || DEFAULT_ITEM_HEIGHT;
|
|
120
|
+
return DEFAULT_ITEM_HEIGHT;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
// 计算分组累积高度/宽度
|
|
124
|
+
const sectionOffsets = React.useMemo(() => {
|
|
125
|
+
const offsets = [0];
|
|
126
|
+
sections.forEach((section) => {
|
|
127
|
+
const headerSize = getHeaderSize();
|
|
128
|
+
const itemSizes = section.items.map((_, i) => getItemSize(i));
|
|
129
|
+
const groupSize = (section.header ? headerSize : 0) +
|
|
130
|
+
itemSizes.reduce((a, b) => a + b, 0) +
|
|
131
|
+
Math.max(0, section.items.length) * space;
|
|
132
|
+
offsets.push(offsets[offsets.length - 1] + groupSize);
|
|
133
|
+
});
|
|
134
|
+
return offsets;
|
|
135
|
+
}, [sections, space, isHorizontal, props.headerHeight, props.headerWidth, props.itemHeight, props.itemWidth, props.itemSize, props.itemData]);
|
|
136
|
+
// 外层虚拟滚动:可见分组
|
|
137
|
+
const [startSection, endSection] = React.useMemo(() => {
|
|
138
|
+
let start = 0;
|
|
139
|
+
let end = sections.length - 1;
|
|
140
|
+
for (let i = 0; i < sections.length; i++) {
|
|
141
|
+
if (sectionOffsets[i + 1] > renderOffset) {
|
|
142
|
+
start = Math.max(0, i - cacheCount);
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
for (let i = start; i < sections.length; i++) {
|
|
147
|
+
if (sectionOffsets[i] >= renderOffset + containerLength) {
|
|
148
|
+
end = Math.min(sections.length - 1, i + cacheCount);
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return [start, end];
|
|
153
|
+
}, [renderOffset, containerLength, sectionOffsets, sections.length, cacheCount]);
|
|
154
|
+
// 触顶/触底事件
|
|
155
|
+
React.useEffect(() => {
|
|
156
|
+
if (onScrollToUpper && renderOffset <= (upperThresholdCount > 0 ? sectionOffsets[upperThresholdCount] : 0)) {
|
|
157
|
+
onScrollToUpper();
|
|
158
|
+
}
|
|
159
|
+
if (onScrollToLower && renderOffset + containerLength >= sectionOffsets[sectionOffsets.length - 1] - (lowerThresholdCount > 0 ? sectionOffsets[sectionOffsets.length - 1] - sectionOffsets[sections.length - lowerThresholdCount] : 0)) {
|
|
160
|
+
onScrollToLower();
|
|
161
|
+
}
|
|
162
|
+
}, [renderOffset, containerLength, sectionOffsets, sections.length, upperThresholdCount, lowerThresholdCount, 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);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
// 其他平台:立即更新以获得更好的响应性
|
|
182
|
+
setScrollViewOffset(newOffset); // 立即更新滚动视图偏移量
|
|
183
|
+
scrollTimeoutRef.current = setTimeout(() => {
|
|
184
|
+
isScrollingRef.current = false;
|
|
185
|
+
}, 200);
|
|
186
|
+
}
|
|
187
|
+
}, []);
|
|
188
|
+
// 智能滚动处理函数
|
|
189
|
+
const handleScroll = React.useCallback((e) => {
|
|
190
|
+
// 兼容Stencil版本和React版本的事件结构
|
|
191
|
+
let newOffset;
|
|
192
|
+
if (e.detail) {
|
|
193
|
+
// React版本的事件结构
|
|
194
|
+
newOffset = isHorizontal ? e.detail.scrollLeft : e.detail.scrollTop;
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
// Stencil版本的事件结构
|
|
198
|
+
newOffset = isHorizontal ? e.scrollLeft : e.scrollTop;
|
|
199
|
+
}
|
|
200
|
+
const diff = newOffset - lastScrollTopRef.current;
|
|
201
|
+
scrollDiffListRef.current.shift();
|
|
202
|
+
scrollDiffListRef.current.push(diff);
|
|
203
|
+
// 只保留抖动检测,移除方向检测
|
|
204
|
+
if (isScrollingRef.current && isShaking(scrollDiffListRef.current)) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
updateRenderOffset(newOffset); // 直接更新渲染偏移量
|
|
208
|
+
onScroll === null || onScroll === void 0 ? void 0 : onScroll({
|
|
209
|
+
scrollTop: isHorizontal ? 0 : newOffset,
|
|
210
|
+
scrollLeft: isHorizontal ? newOffset : 0
|
|
211
|
+
});
|
|
212
|
+
}, [isHorizontal, onScroll, updateRenderOffset, containerLength]);
|
|
213
|
+
// 初始化后的延迟同步 - 确保ScrollView正确设置初始位置
|
|
214
|
+
React.useEffect(() => {
|
|
215
|
+
if (typeof controlledScrollTop === 'number') {
|
|
216
|
+
setScrollViewOffset(controlledScrollTop);
|
|
217
|
+
lastScrollTopRef.current = controlledScrollTop;
|
|
218
|
+
}
|
|
219
|
+
}, [controlledScrollTop]);
|
|
220
|
+
// 清理定时器
|
|
221
|
+
React.useEffect(() => {
|
|
222
|
+
return () => {
|
|
223
|
+
if (scrollTimeoutRef.current) {
|
|
224
|
+
clearTimeout(scrollTimeoutRef.current);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
}, []);
|
|
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属性
|
|
231
|
+
// ScrollView 属性
|
|
232
|
+
const scrollViewProps = {
|
|
233
|
+
scrollY: !isHorizontal,
|
|
234
|
+
scrollX: isHorizontal,
|
|
235
|
+
style: containerStyle,
|
|
236
|
+
enhanced: true,
|
|
237
|
+
showScrollbar: showScrollbar,
|
|
238
|
+
onScroll: handleScroll,
|
|
239
|
+
onScrollToUpper,
|
|
240
|
+
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版本
|
|
247
|
+
}
|
|
248
|
+
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
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}, [scrollViewOffset, isHorizontal]);
|
|
264
|
+
}
|
|
265
|
+
// 总高度/宽度
|
|
266
|
+
const totalLength = sectionOffsets[sectionOffsets.length - 1];
|
|
267
|
+
// 吸顶/吸左 header
|
|
268
|
+
const stickyHeaderNode = React.useMemo(() => {
|
|
269
|
+
if (!stickyHeader)
|
|
270
|
+
return null;
|
|
271
|
+
for (let i = 0; i < sections.length; i++) {
|
|
272
|
+
if (sectionOffsets[i] <= renderOffset && renderOffset < sectionOffsets[i + 1]) {
|
|
273
|
+
const section = sections[i];
|
|
274
|
+
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 }));
|
|
278
|
+
return (jsx(View, { style: stickyHeaderStyle, children: section.header }));
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return null;
|
|
283
|
+
}, [stickyHeader, renderOffset, sectionOffsets, sections, isHorizontal, props.headerHeight, props.headerWidth, props.itemHeight, props.itemWidth, props.itemSize, props.itemData]);
|
|
284
|
+
// 渲染分组+item双层虚拟滚动
|
|
285
|
+
const renderSections = () => {
|
|
286
|
+
const nodes = [];
|
|
287
|
+
let offset = sectionOffsets[startSection];
|
|
288
|
+
for (let s = startSection; s <= endSection; s++) {
|
|
289
|
+
const section = sections[s];
|
|
290
|
+
const headerSize = getHeaderSize();
|
|
291
|
+
const itemSizes = section.items.map((_, i) => getItemSize(i));
|
|
292
|
+
// header
|
|
293
|
+
if (section.header) {
|
|
294
|
+
// 内联样式替代className
|
|
295
|
+
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' + '-' + layout,
|
|
300
|
+
style: sectionHeaderStyle,
|
|
301
|
+
}, section.header));
|
|
302
|
+
offset += headerSize;
|
|
303
|
+
}
|
|
304
|
+
// item offsets
|
|
305
|
+
const itemOffsets = accumulate(itemSizes.map((size) => size + space));
|
|
306
|
+
// 内层虚拟滚动:可见item区间
|
|
307
|
+
let startItem = 0;
|
|
308
|
+
let endItem = section.items.length - 1;
|
|
309
|
+
for (let i = 0; i < section.items.length; i++) {
|
|
310
|
+
if (offset + itemOffsets[i + 1] > renderOffset) {
|
|
311
|
+
startItem = Math.max(0, i - cacheCount);
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
for (let i = startItem; i < section.items.length; i++) {
|
|
316
|
+
if (offset + itemOffsets[i] >= renderOffset + containerLength) {
|
|
317
|
+
endItem = Math.min(section.items.length - 1, i + cacheCount);
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
// 渲染可见item
|
|
322
|
+
for (let i = startItem; i <= endItem; i++) {
|
|
323
|
+
// 内联样式替代className
|
|
324
|
+
const sectionItemStyle = Object.assign({ position: 'absolute', zIndex: 1, boxSizing: 'border-box', width: '100%', minHeight: '20px', overflow: 'hidden', lineHeight: 1 }, (isHorizontal
|
|
325
|
+
? {
|
|
326
|
+
top: 0,
|
|
327
|
+
height: '100%',
|
|
328
|
+
left: offset + itemOffsets[i],
|
|
329
|
+
width: itemSizes[i],
|
|
330
|
+
marginRight: space
|
|
331
|
+
}
|
|
332
|
+
: {
|
|
333
|
+
top: offset + itemOffsets[i],
|
|
334
|
+
height: itemSizes[i],
|
|
335
|
+
marginBottom: space
|
|
336
|
+
}));
|
|
337
|
+
nodes.push(React.createElement(View, {
|
|
338
|
+
key: section.key + '-item-' + i + '-' + layout,
|
|
339
|
+
style: sectionItemStyle,
|
|
340
|
+
}, section.items[i]));
|
|
341
|
+
}
|
|
342
|
+
offset += itemOffsets[itemOffsets.length - 1];
|
|
343
|
+
}
|
|
344
|
+
return nodes;
|
|
345
|
+
};
|
|
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()] }) })));
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
export { List, ListItem, StickyHeader, StickySection, accumulate, List as default, isShaking };
|
|
350
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/components/list/index.tsx"],"sourcesContent":["import { ScrollView, View } from '@tarojs/components'\nimport React from 'react'\n\nimport ListItem from './ListItem'\nimport StickyHeader from './StickyHeader'\nimport StickySection from './StickySection'\n\nexport interface ListProps {\n showScrollbar?: boolean\n scrollTop?: number\n onScroll?: (e: { scrollTop: number, scrollLeft: number }) => void\n onScrollToUpper?: () => void\n onScrollToLower?: () => void\n upperThresholdCount?: number\n lowerThresholdCount?: number\n cacheCount?: number\n stickyHeader?: boolean\n space?: number\n item?: React.ComponentType<any>\n itemCount?: number\n itemData?: any[]\n itemSize?: number | ((index: number, data?: any[]) => number)\n height?: number | string\n width?: number | string\n layout?: 'vertical' | 'horizontal'\n style?: React.CSSProperties\n children?: React.ReactNode\n headerHeight?: number // 纵向 header 高度\n headerWidth?: number // 横向 header 宽度\n itemHeight?: number // 纵向 item 高度\n itemWidth?: number // 横向 item 宽度\n}\n\n// 工具:累加数组\nexport function accumulate(arr: number[]) {\n const result = [0]\n for (let i = 0; i < arr.length; i++) {\n result[i + 1] = result[i] + arr[i]\n }\n return result\n}\n\n// 检测抖动\nexport function isShaking(diffList: number[]): boolean {\n if (diffList.length < 3) return false\n\n // 检查是否有连续的正负交替\n const signs = diffList.map(diff => Math.sign(diff))\n let alternations = 0\n for (let i = 1; i < signs.length; i++) {\n if (signs[i] !== 0 && signs[i] !== signs[i - 1]) {\n alternations++\n }\n }\n\n // 如果交替次数过多,认为是抖动\n return alternations >= 2\n}\n\nconst List: React.FC<ListProps> = (props) => {\n const isH5 = process.env.TARO_ENV === 'h5'\n const {\n stickyHeader = false,\n space = 0,\n height = 400,\n width = '100%',\n showScrollbar = true,\n scrollTop: controlledScrollTop,\n onScroll,\n onScrollToUpper,\n onScrollToLower,\n upperThresholdCount = 0,\n lowerThresholdCount = 0,\n cacheCount = 2,\n style,\n children,\n layout = 'vertical'\n } = props\n\n const isHorizontal = layout === 'horizontal'\n const DEFAULT_ITEM_WIDTH = 120\n const DEFAULT_ITEM_HEIGHT = 40\n\n // 滚动状态管理\n const containerRef = React.useRef<HTMLDivElement>(null)\n\n // 渲染偏移量 - 用于计算应该渲染哪些元素\n const [renderOffset, setRenderOffset] = React.useState(controlledScrollTop ?? 0)\n\n // 滚动视图偏移量 - 只在滚动结束或明确请求时更新到ScrollView\n const [scrollViewOffset, setScrollViewOffset] = React.useState(controlledScrollTop ?? 0)\n\n\n const [containerLength] = React.useState<number>(typeof (isHorizontal ? width : height) === 'number' ? (isHorizontal ? (width as number) : (height as number)) : 400)\n\n // 滚动追踪相关refs\n const isScrollingRef = React.useRef(false)\n const lastScrollTopRef = React.useRef(controlledScrollTop ?? 0)\n const scrollDiffListRef = React.useRef<number[]>([0, 0, 0])\n const scrollTimeoutRef = React.useRef<NodeJS.Timeout | null>(null)\n\n // 解析分组结构,只支持 StickySection 和 ListItem 作为直接子组件\n const sections = React.useMemo(() => {\n const result: Array<{\n header: React.ReactElement | null\n items: React.ReactElement[]\n key: string\n }> = []\n const defaultItems: React.ReactElement[] = []\n React.Children.forEach(children, (child, idx) => {\n if (React.isValidElement(child) && child.type === StickySection) {\n // 分组模式\n const sectionProps = child.props as any\n let header: React.ReactElement | null = null\n const items: React.ReactElement[] = []\n React.Children.forEach(sectionProps.children, (subChild) => {\n if (React.isValidElement(subChild) && subChild.type === StickyHeader) header = subChild\n else if (React.isValidElement(subChild) && subChild.type === ListItem) items.push(subChild)\n })\n result.push({ header, items, key: child.key || String(idx) })\n } else if (React.isValidElement(child) && child.type === ListItem) {\n // 普通 ListItem\n defaultItems.push(child)\n }\n })\n if (defaultItems.length > 0) {\n result.push({ header: null, items: defaultItems, key: 'default' })\n }\n return result\n }, [children])\n\n // 工具:获取 header 尺寸,确保所有 header 相关逻辑一致\n const getHeaderSize = () => {\n if (isHorizontal) {\n if (typeof props.headerWidth === 'number') return props.headerWidth\n if (typeof props.itemWidth === 'number') return props.itemWidth\n if (typeof props.itemSize === 'number') return props.itemSize\n if (typeof props.itemSize === 'function') return props.itemSize(0, props.itemData) || DEFAULT_ITEM_WIDTH\n return DEFAULT_ITEM_WIDTH\n } else {\n if (typeof props.headerHeight === 'number') return props.headerHeight\n if (typeof props.itemHeight === 'number') return props.itemHeight\n if (typeof props.itemSize === 'number') return props.itemSize\n if (typeof props.itemSize === 'function') return props.itemSize(0, props.itemData) || DEFAULT_ITEM_HEIGHT\n return DEFAULT_ITEM_HEIGHT\n }\n }\n\n // 工具:获取 item 尺寸,支持函数/props/默认值\n const getItemSize = (index: number) => {\n if (isHorizontal) {\n if (typeof props.itemWidth === 'number') return props.itemWidth\n if (typeof props.itemSize === 'number') return props.itemSize\n if (typeof props.itemSize === 'function') return props.itemSize(index, props.itemData) || DEFAULT_ITEM_WIDTH\n return DEFAULT_ITEM_WIDTH\n } else {\n if (typeof props.itemHeight === 'number') return props.itemHeight\n if (typeof props.itemSize === 'number') return props.itemSize\n if (typeof props.itemSize === 'function') return props.itemSize(index, props.itemData) || DEFAULT_ITEM_HEIGHT\n return DEFAULT_ITEM_HEIGHT\n }\n }\n\n // 计算分组累积高度/宽度\n const sectionOffsets = React.useMemo(() => {\n const offsets: number[] = [0]\n sections.forEach((section) => {\n const headerSize = getHeaderSize()\n const itemSizes = section.items.map((_, i) => getItemSize(i))\n const groupSize = (section.header ? headerSize : 0) +\n itemSizes.reduce((a, b) => a + b, 0) +\n Math.max(0, section.items.length) * space\n offsets.push(offsets[offsets.length - 1] + groupSize)\n })\n return offsets\n }, [sections, space, isHorizontal, props.headerHeight, props.headerWidth, props.itemHeight, props.itemWidth, props.itemSize, props.itemData])\n\n // 外层虚拟滚动:可见分组\n const [startSection, endSection] = React.useMemo(() => {\n let start = 0; let end = sections.length - 1\n for (let i = 0; i < sections.length; i++) {\n if (sectionOffsets[i + 1] > renderOffset) {\n start = Math.max(0, i - cacheCount)\n break\n }\n }\n for (let i = start; i < sections.length; i++) {\n if (sectionOffsets[i] >= renderOffset + containerLength) {\n end = Math.min(sections.length - 1, i + cacheCount)\n break\n }\n }\n return [start, end]\n }, [renderOffset, containerLength, sectionOffsets, sections.length, cacheCount])\n\n // 触顶/触底事件\n React.useEffect(() => {\n if (onScrollToUpper && renderOffset <= (upperThresholdCount > 0 ? sectionOffsets[upperThresholdCount] : 0)) {\n onScrollToUpper()\n }\n if (onScrollToLower && renderOffset + containerLength >= sectionOffsets[sectionOffsets.length - 1] - (lowerThresholdCount > 0 ? sectionOffsets[sectionOffsets.length - 1] - sectionOffsets[sections.length - lowerThresholdCount] : 0)) {\n onScrollToLower()\n }\n }, [renderOffset, containerLength, sectionOffsets, sections.length, upperThresholdCount, lowerThresholdCount, onScrollToUpper, onScrollToLower])\n\n // 处理渲染偏移量更新\n const updateRenderOffset = React.useCallback((newOffset: number) => {\n lastScrollTopRef.current = newOffset\n isScrollingRef.current = true\n\n if (scrollTimeoutRef.current) {\n clearTimeout(scrollTimeoutRef.current)\n }\n\n setRenderOffset(newOffset) // 立即更新渲染偏移量\n\n // 平台适配:微信小程序使用延时,其他平台立即更新\n const isWeapp = process.env.TARO_ENV === 'weapp'\n if (isWeapp) {\n // 微信小程序:使用延时避免抖动\n scrollTimeoutRef.current = setTimeout(() => {\n isScrollingRef.current = false\n setScrollViewOffset(newOffset) // 滚动结束后,同步滚动视图偏移量\n }, 200)\n } else {\n // 其他平台:立即更新以获得更好的响应性\n setScrollViewOffset(newOffset) // 立即更新滚动视图偏移量\n scrollTimeoutRef.current = setTimeout(() => {\n isScrollingRef.current = false\n }, 200)\n }\n }, [])\n\n\n\n // 智能滚动处理函数\n const handleScroll = React.useCallback((e: any) => {\n // 兼容Stencil版本和React版本的事件结构\n let newOffset: number\n if (e.detail) {\n // React版本的事件结构\n newOffset = isHorizontal ? e.detail.scrollLeft : e.detail.scrollTop\n } else {\n // Stencil版本的事件结构\n newOffset = isHorizontal ? e.scrollLeft : e.scrollTop\n }\n\n const diff = newOffset - lastScrollTopRef.current\n scrollDiffListRef.current.shift()\n scrollDiffListRef.current.push(diff)\n\n // 只保留抖动检测,移除方向检测\n if (isScrollingRef.current && isShaking(scrollDiffListRef.current)) {\n return\n }\n\n updateRenderOffset(newOffset) // 直接更新渲染偏移量\n\n onScroll?.({\n scrollTop: isHorizontal ? 0 : newOffset,\n scrollLeft: isHorizontal ? newOffset : 0\n })\n }, [isHorizontal, onScroll, updateRenderOffset, containerLength])\n\n // 初始化后的延迟同步 - 确保ScrollView正确设置初始位置\n React.useEffect(() => {\n if (typeof controlledScrollTop === 'number') {\n setScrollViewOffset(controlledScrollTop)\n lastScrollTopRef.current = controlledScrollTop\n }\n }, [controlledScrollTop])\n\n // 清理定时器\n React.useEffect(() => {\n return () => {\n if (scrollTimeoutRef.current) {\n clearTimeout(scrollTimeoutRef.current)\n }\n }\n }, [])\n\n // 容器样式\n const containerStyle: React.CSSProperties = {\n position: 'relative',\n boxSizing: 'border-box',\n height: isHorizontal ? width : height,\n width: isHorizontal ? height : width,\n ...style,\n }\n\n // 修改ScrollView组件的props,添加data-testid属性\n // ScrollView 属性\n const scrollViewProps: any = {\n scrollY: !isHorizontal,\n scrollX: isHorizontal,\n style: containerStyle,\n enhanced: true,\n showScrollbar: showScrollbar,\n onScroll: handleScroll,\n onScrollToUpper,\n onScrollToLower,\n 'data-testid': 'taro-list-container'\n }\n\n // 设置ScrollView的滚动位置 - 同时兼容React版本和Stencil版本\n if (isHorizontal) {\n scrollViewProps.scrollLeft = scrollViewOffset // React版本\n scrollViewProps.mpScrollLeft = scrollViewOffset // Stencil版本\n } else {\n scrollViewProps.scrollTop = scrollViewOffset // React版本\n scrollViewProps.mpScrollTop = scrollViewOffset // Stencil版本\n }\n\n // H5上额外使用DOM直接操作确保滚动位置正确\n if (isH5) {\n React.useEffect(() => {\n if (containerRef.current && typeof scrollViewOffset === 'number') {\n if (isHorizontal) {\n containerRef.current.scrollLeft = scrollViewOffset\n } else {\n containerRef.current.scrollTop = scrollViewOffset\n }\n }\n }, [scrollViewOffset, isHorizontal])\n }\n\n // 总高度/宽度\n const totalLength = sectionOffsets[sectionOffsets.length - 1]\n\n // 吸顶/吸左 header\n const stickyHeaderNode = React.useMemo(() => {\n if (!stickyHeader) return null\n for (let i = 0; i < sections.length; i++) {\n if (sectionOffsets[i] <= renderOffset && renderOffset < sectionOffsets[i + 1]) {\n const section = sections[i]\n if (section.header) {\n const headerSize = getHeaderSize()\n // 内联样式替代className\n const stickyHeaderStyle: React.CSSProperties = {\n position: 'sticky',\n top: 0,\n left: 0,\n zIndex: 100,\n background: '#fff',\n boxSizing: 'border-box',\n minHeight: '20px',\n overflow: 'hidden',\n lineHeight: 1,\n ...(isHorizontal ? { width: headerSize } : { height: headerSize })\n }\n return (\n <View style={stickyHeaderStyle}>\n {section.header}\n </View>\n )\n }\n }\n }\n return null\n }, [stickyHeader, renderOffset, sectionOffsets, sections, isHorizontal, props.headerHeight, props.headerWidth, props.itemHeight, props.itemWidth, props.itemSize, props.itemData])\n\n // 渲染分组+item双层虚拟滚动\n const renderSections = () => {\n const nodes: React.ReactNode[] = []\n let offset = sectionOffsets[startSection]\n for (let s = startSection; s <= endSection; s++) {\n const section = sections[s]\n const headerSize = getHeaderSize()\n const itemSizes = section.items.map((_, i) => getItemSize(i))\n // header\n if (section.header) {\n // 内联样式替代className\n const sectionHeaderStyle: React.CSSProperties = {\n position: 'absolute',\n zIndex: 2,\n boxSizing: 'border-box',\n width: '100%',\n minHeight: '20px',\n overflow: 'hidden',\n lineHeight: 1,\n ...(isHorizontal\n ? { top: 0, height: '100%', left: offset, width: headerSize }\n : { top: offset, height: headerSize })\n }\n nodes.push(\n React.createElement(View, {\n key: section.key + '-header' + '-' + layout,\n style: sectionHeaderStyle,\n }, section.header)\n )\n offset += headerSize\n }\n // item offsets\n const itemOffsets = accumulate(itemSizes.map((size) => size + space))\n // 内层虚拟滚动:可见item区间\n let startItem = 0; let endItem = section.items.length - 1\n for (let i = 0; i < section.items.length; i++) {\n if (offset + itemOffsets[i + 1] > renderOffset) {\n startItem = Math.max(0, i - cacheCount)\n break\n }\n }\n for (let i = startItem; i < section.items.length; i++) {\n if (offset + itemOffsets[i] >= renderOffset + containerLength) {\n endItem = Math.min(section.items.length - 1, i + cacheCount)\n break\n }\n }\n // 渲染可见item\n for (let i = startItem; i <= endItem; i++) {\n // 内联样式替代className\n const sectionItemStyle: React.CSSProperties = {\n position: 'absolute',\n zIndex: 1,\n boxSizing: 'border-box',\n width: '100%',\n minHeight: '20px',\n overflow: 'hidden',\n lineHeight: 1,\n ...(isHorizontal\n ? {\n top: 0,\n height: '100%',\n left: offset + itemOffsets[i],\n width: itemSizes[i],\n marginRight: space\n }\n : {\n top: offset + itemOffsets[i],\n height: itemSizes[i],\n marginBottom: space\n })\n }\n nodes.push(\n React.createElement(View, {\n key: section.key + '-item-' + i + '-' + layout,\n style: sectionItemStyle,\n }, section.items[i])\n )\n }\n offset += itemOffsets[itemOffsets.length - 1]\n }\n return nodes\n }\n\n return (\n <ScrollView ref={containerRef} {...scrollViewProps}>\n <View style={isHorizontal ? { width: totalLength, position: 'relative', height: '100%' } : { height: totalLength, position: 'relative', width: '100%' }}>\n {stickyHeaderNode}\n {renderSections()}\n </View>\n </ScrollView>\n )\n}\n\nexport { List, ListItem, StickyHeader, StickySection }\nexport default List\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;;;AAiCA;AACM,SAAU,UAAU,CAAC,GAAa,EAAA;AACtC,IAAA,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC;AAClB,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC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C;AACnB,wBAAA,WAAW,EAAE;AACd;AACD,sBAAE;AACA,wBAAA,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC;AAC5B,wBAAA,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AACpB,wBAAA,YAAY,EAAE;AACf,qBAAA,EACJ;gBACD,KAAK,CAAC,IAAI,CACR,KAAK,CAAC,aAAa,CAAC,IAAI,EAAE;oBACxB,GAAG,EAAE,OAAO,CAAC,GAAG,GAAG,QAAQ,GAAG,CAAC,GAAG,GAAG,GAAG,MAAM;AAC9C,oBAAA,KAAK,EAAE,gBAAgB;iBACxB,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CACrB;;YAEH,MAAM,IAAI,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC;;AAE/C,QAAA,OAAO,KAAK;AACd,KAAC;IAED,QACEA,GAAC,CAAA,UAAU,EAAC,MAAA,CAAA,MAAA,CAAA,EAAA,GAAG,EAAE,YAAY,EAAM,EAAA,eAAe,EAChD,EAAA,QAAA,EAAAC,IAAA,CAAC,IAAI,EAAA,EAAC,KAAK,EAAE,YAAY,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,EACpJ,QAAA,EAAA,CAAA,gBAAgB,EAChB,cAAc,EAAE,CAAA,EAAA,CACZ,EACI,CAAA,CAAA;AAEjB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dom-helpers.js","sources":["../../../src/components/virtual-list/dom-helpers.ts"],"sourcesContent":["// TRICKY According to the spec, scrollLeft should be negative for RTL aligned elements.\n// Chrome does not seem to adhere; its scrollLeft values are positive (measured relative to the left).\n// Safari's elastic bounce makes detecting this even more complicated wrt potential false positives.\n// The safest way to check this is to intentionally set a negative offset,\n// and then verify that the subsequent \"scroll\" event matches the negative offset.\n// If it does not match, then we can assume a non-standard RTL scroll implementation.\n\nlet cachedRTLResult = null\n\nexport function getRTLOffsetType (recalculate = false) {\n if (cachedRTLResult === null || recalculate) {\n const outerDiv = document.createElement('div')\n const outerStyle = outerDiv.style\n outerStyle.width = '50px'\n outerStyle.height = '50px'\n outerStyle.overflow = 'scroll'\n outerStyle.direction = 'rtl'\n const innerDiv = document.createElement('div')\n const innerStyle = innerDiv.style\n innerStyle.width = '100px'\n innerStyle.height = '100px'\n outerDiv.appendChild(innerDiv)\n document.body.appendChild(outerDiv)\n\n if (outerDiv.scrollLeft > 0) {\n cachedRTLResult = 'positive-descending'\n } else {\n outerDiv.scrollLeft = 1\n\n if (outerDiv.scrollLeft === 0) {\n cachedRTLResult = 'negative'\n } else {\n cachedRTLResult = 'positive-ascending'\n }\n }\n\n document.body.removeChild(outerDiv)\n return cachedRTLResult\n }\n\n return cachedRTLResult\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AAEA,IAAI,eAAe,GAAG,IAAI
|
|
1
|
+
{"version":3,"file":"dom-helpers.js","sources":["../../../src/components/virtual-list/dom-helpers.ts"],"sourcesContent":["// TRICKY According to the spec, scrollLeft should be negative for RTL aligned elements.\n// Chrome does not seem to adhere; its scrollLeft values are positive (measured relative to the left).\n// Safari's elastic bounce makes detecting this even more complicated wrt potential false positives.\n// The safest way to check this is to intentionally set a negative offset,\n// and then verify that the subsequent \"scroll\" event matches the negative offset.\n// If it does not match, then we can assume a non-standard RTL scroll implementation.\n\nlet cachedRTLResult = null\n\nexport function getRTLOffsetType (recalculate = false) {\n if (cachedRTLResult === null || recalculate) {\n const outerDiv = document.createElement('div')\n const outerStyle = outerDiv.style\n outerStyle.width = '50px'\n outerStyle.height = '50px'\n outerStyle.overflow = 'scroll'\n outerStyle.direction = 'rtl'\n const innerDiv = document.createElement('div')\n const innerStyle = innerDiv.style\n innerStyle.width = '100px'\n innerStyle.height = '100px'\n outerDiv.appendChild(innerDiv)\n document.body.appendChild(outerDiv)\n\n if (outerDiv.scrollLeft > 0) {\n cachedRTLResult = 'positive-descending'\n } else {\n outerDiv.scrollLeft = 1\n\n if (outerDiv.scrollLeft === 0) {\n cachedRTLResult = 'negative'\n } else {\n cachedRTLResult = 'positive-ascending'\n }\n }\n\n document.body.removeChild(outerDiv)\n return cachedRTLResult\n }\n\n return cachedRTLResult\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AAEA,IAAI,eAAe,GAAG,IAAI;AAEV,SAAA,gBAAgB,CAAE,WAAW,GAAG,KAAK,EAAA;AACnD,IAAA,IAAI,eAAe,KAAK,IAAI,IAAI,WAAW,EAAE;QAC3C,MAAM,QAAQ,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC;AAC9C,QAAA,MAAM,UAAU,GAAG,QAAQ,CAAC,KAAK;AACjC,QAAA,UAAU,CAAC,KAAK,GAAG,MAAM;AACzB,QAAA,UAAU,CAAC,MAAM,GAAG,MAAM;AAC1B,QAAA,UAAU,CAAC,QAAQ,GAAG,QAAQ;AAC9B,QAAA,UAAU,CAAC,SAAS,GAAG,KAAK;QAC5B,MAAM,QAAQ,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC;AAC9C,QAAA,MAAM,UAAU,GAAG,QAAQ,CAAC,KAAK;AACjC,QAAA,UAAU,CAAC,KAAK,GAAG,OAAO;AAC1B,QAAA,UAAU,CAAC,MAAM,GAAG,OAAO;AAC3B,QAAA,QAAQ,CAAC,WAAW,CAAC,QAAQ,CAAC;AAC9B,QAAA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;AAEnC,QAAA,IAAI,QAAQ,CAAC,UAAU,GAAG,CAAC,EAAE;YAC3B,eAAe,GAAG,qBAAqB;;aAClC;AACL,YAAA,QAAQ,CAAC,UAAU,GAAG,CAAC;AAEvB,YAAA,IAAI,QAAQ,CAAC,UAAU,KAAK,CAAC,EAAE;gBAC7B,eAAe,GAAG,UAAU;;iBACvB;gBACL,eAAe,GAAG,oBAAoB;;;AAI1C,QAAA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;AACnC,QAAA,OAAO,eAAe;;AAGxB,IAAA,OAAO,eAAe;AACxB;;;;"}
|
|
@@ -27,7 +27,7 @@ interface VirtualListProps<T = any> extends Omit<StandardProps, 'children'> {
|
|
|
27
27
|
* > - 非 unlimitedSize 模式下如果传入函数,为避免性能问题,每个节点只会调用一次用于设置初始值
|
|
28
28
|
*/
|
|
29
29
|
itemSize: number | ((index?: number, itemData?: T[]) => number);
|
|
30
|
-
/**
|
|
30
|
+
/** 解开高度列表单项大小限制,默认值使用:itemSize。
|
|
31
31
|
*
|
|
32
32
|
* > Note: 通过 itemSize 设置的初始高度与子节点实际高度差异过大会导致隐患,建议将单页大小设置接近于现实高度,在该模式下可以提升用户体验。
|
|
33
33
|
* @default false
|
|
@@ -55,7 +55,7 @@ interface VirtualListProps<T = any> extends Omit<StandardProps, 'children'> {
|
|
|
55
55
|
* @default 50
|
|
56
56
|
*/
|
|
57
57
|
lowerThreshold?: number;
|
|
58
|
-
/** 是否注入 isScrolling 属性到 item 组件。这个参数一般用于实现滚动骨架屏(或其它 placeholder
|
|
58
|
+
/** 是否注入 isScrolling 属性到 item 组件。这个参数一般用于实现滚动骨架屏(或其它 placeholder)时比较有用。 */
|
|
59
59
|
useIsScrolling?: boolean;
|
|
60
60
|
/** 通过 ScrollViewContext 优化组件滚动性能
|
|
61
61
|
* @default false
|
|
@@ -103,7 +103,7 @@ declare namespace VirtualListProps {
|
|
|
103
103
|
diffOffset: number;
|
|
104
104
|
}
|
|
105
105
|
interface IVirtualListEvent<T extends ScrollViewProps.onScrollDetail = ScrollViewProps.onScrollDetail> extends BaseEventOrig {
|
|
106
|
-
/** 滚动方向,可能值为 forward 往前,
|
|
106
|
+
/** 滚动方向,可能值为 forward 往前,backward 往后。 */
|
|
107
107
|
scrollDirection: 'forward' | 'backward';
|
|
108
108
|
/** 滚动距离 */
|
|
109
109
|
scrollOffset: number;
|
|
@@ -118,7 +118,7 @@ declare namespace VirtualListProps {
|
|
|
118
118
|
* @supported weapp, swan, alipay, tt, qq, jd, h5
|
|
119
119
|
* @example_react
|
|
120
120
|
* ```tsx
|
|
121
|
-
* import VirtualList from `@tarojs/components
|
|
121
|
+
* import { VirtualList } from `@tarojs/components-advanced`
|
|
122
122
|
*
|
|
123
123
|
* function buildData (offset = 0) {
|
|
124
124
|
* return Array(100).fill(0).map((_, i) => i + offset);
|
|
@@ -157,7 +157,7 @@ declare namespace VirtualListProps {
|
|
|
157
157
|
* ```js
|
|
158
158
|
* // app.js 入口文件
|
|
159
159
|
* import Vue from 'vue'
|
|
160
|
-
* import VirtualList from '@tarojs/components
|
|
160
|
+
* import { VirtualList } from '@tarojs/components-advanced'
|
|
161
161
|
*
|
|
162
162
|
* Vue.use(VirtualList)
|
|
163
163
|
* ```
|