From b7644cdd62e89d312c0a420e4f7d4100f72e1fd2 Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Wed, 9 Nov 2022 22:21:39 -0800 Subject: [PATCH] Fix jumping when restoring scroll position --- Data Sources/TableViewDataSource.swift | 8 ++++++++ View Controllers/TableViewController.swift | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Data Sources/TableViewDataSource.swift b/Data Sources/TableViewDataSource.swift index dccb659..de60615 100644 --- a/Data Sources/TableViewDataSource.swift +++ b/Data Sources/TableViewDataSource.swift @@ -59,6 +59,14 @@ final class TableViewDataSource: UITableViewDiffableDataSource, + completion: (() -> Void)? = nil) { + updateQueue.async { + super.applySnapshotUsingReloadData(snapshot, completion: completion) + } + } + override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { let currentSnapshot = snapshot() let section = currentSnapshot.sectionIdentifiers[section] diff --git a/View Controllers/TableViewController.swift b/View Controllers/TableViewController.swift index 5b09c67..0759127 100644 --- a/View Controllers/TableViewController.swift +++ b/View Controllers/TableViewController.swift @@ -497,7 +497,7 @@ private extension TableViewController { setPreviousOffset = true } - self.dataSource.apply(update.sections.snapshot(), animatingDifferences: false) { [weak self] in + self.dataSource.applySnapshotUsingReloadData(update.sections.snapshot()) { [weak self] in guard let self = self else { return } if let itemId = update.maintainScrollPositionItemId,