DTCollectionViewManager v8.0.0-beta.1 Release Notes
Release Date: 2020-09-02 // over 3 years ago-
π This is a major release with some breaking changes, please read DTCollectionViewManager 8.0 Migration Guide
π New
Cell and supplementary view events are now available inside mapping closure directly, for example:
// Previous releasesmanager.register(PostCell.self) manager.didSelect(PostCell.self) { cell, model, indexPath in// React to selection}// Newmanager.register(PostCell.self) { mapping in mapping.didSelect { cell, model, indexPath in } }
Those events are now tied to
ViewModelMapping
instance, which means, that events, registered this way, will only trigger, if mapping condition of current mapping applies. For example:manager.register(PostCell.self) { mapping in mapping.condition = .section(0) mapping.didSelect { cell, model, indexPath in// This closure will only get called, when user selects cell in the first section } } manager.register(PostCell.self) { mapping in mapping.condition = .section(1) mapping.didSelect { cell, model, indexPath in// This closure will only get called, when user selects cell in the second section } }
It's now possible to register collection view cells, that don't conform to
DTModelTransfer
protocol:manager.register(UICollectionViewCell.self, String.self) { cell, indexPath, model in// configure cell with model which is of type String when passed into configuration closure.}
π§ This is particularly useful on iOS / tvOS 14 and higher, where you can configure
UICollectionViewListCell
without needing to subclass it.
π Cells, registered in this way, can safely coexist with cells, that conform toDTModelTransfer
protocol. Conditional mappings are also supported (multiple trailing closures syntax available in Swift 5.3):manager.register(UICollectionViewCell.self, for: String.self) { $0.condition = .section(0) } handler { cell, indexPath, model in// configure cell with model which is of type String when passed into configuration closure.}
- β Added event reaction for
UICollectionViewDelegate.collectionView(_:canEditItemAt:)
delegate method. - β Added event reactions for tvOS 13
TVCollectionViewDelegateFullScreenLayout
protocol fromTVUIKit
framework. - π New readme and in-depth documentation, split into several sections for developer convenience.
π Changed
- On iOS/tvOS 14 and higher, cell and supplementary views now use
UICollectionView.dequeueConfiguredReusableCell
andUICollectionView.dequeueConfiguredReusableSupplementary
to be dequeued. - β‘οΈ
DTModelTransfer
update(with:)
method for such cells and supplementary views is called immediately afterdequeueConfiguredReusableCell
\dequeueConfiguredReusableSupplementary
return. - π Generic placeholders for cell/model/view methods have been improved for better readability.
π₯ Breaking
π This release requires Swift 5.3. Minimum iOS / tvOS deployment targets are unchanged (iOS 11, tvOS 11).
π Some context: this release heavily relies on where clauses on contextually generic declarations, that are only available in Swift 5.3 - SE-0267.
π§ Cells, headers and footers created in storyboard now need to be explicitly configured in view mapping:
register(StoryboardCell.self) { mapping in mapping.cellRegisteredByStoryboard = true}registerHeader(StoryboardHeader.self) { mapping in mapping.supplementaryRegisteredByStoryboard = true}
All non-deprecated registration methods now have an additional
handler
closure, that allows to configure cells/headers/footers/supplementary views that are dequeued from UICollectionView. This is a direct replacement forconfigure(_:_:
,configureHeader(_:_:)
,configureFooter(_:_:)
andconfigureSupplementary(_:ofKind:_:
, that are all now deprecated.β‘οΈ On iOS / tvOS 14 / Xcode 12 and higher handler closure, that is passed to registration methods, is used to call new
dequeueConfiguredReusableCell(using:for:item:)
anddequeueConfiguredReusableSupplementary(using:for:)
methods on UICollectionView. Please note, that handler closure is called beforeDTModelTransfer.update(with:)
method because of how new UICollectionView dequeue API works.ViewModelMapping
is now a generic class, that captures view and model information(ViewModelMapping<T,U>).β‘οΈ
CollectionViewUpdater.batchUpdatesInProgress
property was removed.
π Deprecated
- Several cell/header/footer/supplementary view registration methods have been deprecated to unify registration logic. Please use
register(_:mapping:handler:)
,registerHeader(_:mapping:handler:)
,registerFooter(_:mapping:handler:)
andregisterSupplementary(_:forKind:mapping:handler:)
as a replacements for all of those methods. For more information on those changes, please read migration guide - π§
DTCollectionViewManager.configureEvents(for:_:)
, it's functionality has become unnecessary since mapping closure of cell/supplementary registration now captures both cell and model type information for such events. - π
DTCollectionViewManager.configureDiffableDataSource(modelProvider:)
for non-hashable data models. Please use configureDiffableDataSource method for models, that are Hashable. From Apple's documentation:If youβre working in a Swift codebase, always use UICollectionViewDiffableDataSource instead
.
π Fixed
- Supplementary views now correctly use
ViewModelMapping.reuseIdentifier
instead of falling back to name of the view class. - Several event API's have been improved to allow returning nil for methods, that accept nil as a valid value:
contextMenuConfiguration
,previewForHighlightingContextMenu
,previewForDismissingContextMenu