Skip to content

Commit b541baa

Browse files
author
cunjinli
committed
pull
2 parents 52e33a9 + 364f397 commit b541baa

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/recycle-view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ Component({
549549
// 重新渲染事件发生
550550
let beforeReady = false
551551
let afterReady = false
552-
// Fix issue #16
552+
// fix:#16 确保获取slot节点实际高度
553553
this.setData({
554554
hasBeforeSlotHeight: false,
555555
hasAfterSlotHeight: false,

src/utils/recycle-context.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,9 @@ RecycleContext.prototype._recalculateSize = function (list) {
337337
let line = 0
338338
let column = 0
339339
const sizeArray = []
340+
const listLen = list.length
340341
// 把整个页面拆分成200*200的很多个方格, 判断每个数据落在哪个方格上
341-
for (let i = 0; i < list.length; i++) {
342+
for (let i = 0; i < listLen; i++) {
342343
if (typeof list[i].__index__ === 'undefined') {
343344
list[i].__index__ = i
344345
}
@@ -358,6 +359,7 @@ RecycleContext.prototype._recalculateSize = function (list) {
358359
// 判断数据落到哪个方格上
359360
// 超过了宽度, 移动到下一行, 再根据高度判断是否需要移动到下一个方格
360361
if (offsetLeft + itemSize.width > compData.width) {
362+
column = 0
361363
offsetLeft = itemSize.width
362364
// Fixed issue #22
363365
if (sizeArray.length >= 2) {
@@ -368,9 +370,21 @@ RecycleContext.prototype._recalculateSize = function (list) {
368370
// offsetTop += sizeArray[sizeArray.length - 2].height // 加上最后一个数据的高度
369371
// 根据高度判断是否需要移动到下一个方格
370372
if (offsetTop >= RECT_SIZE * (line + 1)) {
373+
// fix: 当区块比较大时,会缺失块区域信息
374+
const lastIdx = i - 1
375+
const lastLine = line
376+
371377
line += parseInt((offsetTop - RECT_SIZE * line) / RECT_SIZE, 10)
378+
379+
for (let idx = lastLine; idx < line; idx++) {
380+
const key = `${idx}.${column}`
381+
if (!sizeMap[key]) {
382+
sizeMap[key] = []
383+
}
384+
sizeMap[key].push(lastIdx)
385+
}
372386
}
373-
column = 0
387+
374388
// 新起一行的元素, beforeHeight是前一个元素的beforeHeight和height相加
375389
if (i === 0) {
376390
itemSize.beforeHeight = 0
@@ -395,6 +409,20 @@ RecycleContext.prototype._recalculateSize = function (list) {
395409
(sizeMap[key] = [])
396410
}
397411
sizeMap[key].push(i)
412+
413+
// fix: 当区块比较大时,会缺失块区域信息
414+
if (listLen - 1 === i && itemSize.height > RECT_SIZE) {
415+
const lastIdx = line
416+
offsetTop += itemSize.height
417+
line += parseInt((offsetTop - RECT_SIZE * line) / RECT_SIZE, 10)
418+
for (let idx = lastIdx; idx <= line; idx++) {
419+
const key = `${idx}.${column}`
420+
if (!sizeMap[key]) {
421+
sizeMap[key] = []
422+
}
423+
sizeMap[key].push(i)
424+
}
425+
}
398426
}
399427
// console.log('sizeMap', sizeMap)
400428
const obj = {

0 commit comments

Comments
 (0)