Skip to content

Commit

Permalink
feat: ✨accommodation supplementaryView 구현(#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lia316 committed Jun 3, 2021
1 parent 7cb223b commit 6316bf5
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 14 deletions.
Binary file not shown.
17 changes: 17 additions & 0 deletions iOS/Airbnb/Airbnb/ConditionPage/Condition/ConditionViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ extension ConditionViewModel {

}


extension ConditionViewModel {

func convertCodable() -> ConditionData {
Expand All @@ -109,6 +110,22 @@ extension ConditionViewModel {

}


extension ConditionViewModel {

func finalCondition() -> String {
let cityDic = [1: "서울", 2: "경기도", 3: "강원도", 4: "충청도", 5: "경상남도", 6: "경상북도", 7: "전라남도", 8: "전라북도"]
let city = cityDic[city] ?? ""
let checkIn = schedule!.checkIn == nil ? "" : "\(schedule!.checkIn!.month)\(schedule!.checkIn!.day)"
let checkOut = schedule!.checkOut == nil ? "" : "\(schedule!.checkOut!.month)\(schedule!.checkOut!.day)"
let date = "\(checkIn) - \(checkOut)"
let peopl = people!.1 != 0 ? "게스트 \(people!.0)명 유아 \(people!.1)" : "게스트 \(people!.0)"
return "\(city)\(date)\(peopl)"
}

}


struct Condition {
var cityId: Int
var schedule: Schedule?
Expand Down
39 changes: 26 additions & 13 deletions iOS/Airbnb/Airbnb/ResultPage/View/RoomsSupplementaryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import UIKit

class RoomsSupplementaryView: UICollectionReusableView {

let label = UILabel()
static let reuseIdentifier = "ResultSupplymentaryView"

static let reuseIdentifier = "ResultSupplymentaryView"

let conditionLabel = UILabel()
let roomCountLabel = UILabel()

override init(frame: CGRect) {
super.init(frame: frame)
configure()
Expand All @@ -27,20 +29,31 @@ class RoomsSupplementaryView: UICollectionReusableView {
extension RoomsSupplementaryView {

private func configure() {
addSubview(label)
label.translatesAutoresizingMaskIntoConstraints = false
label.adjustsFontForContentSizeCategory = true
label.numberOfLines = 0
label.font = UIFont.preferredFont(forTextStyle: .title1)
addSubview(conditionLabel)
addSubview(roomCountLabel)
conditionLabel.translatesAutoresizingMaskIntoConstraints = false
conditionLabel.adjustsFontForContentSizeCategory = true
conditionLabel.font = UIFont.preferredFont(forTextStyle: .caption1)
roomCountLabel.translatesAutoresizingMaskIntoConstraints = false
roomCountLabel.adjustsFontForContentSizeCategory = true
roomCountLabel.font = UIFont.preferredFont(forTextStyle: .title2)

let inset = CGFloat(10)
NSLayoutConstraint.activate([
label.leadingAnchor.constraint(equalTo: leadingAnchor, constant: inset),
label.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -inset),
label.topAnchor.constraint(equalTo: topAnchor, constant: inset),
label.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -inset)
conditionLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: inset),
conditionLabel.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -inset),
conditionLabel.topAnchor.constraint(equalTo: topAnchor, constant: 30),
conditionLabel.bottomAnchor.constraint(equalTo: roomCountLabel.topAnchor, constant: -inset),
roomCountLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: inset),
roomCountLabel.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -inset),
roomCountLabel.topAnchor.constraint(equalTo: conditionLabel.bottomAnchor, constant: inset),
roomCountLabel.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -inset)
])

}

func fillUI(condition: String, resultNum: String) {
self.conditionLabel.text = condition
self.roomCountLabel.text = resultNum
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ extension RoomsViewController {
.sink { rooms in
guard let rooms = rooms else { return }
self.applySnapshots(with: rooms.rooms)
self.updateSupplementaryView(resultNum: rooms.rooms.count)
}
.store(in: &cancelBag)

Expand Down Expand Up @@ -115,14 +116,18 @@ extension RoomsViewController {
let supplementaryRegistration = UICollectionView.SupplementaryRegistration
<RoomsSupplementaryView>(elementKind: RoomsViewController.headerElementKind) {
(supplementaryView, string, indexPath) in
supplementaryView.label.text = "~~~"
}
dataSource.supplementaryViewProvider = { (view, kind, index) in
return self.collectionView.dequeueConfiguredReusableSupplementary(
using: supplementaryRegistration, for: index)
}
}

private func updateSupplementaryView(resultNum: Int) {
let view = self.collectionView.supplementaryView(forElementKind: RoomsViewController.headerElementKind, at: IndexPath(row: 0, section: 0)) as? RoomsSupplementaryView
view?.fillUI(condition: conditionViewModel.finalCondition(), resultNum: "\(resultNum)개의 숙소")
}

private func applySnapshots(with rooms: [Room]) {
var snapshot = NSDiffableDataSourceSnapshot<Int, Room>()
snapshot.appendSections([1])
Expand Down

0 comments on commit 6316bf5

Please sign in to comment.