fix toggle bugs

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-10-20 13:13:38 -05:00
parent 63543b5cf5
commit fa39ce82d1

View File

@ -35,17 +35,14 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable {
//--------------------------------------------------
required public init() {
super.init(frame: .zero)
initialSetup()
}
public override init(frame: CGRect) {
super.init(frame: .zero)
initialSetup()
}
public required init?(coder: NSCoder) {
super.init(coder: coder)
initialSetup()
}
//--------------------------------------------------
@ -125,17 +122,17 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable {
//--------------------------------------------------
open var isOn: Bool = false { didSet { subject.send() }}
public var showText: Bool = false { didSet { subject.send() }}
open var showText: Bool = false { didSet { subject.send() }}
public var onText: String = "On" { didSet { subject.send() }}
open var onText: String = "On" { didSet { subject.send() }}
public var offText: String = "Off" { didSet { subject.send() }}
open var offText: String = "Off" { didSet { subject.send() }}
public var textSize: ToggleTextSize = .small { didSet { subject.send() }}
open var textSize: ToggleTextSize = .small { didSet { subject.send() }}
public var textWeight: ToggleTextWeight = .regular { didSet { subject.send() }}
open var textWeight: ToggleTextWeight = .regular { didSet { subject.send() }}
public var textPosition: ToggleTextPosition = .left { didSet { subject.send() }}
open var textPosition: ToggleTextPosition = .left { didSet { subject.send() }}
open var inputId: String? { didSet { subject.send() }}
@ -173,9 +170,7 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable {
//--------------------------------------------------
// MARK: - Toggle
//--------------------------------------------------
private func updateToggle() {
//private func
func constrainKnob(){
private func constrainKnob(){
self.knobLeadingConstraint?.isActive = false
self.knobTrailingConstraint?.isActive = false
if isOn {
@ -191,6 +186,7 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable {
self.layoutIfNeeded()
}
private func updateToggle() {
let toggleColor = toggleColorConfiguration.getColor(self)
let knobColor = knobColorConfiguration.getColor(self)
@ -204,8 +200,8 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable {
self.knobView.backgroundColor = knobColor
}, completion: nil)
UIView.animate(withDuration: 0.33, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.5, options: [], animations: {
constrainKnob()
UIView.animate(withDuration: 0.33, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.5, options: [], animations: { [weak self] in
self?.constrainKnob()
}, completion: nil)
}
}
@ -304,6 +300,7 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable {
/// This will toggle the state of the Toggle and execute the actionBlock if provided.
open func toggle() {
isOn.toggle()
isSelected = isOn
sendActions(for: .valueChanged)
}