Skip to content

Commit

Permalink
feat: ✨price label touch 시 하드코딩 값 넘겨주기 구현(#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lia316 committed Jun 2, 2021
1 parent 4a4d4ee commit 5d63473
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,21 @@ extension ConditionTableViewController {
self.tableView.reloadData()
})
.store(in: &cancelBag)

viewModel.$price
.receive(on: DispatchQueue.main)
.sink(receiveValue: { _ in
self.dataSource = self.viewModel.generateFirstCondition()
self.tableView.reloadData()
})
.store(in: &cancelBag)

viewModel.$people
.receive(on: DispatchQueue.main)
.sink(receiveValue: { _ in
self.dataSource = self.viewModel.generateFirstCondition()
self.tableView.reloadData()
})
.store(in: &cancelBag)
}
}
32 changes: 24 additions & 8 deletions iOS/Airbnb/Airbnb/ConditionPage/Price/PriceViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ class PriceViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
priceUseCase.requestMainPage(condition: conditionViewModel.convertCodable())
bind()
configure()
configureContainer()
configure()
configureNavigation()
configureToolBar()
priceUseCase.requestMainPage(condition: conditionViewModel.convertCodable())
bind()
}


Expand All @@ -46,7 +45,7 @@ extension PriceViewController {
priceUseCase.$prices.receive(on: DispatchQueue.main)
.sink { prices in
guard let prices = prices else { return }
print(prices)
self.updatePriceLabel(with: prices)
}
.store(in: &cancelBag)

Expand All @@ -59,24 +58,41 @@ extension PriceViewController {
}
}

extension PriceViewController {

@objc private func labelTouched(_ sender: UILabel) {
let price = Price(max: 80000, min: 200000)
conditionViewModel.updateCondition(price: price)
}

}


extension PriceViewController {

private func configure() {
view.backgroundColor = .white
view.addSubview(label)
label.translatesAutoresizingMaskIntoConstraints = false
label.adjustsFontForContentSizeCategory = true
label.isUserInteractionEnabled = true
label.numberOfLines = 0
label.font = UIFont.preferredFont(forTextStyle: .title1)
label.textAlignment = .center

let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(labelTouched(_:)))
label.addGestureRecognizer(gestureRecognizer)

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

}

private func updatePriceLabel(with prices: Prices) {
label.text = prices.prices.map { String($0) }.reduce("") { $0 + "\n" + $1 }
}

}
Expand Down

0 comments on commit 5d63473

Please sign in to comment.