8
8
9
9
import UIKit
10
10
11
- private let kCollapseButtonWidth : CGFloat = 24
12
- private let kRelayIndicatorSize : CGFloat = 16
11
+ protocol LocationCellDelegate : AnyObject {
12
+ func toggle( cell: LocationCell )
13
+ }
13
14
14
15
class LocationCell : UITableViewCell {
15
- typealias CollapseHandler = ( LocationCell ) -> Void
16
+ weak var delegate : LocationCellDelegate ?
17
+
18
+ private let locationLabel : UILabel = {
19
+ let label = UILabel ( )
20
+ label. font = UIFont . systemFont ( ofSize: 16 )
21
+ label. textColor = . white
22
+ label. lineBreakMode = . byWordWrapping
23
+ label. numberOfLines = 0
24
+ label. lineBreakStrategy = [ ]
25
+ return label
26
+ } ( )
16
27
17
- let locationLabel = UILabel ( )
18
- let statusIndicator : UIView = {
28
+ private let statusIndicator : UIView = {
19
29
let view = UIView ( )
20
- view. layer. cornerRadius = kRelayIndicatorSize * 0.5
30
+ view. layer. cornerRadius = 8
21
31
view. layer. cornerCurve = . circular
22
32
return view
23
33
} ( )
24
34
25
- let tickImageView = UIImageView ( image: UIImage ( named: " IconTick " ) )
26
- let collapseButton = UIButton ( type: . custom)
35
+ private let tickImageView : UIImageView = {
36
+ let imageView = UIImageView ( image: UIImage ( resource: . iconTick) )
37
+ imageView. tintColor = . white
38
+ return imageView
39
+ } ( )
40
+
41
+ private let collapseButton : UIButton = {
42
+ let button = UIButton ( type: . custom)
43
+ button. accessibilityIdentifier = . collapseButton
44
+ button. isAccessibilityElement = false
45
+ button. tintColor = . white
46
+ return button
47
+ } ( )
27
48
28
- private let chevronDown = UIImage ( named : " IconChevronDown " )
29
- private let chevronUp = UIImage ( named : " IconChevronUp " )
49
+ private let chevronDown = UIImage ( resource : . iconChevronDown )
50
+ private let chevronUp = UIImage ( resource : . iconChevronUp )
30
51
31
52
var isDisabled = false {
32
53
didSet {
@@ -50,8 +71,6 @@ class LocationCell: UITableViewCell {
50
71
}
51
72
}
52
73
53
- var didCollapseHandler : CollapseHandler ?
54
-
55
74
override var indentationLevel : Int {
56
75
didSet {
57
76
updateBackgroundColor ( )
@@ -103,17 +122,6 @@ class LocationCell: UITableViewCell {
103
122
selectedBackgroundView = UIView ( )
104
123
selectedBackgroundView? . backgroundColor = UIColor . Cell. Background. selected
105
124
106
- locationLabel. font = UIFont . systemFont ( ofSize: 17 )
107
- locationLabel. textColor = . white
108
- locationLabel. lineBreakMode = . byWordWrapping
109
- locationLabel. numberOfLines = 0
110
- locationLabel. lineBreakStrategy = [ ]
111
-
112
- tickImageView. tintColor = . white
113
-
114
- collapseButton. accessibilityIdentifier = . collapseButton
115
- collapseButton. isAccessibilityElement = false
116
- collapseButton. tintColor = . white
117
125
collapseButton. addTarget ( self , action: #selector( handleCollapseButton ( _: ) ) , for: . touchUpInside)
118
126
119
127
[ locationLabel, tickImageView, statusIndicator, collapseButton] . forEach { subview in
@@ -131,7 +139,7 @@ class LocationCell: UITableViewCell {
131
139
tickImageView. leadingAnchor. constraint ( equalTo: contentView. layoutMarginsGuide. leadingAnchor) ,
132
140
tickImageView. centerYAnchor. constraint ( equalTo: contentView. centerYAnchor) ,
133
141
134
- statusIndicator. widthAnchor. constraint ( equalToConstant: kRelayIndicatorSize ) ,
142
+ statusIndicator. widthAnchor. constraint ( equalToConstant: 16 ) ,
135
143
statusIndicator. heightAnchor. constraint ( equalTo: statusIndicator. widthAnchor) ,
136
144
statusIndicator. centerXAnchor. constraint ( equalTo: tickImageView. centerXAnchor) ,
137
145
statusIndicator. centerYAnchor. constraint ( equalTo: tickImageView. centerYAnchor) ,
@@ -148,7 +156,7 @@ class LocationCell: UITableViewCell {
148
156
collapseButton. widthAnchor
149
157
. constraint (
150
158
equalToConstant: UIMetrics . contentLayoutMargins. leading + UIMetrics
151
- . contentLayoutMargins. trailing + kCollapseButtonWidth
159
+ . contentLayoutMargins. trailing + 24
152
160
) ,
153
161
collapseButton. topAnchor. constraint ( equalTo: contentView. topAnchor) ,
154
162
collapseButton. trailingAnchor. constraint ( equalTo: contentView. trailingAnchor) ,
@@ -213,11 +221,11 @@ class LocationCell: UITableViewCell {
213
221
}
214
222
215
223
@objc private func handleCollapseButton( _ sender: UIControl ) {
216
- didCollapseHandler ? ( self )
224
+ delegate ? . toggle ( cell : self )
217
225
}
218
226
219
227
@objc private func toggleCollapseAccessibilityAction( ) -> Bool {
220
- didCollapseHandler ? ( self )
228
+ delegate ? . toggle ( cell : self )
221
229
return true
222
230
}
223
231
@@ -255,3 +263,12 @@ class LocationCell: UITableViewCell {
255
263
}
256
264
}
257
265
}
266
+
267
+ extension LocationCell {
268
+ func configureCell( item: LocationCellViewModel ) {
269
+ accessibilityIdentifier = item. node. code
270
+ locationLabel. text = item. node. name
271
+ showsCollapseControl = !item. node. children. isEmpty
272
+ isExpanded = item. node. showsChildren
273
+ }
274
+ }
0 commit comments