-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFollowDetailViewController.swift
More file actions
349 lines (271 loc) · 10.6 KB
/
FollowDetailViewController.swift
File metadata and controls
349 lines (271 loc) · 10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
//
// FollowDetailViewController.swift
// FollowFeature
//
// Created by kimnahun on 2026-01-23.
// Copyright © 2026 NDGL-iOS. All rights reserved.
//
import Core
import Domain
import DSKit
import RIBs
import RxSwift
import SnapKit
import Then
import UIKit
// MARK: - FollowDetailViewController
final class FollowDetailViewController: UIViewController, FollowDetailPresentable, FollowDetailViewControllable {
// MARK: - Properties
weak var listener: FollowDetailPresentableListener?
private let disposeBag = DisposeBag()
private var dayCollectionViewOriginY: CGFloat = .greatestFiniteMagnitude
private var currentSelectedDay: Int = 1
private var totalDays: Int = 0
// MARK: - UI Components (Scroll)
private let navigationBar = NDGLNavigationBar(
style: .gray,
leadingIcon: DSKitAsset.Assets.icChevronLeft3.image
)
private let scrollView = UIScrollView().then {
$0.showsVerticalScrollIndicator = true
$0.backgroundColor = DSKitAsset.Colors.white.color
}
private let contentView = UIView()
private let mediaInfoView = MediaInfoView()
private let dayCollectionView = DayCollectionView()
private let mapView = TravelMapView()
private let placeListCollectionView = PlaceListCollectionView()
// MARK: - UI Components (Sticky Header)
private let stickyHeaderView = UIView().then {
$0.backgroundColor = UIColor(hexCode: "#FFFFFF")
$0.isHidden = true
}
private let stickyDayCollectionView = DayCollectionView()
// MARK: - UI Components (Fixed)
private let bottomContainerView = UIView().then {
$0.backgroundColor = UIColor(hexCode: "#FFFFFF")
$0.layer.shadowColor = UIColor(hexCode: "#000000").cgColor
$0.layer.shadowOpacity = 0.06
$0.layer.shadowOffset = CGSize(width: 0, height: -10)
$0.layer.shadowRadius = 10
$0.layer.cornerRadius = 20
}
private let addToTripButton = BottomPlacedButton(title: "여행 따라가기")
private let loadingIndicator = UIActivityIndicatorView(style: .large).then {
$0.hidesWhenStopped = true
}
// MARK: - Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
setupConstraints()
setupDelegates()
setupActions()
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
if isMovingFromParent {
listener?.detachFollowDetail()
}
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
dayCollectionViewOriginY = dayCollectionView.frame.origin.y
}
// MARK: - Setup
private func setupUI() {
view.backgroundColor = DSKitAsset.Colors.black50.color
view.addSubviews(navigationBar, scrollView)
scrollView.addSubview(contentView)
[mediaInfoView, dayCollectionView, mapView, placeListCollectionView].forEach {
contentView.addSubview($0)
}
view.addSubview(stickyHeaderView)
stickyHeaderView.addSubview(stickyDayCollectionView)
view.addSubview(bottomContainerView)
bottomContainerView.addSubview(addToTripButton)
view.addSubview(loadingIndicator)
}
private func setupConstraints() {
loadingIndicator.snp.makeConstraints {
$0.center.equalToSuperview()
}
bottomContainerView.snp.makeConstraints {
$0.leading.trailing.bottom.equalToSuperview()
$0.height.equalTo(126.adjustedH)
}
navigationBar.snp.makeConstraints {
$0.top.equalTo(view.safeAreaLayoutGuide)
$0.horizontalEdges.equalToSuperview()
}
scrollView.snp.makeConstraints {
$0.top.equalTo(navigationBar.snp.bottom)
$0.leading.trailing.equalToSuperview()
$0.bottom.equalTo(bottomContainerView.snp.top)
}
contentView.snp.makeConstraints {
$0.edges.equalToSuperview()
$0.width.equalToSuperview()
}
mediaInfoView.snp.makeConstraints {
$0.top.leading.trailing.equalToSuperview()
}
dayCollectionView.snp.makeConstraints {
$0.top.equalTo(mediaInfoView.snp.bottom).offset(24)
$0.leading.equalToSuperview().offset(16)
$0.trailing.equalToSuperview().offset(-16)
$0.height.equalTo(30)
}
mapView.snp.makeConstraints {
$0.top.equalTo(dayCollectionView.snp.bottom).offset(16)
$0.leading.equalToSuperview().offset(24)
$0.trailing.equalToSuperview().offset(-24)
$0.height.equalTo(200)
}
placeListCollectionView.snp.makeConstraints {
$0.top.equalTo(mapView.snp.bottom).offset(16)
$0.leading.equalToSuperview().offset(24)
$0.trailing.equalToSuperview().offset(-24)
$0.bottom.equalToSuperview().offset(-16)
$0.height.greaterThanOrEqualTo(400)
}
stickyHeaderView.snp.makeConstraints {
$0.top.equalTo(navigationBar.snp.bottom)
$0.leading.trailing.equalToSuperview()
$0.height.equalTo(62)
}
stickyDayCollectionView.snp.makeConstraints {
$0.top.equalToSuperview().offset(16)
$0.leading.equalToSuperview().offset(16)
$0.trailing.equalToSuperview().offset(-16)
$0.height.equalTo(30)
}
addToTripButton.snp.makeConstraints {
$0.top.equalToSuperview().offset(20)
$0.leading.equalToSuperview().offset(16)
$0.trailing.equalToSuperview().offset(-16)
$0.height.equalTo(52)
}
}
private func setupDelegates() {
scrollView.delegate = self
mediaInfoView.delegate = self
dayCollectionView.dayDelegate = self
stickyDayCollectionView.dayDelegate = self
placeListCollectionView.placeDelegate = self
}
private func setupActions() {
addToTripButton.addTarget(self, action: #selector(addToTripButtonTapped), for: .touchUpInside)
navigationBar.leadingButtonDidTap
.subscribe(with: self) { owner, _ in
owner.navigationController?.popViewController(animated: true)
}
.disposed(by: disposeBag)
}
// MARK: - Actions
@objc private func addToTripButtonTapped() {
listener?.didTapAddToTrip()
}
private func syncDaySelection(day: Int) {
currentSelectedDay = day
let indexPath = IndexPath(item: day - 1, section: 0)
dayCollectionView.selectItem(at: indexPath, animated: false, scrollPosition: .centeredHorizontally)
stickyDayCollectionView.selectItem(at: indexPath, animated: false, scrollPosition: .centeredHorizontally)
}
}
// MARK: - FollowDetailPresentable
extension FollowDetailViewController {
func showLoading() {
loadingIndicator.startAnimating()
}
func hideLoading() {
loadingIndicator.stopAnimating()
}
func updateTravelDetail(_ detail: TravelDetail) {
mediaInfoView.configure(with: detail)
totalDays = detail.days
dayCollectionView.applySnapshot(totalDays: detail.days, selectedDay: 1)
stickyDayCollectionView.applySnapshot(totalDays: detail.days, selectedDay: 1)
}
func updatePlaces(_ places: [TravelPlace]) {
mapView.configure(with: places)
placeListCollectionView.applySnapshot(places: places)
let cellHeight: CGFloat = 129
let spacing: CGFloat = 13
let height = CGFloat(places.count) * cellHeight + CGFloat(max(0, places.count - 1)) * spacing
placeListCollectionView.snp.updateConstraints {
$0.height.greaterThanOrEqualTo(max(400, height))
}
}
func showTripCreatedModal(onLater: @escaping () -> Void, onViewTrip: @escaping () -> Void) {
let modal = NDGLModalViewController(
title: "여행이 준비됐어요",
subtitle: "이제 선택한 여행을\n그대로 따라갈 수 있어요.",
cancelButtonTitle: "나중에 보러가기",
actionButtonTitle: "여행 보러가기"
)
modal.onCancelTapped = onLater
modal.onActionTapped = onViewTrip
present(modal, animated: true)
}
func showPlaceDetail(_ place: TravelPlace) {
let contentView = PlaceDetailBottomSheetView()
contentView.configure(with: place)
let configuration = BottomSheetConfiguration(
showDim: true,
dimColor: UIColor.black.withAlphaComponent(0.7),
showIndicator: true
)
let bottomSheet = BottomSheetViewController(
contentView: contentView,
contentHeight: 280,
configuration: configuration
)
contentView.onChevronTapped = { [weak self, weak bottomSheet] in
bottomSheet?.dismiss(animated: true) {
self?.listener?.didTapPlaceDetailChevron(place)
}
}
present(bottomSheet, animated: false)
}
}
// MARK: - FollowDetailViewControllable
extension FollowDetailViewController {
func present(_ viewController: ViewControllable) {
navigationController?.pushViewController(viewController.uiviewController, animated: true)
}
func dismiss(_ viewController: ViewControllable) {
navigationController?.popViewController(animated: true)
}
}
// MARK: - UIScrollViewDelegate
extension FollowDetailViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let offsetY = scrollView.contentOffset.y
let threshold = dayCollectionViewOriginY - 16
stickyHeaderView.isHidden = offsetY < threshold
}
}
// MARK: - MediaInfoViewDelegate
extension FollowDetailViewController: MediaInfoViewDelegate {
func mediaInfoViewDidToggleExpand(_ view: MediaInfoView, isExpanded: Bool) {
UIView.animate(withDuration: 0.3) { [weak self] in
self?.view.layoutIfNeeded()
} completion: { [weak self] _ in
self?.dayCollectionViewOriginY = self?.dayCollectionView.frame.origin.y ?? 0
}
}
}
// MARK: - DayCollectionViewDelegate
extension FollowDetailViewController: DayCollectionViewDelegate {
func dayCollectionView(_ collectionView: DayCollectionView, didSelectDay day: Int) {
syncDaySelection(day: day)
listener?.didSelectDay(day)
}
}
// MARK: - PlaceListCollectionViewDelegate
extension FollowDetailViewController: PlaceListCollectionViewDelegate {
func placeListCollectionView(_ collectionView: PlaceListCollectionView, didSelectPlace place: TravelPlace) {
listener?.didSelectPlace(place)
}
}