From ac2d1fb8059f4b8a62f963d815c842ca38a6fe67 Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Fri, 12 Mar 2021 11:09:40 -0800 Subject: [PATCH] Ensure proper cell layout --- View Controllers/TableViewController.swift | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/View Controllers/TableViewController.swift b/View Controllers/TableViewController.swift index 26b9080..2e998ea 100644 --- a/View Controllers/TableViewController.swift +++ b/View Controllers/TableViewController.swift @@ -803,7 +803,7 @@ private extension TableViewController { self.newItemsViewVisibleConstraint?.isActive = true self.view.layoutIfNeeded() } completion: { _ in - self.view.layoutIfNeeded() + self.reloadVisibleItems() } } @@ -814,8 +814,18 @@ private extension TableViewController { self.newItemsViewVisibleConstraint?.isActive = false self.view.layoutIfNeeded() } completion: { _ in - self.view.layoutIfNeeded() + self.reloadVisibleItems() } } + + func reloadVisibleItems() { + guard let visibleItems = tableView.indexPathsForVisibleRows?.compactMap(dataSource.itemIdentifier(for:)) + else { return } + + var snapshot = dataSource.snapshot() + + snapshot.reloadItems(visibleItems) + dataSource.apply(snapshot, animatingDifferences: false) + } } // swiftlint:enable file_length