opening diameter for dev

This commit is contained in:
Kevin G Christiano 2020-06-15 11:36:42 -04:00
parent 242ea90981
commit e4384066ae
2 changed files with 33 additions and 9 deletions

View File

@ -19,6 +19,13 @@ open class LoadingSpinner: View {
public var lineWidth: CGFloat = 3.0
public var speed: Float = 1.5
//--------------------------------------------------
// MARK: - Constraints
//--------------------------------------------------
public var heightConstraint: NSLayoutConstraint?
public var widthConstraint: NSLayoutConstraint?
//--------------------------------------------------
// MARK: - Lifecycle
@ -41,8 +48,19 @@ open class LoadingSpinner: View {
layer.speed = speed
let halfWidth = lineWidth / 2
let radius = (bounds.width - lineWidth) / 2
layer.path = UIBezierPath(arcCenter: CGPoint(x: radius + halfWidth, y: radius + halfWidth), radius: radius, startAngle: -CGFloat.pi / 2, endAngle: 2 * CGFloat.pi, clockwise: true).cgPath
layer.path = UIBezierPath(arcCenter: CGPoint(x: radius + halfWidth,
y: radius + halfWidth),
radius: radius,
startAngle: -CGFloat.pi / 2,
endAngle: 2 * CGFloat.pi,
clockwise: true).cgPath
}
public override func reset() {
super.reset()
heightConstraint?.isActive = false
widthConstraint?.isActive = false
}
//--------------------------------------------------
@ -152,14 +170,12 @@ open class LoadingSpinner: View {
layer.removeAllAnimations()
}
func pinWidthAndHeight(radius: CGFloat) {
func pinWidthAndHeight(diameter: CGFloat) {
let diameter: CGFloat = radius * 2 + lineWidth
NSLayoutConstraint.activate([
heightAnchor.constraint(equalToConstant: diameter),
widthAnchor.constraint(equalToConstant: diameter)
])
heightConstraint = heightAnchor.constraint(equalToConstant: diameter + lineWidth)
widthConstraint = widthAnchor.constraint(equalToConstant: diameter + lineWidth)
heightConstraint?.isActive = true
widthConstraint?.isActive = true
}
//--------------------------------------------------
@ -172,6 +188,10 @@ open class LoadingSpinner: View {
strokeColor = model.strokeColor.uiColor
lineWidth = model.lineWidth
if let diameter = model.diameter {
pinWidthAndHeight(diameter: diameter)
}
}
open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {

View File

@ -18,6 +18,7 @@ open class LoadingSpinnerModel: MoleculeModelProtocol {
public static var identifier: String = "loadingSpinner"
public var strokeColor = Color(uiColor: .mvmBlack)
public var lineWidth: CGFloat = 3
public var diameter: CGFloat?
//--------------------------------------------------
// MARK: - Keys
@ -28,6 +29,7 @@ open class LoadingSpinnerModel: MoleculeModelProtocol {
case backgroundColor
case strokeColor
case lineWidth
case diameter
}
//--------------------------------------------------
@ -38,6 +40,7 @@ open class LoadingSpinnerModel: MoleculeModelProtocol {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
diameter = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .diameter)
if let strokeColor = try typeContainer.decodeIfPresent(Color.self, forKey: .strokeColor) {
self.strokeColor = strokeColor
@ -52,6 +55,7 @@ open class LoadingSpinnerModel: MoleculeModelProtocol {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encodeIfPresent(diameter, forKey: .diameter)
try container.encode(strokeColor, forKey: .strokeColor)
try container.encode(lineWidth, forKey: .lineWidth)
}