Skip to content

Commit 03dc1fc

Browse files
Merge pull request #171 from PopPool/fix/#170-storelist-cell-layout
fix/#170: StoreListCell λ ˆμ΄μ•„μ›ƒ κ°œμ„  및 μ»¨λ²€μ…˜ 적용
2 parents 0bd2e1a + eee1dc6 commit 03dc1fc

File tree

3 files changed

+153
-119
lines changed

3 files changed

+153
-119
lines changed
Lines changed: 95 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import UIKit
22

33
import DesignSystem
4+
import Infrastructure
45

56
import ReactorKit
67
import RxSwift
@@ -10,55 +11,71 @@ import Then
1011
final class StoreListCell: UICollectionViewCell {
1112
static let identifier = "StoreListCell"
1213

14+
// MARK: - Properties
15+
var disposeBag = DisposeBag()
16+
17+
private enum Constant {
18+
static let imageHeight: CGFloat = 140
19+
static let bookmarkSize: CGFloat = 24
20+
static let bookmarkInset: CGFloat = 8
21+
static let categoryTopOffset: CGFloat = 12
22+
static let categoryHeight: CGFloat = 15
23+
static let titleTopOffset: CGFloat = 4
24+
static let addressHeight: CGFloat = 17
25+
static let dateHeight: CGFloat = 15
26+
static let cornerRadius: CGFloat = 12
27+
static let cellCornerRadius: CGFloat = 4
28+
}
29+
1330
// MARK: - Components
14-
private let thumbnailImageView: UIImageView = {
15-
let iv = UIImageView()
16-
iv.contentMode = .scaleAspectFill
17-
iv.clipsToBounds = true
18-
iv.layer.cornerRadius = 12
19-
iv.backgroundColor = .g100
20-
return iv
21-
}()
22-
23-
let bookmarkButton: UIButton = {
24-
let button = UIButton()
25-
button.setImage(UIImage(named: "icon_bookmark"), for: .normal)
26-
button.backgroundColor = .clear
27-
button.layer.cornerRadius = 12
28-
return button
29-
}()
30-
31-
private let categoryTagLabel = PPLabel(style: .KOb11).then {
31+
private let thumbnailImageView = UIImageView().then {
32+
$0.contentMode = .scaleAspectFill
33+
$0.clipsToBounds = true
34+
$0.layer.cornerRadius = Constant.cornerRadius
35+
$0.backgroundColor = .g100
36+
}
37+
38+
let bookmarkButton = UIButton().then {
39+
$0.setImage(UIImage(named: "icon_bookmark"), for: .normal)
40+
$0.backgroundColor = .clear
41+
$0.layer.cornerRadius = Constant.cornerRadius
42+
}
43+
44+
private let categoryTagLabel = PPLabel(style: .bold, fontSize: 11).then {
3245
$0.textColor = .blu500
46+
$0.setLineHeightText(text: "category", font: .korFont(style: .bold, size: 11))
3347
}
3448

35-
private let titleLabel = PPLabel(style: .KOb14).then {
36-
$0.textColor = .g900
49+
private let titleLabel = PPLabel(style: .bold, fontSize: 14).then {
3750
$0.numberOfLines = 2
51+
$0.lineBreakMode = .byTruncatingTail
52+
$0.textColor = .g900
53+
$0.setLineHeightText(text: "title", font: .korFont(style: .bold, size: 14))
3854
}
3955

40-
private let locationLabel = PPLabel(style: .KOm11).then {
56+
private let locationLabel = PPLabel(style: .medium, fontSize: 11).then {
57+
$0.numberOfLines = 1
58+
$0.lineBreakMode = .byTruncatingTail
4159
$0.textColor = .g400
42-
$0.numberOfLines = 2
60+
$0.setLineHeightText(text: "location", font: .korFont(style: .medium, size: 11))
4361
}
4462

45-
private let dateLabel = PPLabel(style: .KOr12).then {
63+
private let dateLabel = PPLabel(style: .medium, fontSize: 11).then {
64+
$0.lineBreakMode = .byTruncatingTail
4665
$0.textColor = .g400
47-
$0.numberOfLines = 2
66+
$0.setLineHeightText(text: "date", font: .korFont(style: .medium, size: 11))
4867
}
4968

50-
var disposeBag = DisposeBag()
51-
5269
// MARK: - Init
5370
override init(frame: CGRect) {
5471
super.init(frame: frame)
55-
56-
setUpConstraints()
57-
configureUI()
72+
self.addViews()
73+
self.setupConstraints()
74+
self.configureUI()
5875
}
5976

6077
required init?(coder: NSCoder) {
61-
fatalError()
78+
fatalError("\(#file), \(#function) Error")
6279
}
6380

6481
override func prepareForReuse() {
@@ -69,55 +86,58 @@ final class StoreListCell: UICollectionViewCell {
6986

7087
// MARK: - SetUp
7188
private extension StoreListCell {
72-
func configureUI() {
73-
// backgroundColor = .white
89+
func addViews() {
90+
[thumbnailImageView, categoryTagLabel, titleLabel, locationLabel, dateLabel, bookmarkButton].forEach {
91+
self.contentView.addSubview($0)
92+
}
7493
}
7594

76-
func setUpConstraints() {
77-
contentView.addSubview(thumbnailImageView)
95+
func setupConstraints() {
7896
thumbnailImageView.snp.makeConstraints { make in
79-
make.top.leading.equalToSuperview()
80-
make.width.equalTo((UIScreen.main.bounds.width - 48) / 2)
81-
make.height.equalTo(thumbnailImageView.snp.width)
97+
make.width.equalTo(self.contentView.bounds.width)
98+
make.height.equalTo(Constant.imageHeight)
99+
make.top.equalToSuperview()
100+
make.centerX.equalToSuperview()
82101
}
83102

84-
contentView.addSubview(bookmarkButton)
85103
bookmarkButton.snp.makeConstraints { make in
86-
make.top.trailing.equalToSuperview().inset(8)
87-
make.size.equalTo(24)
104+
make.size.equalTo(Constant.bookmarkSize)
105+
make.top.trailing.equalToSuperview().inset(Constant.bookmarkInset)
106+
}
107+
108+
categoryTagLabel.snp.makeConstraints { make in
109+
make.leading.equalToSuperview()
110+
make.top.equalTo(self.thumbnailImageView.snp.bottom).offset(Constant.categoryTopOffset)
111+
make.height.equalTo(Constant.categoryHeight)
112+
}
113+
114+
titleLabel.snp.makeConstraints { make in
115+
make.top.equalTo(self.categoryTagLabel.snp.bottom).offset(Constant.titleTopOffset)
116+
make.leading.trailing.equalToSuperview()
117+
}
118+
119+
dateLabel.snp.makeConstraints { make in
120+
make.leading.equalToSuperview()
121+
make.height.equalTo(Constant.dateHeight).priority(.high)
122+
make.bottom.equalToSuperview()
123+
}
124+
125+
locationLabel.snp.makeConstraints { make in
126+
make.leading.trailing.equalToSuperview()
127+
make.bottom.equalTo(self.dateLabel.snp.top)
128+
make.height.equalTo(Constant.addressHeight).priority(.high)
88129
}
130+
}
89131

90-
contentView.addSubview(categoryTagLabel)
91-
contentView.addSubview(titleLabel)
92-
contentView.addSubview(locationLabel)
93-
contentView.addSubview(dateLabel)
94-
95-
// 각 라벨의 μœ„μΉ˜ μ„€μ •
96-
categoryTagLabel.snp.makeConstraints { make in
97-
make.top.equalTo(thumbnailImageView.snp.bottom).offset(10)
98-
make.leading.trailing.equalToSuperview()
99-
make.height.equalTo(16)
100-
}
101-
102-
titleLabel.snp.makeConstraints { make in
103-
make.top.equalTo(categoryTagLabel.snp.bottom).offset(6)
104-
make.leading.trailing.equalToSuperview()
105-
}
106-
107-
locationLabel.snp.makeConstraints { make in
108-
make.top.equalTo(titleLabel.snp.bottom).offset(12)
109-
make.leading.trailing.equalToSuperview()
110-
}
111-
112-
dateLabel.snp.makeConstraints { make in
113-
make.top.equalTo(locationLabel.snp.bottom).offset(6)
114-
make.leading.trailing.equalToSuperview()
115-
make.bottom.lessThanOrEqualToSuperview()
116-
}
117-
}
132+
func configureUI() {
133+
self.contentView.layer.cornerRadius = Constant.cellCornerRadius
134+
self.contentView.clipsToBounds = true
135+
136+
self.thumbnailImageView.layer.cornerRadius = Constant.cornerRadius
137+
self.thumbnailImageView.clipsToBounds = true
138+
}
118139
}
119140

120-
// MARK: - Inputable
121141
extension StoreListCell: Inputable {
122142
struct Input {
123143
let thumbnailURL: String
@@ -129,13 +149,13 @@ extension StoreListCell: Inputable {
129149
}
130150

131151
func injection(with input: Input) {
132-
thumbnailImageView.setPPImage(path: input.thumbnailURL)
133-
categoryTagLabel.updateText(to: "#\(input.category)")
134-
titleLabel.updateText(to: input.title)
135-
locationLabel.updateText(to: input.location)
136-
dateLabel.updateText(to: input.date)
152+
self.thumbnailImageView.setPPImage(path: input.thumbnailURL)
153+
self.categoryTagLabel.updateText(to: "#\(input.category)")
154+
self.titleLabel.updateText(to: input.title)
155+
self.locationLabel.updateText(to: input.location)
156+
self.dateLabel.updateText(to: input.date)
137157

138158
let bookmarkImage = input.isBookmarked ? "icon_bookmark_fill" : "icon_bookmark"
139-
bookmarkButton.setImage(UIImage(named: bookmarkImage), for: .normal)
159+
self.bookmarkButton.setImage(UIImage(named: bookmarkImage), for: .normal)
140160
}
141161
}

β€ŽPoppool/PresentationLayer/Presentation/Presentation/Scene/Map/StoreListView/StoreListView.swiftβ€Ž

Lines changed: 58 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,26 @@ import SnapKit
22
import UIKit
33

44
final class StoreListView: UIView {
5+
6+
// MARK: - Properties
7+
private enum Constant {
8+
static let grabberWidth: CGFloat = 36
9+
static let grabberHeight: CGFloat = 5
10+
static let grabberTopOffset: CGFloat = 14
11+
static let grabberCornerRadius: CGFloat = 2.5
12+
static let collectionViewTopOffset: CGFloat = 8
13+
static let cornerRadius: CGFloat = 16
14+
static let itemHeight: CGFloat = 250
15+
static let minimumLineSpacing: CGFloat = 20
16+
static let minimumInteritemSpacing: CGFloat = 16
17+
static let sectionInsetTop: CGFloat = 16
18+
static let sectionInsetHorizontal: CGFloat = 16
19+
static let sectionInsetBottom: CGFloat = 16
20+
}
21+
522
// MARK: - Components
623
lazy var collectionView: UICollectionView = {
7-
let layout = createLayout()
24+
let layout = self.createLayout()
825
let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
926
cv.backgroundColor = .white
1027
cv.register(StoreListCell.self, forCellWithReuseIdentifier: StoreListCell.identifier)
@@ -14,22 +31,18 @@ final class StoreListView: UIView {
1431
let grabberHandle: UIView = {
1532
let view = UIView()
1633
view.backgroundColor = .g200
17-
view.layer.cornerRadius = 2.5
34+
view.layer.cornerRadius = Constant.grabberCornerRadius
1835
view.isUserInteractionEnabled = true
1936
return view
2037
}()
2138

22-
private let paddingView: UIView = {
23-
let view = UIView()
24-
view.backgroundColor = .clear // κ°„κ²©λ§Œ μΆ”κ°€ν•˜λ―€λ‘œ 투λͺ…
25-
return view
26-
}()
27-
2839
// MARK: - Init
2940
override init(frame: CGRect) {
3041
super.init(frame: frame)
31-
configureLayer() // μ΅œμƒλ‹¨ λ ˆμ΄μ–΄ μ„€μ •
32-
setUpConstraints()
42+
43+
self.configureLayer()
44+
self.addViews()
45+
self.setupConstraints()
3346
}
3447

3548
required init?(coder: NSCoder) {
@@ -39,47 +52,51 @@ final class StoreListView: UIView {
3952

4053
// MARK: - Setup
4154
private extension StoreListView {
55+
func addViews() {
56+
[collectionView, grabberHandle].forEach {
57+
self.addSubview($0)
58+
}
59+
}
60+
61+
func setupConstraints() {
62+
grabberHandle.snp.makeConstraints { make in
63+
make.top.equalToSuperview().offset(Constant.grabberTopOffset).priority(.high)
64+
make.centerX.equalToSuperview()
65+
make.width.equalTo(Constant.grabberWidth)
66+
make.height.equalTo(Constant.grabberHeight)
67+
}
68+
69+
collectionView.snp.makeConstraints { make in
70+
make.top.equalTo(grabberHandle.snp.bottom).offset(Constant.collectionViewTopOffset).priority(.medium)
71+
make.leading.trailing.equalToSuperview()
72+
make.bottom.equalToSuperview()
73+
}
74+
}
75+
4276
func createLayout() -> UICollectionViewFlowLayout {
4377
let layout = UICollectionViewFlowLayout()
4478
layout.scrollDirection = .vertical
45-
layout.minimumLineSpacing = 20
46-
layout.minimumInteritemSpacing = 16
79+
layout.minimumLineSpacing = Constant.minimumLineSpacing
80+
layout.minimumInteritemSpacing = Constant.minimumInteritemSpacing
4781

48-
let totalWidth = UIScreen.main.bounds.width - 32
82+
let totalWidth = UIScreen.main.bounds.width - (Constant.sectionInsetHorizontal * 2)
4983
let itemWidth = (totalWidth - layout.minimumInteritemSpacing) / 2
5084

51-
layout.itemSize = CGSize(width: floor(itemWidth), height: itemWidth + 100)
52-
layout.sectionInset = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
85+
layout.itemSize = CGSize(width: floor(itemWidth), height: Constant.itemHeight)
86+
layout.sectionInset = UIEdgeInsets(
87+
top: Constant.sectionInsetTop,
88+
left: Constant.sectionInsetHorizontal,
89+
bottom: Constant.sectionInsetBottom,
90+
right: Constant.sectionInsetHorizontal
91+
)
5392

5493
return layout
5594
}
5695

57-
func setUpConstraints() {
58-
backgroundColor = .white
59-
addSubview(collectionView)
60-
addSubview(grabberHandle)
61-
grabberHandle.snp.makeConstraints { make in
62-
make.top.equalToSuperview().offset(14).priority(.high)
63-
make.centerX.equalToSuperview()
64-
make.width.equalTo(36)
65-
make.height.equalTo(5)
66-
}
67-
// paddingView.snp.makeConstraints { make in
68-
// make.top.equalTo(grabberHandle.snp.bottom)
69-
// make.leading.trailing.equalToSuperview()
70-
//
71-
// }
72-
73-
collectionView.snp.makeConstraints { make in
74-
make.top.equalTo(grabberHandle.snp.bottom).offset(8).priority(.medium)
75-
make.leading.trailing.equalToSuperview()
76-
make.bottom.equalToSuperview() // bottom μ œμ•½ λ‹€μ‹œ μΆ”κ°€
77-
}
78-
}
79-
8096
func configureLayer() {
81-
layer.cornerRadius = 16
82-
layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner] // 상단 쒌우 μ½”λ„ˆλ§Œ 적용
83-
layer.masksToBounds = true
97+
self.backgroundColor = .white
98+
self.layer.cornerRadius = Constant.cornerRadius
99+
self.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
100+
self.layer.masksToBounds = true
84101
}
85102
}

β€ŽPoppool/PresentationLayer/Presentation/Presentation/Scene/Map/StoreListView/StoreListViewController.swiftβ€Ž

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ final class StoreListViewController: UIViewController, View {
9393
.bind(to: mainView.collectionView.rx.items(dataSource: dataSource))
9494
.disposed(by: disposeBag)
9595

96-
// μ°œν•œ νŒμ—… ν† μŠ€νŠΈ 처리 체인
9796
reactor.state
9897
.map { $0.shouldShowBookmarkToast }
9998
.distinctUntilChanged()
@@ -104,15 +103,13 @@ final class StoreListViewController: UIViewController, View {
104103
if isBookmarking {
105104
toastView.moveButton.rx.tap
106105
.subscribe(onNext: { [weak self] in
107-
// 이동 처리 (예: μ°œν•œ νŒμ—… 리슀트 νŽ˜μ΄μ§€λ‘œ 이동)
108106
})
109107
.disposed(by: self.disposeBag)
110108
}
111109
ToastMaker.createBookMarkToast(isBookMark: isBookmarking)
112110
}
113111
.disposed(by: disposeBag)
114112

115-
// 3) μ•„μ΄ν…œ 선택
116113
mainView.collectionView.rx.itemSelected
117114
.withUnretained(self)
118115
.subscribe(onNext: { owner, indexPath in

0 commit comments

Comments
Β (0)