Skip to content

11.0.0

Latest
Compare
Choose a tag to compare
@DenTelezhkin DenTelezhkin released this 06 Oct 12:46
· 1 commit to main since this release

Added

  • Support for UICollectionViewDelegate.collectionView(_:canPerformPrimaryActionForItemAt:) and UICollectionViewDelegate.collectionView(_:performPrimaryActionForItemAt:) delegate methods on iOS 16 and tvOS 16.
  • Support for UICollectionViewDelegate.collectionView(_:contextMenuConfigurationForItemsAt:point:), UICollectionViewDelegate.collectionView(_:contextMenuConfiguration:highlightPreviewForItemAt:) and UICollectionViewDelegate.collectionView(_:contextMenuConfiguration:dismissalPreviewForItemAt: methods on iOS 16.
  • Support for UIHostingConfiguration on iOS 16 / tvOS 16 / macCatalyst 16:
manager.registerHostingConfiguration(for: Post.self) { _, post, _ in
    UIHostingConfiguration {
        PostView(post: post)
    }
}

It's also possible to incorporate UIKit cell states by simply adding additional parameter to registration:

manager.registerHostingConfiguration(for: Post.self) { state, _, post, _ in
    UIHostingConfiguration {
        PostView(post: post, isSelected: state.isSelected)
    }
}

Additionally, it's possible to customize UICollectionViewCell being used to host SwiftUI view, for example for list cells:

manager.registerHostingConfiguration(for: Post.self, cell: UICollectionViewListCell.self) { _, post, _ in
    UIHostingConfiguration {
        PostView(post: post)
    }
}
  • Support for events, wrapping UICollectionViewDataSourcePrefetching protocol.
manager.register(PostCell.self) { mapping in
    mapping.prefetch { model, indexPath in }
    mapping.cancelPrefetch { model, indexPath in }
}

Please note, that while datasource methods are called once per array of indexPaths, events for models will be called individually, so single model (and indexPath) is passed to each event. Theoretically, this should make prefetching and cancellation easier, since you no longer need to walk through array and find all data models, you can operate on a single data model at a time.

Deprecated

  • Cell / View events, registered with DTCollectionViewManager are soft-deprecated. Please use events in mapping instead:

Deprecated:

    manager.register(PostCell.self)
    manager.didSelect(PostCell.self) { postCell, post, indexPath in }

Recommended:

    manager.register(PostCell.self) { mapping in
        mapping.didSelect { postCell, post, indexPath in }
    }

While previously main benefits for second syntax were mostly syntactic, now with support for SwiftUI it will be hard to actually specialize hosting cells (and might be impossible when iOS 16 hosting configuration is supported), so only second syntax will work for all kinds of cells, and first syntax can only work for non-SwiftUI cells.
New delegate methods for UICollectionView (starting with iOS 16 / tvO 16 SDK) will be added only as extension to mapping protocols, not DTCollectionViewManager itself.