diff --git a/iOS/Airbnb/Airbnb.xcodeproj/project.pbxproj b/iOS/Airbnb/Airbnb.xcodeproj/project.pbxproj index c16b0473a..2e2a8fa4b 100644 --- a/iOS/Airbnb/Airbnb.xcodeproj/project.pbxproj +++ b/iOS/Airbnb/Airbnb.xcodeproj/project.pbxproj @@ -30,7 +30,7 @@ AE87A77D26687F71003E9541 /* PersonCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = AE87A77B26687F71003E9541 /* PersonCell.xib */; }; AE87A7812668992C003E9541 /* PeopleViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE87A7802668992C003E9541 /* PeopleViewModel.swift */; }; AE87A7842668D19D003E9541 /* SearchResultViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE87A7832668D19D003E9541 /* SearchResultViewController.swift */; }; - AE87A7862668DF22003E9541 /* ResultSupplymentaryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE87A7852668DF22003E9541 /* ResultSupplymentaryView.swift */; }; + AE87A7862668DF22003E9541 /* ResultSupplementaryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE87A7852668DF22003E9541 /* ResultSupplementaryView.swift */; }; AE87A7892668DFB1003E9541 /* AccommodationCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE87A7872668DFB1003E9541 /* AccommodationCell.swift */; }; AE87A78A2668DFB1003E9541 /* AccommodationCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = AE87A7882668DFB1003E9541 /* AccommodationCell.xib */; }; AE8CD3B42653538700BCB8FC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE8CD3B32653538700BCB8FC /* AppDelegate.swift */; }; @@ -91,7 +91,7 @@ AE87A77B26687F71003E9541 /* PersonCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PersonCell.xib; sourceTree = ""; }; AE87A7802668992C003E9541 /* PeopleViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PeopleViewModel.swift; sourceTree = ""; }; AE87A7832668D19D003E9541 /* SearchResultViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchResultViewController.swift; sourceTree = ""; }; - AE87A7852668DF22003E9541 /* ResultSupplymentaryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResultSupplymentaryView.swift; sourceTree = ""; }; + AE87A7852668DF22003E9541 /* ResultSupplementaryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResultSupplementaryView.swift; sourceTree = ""; }; AE87A7872668DFB1003E9541 /* AccommodationCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccommodationCell.swift; sourceTree = ""; }; AE87A7882668DFB1003E9541 /* AccommodationCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AccommodationCell.xib; sourceTree = ""; }; AE8CD3B02653538700BCB8FC /* Airbnb.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Airbnb.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -188,7 +188,7 @@ isa = PBXGroup; children = ( AE87A7832668D19D003E9541 /* SearchResultViewController.swift */, - AE87A7852668DF22003E9541 /* ResultSupplymentaryView.swift */, + AE87A7852668DF22003E9541 /* ResultSupplementaryView.swift */, AE87A7872668DFB1003E9541 /* AccommodationCell.swift */, AE87A7882668DFB1003E9541 /* AccommodationCell.xib */, ); @@ -483,7 +483,7 @@ AE8CD3B42653538700BCB8FC /* AppDelegate.swift in Sources */, AE0B5DE926562D4A000B35E7 /* TitleSupplementaryView.swift in Sources */, AE0B5DE62656073E000B35E7 /* CityCell.swift in Sources */, - AE87A7862668DF22003E9541 /* ResultSupplymentaryView.swift in Sources */, + AE87A7862668DF22003E9541 /* ResultSupplementaryView.swift in Sources */, AE8CD3B62653538700BCB8FC /* SceneDelegate.swift in Sources */, AE87A7812668992C003E9541 /* PeopleViewModel.swift in Sources */, AE0B5DF3265642B2000B35E7 /* CategoryCell.swift in Sources */, diff --git a/iOS/Airbnb/Airbnb.xcodeproj/project.xcworkspace/xcuserdata/gimjigyeong.xcuserdatad/UserInterfaceState.xcuserstate b/iOS/Airbnb/Airbnb.xcodeproj/project.xcworkspace/xcuserdata/gimjigyeong.xcuserdatad/UserInterfaceState.xcuserstate index 11d194884..99bef6a48 100644 Binary files a/iOS/Airbnb/Airbnb.xcodeproj/project.xcworkspace/xcuserdata/gimjigyeong.xcuserdatad/UserInterfaceState.xcuserstate and b/iOS/Airbnb/Airbnb.xcodeproj/project.xcworkspace/xcuserdata/gimjigyeong.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/iOS/Airbnb/Airbnb/ResultPage/SearchResultViewController.swift b/iOS/Airbnb/Airbnb/ResultPage/SearchResultViewController.swift index 6b3d7ebf0..bbcaff117 100644 --- a/iOS/Airbnb/Airbnb/ResultPage/SearchResultViewController.swift +++ b/iOS/Airbnb/Airbnb/ResultPage/SearchResultViewController.swift @@ -6,12 +6,141 @@ // import UIKit +import Combine class SearchResultViewController: UIViewController { + static let headerElementKind = "header-element-kind" + + private var collectionView: UICollectionView! + private var dataSource: UICollectionViewDiffableDataSource! + private let mainUseCase = MainPageUseCase() + private var cancelBag = Set() + override func viewDidLoad() { super.viewDidLoad() } } + + +extension SearchResultViewController { + + private func bind() { + mainUseCase.$mainPage.receive(on: DispatchQueue.main) + .sink { mainPage in + guard let mainPage = mainPage else { return } + self.applyInitialSnapshots(with: mainPage) + } + .store(in: &cancelBag) + + mainUseCase.$error + .receive(on: DispatchQueue.main) + .sink { error in + guard let error = error else { return } + print(error) ///사용자에게 에러 표시하는 부분 미구현 + }.store(in: &cancelBag) + } + +} + + +extension SearchResultViewController { + + private func configureHierarchy() { + collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: createLayout()) + collectionView.autoresizingMask = [.flexibleWidth, .flexibleHeight] + collectionView.backgroundColor = .systemBackground + collectionView.delegate = self + view.addSubview(collectionView) + } + + private func createLayout() -> UICollectionViewLayout { + + let sectionProvider = { (sectionIndex: Int, layoutEnvironment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection? in + + let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .fractionalHeight(1.0)) + let item = NSCollectionLayoutItem(layoutSize: itemSize) + item.contentInsets = NSDirectionalEdgeInsets(top: 5, leading: 5, bottom: 5, trailing: 5) + + let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .fractionalWidth(1)) + let group = NSCollectionLayoutGroup.vertical(layoutSize: groupSize, subitems: [item]) + + let section = NSCollectionLayoutSection(group: group) + section.interGroupSpacing = 10 + section.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10) + + + let sectionHeader = NSCollectionLayoutBoundarySupplementaryItem( + layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), + heightDimension: .estimated(44)), + elementKind:SearchResultViewController.headerElementKind, + alignment: .top) + section.boundarySupplementaryItems = [sectionHeader] + + return section + } + return UICollectionViewCompositionalLayout(sectionProvider: sectionProvider) + } + + private func configureDataSource() { + dataSource = UICollectionViewDiffableDataSource(collectionView: collectionView) { + (collectionView, indexPath, item) -> UICollectionViewCell? in + + self.collectionView.register(AccommodationCell.nib, forCellWithReuseIdentifier: AccommodationCell.reuseIdentifier) + let cell = self.collectionView.dequeueReusableCell(withReuseIdentifier: AccommodationCell.reuseIdentifier, for: indexPath) as! AccommodationCell +// cell.fillUI(with: item.city ?? City(id: 0, name: "", image: "", distance: 0)) + return cell + } + self.configureSupplementaryView() + } + + private func configureSupplementaryView() { + let supplementaryRegistration = UICollectionView.SupplementaryRegistration + (elementKind: SearchResultViewController.headerElementKind) { + (supplementaryView, string, indexPath) in +// let sectionKind = Section(rawValue: indexPath.section)! + supplementaryView.label.text = "~~~"//String(describing: sectionKind) + } + dataSource.supplementaryViewProvider = { (view, kind, index) in + return self.collectionView.dequeueConfiguredReusableSupplementary( + using: supplementaryRegistration, for: index) + } + } + + private func applyInitialSnapshots(with mainPage: MainPage) { + var snapshot = NSDiffableDataSourceSnapshot() + snapshot.appendSections([1]) + snapshot.appendItems([1], toSection: 1) + dataSource.apply(snapshot) + } + +} + +extension SearchResultViewController: UICollectionViewDelegate { + + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + let detailViewController = DetailDestinationViewController() + self.navigationController?.pushViewController(detailViewController, animated: true) + } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + + guard let indexPath = self.collectionView.indexPathsForSelectedItems?.first else { return } + if let coordinator = self.transitionCoordinator { + coordinator.animate(alongsideTransition: { context in + self.collectionView.deselectItem(at: indexPath, animated: true) + }) { (context) in + if context.isCancelled { + self.collectionView.selectItem(at: indexPath, animated: false, scrollPosition: []) + } + } + } else { + self.collectionView.deselectItem(at: indexPath, animated: animated) + } + } + +} +