From d42bf02f6ed26f3f2031704eef9481aa5e1818e8 Mon Sep 17 00:00:00 2001 From: "o.o.c." <568071718@qq.com> Date: Sun, 7 Dec 2025 13:12:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=B1=9E=E6=80=A7=20'autoRel?= =?UTF-8?q?oadOnSizeChange'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list-3x/assets/lib/yx-collection-view.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/list-3x/assets/lib/yx-collection-view.ts b/list-3x/assets/lib/yx-collection-view.ts index 73111cd..2ad4477 100644 --- a/list-3x/assets/lib/yx-collection-view.ts +++ b/list-3x/assets/lib/yx-collection-view.ts @@ -662,6 +662,13 @@ export class YXCollectionView extends Component { return this._scrollView.ignoreScrollEndedDuringAutoScroll } + /** + * 列表内的元素位置是在 `reloadData` 那一刻决定的,所以当列表有 Widget 组件或者其他一些情况导致列表节点自身大小改变了但子元素的位置未更新 + * 打开这个属性会在列表节点自身大小变化时自动重新计算一遍布局信息 + */ + @property({ tooltip: `如果列表有 Widget 组件或者希望列表大小改变时自动刷新列表,可以打开此开关` }) + autoReloadOnSizeChange: boolean = false + /** * 通过编辑器注册节点类型 */ @@ -1274,6 +1281,7 @@ export class YXCollectionView extends Component { this.node.on(ScrollView.EventType.SCROLLING, this.onScrolling, this) this.node.on(ScrollView.EventType.TOUCH_UP, this.onScrollTouchUp, this) this.node.on(ScrollView.EventType.SCROLL_ENDED, this.onScrollEnded, this) + this.node.on(NodeEventType.SIZE_CHANGED, this.onSizeChange, this) this._scrollView._yx_startAttenuatingAutoScrollTargetOffset = (touchMoveVelocity, startOffset, originTargetOffset, originScrollTime) => { return this.layout.targetOffset(this, touchMoveVelocity, startOffset, originTargetOffset, originScrollTime) } @@ -1284,6 +1292,7 @@ export class YXCollectionView extends Component { this.node.off(ScrollView.EventType.SCROLLING, this.onScrolling, this) this.node.off(ScrollView.EventType.TOUCH_UP, this.onScrollTouchUp, this) this.node.off(ScrollView.EventType.SCROLL_ENDED, this.onScrollEnded, this) + this.node.off(NodeEventType.SIZE_CHANGED, this.onSizeChange, this) this._scrollView._yx_startAttenuatingAutoScrollTargetOffset = null // 销毁当前所有正在显示的节点 @@ -1430,6 +1439,12 @@ export class YXCollectionView extends Component { this.recycleInvisibleNodes() this.layout.onScrollEnded(this) } + + private onSizeChange() { + if (this.autoReloadOnSizeChange) { + this.reloadData() + } + } } export namespace YXCollectionView {