Skip to content

Commit

Permalink
Refactored out animation part creation into its own method. This shou…
Browse files Browse the repository at this point in the history
…ld resolve the function too long warning.
  • Loading branch information
JobsIsMyHomeboy committed Jul 8, 2019
1 parent d167935 commit fe9cc31
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions Sources/UtiliKit/ActiveLabel/ActiveLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,11 @@ private extension ActiveLabel {
var animations: [CABasicAnimation] = []

for index in 0..<(animationValues.count - 1) {
let animation = CABasicAnimation(keyPath: ActiveLabel.locationKeyPath)
animation.fromValue = animationValues[index]
animation.toValue = animationValues[index + 1]
animation.beginTime = beginTime
animation.duration = animationPartDuration
animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)
let animation = createAnimation(fromValue: animationValues[index],
toValue: animationValues[index + 1],
beginTime: &beginTime,
duration: animationPartDuration)
animations.append(animation)

beginTime = animation.beginTime + animation.duration
}

let group = CAAnimationGroup()
Expand All @@ -373,4 +369,17 @@ private extension ActiveLabel {

return group
}

func createAnimation(fromValue: [NSNumber], toValue: [NSNumber], beginTime: inout Double, duration: Double) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: ActiveLabel.locationKeyPath)
animation.fromValue = fromValue
animation.toValue = toValue
animation.beginTime = beginTime
animation.duration = duration
animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)

beginTime = animation.beginTime + animation.duration

return animation
}
}

0 comments on commit fe9cc31

Please sign in to comment.