fix: don't play add/remove anim on old delegates

This commit is contained in:
2 * r + 2 * t 2026-04-10 01:25:09 +10:00
parent 7a82ca4765
commit e234990c52
3 changed files with 17 additions and 8 deletions

View file

@ -80,8 +80,8 @@ LazyListView {
LazyListView.visibleHeight: modelData?.closed || previewHidden ? 0 : notifInner.implicitHeight
implicitHeight: notifInner.implicitHeight
opacity: LazyListView.removing || modelData?.closed || previewHidden || LazyListView.adding ? 0 : 1
scale: LazyListView.removing || previewHidden ? 0.7 : LazyListView.adding ? 0.7 : 1
opacity: previewHidden || LazyListView.adding ? 0 : 1
scale: previewHidden || LazyListView.adding ? 0.7 : 1
hoverEnabled: true
cursorShape: notifInner.body?.hoveredLink ? Qt.PointingHandCursor : pressed ? Qt.ClosedHandCursor : undefined

View file

@ -367,6 +367,12 @@ void LazyListView::updatePolish() {
relayout();
syncDelegates();
// Clear isNew flags — the add animation only plays for items created
// during the same polish cycle as their model insertion, not for
// delegates created later when scrolling items into the viewport.
for (auto& record : m_layout)
record.isNew = false;
// Position delegates — QML Behavior on y handles the animation
for (auto& entry : m_delegates) {
if (!entry.item || entry.pendingRemoval || entry.pendingInsert)
@ -652,12 +658,14 @@ LazyListView::DelegateEntry LazyListView::createDelegate(int modelIndex) {
entry.item->setParentItem(this);
entry.item->setWidth(width());
// Set adding = true before completeCreate so bindings see it during initial evaluation.
// Only set adding = true for genuinely new model items (not viewport entries).
// Cleared on the next frame in updatePolish when the item becomes visible.
auto* addingAttached =
qobject_cast<LazyListViewAttached*>(qmlAttachedPropertiesObject<LazyListView>(entry.item, true));
if (addingAttached)
addingAttached->setAdding(true);
if (modelIndex < static_cast<int>(m_layout.size()) && m_layout[modelIndex].isNew) {
auto* addingAttached =
qobject_cast<LazyListViewAttached*>(qmlAttachedPropertiesObject<LazyListView>(entry.item, true));
if (addingAttached)
addingAttached->setAdding(true);
}
m_delegate->completeCreate();
@ -852,7 +860,7 @@ void LazyListView::onRowsInserted(const QModelIndex& parent, int first, int last
const int insertCount = last - first + 1;
// Insert new layout records
m_layout.insert(first, insertCount, ItemRecord{ 0, 0, false });
m_layout.insert(first, insertCount, ItemRecord{ 0, 0, false, true });
// Shift existing delegate indices
QHash<int, DelegateEntry> shifted;

View file

@ -169,6 +169,7 @@ private:
qreal targetY = 0;
qreal height = 0;
bool heightKnown = false;
bool isNew = false;
};
struct DelegateEntry {