|
@@ -4,8 +4,12 @@ import { View } from '@tarojs/components';
|
4
|
4
|
import { useList } from './hooks';
|
5
|
5
|
import { classNames, getRect } from './utils';
|
6
|
6
|
|
|
7
|
+import './style.less'
|
|
8
|
+
|
7
|
9
|
export default (props) => {
|
8
|
|
- const { className, itemClassName, style, gutter = 0, list = [], render, ...leftProps } = props
|
|
10
|
+ const { className, itemClassName, style, gutter = 0, list, render, ...leftProps } = props
|
|
11
|
+
|
|
12
|
+ const splitStyle = { width: `${gutter}rpx` }
|
9
|
13
|
|
10
|
14
|
const leftBottom = useRef(0)
|
11
|
15
|
const rightBottom = useRef(0)
|
|
@@ -20,25 +24,22 @@ export default (props) => {
|
20
|
24
|
useEffect(() => {
|
21
|
25
|
if (list && list.length) {
|
22
|
26
|
setCursor(0)
|
23
|
|
- setLeftList([])
|
24
|
|
- setRightList([])
|
25
|
|
- console.log('----------useEffect--------')
|
26
|
27
|
} else {
|
27
|
28
|
setCursor(-1)
|
|
29
|
+ setLeftList([])
|
|
30
|
+ setRightList([])
|
28
|
31
|
}
|
29
|
32
|
}, [list])
|
30
|
33
|
|
31
|
34
|
useEffect(() => {
|
32
|
35
|
const len = !listRef.current ? 0 : listRef.current.length;
|
33
|
36
|
|
34
|
|
- if (!len || cursor >= len) return;
|
|
37
|
+ if (leftRef.current.length + rightRef.current.length >= len) return;
|
35
|
38
|
|
36
|
39
|
const item = listRef.current[cursor] || {}
|
37
|
40
|
item.__vid = `f-${Math.random().toString(36).substring(2)}`
|
38
|
41
|
vidRef.current = item.__vid
|
39
|
42
|
|
40
|
|
- console.log('----------leftRef.current--------', leftRef.current, rightRef.current)
|
41
|
|
-
|
42
|
43
|
if (leftBottom.current <= rightBottom.current) {
|
43
|
44
|
setLeftList([...leftRef.current, item])
|
44
|
45
|
} else {
|
|
@@ -46,12 +47,8 @@ export default (props) => {
|
46
|
47
|
}
|
47
|
48
|
}, [cursor])
|
48
|
49
|
|
49
|
|
-
|
50
|
|
- console.log('---------dddddddd------', vidRef.current, leftRef.current.length, leftList)
|
51
|
|
-
|
52
|
50
|
useEffect(() => {
|
53
|
51
|
const setHeight = (rect) => {
|
54
|
|
- console.log('---------rect------', rect)
|
55
|
52
|
const { bottom } = rect
|
56
|
53
|
if (cursor % 2 === 0) {
|
57
|
54
|
leftBottom.current = bottom
|
|
@@ -63,13 +60,18 @@ export default (props) => {
|
63
|
60
|
|
64
|
61
|
const calcHeight = () => {
|
65
|
62
|
getRect(`.${vidRef.current}`).then((res) => {
|
66
|
|
- if (!res || !res.length) {
|
|
63
|
+ if (!res) {
|
|
64
|
+ // 找不到 node , 则一直重复查询
|
67
|
65
|
const t = setTimeout(() => {
|
68
|
66
|
clearTimeout(t)
|
69
|
67
|
calcHeight()
|
70
|
68
|
}, 300)
|
71
|
69
|
} else {
|
72
|
|
- setHeight(res[0])
|
|
70
|
+ if (Array.isArray(res)) {
|
|
71
|
+ setHeight(res[0])
|
|
72
|
+ } else {
|
|
73
|
+ setHeight(res)
|
|
74
|
+ }
|
73
|
75
|
}
|
74
|
76
|
})
|
75
|
77
|
}
|
|
@@ -89,6 +91,7 @@ export default (props) => {
|
89
|
91
|
))
|
90
|
92
|
}
|
91
|
93
|
</View>
|
|
94
|
+ <View className='masonry-split' style={splitStyle} />
|
92
|
95
|
<View className='masonry-column'>
|
93
|
96
|
{
|
94
|
97
|
rightList.map((item) => (
|