diff --git a/LoopUI/Views/BasalStateView.swift b/LoopUI/Views/BasalStateView.swift index 16c3c82eff..59332eb91a 100644 --- a/LoopUI/Views/BasalStateView.swift +++ b/LoopUI/Views/BasalStateView.swift @@ -10,6 +10,7 @@ import UIKit public final class BasalStateView: UIView { + var netBasalPercent: Double = 0 { didSet { animateToPath(drawPath()) @@ -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) { @@ -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 { @@ -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 } } diff --git a/LoopUI/Views/LevelMaskView.swift b/LoopUI/Views/LevelMaskView.swift index ef5b4d72f0..ec7840fd71 100644 --- a/LoopUI/Views/LevelMaskView.swift +++ b/LoopUI/Views/LevelMaskView.swift @@ -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 } } @@ -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: TimeInterval) { + UIView.animate(withDuration: duration, delay: 0, options: .beginFromCurrentState, animations: { self.updateFillViewFrame() }, completion: nil) } diff --git a/LoopUI/Views/LoopStateView.swift b/LoopUI/Views/LoopStateView.swift index 2cae4ec3e4..df07365c08 100644 --- a/LoopUI/Views/LoopStateView.swift +++ b/LoopUI/Views/LoopStateView.swift @@ -9,6 +9,8 @@ import UIKit public final class LoopStateView: UIView { + var firstDataUpdate = true + enum Freshness { case fresh case aging @@ -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) @@ -122,6 +124,7 @@ public final class LoopStateView: UIView { shapeLayer.removeAnimation(forKey: type(of: self).AnimationKey) } } + firstDataUpdate = false } } }