Skip to content
This repository has been archived by the owner on Nov 15, 2020. It is now read-only.

Fix dequeue not calling for UICollectionReusableView #27

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class CollectionExampleController: UIViewController {
header.on.referenceSize = { _ in
return CGSize(width: self.collectionView!.frame.width, height: 40)
}
header.on.dequeue = { ctx in
ctx.view?.label?.text = "Header Title"
}
let section = CollectionSection.init(list, headerView: header)

self.director?.add(section)
Expand Down
17 changes: 14 additions & 3 deletions Sources/FlowKit/Collection/CollectionDirector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -517,12 +517,22 @@ public extension CollectionDirector {
}

let view = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: identifier, for: indexPath)


switch kind {
case UICollectionView.elementKindSectionHeader:
_ = (section.header as? AbstractCollectionHeaderFooterItem)?.dispatch(.dequeue, type: .header, view: view, section: indexPath.section, collection: collectionView)
case UICollectionView.elementKindSectionFooter:
_ = (section.header as? AbstractCollectionHeaderFooterItem)?.dispatch(.dequeue, type: .footer, view: view, section: indexPath.section, collection: collectionView)
default:
break
}

return view
}

public func collectionView(_ collectionView: UICollectionView, willDisplaySupplementaryView view: UICollectionReusableView, forElementKind elementKind: String, at indexPath: IndexPath) {


guard indexPath.section < sections.count else { return }
switch elementKind {
case UICollectionView.elementKindSectionHeader:
let header = (sections[indexPath.section].header as? AbstractCollectionHeaderFooterItem)
Expand All @@ -539,7 +549,8 @@ public extension CollectionDirector {
}

public func collectionView(_ collectionView: UICollectionView, didEndDisplayingSupplementaryView view: UICollectionReusableView, forElementOfKind elementKind: String, at indexPath: IndexPath) {


guard indexPath.section < sections.count else { return }
switch elementKind {
case UICollectionView.elementKindSectionHeader:
let header = (sections[indexPath.section].header as? AbstractCollectionHeaderFooterItem)
Expand Down