Shopify / FunctionalTableData

Declarative UITableViewDataSource implementation
MIT License
365 stars 30 forks source link

Use NSDiffableDataSource for iOS 13 or greater #206

Closed jasonkemp9099 closed 3 years ago

jasonkemp9099 commented 3 years ago

To workaround crashes in UITableView with large change sets, use UITableViewDiffableDataSource when available (iOS 13 or greater)

Created an Impl protocol, with two implementations:

  1. Original Functional Table Data algorithm
  2. UITableViewDiffableDataSource-backed implementation for iOS 13 and up.

Then just followed the consequences of that. Any other changes are due to getting it working on IOS 13 at runtime. Tests with data exhibiting the crash with the original table data algorithm pass with diffable data sources.

autoreleasefool commented 3 years ago

NSDiffableDataSource is dropping cells if they have the same ID/content as a cell in a different section.

With same ID / different content With same ID / same content
Simulator Screen Shot - iPhone 12 Pro - 2021-03-17 at 10 52 59 Simulator Screen Shot - iPhone 12 Pro - 2021-03-17 at 10 53 13

Only the latter cell with identical content is being displayed. Also getting the following message in the console: [UIDiffableDataSource] Warning: 2 inserted identifier(s) already present; existing items will be moved into place for this current insertion. Please note this will impact performance if items are not unique when inserted.

If I change the content inside the cell or make the cell IDs globally unique, then they both render. Not an issue with classic diffing strategy

jasonkemp9099 commented 3 years ago

NSDiffableDataSource is dropping cells if they have the same ID/content as a cell in a different section.

Nice find. Has to do with my Hashable implementations, I bet. I should make a snapshot test for this too.

Or does it? What's the implementation of isEqual() for that CellConfigType?