Skip to content

Commit

Permalink
feat: PlaceDetail뷰에 Place 데이터 바인딩(#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chandrarla committed Oct 30, 2024
1 parent 1687547 commit e797ec8
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 13 deletions.
7 changes: 7 additions & 0 deletions Common/Sources/Components/ExhibitionCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import UIKit
import SnapKit
import Then

import Core

public class ExhibitionCollectionViewCell: UICollectionViewCell {

public let exhibitionNameLabel = UILabel()
Expand Down Expand Up @@ -62,6 +64,11 @@ public class ExhibitionCollectionViewCell: UICollectionViewCell {
$0.leading.equalToSuperview().offset(16)
}
}

public func bind(with placeInfo: PlaceInfo) {
exhibitionNameLabel.text = placeInfo.title
exhibitionDateLabel.text = placeInfo.duration
}
}


3 changes: 3 additions & 0 deletions Common/Sources/Components/PlaceDetailButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import Core

public class PlaceDetailButton: UIButton {

public var place: Place?

public let locationLabel = UILabel()
public let placeNameLabel = UILabel()
public let eventCountLabel = UILabel()
Expand Down Expand Up @@ -87,6 +89,7 @@ public class PlaceDetailButton: UIButton {
}

public func bind(place: Place) {
self.place = place
locationLabel.text = place.shortenLocation
placeNameLabel.text = place.title
eventCountLabel.text = "\(place.placeInfoList.count)개의 전시가 진행중이에요"
Expand Down
12 changes: 10 additions & 2 deletions Presentation/Sources/Home/View/ExhibitionListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import SnapKit
import Then

import Common
import Core

final class ExhibitionListView: UIView {
private var exhibitionData: Place?

let exhibitionCount = UILabel()
var exhibitionCount = UILabel()
public let allFilterButton = ChipKeyWordButton()
public let freeFilterButton = ChipKeyWordButton()
public let endSoonFilterButton = ChipKeyWordButton()
Expand All @@ -38,7 +40,7 @@ final class ExhibitionListView: UIView {
self.exhibitionCollectionView?.backgroundColor = .clear

exhibitionCount.do {
$0.text = "• 1 개의 전시"
$0.text = ""
$0.font = ViskitFont.caption1Regular.font
$0.textColor = CommonAsset.viskitWhite.color
}
Expand Down Expand Up @@ -107,6 +109,12 @@ final class ExhibitionListView: UIView {
}
}

public func updateExhibitionList(data: Place) {
exhibitionData = data
guard let count = exhibitionData?.placeInfoList.count else { return }
exhibitionCount.text = "\(count) 개의 전시"
}

func setExhibitionCollectionView() {
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .vertical
Expand Down
12 changes: 12 additions & 0 deletions Presentation/Sources/Home/View/OverviewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import UIKit
import Common
import Core

@available(iOS 16.0, *)
final class OverviewViewController: UIViewController {

var overview: [Overview] = mockData
Expand Down Expand Up @@ -122,6 +123,8 @@ final class OverviewViewController: UIViewController {
let placeDetailButton = PlaceDetailButton()
placeDetailButton.bind(place: place)

placeDetailButton.addTarget(self, action: #selector(placeDetailButtonTapped), for: .touchUpInside)

let placeInfoCollectionView = createCollectionView()

overviewStackView.addArrangedSubview(placeDetailButton)
Expand Down Expand Up @@ -173,8 +176,16 @@ final class OverviewViewController: UIViewController {
@objc private func locationButtonTapped() {
viewModel.updateLocationState()
}

@objc private func placeDetailButtonTapped(_ sender: PlaceDetailButton) {
guard let place = sender.place else { return }

let placeDetailVC = PlaceDetailViewController(place: place)
navigationController?.pushViewController(placeDetailVC, animated: true)
}
}

@available(iOS 16.0, *)
extension OverviewViewController: UICollectionViewDataSource {
public func collectionView(
_ collectionView: UICollectionView,
Expand All @@ -195,6 +206,7 @@ extension OverviewViewController: UICollectionViewDataSource {
}
}

@available(iOS 16.0, *)
extension OverviewViewController: UICollectionViewDelegateFlowLayout {
public func collectionView(
_ collectionView: UICollectionView,
Expand Down
38 changes: 28 additions & 10 deletions Presentation/Sources/Home/View/PlaceDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import Core
@available(iOS 16.0, *)
final public class PlaceDetailViewController: UIViewController{

var viewModel: PlaceDetailViewModel

let placeNameLabel = UILabel()
let detailLocationLabel = UILabel()
let findRouteButton = UIButton()
Expand All @@ -25,39 +27,44 @@ final public class PlaceDetailViewController: UIViewController{
let exhibitionListView = ExhibitionListView()
let reviewFeedView = ReviewFeedView()

var viewModel = PlaceDetailViewModel()

public init(viewModel: PlaceDetailViewModel) {
self.viewModel = viewModel
init(place: Place) {
self.viewModel = PlaceDetailViewModel(place: place)
super.init(nibName: nil, bundle: nil)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

public override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.isNavigationBarHidden = false
}

public override func viewDidLoad() {
super.viewDidLoad()
setStyle()
setUI()
setAutolayout()
setDelegate()
configureView()
bind()
setTarget()
}

func setStyle() {
view.backgroundColor = CommonAsset.viskitBlack.color
title = "전시관"

placeNameLabel.do {
$0.text = "국립현대미술관"
$0.text = viewModel.place.title
$0.textColor = CommonAsset.viskitWhite.color
$0.font = ViskitFont.title1.font
$0.numberOfLines = 1
}

detailLocationLabel.do {
$0.text = "서울시 종로구 삼청로 30"
$0.text = viewModel.place.detailLocation
$0.textColor = CommonAsset.viskitGray03.color
$0.font = ViskitFont.body2.font
$0.numberOfLines = 1
Expand Down Expand Up @@ -170,6 +177,10 @@ final public class PlaceDetailViewController: UIViewController{
}
}

private func configureView() {
exhibitionListView.updateExhibitionList(data: viewModel.place)
}

private func bind() {
viewModel.onControlTypeChanged = { [weak self] type in
self?.updateView(for: type)
Expand Down Expand Up @@ -221,7 +232,7 @@ extension PlaceDetailViewController: UICollectionViewDataSource {
) -> Int {
switch collectionView {
case exhibitionListView.exhibitionCollectionView:
return 10
return viewModel.place.placeInfoList.count
case reviewFeedView.reviewFeedCollectionView:
return 10
default:
Expand All @@ -234,21 +245,28 @@ extension PlaceDetailViewController: UICollectionViewDataSource {
let cell: UICollectionViewCell
switch collectionView {
case exhibitionListView.exhibitionCollectionView:
cell = collectionView.dequeueReusableCell(
guard let cell = collectionView.dequeueReusableCell(
withReuseIdentifier: ExhibitionCollectionViewCell.cellIdentifier,
for: indexPath
)
) as? ExhibitionCollectionViewCell else {
fatalError("Could not dequeue ExhibitionCollectionViewCell")
}
let placeInfo = viewModel.place.placeInfoList[indexPath.row]
cell.bind(with: placeInfo)
cell.backgroundColor = CommonAsset.viskitGray10.color
return cell

case reviewFeedView.reviewFeedCollectionView:
cell = collectionView.dequeueReusableCell(
withReuseIdentifier: "DefaultCell",
for: indexPath
)
cell.backgroundColor = .lightGray
return cell

default:
fatalError("Unexpected collection view")
}
return cell
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Common
import Core

public enum FilterType {
case all
Expand All @@ -20,6 +21,8 @@ public enum PlaceDetailControlType: String {
}

public class PlaceDetailViewModel {
public let place: Place

var onControlTypeChanged: ((PlaceDetailControlType) -> Void)?
var onFilterChanged: ((ChipState, ChipState, ChipState) -> Void)?

Expand All @@ -33,7 +36,9 @@ public class PlaceDetailViewModel {
private(set) var freeFilterState: ChipState = .inactive
private(set) var endSoonFilterState: ChipState = .inactive

public init() {}
public init(place: Place) {
self.place = place
}

func updateControlType(to type: PlaceDetailControlType) {
currentControlType = type
Expand Down

0 comments on commit e797ec8

Please sign in to comment.