From da9394663a2ea63962c7f11340574faa863b635a Mon Sep 17 00:00:00 2001 From: Daniele Margutti Date: Sun, 12 May 2019 09:35:29 +0200 Subject: [PATCH] #6 Fix missing dispatch dequeue event for collection's header/footer --- Sources/Collection/CollectionDirector.swift | 20 +++++++++++++++++-- .../Collection/FlowCollectionDirector.swift | 16 --------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Sources/Collection/CollectionDirector.swift b/Sources/Collection/CollectionDirector.swift index 43046a4..a3a9585 100644 --- a/Sources/Collection/CollectionDirector.swift +++ b/Sources/Collection/CollectionDirector.swift @@ -436,8 +436,24 @@ public extension CollectionDirector { func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { let adapter = adapterForHeaderFooter(kind, indexPath: indexPath) - return adapter?.dequeueHeaderFooterForDirector(self, type: kind, indexPath: indexPath) ?? UICollectionReusableView() - } + let view = adapter?.dequeueHeaderFooterForDirector(self, type: kind, indexPath: indexPath) ?? UICollectionReusableView() + let _ = adapter?.dispatch(.dequeue, isHeader: (kind == UICollectionView.elementKindSectionHeader), view: view, section: sections[indexPath.section], index: indexPath.section) + return view + } + + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize { + guard let size = sections[section].headerView?.dispatch(.referenceSize, isHeader: true, view: nil, section: sections[section], index: section) as? CGSize else { + return .zero + } + return size + } + + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize { + guard let size = sections[section].footerView?.dispatch(.referenceSize, isHeader: false, view: nil, section: sections[section], index: section) as? CGSize else { + return .zero + } + return size + } func collectionView(_ collectionView: UICollectionView, willDisplaySupplementaryView view: UICollectionReusableView, forElementKind elementKind: String, at indexPath: IndexPath) { let adapter = adapterForHeaderFooter(elementKind, indexPath: indexPath) diff --git a/Sources/Collection/FlowCollectionDirector.swift b/Sources/Collection/FlowCollectionDirector.swift index c55e37f..098008d 100644 --- a/Sources/Collection/FlowCollectionDirector.swift +++ b/Sources/Collection/FlowCollectionDirector.swift @@ -166,20 +166,4 @@ public extension FlowCollectionDirector { return value } - func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize { - guard let size = sections[section].headerView?.dispatch(.referenceSize, isHeader: true, view: nil, section: sections[section], index: section) as? CGSize else { - return .zero - } - return size - } - - func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize { - guard let size = sections[section].footerView?.dispatch(.referenceSize, isHeader: false, view: nil, section: sections[section], index: section) as? CGSize else { - return .zero - } - return size - } - - - }