Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Disable animation on first render, since we'd be animating from a
default value so the animation is deceptive.
  • Loading branch information
Bharat Mediratta committed Jan 2, 2017
commit 99bf3f8458577ae24ba923edc705078b5a53903a
25 changes: 11 additions & 14 deletions LoopUI/Views/BasalStateView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import UIKit


public final class BasalStateView: UIView {

var netBasalPercent: Double = 0 {
didSet {
animateToPath(drawPath())
Expand All @@ -30,8 +31,6 @@ public final class BasalStateView: UIView {
shapeLayer.lineWidth = 2
shapeLayer.fillColor = UIColor.doseTintColor.withAlphaComponent(0.5).cgColor
shapeLayer.strokeColor = UIColor.doseTintColor.cgColor

shapeLayer.path = drawPath()
}

required public init?(coder aDecoder: NSCoder) {
Expand All @@ -40,14 +39,10 @@ public final class BasalStateView: UIView {
shapeLayer.lineWidth = 2
shapeLayer.fillColor = UIColor.doseTintColor.withAlphaComponent(0.5).cgColor
shapeLayer.strokeColor = UIColor.doseTintColor.cgColor

shapeLayer.path = drawPath()
}

override public func layoutSubviews() {
super.layoutSubviews()

shapeLayer.path = drawPath()
}

private func drawPath() -> CGPath {
Expand Down Expand Up @@ -75,14 +70,16 @@ public final class BasalStateView: UIView {
private static let AnimationKey = "com.loudnate.Naterade.shapePathAnimation"

private func animateToPath(_ path: CGPath) {
let animation = CABasicAnimation(keyPath: "path")
animation.fromValue = shapeLayer.path ?? drawPath()
animation.toValue = path
animation.duration = 1
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)

shapeLayer.add(animation, forKey: type(of: self).AnimationKey)

if shapeLayer.path != nil {
let animation = CABasicAnimation(keyPath: "path")
animation.fromValue = shapeLayer.path ?? drawPath()
animation.toValue = path
animation.duration = 1
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)

shapeLayer.add(animation, forKey: type(of: self).AnimationKey)
}

shapeLayer.path = path
}
}
8 changes: 5 additions & 3 deletions LoopUI/Views/LevelMaskView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import UIKit
// Inspired by https://github.com/carekit-apple/CareKit/blob/master/CareKit/CareCard/OCKHeartView.h

public class LevelMaskView: UIView {
var firstDataUpdate = true

var value: Double = 1.0 {
didSet {
animateFill()
animateFill(duration: firstDataUpdate ? 0 : 1.25)
firstDataUpdate = false
}
}

Expand Down Expand Up @@ -66,8 +68,8 @@ public class LevelMaskView: UIView {
fillView?.backgroundColor = tintColor
}

private func animateFill() {
UIView.animate(withDuration: 1.25, delay: 0, options: .beginFromCurrentState, animations: {
private func animateFill(duration: Double) {
UIView.animate(withDuration: duration, delay: 0, options: .beginFromCurrentState, animations: {
self.updateFillViewFrame()
}, completion: nil)
}
Expand Down
5 changes: 4 additions & 1 deletion LoopUI/Views/LoopStateView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import UIKit

public final class LoopStateView: UIView {
var firstDataUpdate = true

enum Freshness {
case fresh
case aging
Expand Down Expand Up @@ -112,7 +114,7 @@ public final class LoopStateView: UIView {

let group = CAAnimationGroup()
group.animations = [path, width]
group.duration = 1
group.duration = firstDataUpdate ? 0 : 1
group.repeatCount = HUGE
group.autoreverses = true
group.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
Expand All @@ -122,6 +124,7 @@ public final class LoopStateView: UIView {
shapeLayer.removeAnimation(forKey: type(of: self).AnimationKey)
}
}
firstDataUpdate = false
}
}
}
Expand Down