Skip to content

Commit a604f23

Browse files
committed
refactor #98: StatusChip 컴포넌트 적용
1 parent b7fea08 commit a604f23

4 files changed

Lines changed: 55 additions & 57 deletions

File tree

dogether/Presentation/Common/FilterStackView.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,38 @@ import Foundation
1010
final class FilterStackView: BaseStackView {
1111
var mainDelegate: MainDelegate? {
1212
didSet {
13-
[allButton, waitButton, approveButton, rejectButton].forEach { $0.mainDelegate = mainDelegate }
13+
[allChip, waitChip, approveChip, rejectChip].forEach { $0.mainDelegate = mainDelegate }
1414
}
1515
}
16-
16+
1717
var certificationListDelegate: CertificationListPageDelegate? {
1818
didSet {
19-
[allButton, waitButton, approveButton, rejectButton].forEach { $0.certificationListDelegate = certificationListDelegate }
19+
[allChip, waitChip, approveChip, rejectChip].forEach { $0.certificationListDelegate = certificationListDelegate }
2020
}
2121
}
22-
23-
private let allButton = FilterButton(type: .all)
24-
private let waitButton = FilterButton(type: .status(.pending))
25-
private let rejectButton = FilterButton(type: .status(.reject))
26-
private let approveButton = FilterButton(type: .status(.approve))
27-
22+
23+
private let allChip = StatusChip(filterType: .all)
24+
private let waitChip = StatusChip(filterType: .status(.pending))
25+
private let rejectChip = StatusChip(filterType: .status(.reject))
26+
private let approveChip = StatusChip(filterType: .status(.approve))
27+
2828
override func configureView() {
2929
axis = .horizontal
3030
spacing = 8
3131
}
32-
32+
3333
override func configureAction() { }
34-
34+
3535
override func configureHierarchy() {
36-
[allButton, waitButton, approveButton, rejectButton].forEach { addArrangedSubview($0) }
36+
[allChip, waitChip, approveChip, rejectChip].forEach { addArrangedSubview($0) }
3737
}
38-
38+
3939
override func configureConstraints() { }
40-
40+
4141
// MARK: - updateView
4242
override func updateView(_ data: any BaseEntity) {
4343
if let datas = data as? FilterTypes {
44-
[allButton, waitButton, rejectButton, approveButton].forEach { $0.updateView(datas) }
44+
[allChip, waitChip, rejectChip, approveChip].forEach { $0.updateView(datas) }
4545
}
4646
}
4747
}

dogether/Presentation/Common/StatusChip.swift

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,93 +19,95 @@ final class StatusChip: BaseButton {
1919
guard let filterType = filterType else { return }
2020
addAction(
2121
UIAction { [weak self] _ in
22-
self?.mainDelegate?.selectFilterAction(filterType: filterType)
22+
guard let self else { return }
23+
mainDelegate?.selectFilterAction(filterType: filterType)
2324
}, for: .touchUpInside
2425
)
2526
}
2627
}
27-
28+
2829
var certificationListDelegate: CertificationListPageDelegate? {
2930
didSet {
3031
guard let filterType = filterType else { return }
3132
addAction(
3233
UIAction { [weak self] _ in
33-
self?.certificationListDelegate?.selectFilterAction(filterType: filterType)
34+
guard let self else { return }
35+
certificationListDelegate?.selectFilterAction(filterType: filterType)
3436
}, for: .touchUpInside
3537
)
3638
}
3739
}
38-
40+
3941
private let style: StatusChipStyle
4042
private let filterType: FilterTypes?
41-
43+
4244
private let icon = UIImageView()
4345
private let label = UILabel()
4446
private let stackView = UIStackView()
45-
47+
4648
// MARK: - Initializers
47-
49+
4850
/// selectable 스타일용 (FilterButton 대체)
4951
init(filterType: FilterTypes) {
5052
self.style = .selectable
5153
self.filterType = filterType
52-
54+
5355
super.init(frame: .zero)
5456
}
55-
57+
5658
/// display 스타일용 (TodoStatusButton 대체)
5759
init() {
5860
self.style = .display
5961
self.filterType = nil
60-
62+
6163
super.init(frame: .zero)
6264
}
63-
65+
6466
required init?(coder: NSCoder) { fatalError() }
65-
67+
6668
// MARK: - Configure
67-
69+
6870
override func configureView() {
6971
layer.cornerRadius = 16
70-
72+
7173
if style == .selectable {
7274
layer.borderWidth = 1
7375
}
74-
76+
7577
icon.image = filterType?.image?.withRenderingMode(.alwaysTemplate)
76-
78+
7779
label.text = filterType?.text
7880
label.font = Fonts.body2S
79-
81+
8082
stackView.axis = .horizontal
8183
stackView.spacing = 4
8284
stackView.alignment = .center
8385
stackView.isUserInteractionEnabled = false
8486
}
85-
87+
8688
override func configureAction() { }
87-
89+
8890
override func configureHierarchy() {
8991
let views = icon.image == nil ? [label] : [icon, label]
9092
views.forEach { stackView.addArrangedSubview($0) }
91-
93+
9294
addSubview(stackView)
9395
}
94-
96+
9597
override func configureConstraints() {
9698
stackView.snp.makeConstraints {
9799
$0.verticalEdges.equalToSuperview().inset(6)
98100
$0.horizontalEdges.equalToSuperview().inset(12)
99101
$0.center.equalToSuperview()
100102
}
101-
103+
102104
icon.snp.makeConstraints {
103105
$0.width.height.equalTo(16)
104106
}
105107
}
106-
108+
107109
// MARK: - updateView
108-
110+
109111
override func updateView(_ data: any BaseEntity) {
110112
switch style {
111113
case .selectable:
@@ -114,35 +116,31 @@ final class StatusChip: BaseButton {
114116
updateDisplayStyle(data)
115117
}
116118
}
117-
119+
118120
private func updateSelectableStyle(_ data: any BaseEntity) {
119121
guard let selectedFilter = data as? FilterTypes,
120122
let filterType = filterType else { return }
121-
123+
122124
let isSelected = filterType == selectedFilter
123-
125+
124126
backgroundColor = isSelected ? filterType.backgroundColor : .clear
125127
layer.borderColor = isSelected ? filterType.backgroundColor.cgColor : UIColor.grey500.cgColor // FIXME: 컬러 추가 필요
126128
icon.tintColor = isSelected ? .grey900 : Color.Icon.secondary // FIXME: 컬러 추가 필요
127129
label.textColor = isSelected ? Color.Text.inverse : Color.Text.secondary
128130
}
129-
131+
130132
private func updateDisplayStyle(_ data: any BaseEntity) {
131133
if let status = data as? TodoStatus {
132134
backgroundColor = status.backgroundColor
133135
icon.image = status.image?.withRenderingMode(.alwaysTemplate)
134136
icon.tintColor = .grey900 // FIXME: 컬러 추가 필요
135137
label.text = status.text
136138
label.textColor = Color.Text.inverse
137-
138-
rebuildStackView()
139+
140+
stackView.arrangedSubviews.forEach { stackView.removeArrangedSubview($0); $0.removeFromSuperview() }
141+
142+
let views = icon.image == nil ? [label] : [icon, label]
143+
views.forEach { stackView.addArrangedSubview($0) }
139144
}
140145
}
141-
142-
private func rebuildStackView() {
143-
stackView.arrangedSubviews.forEach { stackView.removeArrangedSubview($0); $0.removeFromSuperview() }
144-
145-
let views = icon.image == nil ? [label] : [icon, label]
146-
views.forEach { stackView.addArrangedSubview($0) }
147-
}
148146
}

dogether/Presentation/Features/Certification/Components/CertificationPage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class CertificationPage: BasePage {
2626
private let certificationScrollView = UIScrollView()
2727
private let certificationStackView = UIStackView()
2828
private let certificationListView = CertificationListView()
29-
private let statusView = TodoStatusButton()
29+
private let statusView = StatusChip()
3030
private let contentLabel = UILabel()
3131
private let reviewFeedbackView = ReviewFeedbackView()
3232
// private let certificateButton = DogetherButton("인증하기")

dogether/Presentation/Features/CertificationList/Components/CertificationListCell.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ final class CertificationCell: UICollectionViewCell {
1111
static let reuseIdentifier = "CertificationCell"
1212

1313
private let imageView = UIImageView()
14-
private let statusButton = TodoStatusButton()
14+
private let statusView = StatusChip()
1515

1616
override init(frame: CGRect) {
1717
super.init(frame: frame)
@@ -23,13 +23,13 @@ final class CertificationCell: UICollectionViewCell {
2323
imageView.clipsToBounds = true
2424

2525
contentView.addSubview(imageView)
26-
contentView.addSubview(statusButton)
26+
contentView.addSubview(statusView)
2727

2828
imageView.snp.makeConstraints {
2929
$0.top.leading.trailing.bottom.equalToSuperview()
3030
}
3131

32-
statusButton.snp.makeConstraints {
32+
statusView.snp.makeConstraints {
3333
$0.leading.equalToSuperview().offset(12)
3434
$0.bottom.equalToSuperview().offset(-12)
3535
}
@@ -46,6 +46,6 @@ final class CertificationCell: UICollectionViewCell {
4646
func configure(with certificationItem: TodoEntity) {
4747
imageView.loadImage(url: certificationItem.certificationMediaUrl)
4848

49-
statusButton.updateView(certificationItem.status)
49+
statusView.updateView(certificationItem.status)
5050
}
5151
}

0 commit comments

Comments
 (0)