Skip to content

Commit

Permalink
Refactor: 홈 화면 추천 VC, 테마 컬렉션 VC를 UIView로 전환
Browse files Browse the repository at this point in the history
- Base View에 layoutSubviews 오버라이딩 함수 추가
- 필요없는 파일 삭제
  • Loading branch information
Minny27 committed Mar 20, 2024
1 parent ac1f51f commit 7afc7fa
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 86 deletions.
14 changes: 14 additions & 0 deletions Nagaza/Sources/Presentation/Base/NagazaBaseView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import UIKit

class NagazaBaseView: UIView {
private var afterViewDidLoad = true

override init(frame: CGRect) {
super.init(frame: frame)
makeUI()
Expand All @@ -17,7 +19,19 @@ class NagazaBaseView: UIView {
fatalError("init(coder:) has not been implemented")
}

override func layoutSubviews() {
super.layoutSubviews()

if afterViewDidLoad {
afterViewDidLoad.toggle()
adjustLayoutAfterRendering()
}
}

/// Set up constraints of view and add subviews
func makeUI() { }

/// Adjust layout after rendering
func adjustLayoutAfterRendering() { }
}

Original file line number Diff line number Diff line change
Expand Up @@ -49,33 +49,18 @@ final class HomeViewController: NagazaBaseViewController {

private let mapButtonTapped = PublishSubject<String>()

private lazy var recommendedThemeViewController: RecommendThemeViewController = {
let vc = RecommendThemeViewController.create(with: viewModel)
return vc
}()

private lazy var themesViewController: HomeThemesCollectionViewController = {
let vc = HomeThemesCollectionViewController.create(with: viewModel)
return vc
}()
private lazy var recommendedThemeView = RecommendThemeView()

private lazy var scrollView = UIScrollView()
private lazy var themesCollectionView: UICollectionView = {
let layout = UICollectionViewCompositionalLayout.listLayout(withEstimatedHeight: 215)

private lazy var recommendedContainer: UIView = {
let view = UIView()
view.backgroundColor = .clear
add(child: recommendedThemeViewController, container: view)
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
collectionView.isScrollEnabled = false

return view
return collectionView
}()

private lazy var themesContainer: UIView = {
let view = UIView()
view.backgroundColor = .white
add(child: themesViewController, container: view)

return view
}()
private lazy var scrollView = UIScrollView()

static func create(with viewModel: HomeViewModel) -> HomeViewController {
let vc = HomeViewController()
Expand Down Expand Up @@ -130,14 +115,14 @@ final class HomeViewController: NagazaBaseViewController {
$0.edges.equalToSuperview()
}

scrollView.addSubviews([recommendedContainer, themesContainer])
recommendedContainer.snp.makeConstraints {
scrollView.addSubviews([recommendedThemeView, themesCollectionView])
recommendedThemeView.snp.makeConstraints {
$0.top.leading.trailing.width.equalTo(scrollView)
$0.height.equalTo(CGFloat.windowFrameheight / 2)
}

themesContainer.snp.makeConstraints {
$0.top.equalTo(recommendedContainer.snp.bottom)
themesCollectionView.snp.makeConstraints {
$0.top.equalTo(recommendedThemeView.snp.bottom)
$0.leading.trailing.width.bottom.equalTo(scrollView)
$0.height.equalTo(themesViewEstimatedHeight * CGFloat(themesViewGroupCount))
}
Expand Down Expand Up @@ -268,12 +253,12 @@ extension HomeViewController {
supplementaryView.themeLabel.text = sectionType.title
}

dataSource = DataSource(collectionView: themesViewController.collectionView, cellProvider: { collectionView, indexPath, itemIdentifier in
dataSource = DataSource(collectionView: themesCollectionView, cellProvider: { collectionView, indexPath, itemIdentifier in
return collectionView.dequeueConfiguredReusableCell(using: roomCellRegistraition, for: indexPath, item: itemIdentifier)
})

dataSource.supplementaryViewProvider = { (view, kind, index) in
return self.themesViewController.collectionView.dequeueConfiguredReusableSupplementary(
return self.themesCollectionView.dequeueConfiguredReusableSupplementary(
using: headerRegistration,
for: index
)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import RxSwift
import SnapKit

// TODO: Haert Components 제거
final class RecommendThemeViewController: NagazaBaseViewController {
private var viewModel: HomeViewModel!
final class RecommendThemeView: NagazaBaseView {
// private var viewModel: HomeViewModel!

lazy var recommandThemeBackgroundTopGradientView = UIView()
lazy var recommandThemeBackgroundBottomGradientView = UIView()
private lazy var recommandThemeBackgroundTopGradientView = UIView()
private lazy var recommandThemeBackgroundBottomGradientView = UIView()

private lazy var heartIcon: UIButton = {
let btn = UIButton()

btn.addTarget(self,
action: #selector(heartTapped(_:)),
for: .touchUpInside
)
// btn.addTarget(self,
// action: #selector(heartTapped(_:)),
// for: .touchUpInside
// )
btn.setImage(UIImage(systemName: "heart"),
for: .normal
)
Expand Down Expand Up @@ -87,24 +87,17 @@ final class RecommendThemeViewController: NagazaBaseViewController {
return btn
}()

static func create(with viewModel: HomeViewModel) -> RecommendThemeViewController {
let vc = RecommendThemeViewController()
vc.viewModel = viewModel

return vc
}

override func makeUI() {
// TODO: 이미지에 따른 추천 색상으로 변경
let middleColor = UIColor.systemPink
view.backgroundColor = middleColor
self.backgroundColor = middleColor

labelStackView.addArrangedSubviews([
userNameLabel,
recommendLabel
])

view.addSubviews([
self.addSubviews([
recommandThemeBackgroundTopGradientView,
recommandThemeBackgroundBottomGradientView,
posterImageView,
Expand Down Expand Up @@ -136,12 +129,12 @@ final class RecommendThemeViewController: NagazaBaseViewController {
}

override func adjustLayoutAfterRendering() {
let gradientHeight = view.bounds.height / 2
let gradientHeight = self.bounds.height / 2

let topGradientFrame = CGRect(
x: 0,
y: 0,
width: view.bounds.width,
width: self.bounds.width,
height: gradientHeight
)
recommandThemeBackgroundTopGradientView.frame = topGradientFrame
Expand All @@ -152,8 +145,8 @@ final class RecommendThemeViewController: NagazaBaseViewController {

let bottomGradientFrame = CGRect(
x: 0,
y: view.bounds.height - gradientHeight,
width: view.bounds.width,
y: self.bounds.height - gradientHeight,
width: self.bounds.width,
height: gradientHeight
)
recommandThemeBackgroundBottomGradientView.frame = bottomGradientFrame
Expand All @@ -164,10 +157,6 @@ final class RecommendThemeViewController: NagazaBaseViewController {
])
}

override func bindViewModel() {

}

@objc private func heartTapped(_ sender: UIButton) {
sender.isSelected.toggle()
}
Expand Down

0 comments on commit 7afc7fa

Please sign in to comment.