added isAnimated to checkbox
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
48281da2e1
commit
3beacb2a5e
@ -98,7 +98,8 @@ open class CheckboxBase: Control, Accessable, DataTrackable, Errorable {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
}
|
||||
|
||||
//can't bind to @Proxy
|
||||
open var isAnimated: Bool = true { didSet { didChange() }}
|
||||
|
||||
open override var isSelected: Bool { didSet { didChange() }}
|
||||
|
||||
open var labelText: String? { didSet { didChange() }}
|
||||
@ -369,8 +370,6 @@ open class CheckboxBase: Control, Accessable, DataTrackable, Errorable {
|
||||
self.shapeLayer = nil
|
||||
}
|
||||
|
||||
selectorView.backgroundColor = backgroundColor
|
||||
selectorView.layer.borderColor = borderColor.cgColor
|
||||
selectorView.layer.cornerRadius = VDSFormControls.borderradius
|
||||
selectorView.layer.borderWidth = VDSFormControls.widthBorder
|
||||
|
||||
@ -407,5 +406,30 @@ open class CheckboxBase: Control, Accessable, DataTrackable, Errorable {
|
||||
shapeLayer.strokeEnd = isSelected ? 1 : 0
|
||||
}
|
||||
}
|
||||
|
||||
shapeLayer?.removeAllAnimations()
|
||||
|
||||
if isAnimated {
|
||||
let animateStrokeEnd = CABasicAnimation(keyPath: "strokeEnd")
|
||||
animateStrokeEnd.timingFunction = CAMediaTimingFunction(name: .linear)
|
||||
animateStrokeEnd.duration = 0.3
|
||||
animateStrokeEnd.fillMode = .both
|
||||
animateStrokeEnd.isRemovedOnCompletion = false
|
||||
animateStrokeEnd.fromValue = !isSelected ? 1 : 0
|
||||
animateStrokeEnd.toValue = isSelected ? 1 : 0
|
||||
self.shapeLayer?.add(animateStrokeEnd, forKey: "strokeEnd")
|
||||
|
||||
UIView.animate(withDuration: 0.2, delay: 0.1, options: .curveEaseOut, animations: {
|
||||
self.selectorView.backgroundColor = backgroundColor
|
||||
self.selectorView.layer.borderColor = borderColor.cgColor
|
||||
})
|
||||
} else {
|
||||
CATransaction.withDisabledAnimations {
|
||||
self.shapeLayer?.strokeEnd = isSelected ? 1 : 0
|
||||
}
|
||||
|
||||
selectorView.backgroundColor = backgroundColor
|
||||
selectorView.layer.borderColor = borderColor.cgColor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user