Skip to content

Commit d40d160

Browse files
committed
Convert animationDuration to computed property (fixes #196) [swift]
1 parent 3f22ffa commit d40d160

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

Sources/Swift/MarqueeLabel.swift

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,19 @@ open class MarqueeLabel: UILabel, CAAnimationDelegate {
337337
@IBInspectable open var animationDelay: CGFloat = 1.0
338338

339339

340-
/** The read-only duration of the scroll animation (not including delay).
340+
/** The read-only/computed duration of the scroll animation (not including delay).
341341

342-
The value of this property is calculated from the value set to the `speed` property. If a .duration value is
343-
used to set the label animation speed, this value will be equivalent.
342+
The value of this property is calculated from the value set to the `speed` property. If a duration-type speed is
343+
used to set the label animation speed, `animationDuration` will be equivalent to that value.
344344
*/
345-
private(set) public var animationDuration: CGFloat = 0.0
345+
public var animationDuration: CGFloat {
346+
switch self.speed {
347+
case .rate(let rate):
348+
return CGFloat(fabs(self.awayOffset) / rate)
349+
case .duration(let duration):
350+
return duration
351+
}
352+
}
346353

347354
//
348355
// MARK: - Class Functions and Helpers
@@ -607,16 +614,6 @@ open class MarqueeLabel: UILabel, CAAnimationDelegate {
607614

608615
// Label DOES need to scroll
609616

610-
// Recompute the animation duration
611-
animationDuration = {
612-
switch self.speed {
613-
case .rate(let rate):
614-
return CGFloat(fabs(self.awayOffset) / rate)
615-
case .duration(let duration):
616-
return duration
617-
}
618-
}()
619-
620617
// Spacing between primary and second sublabel must be at least equal to leadingBuffer, and at least equal to the fadeLength
621618
let minTrailing = max(max(leadingBuffer, trailingBuffer), fadeLength)
622619

0 commit comments

Comments
 (0)