Reputation: 149
Is there any way that I can make UICollectionViewDiffableDataSource stop scrolling collection view while we apply snapshot?
I am using this library: https://github.com/ra1028/DiffableDataSources
I have a situation where I want to keep the collection view scroll position while I load more data using UIRefreshControl.
var snapshot = DiffableDataSourceSnapshot<ChatKitDataSourceSection, ChatKitMessage>()
snapshot.deleteAllItems()
snapshot.appendSections(self.items)
self.items.forEach { section in
snapshot.appendItems(section.rowItems, toSection: section)
}
self.apply(snapshot, animatingDifferences: true, completion: completion)
That's how I am updating the snapshot every time I load more data.
Upvotes: 2
Views: 1165
Reputation: 11
Can you ensure your for your model that conforms to Hashable, that you're not setting a new UUID() for your id every time you apply your snapshot. This will cause a reload that will scroll back to the top.
Ensure you have an id for your model that is unique per instance but wont get overwritten if you have the same data when applying a new snaphot
Upvotes: 1