@@ -10,6 +10,7 @@ import Foundation
1010
1111open class PresentableCollectionViewDataManager : NSObject , PresentableManager , UICollectionViewDataSource , UICollectionViewDelegate {
1212
13+ // TODO: Can we remove this?
1314 public var needsReloadData : ( ( ) -> ( ) ) ?
1415 public var sizeForHeaderInSection : ( ( _ section: Int ) -> ( CGSize ) ) ?
1516 public var sizeForFooterInSection : ( ( _ section: Int ) -> ( CGSize ) ) ?
@@ -33,6 +34,7 @@ open class PresentableCollectionViewDataManager: NSObject, PresentableManager, U
3334 // MARK: Actions
3435
3536 public func reloadData( ) {
37+ collectionView? . collectionViewLayout. invalidateLayout ( )
3638 collectionView? . reloadData ( )
3739 }
3840
@@ -68,38 +70,44 @@ open class PresentableCollectionViewDataManager: NSObject, PresentableManager, U
6870 fatalError ( )
6971 }
7072 let view = collectionView. dequeueReusableSupplementaryView ( ofKind: kind, withReuseIdentifier: presentable. identifier, for: indexPath)
73+ presentable. runConfigure ( with: view)
7174 return view
7275 }
7376 else {
7477 guard let presentable: AnyPresentable = data. footer ( forSection: indexPath. section) else {
7578 fatalError ( )
7679 }
7780 let view = collectionView. dequeueReusableSupplementaryView ( ofKind: kind, withReuseIdentifier: presentable. identifier, for: indexPath)
81+ presentable. runConfigure ( with: view)
7882 return view
7983 }
8084 }
8185
86+ // MARK: Delegate
87+
88+ open func collectionView( _ collectionView: UICollectionView , didSelectItemAt indexPath: IndexPath ) {
89+ let presentable : AnyPresentable = data. presentable ( forIndexPath: indexPath)
90+ presentable. selected ? ( )
91+ selectedItem ? ( ( presentable: presentable, indexPath: indexPath, collectionView: collectionView) )
92+ }
93+
94+ }
95+
96+
97+ extension PresentableCollectionViewDataManager : UICollectionViewDelegateFlowLayout {
98+
8299 open func collectionView( _ collectionView: UICollectionView , layout collectionViewLayout: UICollectionViewLayout , referenceSizeForHeaderInSection section: Int ) -> CGSize {
83100 guard let _ = data. header ( forSection: section) else {
84101 return CGSize . zero
85102 }
86103 return sizeForHeaderInSection ? ( section) ?? CGSize ( width: collectionView. frame. width, height: 44 )
87104 }
88-
105+
89106 open func collectionView( _ collectionView: UICollectionView , layout collectionViewLayout: UICollectionViewLayout , referenceSizeForFooterInSection section: Int ) -> CGSize {
90107 guard let _ = data. footer ( forSection: section) else {
91108 return CGSize . zero
92109 }
93110 return sizeForFooterInSection ? ( section) ?? CGSize ( width: collectionView. frame. width, height: 44 )
94111 }
95-
96-
97- // MARK: Delegate
98-
99- open func collectionView( _ collectionView: UICollectionView , didSelectItemAt indexPath: IndexPath ) {
100- let presentable : AnyPresentable = data. presentable ( forIndexPath: indexPath)
101- presentable. selected ? ( )
102- selectedItem ? ( ( presentable: presentable, indexPath: indexPath, collectionView: collectionView) )
103- }
104-
112+
105113}
0 commit comments