@@ -81,18 +81,13 @@ open class UKCircularProgress: UIView, UKComponent {
81
81
}
82
82
}
83
83
84
- CATransaction . begin ( )
85
- CATransaction . setDisableActions ( true )
86
-
87
84
let progress = self . model. progress ( for: self . currentValue)
88
85
self . progressLayer. strokeEnd = progress
89
86
if !self . model. isStripesLayerHidden {
90
87
self . stripesMaskLayer. strokeStart = self . model. stripedArcStart ( for: progress)
91
88
self . stripesMaskLayer. strokeEnd = self . model. stripedArcEnd ( for: progress)
92
89
}
93
90
self . label. text = self . model. label
94
-
95
- CATransaction . commit ( )
96
91
}
97
92
98
93
// MARK: - Style
@@ -102,6 +97,7 @@ open class UKCircularProgress: UIView, UKComponent {
102
97
Self . Style. progressLayer ( self . progressLayer, model: self . model)
103
98
Self . Style. label ( self . label, model: self . model)
104
99
Self . Style. stripesLayer ( self . stripesLayer, model: self . model)
100
+ Self . Style. stripesMaskLayer ( self . stripesMaskLayer, model: self . model)
105
101
}
106
102
107
103
// MARK: - Update
@@ -110,8 +106,21 @@ open class UKCircularProgress: UIView, UKComponent {
110
106
guard self . model != oldModel else { return }
111
107
self . style ( )
112
108
self . updateShapePaths ( )
113
- self . updateProgress ( )
114
109
110
+ if self . model. shouldUpdateText ( oldModel) {
111
+ UIView . transition (
112
+ with: self . label,
113
+ duration: self . model. animationDuration,
114
+ options: . transitionCrossDissolve,
115
+ animations: {
116
+ self . label. text = self . model. label
117
+ } ,
118
+ completion: nil
119
+ )
120
+ }
121
+ if self . model. shouldRecalculateProgress ( oldModel) {
122
+ self . updateProgress ( )
123
+ }
115
124
if self . model. shouldInvalidateIntrinsicContentSize ( oldModel) {
116
125
self . invalidateIntrinsicContentSize ( )
117
126
}
@@ -130,15 +139,7 @@ open class UKCircularProgress: UIView, UKComponent {
130
139
self . backgroundLayer. path = circlePath. cgPath
131
140
self . progressLayer. path = circlePath. cgPath
132
141
self . stripesMaskLayer. path = circlePath. cgPath
133
-
134
- let stripesPath = self . model. stripesBezierPath ( in: self . bounds)
135
- var transform = CGAffineTransform . identity
136
- transform = transform
137
- . translatedBy ( x: center. x, y: center. y)
138
- . rotated ( by: - CGFloat. pi / 2 )
139
- . translatedBy ( x: - center. x, y: - center. y)
140
- stripesPath. apply ( transform)
141
- self . stripesLayer. path = stripesPath. cgPath
142
+ self . stripesLayer. path = self . model. stripesBezierPath ( in: self . bounds) . cgPath
142
143
}
143
144
144
145
private func updateProgress( ) {
@@ -153,20 +154,6 @@ open class UKCircularProgress: UIView, UKComponent {
153
154
self . stripesMaskLayer. strokeEnd = self . model. stripedArcEnd ( for: progress)
154
155
}
155
156
CATransaction . commit ( )
156
-
157
- if let labelText = self . model. label {
158
- UIView . transition (
159
- with: self . label,
160
- duration: self . model. animationDuration,
161
- options: . transitionCrossDissolve,
162
- animations: {
163
- self . label. text = labelText
164
- } ,
165
- completion: nil
166
- )
167
- } else {
168
- self . label. text = nil
169
- }
170
157
}
171
158
172
159
// MARK: - Layout
@@ -202,9 +189,6 @@ open class UKCircularProgress: UIView, UKComponent {
202
189
}
203
190
204
191
private func handleTraitChanges( ) {
205
- Self . Style. backgroundLayer ( self . backgroundLayer, model: self . model)
206
- Self . Style. progressLayer ( self . progressLayer, model: self . model)
207
- Self . Style. label ( self . label, model: self . model)
208
192
Self . Style. backgroundLayer ( self . backgroundLayer, model: self . model)
209
193
Self . Style. progressLayer ( self . progressLayer, model: self . model)
210
194
Self . Style. stripesLayer ( self . stripesLayer, model: self . model)
@@ -227,14 +211,20 @@ extension UKCircularProgress {
227
211
layer. isHidden = model. isBackgroundLayerHidden
228
212
}
229
213
230
- static func progressLayer( _ layer: CAShapeLayer , model: CircularProgressVM ) {
214
+ static func progressLayer(
215
+ _ layer: CAShapeLayer ,
216
+ model: CircularProgressVM
217
+ ) {
231
218
layer. fillColor = UIColor . clear. cgColor
232
219
layer. strokeColor = model. color. main. uiColor. cgColor
233
220
layer. lineCap = . round
234
221
layer. lineWidth = model. circularLineWidth
235
222
}
236
223
237
- static func label( _ label: UILabel , model: CircularProgressVM ) {
224
+ static func label(
225
+ _ label: UILabel ,
226
+ model: CircularProgressVM
227
+ ) {
238
228
label. textAlignment = . center
239
229
label. adjustsFontSizeToFitWidth = true
240
230
label. minimumScaleFactor = 0.5
0 commit comments