Merge remote-tracking branch 'origin/develop' into bugfix/CXTDT-82220

This commit is contained in:
Kyle Matthew Hedden 2020-08-06 15:48:44 -04:00
commit af2425e296
2 changed files with 28 additions and 18 deletions

View File

@ -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)

View File

@ -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
}
@ -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
@ -170,20 +193,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)
}
}
}