ListCollectionController
open class ListCollectionController<T> : BaseCollectionController<T>, UICollectionViewDataSourcePrefetching
A subclass of BaseCollectionController
that serves as a base class that handles paginated list behavior for a CollectionViewController
.
This CollectionController
subclass manages paginated lists by keeping track of the current and loaded pages as well as prefetching succeeding pages.
This shows a loading cell at the end of the list when it has not yet reached the last page. Also by default, the layout returns a ListCollectionViewFlowLayout
which is similar to a table view.
By default, this uses ListItemCell
for its cells.
The associated type can conform to the ListItemCellPresentable
to be able to configure the cells to present content of the type.
When subclassed, the registerComponents
and collectionView(collectionView:cellForItemAt:)
can be overriden to bypass usage of the ListItemCell
.
The typical usage of this class when subclassed is:
- Optionally override
registerComponents
to register cells and reusable views. - Override
loadContent(completion:)
to fetch and update content. - Optionally override
collectionView(collectionView:cellForItemAt:)
for configuring cells. Override
collectionView(collectionView:didSelectItemtAt:)
for cell select actions.
Note
Due to what maybe seems to be a bug with the Swift, methods not initially in the superclass and implemented in the subclass may not be executed. To get around this, the method needs to have an @objc
attribue.
-
Declaration
Swift
override open var collectionViewLayout: UICollectionViewLayout { get }
-
The current page loaded in the list.
Declaration
Swift
open var currentPage: Int
-
Total number of items in the whole list
Declaration
Swift
open var totalItems: Int
-
Represents whether the last loaded content is on the last page.
Declaration
Swift
open var onLastPage: Bool { get }
-
The index path of the loading cell.
Declaration
Swift
open var loadCellIndexPath: IndexPath { get }
-
Declaration
Swift
override open func setupCollectionView()
-
Declaration
Swift
override open func registerComponents()
-
Checks whether the given index path is the location of the loading cell.
Declaration
Swift
open func isLoadingCell(at indexPath: IndexPath) -> Bool
Parameters
indexPath
The index path to check.
Return Value
Returns true if the index path is the location of the loading cell otherwise, it returns false.
-
Returns the visible index paths in the collection view from the given index paths.
Declaration
Swift
open func visibleIndexPaths(from indexPaths: [IndexPath]) -> [IndexPath]
Parameters
indexPaths
The index paths to check if visible.
Return Value
The intersecting index paths from the visible index paths of the collection view.
-
Updates the collection view and collection data provider with the given items.
This updates the collectionview and collection data provider with the following steps:
- If
newItems
is empty, do nothing. - If
currentPage
is 0, remove all existing items. Then add new items, increment page and reload the collection view. - If
currentPage
is more than 0, perform batch updates by adding new items and cells.
Declaration
Swift
open func updateCollection(with newItems: [T])
Parameters
newItems
The new items to add to the collection view and collection data provider.
- If
-
Undocumented
Declaration
Swift
override open func refreshContent()
-
Undocumented
Declaration
Swift
override open func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
-
Undocumented
Declaration
Swift
override open func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
-
Undocumented
Declaration
Swift
open func collectionView(_ collectionView: UICollectionView, prefetchItemsAt indexPaths: [IndexPath])