From e3cb12d57157a2860324073b5371140e5696c81d Mon Sep 17 00:00:00 2001 From: "Yida.Xu" <522918670@qq.com> Date: Sun, 27 Apr 2025 20:19:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A1=E3=80=81=E5=BD=93?= =?UTF-8?q?=E6=8C=82=E8=BD=BD=E6=9C=89widget=E7=BB=84=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E4=B8=94=E5=9C=A8UI=20start=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=B8=AD=E5=88=9B=E5=BB=BA=E5=B9=B6reloadData=E6=97=B6?= =?UTF-8?q?=EF=BC=8CscrollView=E7=9A=84=E5=B0=BA=E5=AF=B8=E6=9C=89?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E8=8E=B7=E5=8F=96=E9=94=99=E8=AF=AF=EF=BC=88?= =?UTF-8?q?widget=E6=9C=AAupdate=E5=89=8D=E7=9A=84=E5=B0=BA=E5=AF=B8?= =?UTF-8?q?=EF=BC=89=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C2=E3=80=81?= =?UTF-8?q?=E6=8C=82=E8=BD=BDwidget=E5=B9=B6=E5=B0=BA=E5=AF=B8=E5=8F=91?= =?UTF-8?q?=E7=94=9F=E5=8F=98=E5=8C=96=E6=97=B6=EF=BC=8Ccontent=E7=9A=84?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E7=AD=89=E6=B2=A1=E6=B3=95=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=88=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E5=B9=B6=E8=B5=8B=E5=80=BCscrollview=20content?= =?UTF-8?q?=E6=9C=80=E6=97=A9=E6=98=AF=E5=9C=A8onLoad=EF=BC=8C=E5=9C=A8?= =?UTF-8?q?=E6=AD=A4=E4=B9=8B=E5=89=8D=E7=9A=84onEnable=E5=9B=9E=E8=B0=83?= =?UTF-8?q?=E4=B8=ADcontent=E8=8B=A5=E4=B8=BA=E7=A9=BA=E6=98=AF=E4=B8=8D?= =?UTF-8?q?=E4=BC=9A=E7=9B=91=E5=90=AC=E5=88=B0=E4=BA=8B=E4=BB=B6=E7=9A=84?= =?UTF-8?q?=20via:https://github.com/cocos/cocos-engine/blob/dbae22d3498d9?= =?UTF-8?q?1e49712b766b2587b8d68e4ddd2/cocos/ui/scroll-view.ts#L997?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list-3x/assets/lib/yx-collection-view.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/list-3x/assets/lib/yx-collection-view.ts b/list-3x/assets/lib/yx-collection-view.ts index cef975e..dbeb222 100644 --- a/list-3x/assets/lib/yx-collection-view.ts +++ b/list-3x/assets/lib/yx-collection-view.ts @@ -1,4 +1,4 @@ -import { _decorator, Component, Enum, Event, EventMouse, EventTouch, instantiate, Mask, math, Node, NodeEventType, NodePool, Prefab, ScrollView, UIOpacity, UITransform } from 'cc'; +import { _decorator, Component, Enum, Event, EventMouse, EventTouch, instantiate, Mask, math, Node, NodeEventType, NodePool, Prefab, ScrollView, UIOpacity, UITransform, Widget } from 'cc'; const { ccclass, property, executionOrder, disallowMultiple, help } = _decorator; const _vec3Out = new math.Vec3() @@ -294,6 +294,17 @@ class _scroll_view extends ScrollView { } return result } + + set content(value) { + super.content = value; + if (value) { + value.on(NodeEventType.SIZE_CHANGED, this._calculateBoundary, this); + value.on(NodeEventType.TRANSFORM_CHANGED, this._scaleChanged, this); + } + } + get content() { + return super.content; + } } class _yx_node_pool extends NodePool { @@ -563,7 +574,7 @@ export class YXCollectionView extends Component { let transform = content.getComponent(UITransform) || content.addComponent(UITransform) transform.contentSize = this.node.getComponent(UITransform).contentSize - + this.getComponent(Widget).updateAlignment?.(); result.content = content } @@ -919,6 +930,7 @@ export class YXCollectionView extends Component { */ reloadData() { if (this.node.activeInHierarchy && this.node.parent) { + // this.getComponent(Widget).updateAlignment?.(); this._reloadData() return }