sectionSnapshotHandlers
The diffable data source’s handlers for expanding and collapsing items.
Declaration
@MainActor @preconcurrency var sectionSnapshotHandlers: UICollectionViewDiffableDataSource<SectionIdentifierType, ItemIdentifierType>.SectionSnapshotHandlers<ItemIdentifierType> { get set }Discussion
Provide section snapshot handlers to support the expanding or collapsing of items in your collection view.
Use the snapshotForExpandingParent handler to customize the snapshot that returns when a particular parent item is expanded.
// Allow every item to be collapsed
dataSource.sectionSnapshotHandlers.shouldCollapseItem = { item in return true }
dataSource.sectionSnapshotHandlers.snapshotForExpandingParent = {
parent, currentChildSnapshot -> NSDiffableDataSourceSectionSnapshot<String> in
// Return child snapshot for the parent, or just currentChildSnapshot
}