@@ -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}
0 commit comments