Skip to content

Commit

Permalink
wip: ⚙️숙소 검색 뷰 골격 생성(#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lia316 committed Jun 3, 2021
1 parent b367a28 commit 5c5fe7d
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 4 deletions.
8 changes: 4 additions & 4 deletions iOS/Airbnb/Airbnb.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -91,7 +91,7 @@
AE87A77B26687F71003E9541 /* PersonCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PersonCell.xib; sourceTree = "<group>"; };
AE87A7802668992C003E9541 /* PeopleViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PeopleViewModel.swift; sourceTree = "<group>"; };
AE87A7832668D19D003E9541 /* SearchResultViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchResultViewController.swift; sourceTree = "<group>"; };
AE87A7852668DF22003E9541 /* ResultSupplymentaryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResultSupplymentaryView.swift; sourceTree = "<group>"; };
AE87A7852668DF22003E9541 /* ResultSupplementaryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResultSupplementaryView.swift; sourceTree = "<group>"; };
AE87A7872668DFB1003E9541 /* AccommodationCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccommodationCell.swift; sourceTree = "<group>"; };
AE87A7882668DFB1003E9541 /* AccommodationCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AccommodationCell.xib; sourceTree = "<group>"; };
AE8CD3B02653538700BCB8FC /* Airbnb.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Airbnb.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -188,7 +188,7 @@
isa = PBXGroup;
children = (
AE87A7832668D19D003E9541 /* SearchResultViewController.swift */,
AE87A7852668DF22003E9541 /* ResultSupplymentaryView.swift */,
AE87A7852668DF22003E9541 /* ResultSupplementaryView.swift */,
AE87A7872668DFB1003E9541 /* AccommodationCell.swift */,
AE87A7882668DFB1003E9541 /* AccommodationCell.xib */,
);
Expand Down Expand Up @@ -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 */,
Expand Down
Binary file not shown.
129 changes: 129 additions & 0 deletions iOS/Airbnb/Airbnb/ResultPage/SearchResultViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Int, Int>!
private let mainUseCase = MainPageUseCase()
private var cancelBag = Set<AnyCancellable>()

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<Int, Int>(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
<ResultSupplementaryView>(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<Int, Int>()
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)
}
}

}

0 comments on commit 5c5fe7d

Please sign in to comment.