fix: only destroy delegates when visually out of viewport

This commit is contained in:
2 * r + 2 * t 2026-04-03 18:37:14 +11:00
parent 700ad61969
commit 1c09222dd7

View file

@ -549,10 +549,19 @@ void LazyListView::syncDelegates() {
visibleIndices.insert(i);
}
// Collect delegates to destroy (outside visible range and not animating)
// Collect delegates to destroy — only if visually outside the viewport
const auto vp = effectiveViewport();
QList<int> toRemove;
for (auto it = m_delegates.begin(); it != m_delegates.end(); ++it) {
if (!visibleIndices.contains(it.key()) && !it->animation)
if (visibleIndices.contains(it.key()) || it->animation)
continue;
if (!it->item) {
toRemove.append(it.key());
continue;
}
const qreal itemTop = it->item->y();
const qreal itemBottom = itemTop + delegateVisibleHeight(it->item);
if (itemBottom < vp.top() || itemTop > vp.bottom())
toRemove.append(it.key());
}