From 8ae7606aef9080c533fbf7e5d4db6a2265b4fd9a Mon Sep 17 00:00:00 2001 From: "o.o.c." <568071718@qq.com> Date: Sat, 6 Dec 2025 15:05:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20ignoreScrollEndedDuringAut?= =?UTF-8?q?oScroll=20=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list-3x/assets/lib/yx-collection-view.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/list-3x/assets/lib/yx-collection-view.ts b/list-3x/assets/lib/yx-collection-view.ts index 48fdb6e..73111cd 100644 --- a/list-3x/assets/lib/yx-collection-view.ts +++ b/list-3x/assets/lib/yx-collection-view.ts @@ -115,7 +115,7 @@ class _yx_node_element_comp extends Component { /** * 私有组件 * 内部滚动视图组件 - * https://github.com/cocos/cocos-engine/blob/v3.8.0/cocos/ui/scroll-view.ts + * https://github.com/cocos/cocos-engine/blob/v3.8.8/cocos/ui/scroll-view.ts */ class _scroll_view extends ScrollView { @@ -238,6 +238,15 @@ class _scroll_view extends ScrollView { super._stopPropagationIfTargetIsMe(event) } + ignoreScrollEndedDuringAutoScroll = false + protected _dispatchEvent(event: string): void { + // 这里非常奇怪,在快速滑动的时候收到了 `SCROLL_ENDED` 但是 `isAutoScrolling` 还是 true,感觉不太符合常理,看源码似乎是设计如此,不清楚是何用意 + if (this.ignoreScrollEndedDuringAutoScroll && event === ScrollView.EventType.SCROLL_ENDED as string && this.isAutoScrolling()) { + return + } + super._dispatchEvent(event) + } + /** * 获取本次滑动是要滑动哪个列表 */ @@ -641,6 +650,18 @@ export class YXCollectionView extends Component { @property({ tooltip: `滚动过程中,每多少帧回收一次不可见节点,1表示每帧都回收,0表示不在滚动过程中回收不可见节点` }) recycleInterval: number = 1 + /** + * bug?? 还是特性?? 当列表快速滑动的时候会收到 `scroll-ended` 事件,但实际上快速滑动阶段只是手指频繁的松开按下,不应该定性为滚动结束 + * 将这个属性设置为 `true` 后不会在快速滑动时发送 `scroll-ended` 事件 + * 该属性为实验性的功能,暂时不清楚是否有其他隐患,如果碰到快速滑动行为引发一些奇怪问题时可以尝试修改此属性 + */ + set ignoreScrollEndedDuringAutoScroll(value: boolean) { + this._scrollView.ignoreScrollEndedDuringAutoScroll = value + } + get ignoreScrollEndedDuringAutoScroll(): boolean { + return this._scrollView.ignoreScrollEndedDuringAutoScroll + } + /** * 通过编辑器注册节点类型 */