Fix collection view issues

This commit is contained in:
Justin Mazzocchi 2022-05-05 20:11:08 -07:00
parent 4db6fd85b2
commit 5ff2d41d7c
2 changed files with 30 additions and 32 deletions

View file

@ -14,25 +14,49 @@ final class ExploreDataSource: UICollectionViewDiffableDataSource<ExploreViewMod
init(collectionView: UICollectionView, viewModel: ExploreViewModel) {
self.collectionView = collectionView
let tagRegistration = UICollectionView.CellRegistration<TagCollectionViewCell, TagViewModel> {
$0.viewModel = $2
}
let instanceRegistration = UICollectionView.CellRegistration<InstanceCollectionViewCell, InstanceViewModel> {
$0.viewModel = $2
}
let itemRegistration = UICollectionView.CellRegistration
<SeparatorConfiguredCollectionViewListCell, ExploreViewModel.Item> {
var configuration = $0.defaultContentConfiguration()
switch $2 {
case .profileDirectory:
configuration.text = NSLocalizedString("explore.profile-directory", comment: "")
configuration.image = UIImage(systemName: "person.crop.square.fill.and.at.rectangle")
default:
break
}
$0.contentConfiguration = configuration
$0.accessories = [.disclosureIndicator()]
}
super.init(collectionView: collectionView) {
switch $2 {
case let .tag(tag):
return $0.dequeueConfiguredReusableCell(
using: Self.tagRegistration,
using: tagRegistration,
for: $1,
item: viewModel.viewModel(tag: tag))
case .instance:
return $0.dequeueConfiguredReusableCell(
using: Self.instanceRegistration,
using: instanceRegistration,
for: $1,
item: viewModel.instanceViewModel)
default:
return $0.dequeueConfiguredReusableCell(using: Self.itemRegistration, for: $1, item: $2)
return $0.dequeueConfiguredReusableCell(using: itemRegistration, for: $1, item: $2)
}
}
let headerRegistration = UICollectionView.SupplementaryRegistration
<ExploreSectionHeaderView>(elementKind: "Header") { [weak self] in
<ExploreSectionHeaderView>(elementKind: UICollectionView.elementKindSectionHeader) { [weak self] in
$0.label.text = self?.snapshot().sectionIdentifiers[$2.section].displayName
}
@ -55,30 +79,6 @@ final class ExploreDataSource: UICollectionViewDiffableDataSource<ExploreViewMod
}
private extension ExploreDataSource {
static let tagRegistration = UICollectionView.CellRegistration<TagCollectionViewCell, TagViewModel> {
$0.viewModel = $2
}
static let instanceRegistration = UICollectionView.CellRegistration<InstanceCollectionViewCell, InstanceViewModel> {
$0.viewModel = $2
}
static let itemRegistration = UICollectionView.CellRegistration
<SeparatorConfiguredCollectionViewListCell, ExploreViewModel.Item> {
var configuration = $0.defaultContentConfiguration()
switch $2 {
case .profileDirectory:
configuration.text = NSLocalizedString("explore.profile-directory", comment: "")
configuration.image = UIImage(systemName: "person.crop.square.fill.and.at.rectangle")
default:
break
}
$0.contentConfiguration = configuration
$0.accessories = [.disclosureIndicator()]
}
func update(tags: [Tag], instanceViewModel: InstanceViewModel?) {
var newsnapshot = NSDiffableDataSourceSnapshot<ExploreViewModel.Section, ExploreViewModel.Item>()

View file

@ -26,7 +26,7 @@ final class EmojiPickerViewController: UICollectionViewController {
}
let headerRegistration = UICollectionView.SupplementaryRegistration
<EmojiCategoryHeaderView>(elementKind: "Header") { [weak self] in
<EmojiCategoryHeaderView>(elementKind: UICollectionView.elementKindSectionHeader) { [weak self] in
$0.label.text = self?.dataSource.snapshot().sectionIdentifiers[$2.section].displayName
}
@ -184,8 +184,6 @@ final class EmojiPickerViewController: UICollectionViewController {
}
private extension EmojiPickerViewController {
static let headerElementKind = "com.metabolist.metatext.emoji-picker.header"
static func layout() -> UICollectionViewLayout {
let itemSize = NSCollectionLayoutSize(
widthDimension: .absolute(.minimumButtonDimension),
@ -212,7 +210,7 @@ private extension EmojiPickerViewController {
heightDimension: .estimated(.defaultSpacing))
let header = NSCollectionLayoutBoundarySupplementaryItem(
layoutSize: headerSize,
elementKind: Self.headerElementKind,
elementKind: UICollectionView.elementKindSectionHeader,
alignment: .top)
section.boundarySupplementaryItems = [header]