@@ -81,18 +81,13 @@ open class UKCircularProgress: UIView, UKComponent {
8181 }
8282 }
8383
84- CATransaction . begin ( )
85- CATransaction . setDisableActions ( true )
86-
8784 let progress = self . model. progress ( for: self . currentValue)
8885 self . progressLayer. strokeEnd = progress
8986 if !self . model. isStripesLayerHidden {
9087 self . stripesMaskLayer. strokeStart = self . model. stripedArcStart ( for: progress)
9188 self . stripesMaskLayer. strokeEnd = self . model. stripedArcEnd ( for: progress)
9289 }
9390 self . label. text = self . model. label
94-
95- CATransaction . commit ( )
9691 }
9792
9893 // MARK: - Style
@@ -102,6 +97,7 @@ open class UKCircularProgress: UIView, UKComponent {
10297 Self . Style. progressLayer ( self . progressLayer, model: self . model)
10398 Self . Style. label ( self . label, model: self . model)
10499 Self . Style. stripesLayer ( self . stripesLayer, model: self . model)
100+ Self . Style. stripesMaskLayer ( self . stripesMaskLayer, model: self . model)
105101 }
106102
107103 // MARK: - Update
@@ -110,8 +106,21 @@ open class UKCircularProgress: UIView, UKComponent {
110106 guard self . model != oldModel else { return }
111107 self . style ( )
112108 self . updateShapePaths ( )
113- self . updateProgress ( )
114109
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+ }
115124 if self . model. shouldInvalidateIntrinsicContentSize ( oldModel) {
116125 self . invalidateIntrinsicContentSize ( )
117126 }
@@ -130,15 +139,7 @@ open class UKCircularProgress: UIView, UKComponent {
130139 self . backgroundLayer. path = circlePath. cgPath
131140 self . progressLayer. path = circlePath. cgPath
132141 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
142143 }
143144
144145 private func updateProgress( ) {
@@ -153,20 +154,6 @@ open class UKCircularProgress: UIView, UKComponent {
153154 self . stripesMaskLayer. strokeEnd = self . model. stripedArcEnd ( for: progress)
154155 }
155156 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- }
170157 }
171158
172159 // MARK: - Layout
@@ -202,9 +189,6 @@ open class UKCircularProgress: UIView, UKComponent {
202189 }
203190
204191 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)
208192 Self . Style. backgroundLayer ( self . backgroundLayer, model: self . model)
209193 Self . Style. progressLayer ( self . progressLayer, model: self . model)
210194 Self . Style. stripesLayer ( self . stripesLayer, model: self . model)
@@ -227,14 +211,20 @@ extension UKCircularProgress {
227211 layer. isHidden = model. isBackgroundLayerHidden
228212 }
229213
230- static func progressLayer( _ layer: CAShapeLayer , model: CircularProgressVM ) {
214+ static func progressLayer(
215+ _ layer: CAShapeLayer ,
216+ model: CircularProgressVM
217+ ) {
231218 layer. fillColor = UIColor . clear. cgColor
232219 layer. strokeColor = model. color. main. uiColor. cgColor
233220 layer. lineCap = . round
234221 layer. lineWidth = model. circularLineWidth
235222 }
236223
237- static func label( _ label: UILabel , model: CircularProgressVM ) {
224+ static func label(
225+ _ label: UILabel ,
226+ model: CircularProgressVM
227+ ) {
238228 label. textAlignment = . center
239229 label. adjustsFontSizeToFitWidth = true
240230 label. minimumScaleFactor = 0.5
0 commit comments