@@ -84,7 +84,7 @@ final class HomeViewController: UIViewController {
84
84
85
85
NSLayoutConstraint . activate ( [
86
86
self . homeView. topAnchor. constraint ( equalTo: self . view. safeAreaLayoutGuide. topAnchor) ,
87
- self . homeView. bottomAnchor. constraint ( equalTo: self . view. safeAreaLayoutGuide . bottomAnchor) ,
87
+ self . homeView. bottomAnchor. constraint ( equalTo: self . view. bottomAnchor) ,
88
88
self . homeView. leadingAnchor. constraint ( equalTo: self . view. safeAreaLayoutGuide. leadingAnchor) ,
89
89
self . homeView. trailingAnchor. constraint ( equalTo: self . view. safeAreaLayoutGuide. trailingAnchor)
90
90
] )
@@ -222,7 +222,38 @@ extension HomeViewController: UICollectionViewDataSource {
222
222
}
223
223
224
224
func collectionView( _ collectionView: UICollectionView , viewForSupplementaryElementOfKind kind: String , at indexPath: IndexPath ) -> UICollectionReusableView {
225
- guard let header = collectionView. dequeueReusableSupplementaryView ( ofKind: kind, withReuseIdentifier: FavoriteCollectionHeaderView . identifier, for: indexPath) as? FavoriteCollectionHeaderView else { return UICollectionReusableView ( ) }
225
+ switch kind {
226
+ case UICollectionView . elementKindSectionFooter :
227
+ if let footer = footer ( with: collectionView, indexPath: indexPath) {
228
+ return footer
229
+ }
230
+ case UICollectionView . elementKindSectionHeader :
231
+ if let header = header ( with: collectionView, indexPath: indexPath) {
232
+ return header
233
+ }
234
+ default :
235
+ return UICollectionReusableView ( )
236
+ }
237
+ return UICollectionReusableView ( )
238
+ }
239
+
240
+ private func footer( with collectionView: UICollectionView , indexPath: IndexPath ) -> SourceFooterView ? {
241
+ guard let footer = collectionView. dequeueReusableSupplementaryView ( ofKind: UICollectionView . elementKindSectionFooter, withReuseIdentifier: SourceFooterView . identifier, for: indexPath) as? SourceFooterView else { return nil }
242
+ if let maxSize = self . footerSize ( with: collectionView) {
243
+ footer. frame. size = maxSize
244
+ }
245
+ return footer
246
+ }
247
+
248
+ private func footerSize( with collectionView: UICollectionView ) -> CGSize ? {
249
+ guard collectionView. contentSize. height < collectionView. frame. height else { return nil }
250
+ let gap = collectionView. frame. height - collectionView. contentSize. height
251
+ return CGSize ( width: self . view. frame. width, height: SourceFooterView . height + gap)
252
+ }
253
+
254
+ private func header( with collectionView: UICollectionView , indexPath: IndexPath ) -> FavoriteCollectionHeaderView ? {
255
+ guard let header = collectionView. dequeueReusableSupplementaryView ( ofKind: UICollectionView . elementKindSectionHeader, withReuseIdentifier: FavoriteCollectionHeaderView . identifier, for: indexPath) as? FavoriteCollectionHeaderView else { return nil }
256
+
226
257
guard let stationId = self . viewModel? . homeFavoriteList ? [ indexPath. section] ? . stationId,
227
258
let stationName = self . viewModel? . stationName ( by: stationId) ,
228
259
let arsId = self . viewModel? . homeFavoriteList ? [ indexPath. section] ? . arsId else { return header }
@@ -248,6 +279,11 @@ extension HomeViewController: UICollectionViewDelegateFlowLayout {
248
279
return CGSize ( width: self . view. frame. width, height: FavoriteCollectionHeaderView . height)
249
280
}
250
281
}
282
+
283
+ func collectionView( _ collectionView: UICollectionView , layout collectionViewLayout: UICollectionViewLayout , referenceSizeForFooterInSection section: Int ) -> CGSize {
284
+ guard section == ( self . viewModel? . homeFavoriteList? . count ( ) ?? 1 ) - 1 else { return CGSize . zero }
285
+ return CGSize ( width: self . view. frame. width, height: SourceFooterView . height)
286
+ }
251
287
}
252
288
253
289
// MARK: - HomeSearchButtonDelegate : UICollectionView
0 commit comments