Skip to content

Commit 3234cd6

Browse files
authored
Merge pull request #383 from Team-WSS/Fix/#382
[Fix] #382 - 홈뷰 취향추천 컬렉션뷰의 높이 동적 조절 반영
2 parents a4959de + d20cdf5 commit 3234cd6

File tree

5 files changed

+81
-49
lines changed

5 files changed

+81
-49
lines changed

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Prefix
2525
-->
2626

2727
### ⭐️Issue
28-
close #
28+
- close #
2929
<br/>
3030

3131
### 🌟Motivation

WSSiOS/WSSiOS.xcodeproj/project.pbxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@
468468
E45FEFAD2CFC306800B73D80 /* LibraryChildViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E45FEFAC2CFC306800B73D80 /* LibraryChildViewController.swift */; };
469469
E45FEFB02CFC30A600B73D80 /* LibraryChildViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E45FEFAF2CFC30A600B73D80 /* LibraryChildViewModel.swift */; };
470470
E45FEFB22CFC30BD00B73D80 /* LibraryViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E45FEFB12CFC30BD00B73D80 /* LibraryViewModel.swift */; };
471-
E486AE292CFEB2CC00465AEE /* Config.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = E486AE282CFEB2CC00465AEE /* Config.xcconfig */; };
472471
E497C9B62CF3AFBD0079C30D /* MyPageEditAvatarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E497C9B52CF3AFBD0079C30D /* MyPageEditAvatarViewController.swift */; };
473472
E497C9B82CF3B0160079C30D /* MyPageEditAvatarViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E497C9B72CF3B0160079C30D /* MyPageEditAvatarViewModel.swift */; };
474473
E497C9BA2CF3B0220079C30D /* MyPageEditAvatarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E497C9B92CF3B0220079C30D /* MyPageEditAvatarView.swift */; };

WSSiOS/WSSiOS/Source/Presentation/Home/Home/HomeView/HomeAssistantView/HomeTasteRecommendView.swift

Lines changed: 64 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ final class HomeTasteRecommendView: UIView {
1414

1515
//MARK: - UI Components
1616

17+
private var stackView = UIStackView()
1718
private var titleLabel = UILabel()
1819
private var subTitleLabel = UILabel()
1920
let tasteRecommendCollectionView = UICollectionView(frame: .zero,
@@ -27,6 +28,8 @@ final class HomeTasteRecommendView: UIView {
2728
super.init(frame: .zero)
2829

2930
setUI()
31+
setHierarchy()
32+
setLayout()
3033
}
3134

3235
@available(*, unavailable)
@@ -35,6 +38,10 @@ final class HomeTasteRecommendView: UIView {
3538
}
3639

3740
private func setUI() {
41+
stackView.do {
42+
$0.axis = .vertical
43+
}
44+
3845
titleLabel.do {
3946
$0.applyWSSFont(.headline1, with: StringLiterals.Home.Title.recommend)
4047
$0.textColor = .wssBlack
@@ -43,77 +50,91 @@ final class HomeTasteRecommendView: UIView {
4350
subTitleLabel.do {
4451
$0.applyWSSFont(.body2, with: StringLiterals.Home.SubTitle.recommend)
4552
$0.textColor = .wssGray200
53+
$0.isHidden = true
4654
}
4755

4856
tasteRecommendCollectionView.do {
4957
$0.showsVerticalScrollIndicator = false
5058
$0.isScrollEnabled = false
59+
$0.isHidden = true
5160
}
5261

5362
tasteRecommendCollectionViewLayout.do {
5463
$0.scrollDirection = .vertical
5564
$0.minimumLineSpacing = 18
5665
$0.minimumInteritemSpacing = 9
57-
$0.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 40, right: 0)
5866
$0.itemSize = CGSize(width: (UIScreen.main.bounds.width - 49) / 2, height: 300)
5967
tasteRecommendCollectionView.setCollectionViewLayout($0, animated: false)
6068
}
69+
70+
unregisterView.do {
71+
$0.isHidden = true
72+
}
73+
}
74+
75+
private func setHierarchy() {
76+
self.addSubview(stackView)
77+
stackView.addArrangedSubviews(titleLabel,
78+
subTitleLabel,
79+
tasteRecommendCollectionView,
80+
unregisterView)
81+
}
82+
83+
private func setLayout() {
84+
stackView.snp.makeConstraints {
85+
$0.horizontalEdges.equalToSuperview().inset(20)
86+
$0.top.equalToSuperview()
87+
$0.bottom.equalToSuperview().inset(56)
88+
}
89+
90+
tasteRecommendCollectionView.snp.makeConstraints {
91+
$0.height.equalTo(0)
92+
}
93+
94+
unregisterView.snp.makeConstraints {
95+
$0.height.equalTo(133)
96+
}
6197
}
6298

6399
//MARK: - Custom Method
64100

65101
func updateView(_ isLogined: Bool, _ isEmpty: Bool) {
66102
if isLogined {
67103
if isEmpty {
68-
self.addSubviews(titleLabel,
69-
unregisterView)
70-
titleLabel.snp.makeConstraints {
71-
$0.top.equalToSuperview()
72-
$0.leading.equalToSuperview().inset(20)
73-
}
74-
unregisterView.snp.makeConstraints {
75-
$0.top.equalTo(titleLabel.snp.bottom).offset(11)
76-
$0.leading.trailing.equalToSuperview().inset(20)
77-
$0.bottom.equalToSuperview().inset(56)
78-
$0.height.equalTo(133)
104+
unregisterView.isHidden = false
105+
subTitleLabel.isHidden = true
106+
tasteRecommendCollectionView.isHidden = true
107+
108+
stackView.do {
109+
$0.setCustomSpacing(11, after: titleLabel)
79110
}
80-
subTitleLabel.removeFromSuperview()
81-
tasteRecommendCollectionView.removeFromSuperview()
82111
} else {
83-
self.addSubviews(titleLabel,
84-
subTitleLabel,
85-
tasteRecommendCollectionView)
86-
titleLabel.snp.makeConstraints {
87-
$0.top.equalToSuperview()
88-
$0.leading.equalToSuperview().inset(20)
89-
}
90-
subTitleLabel.snp.makeConstraints {
91-
$0.top.equalTo(titleLabel.snp.bottom).offset(2)
92-
$0.leading.equalTo(titleLabel.snp.leading)
93-
}
112+
subTitleLabel.isHidden = false
113+
tasteRecommendCollectionView.isHidden = false
114+
unregisterView.isHidden = true
94115

95-
tasteRecommendCollectionView.snp.makeConstraints {
96-
$0.top.equalTo(subTitleLabel.snp.bottom).offset(20)
97-
$0.leading.trailing.bottom.equalToSuperview().inset(20)
98-
$0.height.equalTo(1591)
116+
stackView.do {
117+
$0.setCustomSpacing(2, after: titleLabel)
118+
$0.setCustomSpacing(20, after: subTitleLabel)
119+
$0.snp.updateConstraints {
120+
$0.bottom.equalToSuperview().inset(40)
121+
}
99122
}
100-
unregisterView.removeFromSuperview()
101123
}
102124
} else {
103-
self.addSubviews(titleLabel,
104-
unregisterView)
105-
titleLabel.snp.makeConstraints {
106-
$0.top.equalToSuperview()
107-
$0.leading.equalToSuperview().inset(20)
108-
}
109-
unregisterView.snp.makeConstraints {
110-
$0.top.equalTo(titleLabel.snp.bottom).offset(11)
111-
$0.leading.trailing.equalToSuperview().inset(20)
112-
$0.bottom.equalToSuperview().inset(56)
113-
$0.height.equalTo(133)
125+
unregisterView.isHidden = false
126+
subTitleLabel.isHidden = true
127+
tasteRecommendCollectionView.isHidden = true
128+
129+
stackView.do {
130+
$0.setCustomSpacing(11, after: titleLabel)
114131
}
115-
subTitleLabel.removeFromSuperview()
116-
tasteRecommendCollectionView.removeFromSuperview()
132+
}
133+
}
134+
135+
func updateCollectionViewHeight(height: CGFloat) {
136+
tasteRecommendCollectionView.snp.updateConstraints {
137+
$0.height.equalTo(height)
117138
}
118139
}
119140
}

WSSiOS/WSSiOS/Source/Presentation/Home/Home/HomeViewController/HomeViewController.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ final class HomeViewController: UIViewController {
9999
todayPopularCellSelected: rootView.todayPopularView.todayPopularCollectionView.rx.itemSelected,
100100
interestCellSelected: rootView.interestView.interestCollectionView.rx.itemSelected,
101101
tasteRecommendCellSelected: rootView.tasteRecommendView.tasteRecommendCollectionView.rx.itemSelected,
102+
tasteRecommendCollectionViewContentSize: rootView.tasteRecommendView.tasteRecommendCollectionView.rx.observe(CGSize.self, "contentSize"),
102103
announcementButtonDidTap: rootView.headerView.announcementButton.rx.tap,
103104
registerInterestNovelButtonTapped: rootView.interestView.unregisterView.registerButton.rx.tap,
104105
setPreferredGenresButtonTapped: rootView.tasteRecommendView.unregisterView.registerButton.rx.tap
@@ -175,16 +176,20 @@ final class HomeViewController: UIViewController {
175176
}
176177
.disposed(by: disposeBag)
177178

179+
output.tasteRecommendCollectionViewHeight
180+
.drive(with: self, onNext: { owner, height in
181+
owner.rootView.tasteRecommendView.updateCollectionViewHeight(height: height)
182+
})
183+
.disposed(by: disposeBag)
184+
178185
output.updateTasteRecommendView
179186
.observe(on: MainScheduler.instance)
180-
.subscribe(with: self, onNext: { owner, data in
181-
let isLogined = data.0
182-
let isEmpty = data.1
187+
.subscribe(with: self, onNext: { owner, updateData in
188+
let (isLogined, isEmpty) = updateData
183189
owner.rootView.tasteRecommendView.updateView(isLogined, isEmpty)
184190
})
185191
.disposed(by: disposeBag)
186192

187-
188193
output.pushToMyPageViewController
189194
.observe(on: MainScheduler.instance)
190195
.bind(with: self, onNext: { owner, _ in

WSSiOS/WSSiOS/Source/Presentation/Home/Home/HomeViewModel/HomeViewModel.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ final class HomeViewModel: ViewModelType {
5252
let todayPopularCellSelected: ControlEvent<IndexPath>
5353
let interestCellSelected: ControlEvent<IndexPath>
5454
let tasteRecommendCellSelected: ControlEvent<IndexPath>
55+
let tasteRecommendCollectionViewContentSize: Observable<CGSize?>
5556
let announcementButtonDidTap: ControlEvent<Void>
5657
let registerInterestNovelButtonTapped: ControlEvent<Void>
5758
let setPreferredGenresButtonTapped: ControlEvent<Void>
@@ -70,6 +71,7 @@ final class HomeViewModel: ViewModelType {
7071
let pushToNormalSearchViewController: Observable<Void>
7172

7273
var tasteRecommendList: Observable<[TasteRecommendNovel]>
74+
let tasteRecommendCollectionViewHeight: Driver<CGFloat>
7375
let updateTasteRecommendView: Observable<(Bool, Bool)>
7476
let pushToMyPageViewController: Observable<Void>
7577

@@ -179,6 +181,10 @@ extension HomeViewModel {
179181
})
180182
.disposed(by: disposeBag)
181183

184+
let tasteRecommendCollectionViewHeight = input.tasteRecommendCollectionViewContentSize
185+
.map { $0?.height ?? 0 }
186+
.asDriver(onErrorJustReturn: 0)
187+
182188
input.announcementButtonDidTap
183189
.subscribe(with: self, onNext: { owner, _ in
184190
if owner.isLogined {
@@ -216,6 +222,7 @@ extension HomeViewModel {
216222
updateInterestView: updateInterestView.asObservable(),
217223
pushToNormalSearchViewController: pushToNormalSearchViewController.asObservable(),
218224
tasteRecommendList: tasteRecommendList.asObservable(),
225+
tasteRecommendCollectionViewHeight: tasteRecommendCollectionViewHeight.asDriver(),
219226
updateTasteRecommendView: updateTasteRecommendView.asObservable(),
220227
pushToMyPageViewController: pushToMyPageViewController.asObservable(),
221228
pushToNovelDetailViewController: pushToNovelDetailViewController.asObservable(),

0 commit comments

Comments
 (0)