Skip to content

Commit

Permalink
refactor: 불필요한 코드 제거 및 레이아웃 수정
Browse files Browse the repository at this point in the history
- 불필요한 ViewController 생성자 제거
- Filtering 뷰 레이아웃 수정

jeremy0405/airbnb/#6
  • Loading branch information
sanghyeok-kim committed Jun 8, 2022
1 parent 07e1dcc commit bd709e4
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
{
"min": 101,
"max": 200,
"max": null,
"count": 2
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ private extension CalendarViewController {
view.addSubview(weekDayStackView)

weekDayStackView.snp.makeConstraints { make in
make.top.equalTo(view.safeAreaLayoutGuide.snp.top).offset(16)
make.leading.trailing.equalToSuperview().inset(16)
make.top.leading.trailing.equalToSuperview()
}
}

func layoutCalendarCollectionView() {
view.addSubview(calendarCollectionView)

calendarCollectionView.snp.makeConstraints { make in
make.top.equalTo(weekDayStackView.snp.bottom)
make.leading.trailing.bottom.equalToSuperview().inset(16)
make.leading.trailing.bottom.equalToSuperview()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class FilteringViewController: UIViewController {

private var viewModel: FilteringViewModel?

private var childViewControllerMap: [FilteringCondition: UIViewController] = [.checkInAndOut: CalendarViewController(), .headCount: HeadCountViewController(), .fee: PriceRangeViewController()]
private var childViewControllerMap: [FilteringCondition: UIViewController] = [.checkInAndOut: CalendarViewController(),
.headCount: HeadCountViewController(),
.fee: PriceRangeViewController()]

private var targetViewController: UIViewController = UIViewController() {
didSet(previousViewController) {
Expand Down Expand Up @@ -132,14 +134,14 @@ private extension FilteringViewController {
make.bottom.equalTo(nextStepView.snp.top)
make.height.equalTo(tableView.contentSize)
}

}

func layoutChildViewController() {
children.forEach { childViewController in
view.addSubview(childViewController.view)
childViewController.view.snp.makeConstraints { make in
make.leading.trailing.top.equalToSuperview()
make.leading.trailing.equalToSuperview().inset(16)
make.top.equalTo(view.safeAreaLayoutGuide).offset(16)
make.bottom.equalTo(tableView.snp.top)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ final class HistogramView: UIView {
return CGPoint(x: coordX, y: coordY)
}

override init(frame: CGRect) {
super.init(frame: frame)
}

@available (*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

func layout() {

}
// override init(frame: CGRect) {
// super.init(frame: frame)
// }
//
// @available (*, unavailable)
// required init?(coder: NSCoder) {
// fatalError("init(coder:) has not been implemented")
// }
//
// func layout() {
//
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,26 @@ class PriceRangeViewController: UIViewController {
return stackView
}()

private let averagePriceLabel = CustomLabel(text: "평균 1박 요금은 ₩165,556 입니다.",
font: .SFProDisplay.semiBold,
fontColor: .Custom.gray3)
init() {
super.init(nibName: nil, bundle: nil)
}
let histogram = HistogramView()
let histogramForegroundView = UIView()
let histogramBackground = UIView()
private lazy var averagePriceLabel = CustomLabel(font: .SFProDisplay.semiBold,
fontColor: .Custom.gray3)

private lazy var histogram: HistogramView = {
let histogram = HistogramView()
histogram.backgroundColor = .clear
return histogram
}()

private lazy var histogramBackgroundView: UIView = {
let view = UIView()
view.backgroundColor = .Custom.gray4
return view
}()

private lazy var histogramForegroundView: UIView = {
let view = UIView()
view.backgroundColor = .Custom.gray3
return view
}()

private lazy var slider: CustomSlider = {
let slider = CustomSlider()
Expand All @@ -60,52 +71,17 @@ class PriceRangeViewController: UIViewController {
return slider
}()

@objc private func changeValue() {
let width = histogram.frame.width
histogramForegroundView.snp.updateConstraints { make in
make.leading.equalToSuperview().offset(width * slider.lower)
make.trailing.equalToSuperview().inset(width * (1 - slider.upper))
}
}

@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
super.viewDidLoad()
bind()

histogram.backgroundColor = .clear
self.view.addSubview(histogram)
layoutPriceRangeLabel()
layoutPriceRangeStackView()

histogram.addSubview(histogramBackground)
histogram.addSubview(histogramForegroundView)
layoutAveragePriceLabel()

histogramBackground.backgroundColor = .Custom.gray4
histogramForegroundView.backgroundColor = .Custom.gray3

histogram.snp.makeConstraints { make in
make.top.equalTo(averagePriceLabel.snp.bottom)
make.leading.trailing.equalToSuperview()
make.bottom.equalToSuperview()

}

histogramForegroundView.snp.makeConstraints { make in
make.leading.trailing.equalToSuperview()
make.top.bottom.equalToSuperview()
}

histogramBackground.snp.makeConstraints { make in
make.edges.equalToSuperview()
}

bind()

layoutHistogram()
layoutHistogramBackgroundView()
layoutHistogramForegroundView()
layoutSlider()
}

private func bind() {
Expand All @@ -127,6 +103,20 @@ class PriceRangeViewController: UIViewController {
}
}

// MARK: - Selector Function

private extension PriceRangeViewController {

@objc private func changeValue() {
let width = histogram.frame.width
histogramForegroundView.snp.updateConstraints { make in
make.leading.equalToSuperview().offset(width * slider.lower)
make.trailing.equalToSuperview().inset(width * (1 - slider.upper))
}
}

}

// MARK: - View Layout

private extension PriceRangeViewController {
Expand All @@ -138,11 +128,9 @@ private extension PriceRangeViewController {
make.top.equalTo(view.safeAreaLayoutGuide).offset(32)
make.leading.equalToSuperview()
}

}

func layoutPriceRangeStackView() {

view.addSubview(priceRangeStackView)

priceRangeStackView.snp.makeConstraints { make in
Expand All @@ -153,18 +141,47 @@ private extension PriceRangeViewController {

func layoutAveragePriceLabel() {
view.addSubview(averagePriceLabel)
view.addSubview(slider)

averagePriceLabel.snp.makeConstraints { make in
make.top.equalTo(priceRangeStackView.snp.bottom).offset(8)
make.leading.equalTo(priceRangeLabel)
}
}

func layoutHistogram() {
view.addSubview(histogram)

histogram.snp.makeConstraints { make in
make.top.equalTo(averagePriceLabel.snp.bottom).offset(30)
make.leading.trailing.equalToSuperview()
}
}

func layoutHistogramBackgroundView() {
histogram.addSubview(histogramBackgroundView)

histogramBackgroundView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
}

func layoutHistogramForegroundView() {
histogram.addSubview(histogramForegroundView)

histogramForegroundView.snp.makeConstraints { make in
make.leading.trailing.equalToSuperview()
make.top.bottom.equalToSuperview()
}
}

func layoutSlider() {
view.addSubview(slider)

slider.snp.makeConstraints { make in
make.leading.trailing.equalToSuperview()
make.height.equalTo(20)
make.bottom.equalToSuperview()
make.centerY.equalTo(histogram.snp.bottom)

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import Foundation
class PriceRangeViewModel {

let loadAction = PublishRelay<Void>()


let loadedState = PublishRelay<PriceRange>()

@NetworkInject(keypath: \.priceRangeRepository)
Expand Down

0 comments on commit bd709e4

Please sign in to comment.