-
Notifications
You must be signed in to change notification settings - Fork 4
Home
The functionality is split into two modules:
-
SectionKit:This package contains the core functionality.
Please note:
ListCollectionViewAdapterandListSectionControllerwill not animate updates to the list of sections/items and callreloadData()/reloadSections(_:)respectively. On iOS 13+ you can use theFoundationDiffingListCollectionViewAdapterorFoundationDiffingListSectionController
to get animated updates. When targeting iOS versions lower than 13, you can implement your own difference calculation by overridingcalculateUpdate(from:to:)or you can use a class contained inDiffingSectionKit.Besides that, the
SingleSectionCollectionViewAdapter,SingleModelSectionControllerandSingleItemSectionControllersupport animated updates out of the box. -
DiffingSectionKit:This package extends
SectionKitby containing three more base classes,DiffingListCollectionViewAdapter,DiffingListSectionControllerandManualDiffingListSectionController. They simply overridecalculateUpdate(from:to:)where the difference between the old and new data is calculated using DifferenceKit. Therefore, animations are performed when the list of sections/items is updated (separate inserts/deletes/moves instead ofreloadData()/reloadSections(_:)).
The currently supported APIs are:
UICollectionViewDataSourceUICollectionViewDataSourcePrefetchingUICollectionViewDelegateUICollectionViewDragDelegateUICollectionViewDropDelegateUICollectionViewDelegateFlowLayoutUIScrollViewDelegate
Other APIs can be easily added by extending ListCollectionViewAdapter or SingleSectionCollectionViewAdapter.
-
ListCollectionViewAdapter:A
CollectionViewAdapterthat contains a list of sections. Changes to that list will result in a call toreloadData()on the underlyingUICollectionView. -
SingleSectionCollectionViewAdapter:A
CollectionViewAdapterthat contains a single section. It will perform animated updates to the list of sections of theUICollectionView, but updates within the section are handled by the respectiveSectionController. -
FoundationDiffingListCollectionViewAdapter(iOS 13+):A
CollectionViewAdapterthat contains a list of sections. Separate inserts/deletes/moves will be performed when the list of sections change usingFoundation.CollectionDifference(which is only available on iOS 13+). Updates within a section are handled by the respectiveSectionController. -
DiffingListCollectionViewAdapter(DiffingSectionKit):A
CollectionViewAdapterthat contains a list of sections. Separate inserts/deletes/moves will be performed when the list of sections change using DifferenceKit. Updates within a section are handled by the respectiveSectionController.
-
BaseSectionController:A base class that implements overridable methods/properties from the following protocols:
SectionControllerSectionDataSource-
SectionDataSourcePrefetchingDelegate(iOS 10+) SectionDelegateSectionFlowDelegate-
SectionDragDelegate(iOS 11+) -
SectionDropDelegate(iOS 11+)
-
SingleModelSectionController<Model>:A
SectionControllerthat displays data of a single model. Unless overridden,numberOfItemswill always be1and a change to itsmodelwill perform a call toreloadItems(at:).Warning: If
numberOfItemsis overridden,calculateUpdate(from:to:)needs to be overridden as well.This
SectionControlleris typically used when there are one or multiple different cells from a single model. If however all items are semantically similar and one could derive an array of them, it is recommended to use theListSectionControllerinstead. -
SingleItemSectionController<Model, Item>:In contrast to the
SingleModelSectionController, thisSectionControllerwill conditionally display0or1item and animate this change accordingly.Warning: If
numberOfItemsis overridden,calculateUpdate(from:to:)needs to be overridden as well.This
SectionControlleris typically used when one item should be displayed conditionally. If multiple items should be displayed, it is recommended to use theListSectionControllerinstead. -
ListSectionController<Model, Item>:A
SectionControllerthat contains a list of items. Changes to that list will result in a call toreloadSections(_:)on the underlyingUICollectionView.This
SectionControlleris typically used when there are multiple semantically similar items of a model to be displayed and the list of items (almost) never changes or should not perform animated updates. -
FoundationDiffingListSectionController<Model, Item: Hashable>(iOS 13+):A
SectionControllerthat contains a list of items and animate the difference whenever there is an update.This
SectionControlleris typically used when there are multiple semantically similar items of a model to be displayed and the list of items may dynamically change. -
DiffingListSectionController<Model, Item: Differentiable>(DiffingSectionKit):A
SectionControllerthat contains a list of items and animate the difference whenever there is an update.This
SectionControlleris typically used when there are multiple semantically similar items of a model to be displayed and the list of items may dynamically change. -
ManualDiffingListSectionController<Model, Item>(DiffingSectionKit):A
SectionControllerthat contains a list of items and animate the difference whenever there is an update.This
SectionControlleris typically used when there are multiple semantically similar items of a model to be displayed and the list of items may dynamically change.Note: Compared to the
DiffingListSectionControllerthis class doesn't have aDifferentiableconstraint on the genericItemtype, instead it requires closures in the init to get diffing information for an item.