记录了更新区域,保证只有可见区域变化之后才去更新节点

This commit is contained in:
o.o.c 2024-12-21 11:50:19 +08:00
parent 4dd5167400
commit aecd893457
2 changed files with 50 additions and 4 deletions

View File

@ -1025,6 +1025,9 @@ export class YXCollectionView extends Component {
rect = this.visibleRect
}
// 记录最后一次更新的内容范围
this.lastReloadVisibleCellsInRect = rect.clone()
// 根据可见区域,找出对应的布局属性
let layoutAttributes = this.layout.layoutAttributesForElementsInRect(rect, this)
@ -1093,6 +1096,7 @@ export class YXCollectionView extends Component {
layoutAttributes = []
}
private lastReloadVisibleCellsInRect: cc.Rect = null
/**
* 使
@ -1124,6 +1128,9 @@ export class YXCollectionView extends Component {
visibleRect = this.visibleRect
}
// 记录最后一次回收节点时的内容范围
this.lastRecycleInvisibleNodesInRect = visibleRect.clone()
const _realFrame = _recycleInvisibleNodes_realFrame
const _contentSize = this.scrollView.content.getContentSize()
@ -1153,6 +1160,7 @@ export class YXCollectionView extends Component {
}
})
}
private lastRecycleInvisibleNodesInRect: cc.Rect = null
/**
* /
@ -1293,8 +1301,18 @@ export class YXCollectionView extends Component {
this.reloadVisibleCells()
return
}
if (this.layout.shouldUpdateAttributesForBoundsChange()) {
return // 当开启了实时更新节点布局属性时,为了保证实时性,去 onScrolling 里面处理
}
if ((this.frameInterval <= 1) || (this._frameIdx % this.frameInterval == 0)) {
this.reloadVisibleCells()
// 检查只有显示区域发生变化了才去更新当前可见节点
const visibleRect = this.visibleRect
let boundsChange = this.lastReloadVisibleCellsInRect == null || this.lastReloadVisibleCellsInRect.equals(visibleRect) == false
if (boundsChange) {
this.reloadVisibleCells(visibleRect)
}
return
}
}
@ -1311,7 +1329,12 @@ export class YXCollectionView extends Component {
}
if ((this.recycleInterval >= 1) && (this._frameIdx % this.recycleInterval == 0)) {
this.recycleInvisibleNodes()
// 检查只有显示区域发生变化了才去回收当前可见节点
const visibleRect = this.visibleRect
let boundsChange = this.lastRecycleInvisibleNodesInRect == null || this.lastRecycleInvisibleNodesInRect.equals(visibleRect) == false
if (boundsChange) {
this.recycleInvisibleNodes(visibleRect)
}
return
}
}

View File

@ -1026,6 +1026,9 @@ export class YXCollectionView extends Component {
rect = this.visibleRect
}
// 记录最后一次更新的内容范围
this.lastReloadVisibleCellsInRect = rect.clone()
// 根据可见区域,找出对应的布局属性
let layoutAttributes = this.layout.layoutAttributesForElementsInRect(rect, this)
@ -1094,6 +1097,7 @@ export class YXCollectionView extends Component {
layoutAttributes = []
}
private lastReloadVisibleCellsInRect: math.Rect = null
/**
* 使
@ -1133,6 +1137,9 @@ export class YXCollectionView extends Component {
visibleRect = this.visibleRect
}
// 记录最后一次回收节点时的内容范围
this.lastRecycleInvisibleNodesInRect = visibleRect.clone()
const _realFrame = _recycleInvisibleNodes_realFrame
const _contentSize = this.scrollView.content.getComponent(UITransform).contentSize
@ -1162,6 +1169,7 @@ export class YXCollectionView extends Component {
}
})
}
private lastRecycleInvisibleNodesInRect: math.Rect = null
/**
* /
@ -1302,8 +1310,18 @@ export class YXCollectionView extends Component {
this.reloadVisibleCells()
return
}
if (this.layout.shouldUpdateAttributesForBoundsChange()) {
return // 当开启了实时更新节点布局属性时,为了保证实时性,去 onScrolling 里面处理
}
if ((this.frameInterval <= 1) || (this._frameIdx % this.frameInterval == 0)) {
this.reloadVisibleCells()
// 检查只有显示区域发生变化了才去更新当前可见节点
const visibleRect = this.visibleRect
let boundsChange = this.lastReloadVisibleCellsInRect == null || this.lastReloadVisibleCellsInRect.equals(visibleRect) == false
if (boundsChange) {
this.reloadVisibleCells(visibleRect)
}
return
}
}
@ -1320,7 +1338,12 @@ export class YXCollectionView extends Component {
}
if ((this.recycleInterval >= 1) && (this._frameIdx % this.recycleInterval == 0)) {
this.recycleInvisibleNodes()
// 检查只有显示区域发生变化了才去回收当前可见节点
const visibleRect = this.visibleRect
let boundsChange = this.lastRecycleInvisibleNodesInRect == null || this.lastRecycleInvisibleNodesInRect.equals(visibleRect) == false
if (boundsChange) {
this.recycleInvisibleNodes(visibleRect)
}
return
}
}