-
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support item expanding and collapsing #146
base: main
Are you sure you want to change the base?
Conversation
1787986
to
238a869
Compare
self.apply(destinationSectionSnapshot, to: $0.id, animatingDifferences: animated) { [weak self] in | ||
self?._applySnapshotCompletion(source: source, | ||
destination: destination, | ||
completion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Execute completion
multiple times?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, yup 🤦 Great catch.
Any ideas? Thinking a dispatch group might work here?
Related to the above, found this super interesting response from Apple:
Also goes on to say that "applying snapshots from a background queue is almost always unnecessary in general." |
Issue #33
Describe your changes
This is a WIP of an implementation to support nested items (i.e. nested CellViewModels), enabled by
NSDiffableDataSourceSectionSnapshot
s.What's been done so far
CellViewModel
now includes achildren
property, which allows us to provide an array ofAnyCellViewModel
s. Each of those can havechildren
, and so on.DiffableSectionSnapshot
, which is a typealias forNSDiffableDataSourceSectionSnapshot
. The ability to append items to other items is only supported through section snapshots. The logic to do so is recursive - appending the items for each top level cell, then for each of those going into all of their children, and so on.DiffableDataSource
, I added a check to see if we have at least one section with at least one cell that has non-empty children. If that's the case, we split off into creating section snapshots. Otherwise, we proceed with the existing standard snapshot approach.Simulator.Screen.Recording.-.iPhone.16.Pro.-.2024-11-16.at.12.06.50.mp4
What still needs to be done
self.snapshot()
, then reconfigure from there.CollectionViewModel
to ensure that we're referencing the snapshot'svisibleItems
when we're grabbing aCellViewModel
for a given index path. The index paths all change when you expand/collapse an item, so we have to account for that.