-
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:
ListCollectionViewAdapter
andListSectionController
will not animate updates to the list of sections/items and callreloadData()
/reloadSections(_:)
respectively. On iOS 13+ you can use theFoundationDiffingListCollectionViewAdapter
orFoundationDiffingListSectionController
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
,SingleModelSectionController
andSingleItemSectionController
support animated updates out of the box. -
DiffingSectionKit
:This package extends
SectionKit
by containing three more base classes,DiffingListCollectionViewAdapter
,DiffingListSectionController
andManualDiffingListSectionController
. 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:
UICollectionViewDataSource
UICollectionViewDataSourcePrefetching
UICollectionViewDelegate
UICollectionViewDragDelegate
UICollectionViewDropDelegate
UICollectionViewDelegateFlowLayout
UIScrollViewDelegate
Other APIs can be easily added by extending ListCollectionViewAdapter
or SingleSectionCollectionViewAdapter
.
-
ListCollectionViewAdapter
:A
CollectionViewAdapter
that contains a list of sections. Changes to that list will result in a call toreloadData()
on the underlyingUICollectionView
. -
SingleSectionCollectionViewAdapter
:A
CollectionViewAdapter
that 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
CollectionViewAdapter
that 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
CollectionViewAdapter
that 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:
SectionController
SectionDataSource
-
SectionDataSourcePrefetchingDelegate
(iOS 10+) SectionDelegate
SectionFlowDelegate
-
SectionDragDelegate
(iOS 11+) -
SectionDropDelegate
(iOS 11+)
-
SingleModelSectionController<Model>
:A
SectionController
that displays data of a single model. Unless overridden,numberOfItems
will always be1
and a change to itsmodel
will perform a call toreloadItems(at:)
.Warning: If
numberOfItems
is overridden,calculateUpdate(from:to:)
needs to be overridden as well.This
SectionController
is 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 theListSectionController
instead. -
SingleItemSectionController<Model, Item>
:In contrast to the
SingleModelSectionController
, thisSectionController
will conditionally display0
or1
item and animate this change accordingly.Warning: If
numberOfItems
is overridden,calculateUpdate(from:to:)
needs to be overridden as well.This
SectionController
is typically used when one item should be displayed conditionally. If multiple items should be displayed, it is recommended to use theListSectionController
instead. -
ListSectionController<Model, Item>
:A
SectionController
that contains a list of items. Changes to that list will result in a call toreloadSections(_:)
on the underlyingUICollectionView
.This
SectionController
is 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
SectionController
that contains a list of items and animate the difference whenever there is an update.This
SectionController
is 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
SectionController
that contains a list of items and animate the difference whenever there is an update.This
SectionController
is 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
SectionController
that contains a list of items and animate the difference whenever there is an update.This
SectionController
is 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
DiffingListSectionController
this class doesn't have aDifferentiable
constraint on the genericItem
type, instead it requires closures in the init to get diffing information for an item.