From bced3600fc3ddb710f3aa5029945fd11fb08367a Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Fri, 24 Jul 2020 12:19:48 -0400 Subject: [PATCH 1/3] adjust wheel animation to remain on CALayer and not hitting main CPU thread on every cycle. --- MVMCoreUI/Atomic/Atoms/Views/Wheel.swift | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Wheel.swift b/MVMCoreUI/Atomic/Atoms/Views/Wheel.swift index da71ea0f..d81af71c 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Wheel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Wheel.swift @@ -11,7 +11,7 @@ import UIKit @objcMembers open class Wheel: View, MVMCoreUIViewConstrainingProtocol { var heightConstraint: NSLayoutConstraint? - var gradientLayer: CALayer? + weak var gradientLayer: CALayer? var graphModel: WheelModel? { return model as? WheelModel } @@ -170,20 +170,9 @@ import UIKit rotation.timingFunction = CAMediaTimingFunction(name: .linear) rotation.fillMode = .both rotation.isRemovedOnCompletion = false + rotation.repeatCount = Float.greatestFiniteMagnitude - //avoid infinity animation take high CPU momery usage when layer is not displayed - rotation.delegate = self - rotation.repeatCount = 1 self.gradientLayer?.add(rotation, forKey: "rotation") }) } } - - -extension Wheel: CAAnimationDelegate { - public func animationDidStop(_ anim: CAAnimation, finished flag: Bool) { - if let object = graphModel { - rotationAnimation(object) - } - } -} From abce7cfca50d3810ee9edfe04b6277155c588201 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 3 Aug 2020 13:53:59 -0400 Subject: [PATCH 2/3] conic gradient --- MVMCoreUI/Atomic/Atoms/Views/Wheel.swift | 27 ++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Wheel.swift b/MVMCoreUI/Atomic/Atoms/Views/Wheel.swift index da71ea0f..430aad94 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Wheel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Wheel.swift @@ -19,8 +19,6 @@ import UIKit // MARK: setup open override func setupView() { super.setupView() - //avoid adding height constraint multiple times - guard heightConstraint == nil else { return } heightConstraint = heightAnchor.constraint(equalToConstant: 0) heightConstraint?.isActive = true widthAnchor.constraint(equalTo: heightAnchor).isActive = true @@ -51,6 +49,31 @@ import UIKit } heightConstraint?.constant = graphObject.diameter + // iOS 12 uses the conic gradient and a mask for simplicity. + if #available(iOS 12, *) { + let gradient = CAGradientLayer() + gradient.type = .conic + gradient.startPoint = CGPoint(x: 0.5, y: 0.5) + gradient.endPoint = CGPoint(x: 0.5, y: 0.0) + gradient.frame = CGRect(x: 0, y: 0, width: graphObject.diameter, height: graphObject.diameter) + gradient.colors = graphObject.colors.map({ (color) -> CGColor in + return color.cgColor + }) + gradientLayer = gradient + layer.addSublayer(gradient) + + let center = CGPoint(x: gradient.bounds.midX, y: gradient.bounds.midY) + let radius = (graphObject.diameter - graphObject.lineWidth) / 2.0 + let path = UIBezierPath(arcCenter: center, radius: radius, startAngle: (3 / 2 * .pi), endAngle: -(1 / 2 * .pi), clockwise: false) + let mask = CAShapeLayer() + mask.fillColor = UIColor.clear.cgColor + mask.strokeColor = UIColor.white.cgColor + mask.lineWidth = graphObject.lineWidth + mask.path = path.cgPath + gradient.mask = mask + return + } + //create circle path let radius = graphObject.diameter / 2.0 From 7ebf729318f8dac042a2cb7c97073d5f28671aff Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 3 Aug 2020 16:31:29 -0400 Subject: [PATCH 3/3] no hugs and opening up space. --- MVMCoreUI/Atomic/Atoms/Views/LeftRightLabelView.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/LeftRightLabelView.swift b/MVMCoreUI/Atomic/Atoms/Views/LeftRightLabelView.swift index 3981152a..aca7113f 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/LeftRightLabelView.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/LeftRightLabelView.swift @@ -6,7 +6,6 @@ // Copyright © 2019 Verizon Wireless. All rights reserved. // -import Foundation @objcMembers open class LeftRightLabelView: View { @@ -111,7 +110,7 @@ import Foundation bottomAnchor.constraint(greaterThanOrEqualTo: leftTextLabel.bottomAnchor).isActive = true - rightTextLabelLeading = rightTextLabel.leadingAnchor.constraint(equalTo: leftTextLabel.trailingAnchor, constant: Padding.Four) + rightTextLabelLeading = rightTextLabel.leadingAnchor.constraint(greaterThanOrEqualTo: leftTextLabel.trailingAnchor, constant: Padding.Four) rightTextLabelLeading?.isActive = true rightTextLabel.topAnchor.constraint(equalTo: topAnchor).isActive = true @@ -133,7 +132,6 @@ import Foundation rightTextWidth.priority = UILayoutPriority(rawValue: 995) rightTextWidth.isActive = true - rightTextLabel.setContentHuggingPriority(.required, for: .horizontal) leftTextLabel.setContentCompressionResistancePriority(.required, for: .vertical) rightTextLabel.setContentCompressionResistancePriority(.required, for: .vertical) rightTextLabel.setContentCompressionResistancePriority(.required, for: .horizontal)