From 8c8a6c5f8d1d0c2f4a04490aa1cecffb81129f1f Mon Sep 17 00:00:00 2001 From: JISU LEE Date: Thu, 25 Nov 2021 17:21:18 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20#271=20=ED=99=88=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=ED=91=9C=EC=8B=9C=20=EC=84=A4=EC=A0=95=20=EB=B0=8F=20=EC=B6=9C?= =?UTF-8?q?=EC=B2=98=ED=91=9C=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BBus/BBus.xcodeproj/project.pbxproj | 4 ++ .../Foreground/Home/HomeViewController.swift | 40 +++++++++++++++++- .../Home/View/EmptyFavoriteNoticeView.swift | 15 ++++++- .../View/FavoriteCollectionViewCell.swift | 1 - BBus/BBus/Foreground/Home/View/HomeView.swift | 1 + .../Home/View/SourceFooterView.swift | 42 +++++++++++++++++++ 6 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 BBus/BBus/Foreground/Home/View/SourceFooterView.swift diff --git a/BBus/BBus.xcodeproj/project.pbxproj b/BBus/BBus.xcodeproj/project.pbxproj index a1b3dd78..a4afc7e6 100644 --- a/BBus/BBus.xcodeproj/project.pbxproj +++ b/BBus/BBus.xcodeproj/project.pbxproj @@ -62,6 +62,7 @@ 4AA294B3273C111C008E5497 /* GetFavoriteItemListFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AA294B2273C111C008E5497 /* GetFavoriteItemListFetcher.swift */; }; 4AA294B5273C11DE008E5497 /* CreateFavoriteItemFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AA294B4273C11DE008E5497 /* CreateFavoriteItemFetcher.swift */; }; 4AA294B7273C1275008E5497 /* DeleteFavoriteItemFetchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AA294B6273C1275008E5497 /* DeleteFavoriteItemFetchable.swift */; }; + 4AC79161274F6FDB00019827 /* SourceFooterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AC79160274F6FDB00019827 /* SourceFooterView.swift */; }; 4ACA51E3272FCD9600EC0531 /* HomeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4ACA51E2272FCD9600EC0531 /* HomeModel.swift */; }; 4ACA51E5272FCD9C00EC0531 /* HomeUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4ACA51E4272FCD9C00EC0531 /* HomeUseCase.swift */; }; 4ACA51E7272FCDA600EC0531 /* HomeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4ACA51E6272FCDA600EC0531 /* HomeViewModel.swift */; }; @@ -194,6 +195,7 @@ 4AA294B2273C111C008E5497 /* GetFavoriteItemListFetcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetFavoriteItemListFetcher.swift; sourceTree = ""; }; 4AA294B4273C11DE008E5497 /* CreateFavoriteItemFetcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateFavoriteItemFetcher.swift; sourceTree = ""; }; 4AA294B6273C1275008E5497 /* DeleteFavoriteItemFetchable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteFavoriteItemFetchable.swift; sourceTree = ""; }; + 4AC79160274F6FDB00019827 /* SourceFooterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceFooterView.swift; sourceTree = ""; }; 4ACA51E2272FCD9600EC0531 /* HomeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeModel.swift; sourceTree = ""; }; 4ACA51E4272FCD9C00EC0531 /* HomeUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeUseCase.swift; sourceTree = ""; }; 4ACA51E6272FCDA600EC0531 /* HomeViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeViewModel.swift; sourceTree = ""; }; @@ -437,6 +439,7 @@ 4A1A22DA27326FD100476861 /* HomeNavigationView.swift */, 4A7BBFF02737D6C20029915F /* RemainCongestionBadgeLabel.swift */, 4A917DF127462E36002489FE /* EmptyFavoriteNoticeView.swift */, + 4AC79160274F6FDB00019827 /* SourceFooterView.swift */, ); path = View; sourceTree = ""; @@ -959,6 +962,7 @@ 4A06AEC8274159D10027222D /* FavoriteItemDTO.swift in Sources */, 4ACA521F272FCEAA00EC0531 /* AlarmSettingBusArriveInfo.swift in Sources */, 4A1A22DB27326FD100476861 /* HomeNavigationView.swift in Sources */, + 4AC79161274F6FDB00019827 /* SourceFooterView.swift in Sources */, 0484107627464D49006F8636 /* AlarmSettingBusArriveInfos.swift in Sources */, 4ACA5225272FCEBF00EC0531 /* AlarmSettingView.swift in Sources */, 87038A92273C12320078EAE3 /* GetBusPosByRtidFetcher.swift in Sources */, diff --git a/BBus/BBus/Foreground/Home/HomeViewController.swift b/BBus/BBus/Foreground/Home/HomeViewController.swift index 1f0c4ab9..4d22aa27 100644 --- a/BBus/BBus/Foreground/Home/HomeViewController.swift +++ b/BBus/BBus/Foreground/Home/HomeViewController.swift @@ -84,7 +84,7 @@ final class HomeViewController: UIViewController { NSLayoutConstraint.activate([ self.homeView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor), - self.homeView.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor), + self.homeView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor), self.homeView.leadingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.leadingAnchor), self.homeView.trailingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.trailingAnchor) ]) @@ -222,7 +222,38 @@ extension HomeViewController: UICollectionViewDataSource { } func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { - guard let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: FavoriteCollectionHeaderView.identifier, for: indexPath) as? FavoriteCollectionHeaderView else { return UICollectionReusableView() } + switch kind { + case UICollectionView.elementKindSectionFooter : + if let footer = footer(with: collectionView, indexPath: indexPath) { + return footer + } + case UICollectionView.elementKindSectionHeader : + if let header = header(with: collectionView, indexPath: indexPath) { + return header + } + default : + return UICollectionReusableView() + } + return UICollectionReusableView() + } + + private func footer(with collectionView: UICollectionView, indexPath: IndexPath) -> SourceFooterView? { + guard let footer = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: SourceFooterView.identifier, for: indexPath) as? SourceFooterView else { return nil } + if let maxSize = self.footerSize(with: collectionView) { + footer.frame.size = maxSize + } + return footer + } + + private func footerSize(with collectionView: UICollectionView) -> CGSize? { + guard collectionView.contentSize.height < collectionView.frame.height else { return nil } + let gap = collectionView.frame.height - collectionView.contentSize.height + return CGSize(width: self.view.frame.width, height: SourceFooterView.height + gap) + } + + private func header(with collectionView: UICollectionView, indexPath: IndexPath) -> FavoriteCollectionHeaderView? { + guard let header = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: FavoriteCollectionHeaderView.identifier, for: indexPath) as? FavoriteCollectionHeaderView else { return nil } + guard let stationId = self.viewModel?.homeFavoriteList?[indexPath.section]?.stationId, let stationName = self.viewModel?.stationName(by: stationId), let arsId = self.viewModel?.homeFavoriteList?[indexPath.section]?.arsId else { return header } @@ -248,6 +279,11 @@ extension HomeViewController: UICollectionViewDelegateFlowLayout { return CGSize(width: self.view.frame.width, height: FavoriteCollectionHeaderView.height) } } + + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize { + guard section == (self.viewModel?.homeFavoriteList?.count() ?? 1) - 1 else { return CGSize.zero } + return CGSize(width: self.view.frame.width, height: SourceFooterView.height) + } } // MARK: - HomeSearchButtonDelegate : UICollectionView diff --git a/BBus/BBus/Foreground/Home/View/EmptyFavoriteNoticeView.swift b/BBus/BBus/Foreground/Home/View/EmptyFavoriteNoticeView.swift index 887cb4fe..1e480c87 100644 --- a/BBus/BBus/Foreground/Home/View/EmptyFavoriteNoticeView.swift +++ b/BBus/BBus/Foreground/Home/View/EmptyFavoriteNoticeView.swift @@ -24,6 +24,13 @@ final class EmptyFavoriteNoticeView: UIView { label.font = UIFont.systemFont(ofSize: 15) return label }() + private lazy var sourceLabel: UILabel = { + let label = UILabel() + label.text = "출처 : 서울특별시" + label.font = UIFont.systemFont(ofSize: 15) + label.textColor = BBusColor.bbusGray + return label + }() convenience init() { self.init(frame: CGRect()) @@ -43,7 +50,7 @@ final class EmptyFavoriteNoticeView: UIView { let half: CGFloat = 0.5 let centerYInterval: CGFloat = -30 - self.addSubviews(self.noticeImage, self.noticeLabel) + self.addSubviews(self.noticeImage, self.noticeLabel, self.sourceLabel) NSLayoutConstraint.activate([ self.noticeImage.centerXAnchor.constraint(equalTo: self.centerXAnchor), @@ -57,5 +64,11 @@ final class EmptyFavoriteNoticeView: UIView { self.noticeLabel.centerXAnchor.constraint(equalTo: self.centerXAnchor), self.noticeLabel.widthAnchor.constraint(equalTo: self.noticeImage.widthAnchor, multiplier: 1.2) ]) + + let sourceLabelBottominterval: CGFloat = -30 + NSLayoutConstraint.activate([ + self.sourceLabel.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: sourceLabelBottominterval), + self.sourceLabel.centerXAnchor.constraint(equalTo: self.centerXAnchor) + ]) } } diff --git a/BBus/BBus/Foreground/Home/View/FavoriteCollectionViewCell.swift b/BBus/BBus/Foreground/Home/View/FavoriteCollectionViewCell.swift index 472fbe39..f82ec78b 100644 --- a/BBus/BBus/Foreground/Home/View/FavoriteCollectionViewCell.swift +++ b/BBus/BBus/Foreground/Home/View/FavoriteCollectionViewCell.swift @@ -30,7 +30,6 @@ class FavoriteCollectionViewCell: UICollectionViewCell { private lazy var busNumberLabel: UILabel = { let label = UILabel() - label.text = "272" label.font = UIFont.boldSystemFont(ofSize: self.busNumberFontSize) label.textColor = BBusColor.bbusTypeBlue return label diff --git a/BBus/BBus/Foreground/Home/View/HomeView.swift b/BBus/BBus/Foreground/Home/View/HomeView.swift index a68b79fa..7e764866 100644 --- a/BBus/BBus/Foreground/Home/View/HomeView.swift +++ b/BBus/BBus/Foreground/Home/View/HomeView.swift @@ -12,6 +12,7 @@ final class HomeView: UIView { private lazy var favoriteCollectionView: UICollectionView = { let collectionView = UICollectionView(frame: CGRect(), collectionViewLayout: self.collectionViewLayout()) collectionView.register(FavoriteCollectionHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: FavoriteCollectionHeaderView.identifier) + collectionView.register(SourceFooterView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: SourceFooterView.identifier) collectionView.register(FavoriteCollectionViewCell.self, forCellWithReuseIdentifier: FavoriteCollectionViewCell.identifier) let backgroundView = UIView() backgroundView.backgroundColor = BBusColor.bbusBackground diff --git a/BBus/BBus/Foreground/Home/View/SourceFooterView.swift b/BBus/BBus/Foreground/Home/View/SourceFooterView.swift new file mode 100644 index 00000000..acf80cd0 --- /dev/null +++ b/BBus/BBus/Foreground/Home/View/SourceFooterView.swift @@ -0,0 +1,42 @@ +// +// CollectionReusableView.swift +// BBus +// +// Created by 이지수 on 2021/11/25. +// + +import UIKit + +final class SourceFooterView: UICollectionReusableView { + + static let identifier = "SourceFooterView" + static let height: CGFloat = 100 + + private lazy var sourceLabel: UILabel = { + let label = UILabel() + label.text = "출처 : 서울특별시" + label.font = UIFont.systemFont(ofSize: 15) + label.textColor = BBusColor.bbusGray + return label + }() + + required override init(frame: CGRect) { + super.init(frame: frame) + self.configureLayout() + } + + required init?(coder: NSCoder) { + super.init(coder: coder) + self.configureLayout() + } + + private func configureLayout() { + self.addSubviews(self.sourceLabel) + + let half: CGFloat = 0.5 + NSLayoutConstraint.activate([ + self.sourceLabel.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: -Self.height * half), + self.sourceLabel.centerXAnchor.constraint(equalTo: self.centerXAnchor) + ]) + } +}