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 lineWidth: CGFloat = 3.0
public var speed: Float = 1.5 public var speed: Float = 1.5
//--------------------------------------------------
// MARK: - Constraints
//--------------------------------------------------
public var heightConstraint: NSLayoutConstraint?
public var widthConstraint: NSLayoutConstraint?
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Lifecycle // MARK: - Lifecycle
@ -41,8 +48,19 @@ open class LoadingSpinner: View {
layer.speed = speed layer.speed = speed
let halfWidth = lineWidth / 2 let halfWidth = lineWidth / 2
let radius = (bounds.width - 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() layer.removeAllAnimations()
} }
func pinWidthAndHeight(radius: CGFloat) { func pinWidthAndHeight(diameter: CGFloat) {
let diameter: CGFloat = radius * 2 + lineWidth heightConstraint = heightAnchor.constraint(equalToConstant: diameter + lineWidth)
widthConstraint = widthAnchor.constraint(equalToConstant: diameter + lineWidth)
NSLayoutConstraint.activate([ heightConstraint?.isActive = true
heightAnchor.constraint(equalToConstant: diameter), widthConstraint?.isActive = true
widthAnchor.constraint(equalToConstant: diameter)
])
} }
//-------------------------------------------------- //--------------------------------------------------
@ -172,6 +188,10 @@ open class LoadingSpinner: View {
strokeColor = model.strokeColor.uiColor strokeColor = model.strokeColor.uiColor
lineWidth = model.lineWidth lineWidth = model.lineWidth
if let diameter = model.diameter {
pinWidthAndHeight(diameter: diameter)
}
} }
open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { 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 static var identifier: String = "loadingSpinner"
public var strokeColor = Color(uiColor: .mvmBlack) public var strokeColor = Color(uiColor: .mvmBlack)
public var lineWidth: CGFloat = 3 public var lineWidth: CGFloat = 3
public var diameter: CGFloat?
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Keys // MARK: - Keys
@ -28,6 +29,7 @@ open class LoadingSpinnerModel: MoleculeModelProtocol {
case backgroundColor case backgroundColor
case strokeColor case strokeColor
case lineWidth case lineWidth
case diameter
} }
//-------------------------------------------------- //--------------------------------------------------
@ -38,6 +40,7 @@ open class LoadingSpinnerModel: MoleculeModelProtocol {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) 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) { if let strokeColor = try typeContainer.decodeIfPresent(Color.self, forKey: .strokeColor) {
self.strokeColor = strokeColor self.strokeColor = strokeColor
@ -52,6 +55,7 @@ open class LoadingSpinnerModel: MoleculeModelProtocol {
var container = encoder.container(keyedBy: CodingKeys.self) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(moleculeName, forKey: .moleculeName) try container.encode(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encodeIfPresent(diameter, forKey: .diameter)
try container.encode(strokeColor, forKey: .strokeColor) try container.encode(strokeColor, forKey: .strokeColor)
try container.encode(lineWidth, forKey: .lineWidth) try container.encode(lineWidth, forKey: .lineWidth)
} }