From ae339525047d0260d15483682ab81dff2c795614 Mon Sep 17 00:00:00 2001 From: Kyle Van Essen Date: Wed, 20 Sep 2023 16:42:24 -0700 Subject: [PATCH] Force layout before appear, to avoid animated updates (#505) * Force layout of views before they appear, to avoid animated updates occurring when cells are recycled. --- CHANGELOG.md | 1 + .../PresentationState.HeaderFooterState.swift | 14 +++++++++----- .../PresentationState.ItemState.swift | 16 ++++++++++------ 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6772690..551a6469 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Fixed a bug that resulted in header/footer views not properly updating, by fixing the underlying tracking of collection view supplementary views. - Fixed an issue where supplementary views (headers or footers) that contained a first responder would result in the view being duplicated when scrolled off-screen. +- Fixed an issue where animations would occur when dequeuing / reusing cells. A layout is now forced without animation before presentation. ### Added diff --git a/ListableUI/Sources/Internal/PresentationState/PresentationState.HeaderFooterState.swift b/ListableUI/Sources/Internal/PresentationState/PresentationState.HeaderFooterState.swift index 49128916..e7ac5a68 100644 --- a/ListableUI/Sources/Internal/PresentationState/PresentationState.HeaderFooterState.swift +++ b/ListableUI/Sources/Internal/PresentationState/PresentationState.HeaderFooterState.swift @@ -175,11 +175,15 @@ extension PresentationState HeaderFooterContentView(frame: frame) } - self.applyTo( - view: view, - for: .willDisplay, - with: .init(environment: environment) - ) + UIView.performWithoutAnimation { + self.applyTo( + view: view, + for: .willDisplay, + with: .init(environment: environment) + ) + + view.layoutIfNeeded() + } return view } diff --git a/ListableUI/Sources/Internal/PresentationState/PresentationState.ItemState.swift b/ListableUI/Sources/Internal/PresentationState/PresentationState.ItemState.swift index 891687e7..e671419e 100644 --- a/ListableUI/Sources/Internal/PresentationState/PresentationState.ItemState.swift +++ b/ListableUI/Sources/Internal/PresentationState/PresentationState.ItemState.swift @@ -259,12 +259,16 @@ extension PresentationState let itemState = ListableUI.ItemState(cell: cell, isReordering: false) - self.applyTo( - cell: cell, - itemState: itemState, - reason: .willDisplay, - environment: environment - ) + UIView.performWithoutAnimation { + self.applyTo( + cell: cell, + itemState: itemState, + reason: .willDisplay, + environment: environment + ) + + cell.layoutIfNeeded() + } return cell }