Apply NSDiffableDataSourceSnapshot with same data results in a animation

907 views Asked by At

I have a UITableView with a UITableViewDiffableDataSource in which I support a pull to refresh and a pagination. When I'm creating a new snapshot with the same data and apply that snapshot, it results in a weird animation where the first few elements are sliding up and the new elements with the same data are sliding in from the left. Here is a snippet of the update:

var snapshot = NSDiffableDataSourceSnapshot<String, MyItemIdentifier>()

sections.forEach { section in 
  snapshot.appendSections([section.title])
  snapshot.appendItems(section.items, toSection: section.title)
}

self.dataSource?.apply(snapshot)

When the data hasn't changed, applying a new snapshot with the same content as the previous one shouldn't result in an animation whatsoever ? I've checked the hash value of the existing content with the new ones and they're all the same.

In addition, I have an infinite scrolling that loads items 10 by 10. When I scroll down and load the next page, 10 more items are appended to the existing data. I create a new snapshot and apply it to the data source, which results again in a weird animation and my table view jumping to the top.

Between changes, new objects are created but they have the same hash so it shouldn't affect the refresh of the table, right?

Does anyone have an idea what could cause the table view to think that the existing content has changed despite it hasn't? The only information I found about how the data source is doing the diff is that it checks the hash for each section and item.

0

There are 0 answers