-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathHomeForMemberCompositionalLayout.swift
337 lines (289 loc) · 18.4 KB
/
HomeForMemberCompositionalLayout.swift
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
//
// HomeForMemberCompositionalLayout.swift
// HomeFeature
//
// Created by Jae Hyun Lee on 11/22/24.
// Copyright © 2024 SOPT-iOS. All rights reserved.
//
import UIKit
import Combine
import Core
extension HomeForMemberVC {
private enum Metric {
static let collectionViewDefaultSideInset: Double = 20
static let defaultItemSpacing: Double = 16
static let defaultGroupSpacing: Double = 12
static let defaultLineSpacing: Double = 56
static let productItemSpacing: Double = 15
static let appServiceItemSpacing: Double = 16
static let mainProductSectionSpacing: Double = 44
static let announcementWidth: Double = 300
}
func createLayout() -> UICollectionViewCompositionalLayout {
return UICollectionViewCompositionalLayout { sectionIndex, env in
guard let sectionKind = HomeForMemberSectionLayoutKind(rawValue: sectionIndex)
else { return self.createEmptySection() }
switch sectionKind {
case .dashBoard:
return self.createDashBoardSection()
case .calendar:
return self.createCalendarSection()
case .mainProduct:
return self.createMainProductSection()
case .appService:
return self.createAppServiceSection()
case .insight:
return self.createInsightSection()
case .announcement:
return self.createAnnouncementSection()
case .group:
return self.createGroupSection()
case .coffeeChat:
return self.createCoffeeChatSection()
case .socialLinks:
return self.createSocialLinksSection()
}
}
}
private func createDashBoardSection() -> NSCollectionLayoutSection {
/// item: 유저 정보 및 활동 히스토리 카드
let dashBoardItemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
heightDimension: .absolute(123))
let dashBoardItem = NSCollectionLayoutItem(layoutSize: dashBoardItemSize)
/// group: 유저 정보 및 활동 히스토리 카드
let dashBoardGroupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
heightDimension: .estimated(123))
let dashBoardGroup = NSCollectionLayoutGroup.vertical(layoutSize: dashBoardGroupSize,
subitems: [dashBoardItem])
/// section 지정
let section = NSCollectionLayoutSection(group: dashBoardGroup)
section.contentInsets = NSDirectionalEdgeInsets(top: 12,
leading: Metric.collectionViewDefaultSideInset,
bottom: 0,
trailing: Metric.collectionViewDefaultSideInset)
return section
}
private func createCalendarSection() -> NSCollectionLayoutSection {
/// item: 캘린더 카드
let calendarItemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
heightDimension: .absolute(56))
let calendarItem = NSCollectionLayoutItem(layoutSize: calendarItemSize)
/// group: 캘린더 카드
let calendarGroupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
heightDimension: .estimated(56))
let calendarGroup = NSCollectionLayoutGroup.vertical(layoutSize: calendarGroupSize,
subitems: [calendarItem])
/// section 지정
let section = NSCollectionLayoutSection(group: calendarGroup)
section.contentInsets = NSDirectionalEdgeInsets(top: 12,
leading: Metric.collectionViewDefaultSideInset,
bottom: 0,
trailing: Metric.collectionViewDefaultSideInset)
return section
}
private func createMainProductSection() -> NSCollectionLayoutSection {
/// item: 프로덕트 카드
let productItemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.25),
heightDimension: .absolute(92))
let productItem = NSCollectionLayoutItem(layoutSize: productItemSize)
/// group: 프로덕트 카드
let productGroupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
heightDimension: .estimated(92))
let productGroup = NSCollectionLayoutGroup.horizontal(layoutSize: productGroupSize,
subitems: [productItem])
productGroup.interItemSpacing = .fixed(Metric.productItemSpacing)
/// section 지정
let section = NSCollectionLayoutSection(group: productGroup)
section.contentInsets = NSDirectionalEdgeInsets(top: Metric.defaultItemSpacing,
leading: Metric.collectionViewDefaultSideInset,
bottom: Metric.mainProductSectionSpacing,
trailing: Metric.collectionViewDefaultSideInset)
return section
}
private func createAppServiceSection() -> NSCollectionLayoutSection {
/// header: default
let headerSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
heightDimension: .absolute(30))
let header = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerSize,
elementKind: UICollectionView.elementKindSectionHeader,
alignment: .top)
/// item: 앱 서비스 카드
let appServiceItemSize = NSCollectionLayoutSize(widthDimension: .absolute(80),
heightDimension: .absolute(106))
let appServiceItem = NSCollectionLayoutItem(layoutSize: appServiceItemSize)
/// group: 앱 서비스 카드
let appServiceGroupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
heightDimension: .estimated(106))
let appServiceGroup = NSCollectionLayoutGroup.horizontal(layoutSize: appServiceGroupSize,
subitems: [appServiceItem])
appServiceGroup.interItemSpacing = .fixed(Metric.appServiceItemSpacing)
/// section 지정
let section = NSCollectionLayoutSection(group: appServiceGroup)
section.boundarySupplementaryItems = [header]
section.contentInsets = NSDirectionalEdgeInsets(top: Metric.defaultItemSpacing,
leading: Metric.collectionViewDefaultSideInset,
bottom: Metric.defaultLineSpacing,
trailing: Metric.collectionViewDefaultSideInset)
return section
}
private func createInsightSection() -> NSCollectionLayoutSection {
/// header: default
let headerSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
heightDimension: .absolute(30))
let header = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerSize,
elementKind: UICollectionView.elementKindSectionHeader,
alignment: .top)
/// item: 인사이트 카드
let insightItemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
heightDimension: .absolute(80))
let insightItem = NSCollectionLayoutItem(layoutSize: insightItemSize)
/// group: 인사이트 카드
let insightGroupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
heightDimension: .estimated(80))
let insightGroup = NSCollectionLayoutGroup.horizontal(layoutSize: insightGroupSize,
subitems: [insightItem])
/// section 지정
let section = NSCollectionLayoutSection(group: insightGroup)
section.boundarySupplementaryItems = [header]
section.contentInsets = NSDirectionalEdgeInsets(top: Metric.defaultItemSpacing,
leading: Metric.collectionViewDefaultSideInset,
bottom: Metric.defaultLineSpacing,
trailing: Metric.collectionViewDefaultSideInset)
return section
}
private func createGroupSection() -> NSCollectionLayoutSection {
/// header: default
let headerSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
heightDimension: .absolute(30))
let header = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerSize,
elementKind: UICollectionView.elementKindSectionHeader,
alignment: .top)
header.contentInsets = .init(top: 0,
leading: 0,
bottom: 0,
trailing: Metric.collectionViewDefaultSideInset)
/// item: 모임 카드
let groupItemSize = NSCollectionLayoutSize(widthDimension: .absolute(140),
heightDimension: .estimated(170))
let groupItem = NSCollectionLayoutItem(layoutSize: groupItemSize)
/// group: 모임 카드
let groupGroupSize = NSCollectionLayoutSize(widthDimension: .absolute(150),
heightDimension: .estimated(170))
let groupGroup = NSCollectionLayoutGroup.horizontal(layoutSize: groupGroupSize,
subitems: [groupItem])
groupGroup.interItemSpacing = .fixed(12)
/// section 지정
let section = NSCollectionLayoutSection(
group: groupGroup
)
section.boundarySupplementaryItems = [header]
section.contentInsets = NSDirectionalEdgeInsets(top: Metric.defaultItemSpacing,
leading: Metric.collectionViewDefaultSideInset,
bottom: Metric.defaultLineSpacing,
trailing: 0)
section.orthogonalScrollingBehavior = .groupPaging
return section
}
private func createCoffeeChatSection() -> NSCollectionLayoutSection {
/// header: default
let headerSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
heightDimension: .absolute(30))
let header = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerSize,
elementKind: UICollectionView.elementKindSectionHeader,
alignment: .top)
header.contentInsets = .init(top: 0,
leading: 0,
bottom: 0,
trailing: Metric.collectionViewDefaultSideInset)
/// item: 커피챗 카드
let coffeeChatItemSize = NSCollectionLayoutSize(widthDimension: .absolute(280),
heightDimension: .estimated(234))
let coffeeChatItem = NSCollectionLayoutItem(layoutSize: coffeeChatItemSize)
/// group: 커피챗 카드
let coffeeChatGroupSize = NSCollectionLayoutSize(widthDimension: .absolute(280),
heightDimension: .estimated(234))
let coffeeChatGroup = NSCollectionLayoutGroup.horizontal(layoutSize: coffeeChatGroupSize,
subitems: [coffeeChatItem])
/// section 지정
let section = NSCollectionLayoutSection(
group: coffeeChatGroup
)
section.boundarySupplementaryItems = [header]
section.contentInsets = NSDirectionalEdgeInsets(top: 16,
leading: Metric.collectionViewDefaultSideInset,
bottom: Metric.defaultLineSpacing,
trailing: Metric.collectionViewDefaultSideInset)
section.interGroupSpacing = 12
section.orthogonalScrollingBehavior = .groupPaging
return section
}
private func createAnnouncementSection() -> NSCollectionLayoutSection {
/// header: default
let headerSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
heightDimension: .absolute(30))
let header = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerSize,
elementKind: UICollectionView.elementKindSectionHeader,
alignment: .top)
/// item: 홍보 카드
let announcementItemSize = NSCollectionLayoutSize(widthDimension: .absolute(Metric.announcementWidth),
heightDimension: .absolute(308))
let announctementItem = NSCollectionLayoutItem(layoutSize: announcementItemSize)
/// group: 홍보 카드
let announcementGroupSize = NSCollectionLayoutSize(widthDimension: .absolute(Metric.announcementWidth),
heightDimension: .absolute(308))
let announcementGroup = NSCollectionLayoutGroup.vertical(layoutSize: announcementGroupSize,
subitems: [announctementItem])
/// section 지정
let section = NSCollectionLayoutSection(group: announcementGroup)
section.boundarySupplementaryItems = [header]
section.contentInsets = NSDirectionalEdgeInsets(top: 16,
leading: Metric.collectionViewDefaultSideInset,
bottom: 0,
trailing: Metric.collectionViewDefaultSideInset)
/// footer: pageController 추가
let footerSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
heightDimension: .estimated(24))
let footer = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: footerSize,
elementKind: UICollectionView.elementKindSectionFooter,
alignment: .bottomLeading)
/// 포커스 중인 페이지 인덱스 계산
section.visibleItemsInvalidationHandler = { [weak self] items, offset, env in
let pageWidth = Metric.announcementWidth
let currentPage = Int(ceil(offset.x / (pageWidth + Metric.defaultGroupSpacing)))
self?.viewModel.currentCardPage.send(currentPage)
}
section.boundarySupplementaryItems = [header, footer]
section.orthogonalScrollingBehavior = .groupPaging
section.interGroupSpacing = 12
return section
}
private func createSocialLinksSection() -> NSCollectionLayoutSection {
/// item: 소셜 링크 카드
let socialLinkItemSize = NSCollectionLayoutSize(widthDimension: .absolute(97),
heightDimension: .absolute(40))
let socialLinkItem = NSCollectionLayoutItem(layoutSize: socialLinkItemSize)
/// group: 소셜 링크 카드
let socialLinkGroupSize = NSCollectionLayoutSize(widthDimension: .absolute(97),
heightDimension: .absolute(40))
let socialLinkGroup = NSCollectionLayoutGroup.vertical(layoutSize: socialLinkGroupSize,
subitems: [socialLinkItem])
/// section 지정
let section = NSCollectionLayoutSection(group: socialLinkGroup)
section.contentInsets = NSDirectionalEdgeInsets(top: Metric.defaultLineSpacing,
leading: Metric.collectionViewDefaultSideInset,
bottom: 0,
trailing: 0)
section.interGroupSpacing = 6
return section
}
private func createEmptySection() -> NSCollectionLayoutSection {
let itemSize = NSCollectionLayoutSize(widthDimension: .absolute(1),
heightDimension: .absolute(1))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
let groupSize = NSCollectionLayoutSize(widthDimension: .absolute(1),
heightDimension: .absolute(1))
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize,
subitems: [item])
return NSCollectionLayoutSection(group: group)
}
}