提交 42270934 编写于 作者: 雪洛's avatar 雪洛

Revert "Revert "perf: 优化长列表示例性能""

This reverts commit 4fa1ffd4.
上级 4fa1ffd4
...@@ -109,25 +109,39 @@ ...@@ -109,25 +109,39 @@
this.rearrangeQueue = [] as number[] this.rearrangeQueue = [] as number[]
}, },
rearrange(scrollTop : number) { rearrange(scrollTop : number) {
this.offsetThreshold[0] = Math.max(scrollTop - this.scrollElementHeight * 5, 0) const offsetStart = this.offsetThreshold[0] = Math.max(scrollTop - this.scrollElementHeight * 5, 0)
this.offsetThreshold[1] = Math.max(scrollTop - this.scrollElementHeight * 3, 0) this.offsetThreshold[1] = Math.max(scrollTop - this.scrollElementHeight * 3, 0)
this.offsetThreshold[2] = Math.min(scrollTop + this.scrollElementHeight * 4, this.placeholderHeight) this.offsetThreshold[2] = Math.min(scrollTop + this.scrollElementHeight * 4, this.placeholderHeight)
this.offsetThreshold[3] = Math.min(scrollTop + this.scrollElementHeight * 6, this.placeholderHeight) const offsetEnd =this.offsetThreshold[3] = Math.min(scrollTop + this.scrollElementHeight * 6, this.placeholderHeight)
const items = [] as any[] const items = [] as any[]
const defaultItemSize = this.defaultItemSize
const cachedSize = this.cachedSize
const list = this.list
let tempTotalHeight = 0 let tempTotalHeight = 0
let containerTop = 0 let containerTop = 0
for (let i = 0; i < this.list.length; i++) { let start = false, end = false
const item = this.list[i] for (let i = 0; i < list.length; i++) {
let itemSize = this.defaultItemSize const item = list[i]
const cachedItemSize = this.cachedSize.get(item) let itemSize = defaultItemSize
const cachedItemSize = cachedSize.get(item)
if (cachedItemSize != null) { if (cachedItemSize != null) {
itemSize = cachedItemSize itemSize = cachedItemSize
} }
tempTotalHeight += itemSize tempTotalHeight += itemSize
if (tempTotalHeight >= this.offsetThreshold[0] && tempTotalHeight <= this.offsetThreshold[3]) { if (end) {
items.push(item) continue
} else if (tempTotalHeight < this.offsetThreshold[0]) { }
if (tempTotalHeight < offsetStart) {
containerTop = tempTotalHeight containerTop = tempTotalHeight
} else if (tempTotalHeight >= offsetStart && tempTotalHeight <= offsetEnd) {
if (start == false) {
start = true
}
items.push(item)
} else {
if (!end) {
end = true
}
} }
} }
this.placeholderHeight = tempTotalHeight this.placeholderHeight = tempTotalHeight
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册