From 422709347fd65293734a88813ee69128c97f3ae6 Mon Sep 17 00:00:00 2001 From: wangyaqi Date: Fri, 29 Mar 2024 11:11:51 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"Revert=20"perf:=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E9=95=BF=E5=88=97=E8=A1=A8=E7=A4=BA=E4=BE=8B=E6=80=A7=E8=83=BD?= =?UTF-8?q?""?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 4fa1ffd4852c79cf380304bda7bfc9231c20e882. --- .../custom-long-list/custom-list-view.uvue | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/pages/template/custom-long-list/custom-list-view.uvue b/pages/template/custom-long-list/custom-list-view.uvue index d0438333..4b8faf9c 100644 --- a/pages/template/custom-long-list/custom-list-view.uvue +++ b/pages/template/custom-long-list/custom-list-view.uvue @@ -109,25 +109,39 @@ this.rearrangeQueue = [] as 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[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 defaultItemSize = this.defaultItemSize + const cachedSize = this.cachedSize + const list = this.list let tempTotalHeight = 0 let containerTop = 0 - for (let i = 0; i < this.list.length; i++) { - const item = this.list[i] - let itemSize = this.defaultItemSize - const cachedItemSize = this.cachedSize.get(item) + let start = false, end = false + for (let i = 0; i < list.length; i++) { + const item = list[i] + let itemSize = defaultItemSize + const cachedItemSize = cachedSize.get(item) if (cachedItemSize != null) { itemSize = cachedItemSize } tempTotalHeight += itemSize - if (tempTotalHeight >= this.offsetThreshold[0] && tempTotalHeight <= this.offsetThreshold[3]) { - items.push(item) - } else if (tempTotalHeight < this.offsetThreshold[0]) { + if (end) { + continue + } + if (tempTotalHeight < offsetStart) { containerTop = tempTotalHeight + } else if (tempTotalHeight >= offsetStart && tempTotalHeight <= offsetEnd) { + if (start == false) { + start = true + } + items.push(item) + } else { + if (!end) { + end = true + } } } this.placeholderHeight = tempTotalHeight -- GitLab