fix toggle bugs
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
63543b5cf5
commit
fa39ce82d1
@ -35,17 +35,14 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
required public init() {
|
required public init() {
|
||||||
super.init(frame: .zero)
|
super.init(frame: .zero)
|
||||||
initialSetup()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override init(frame: CGRect) {
|
public override init(frame: CGRect) {
|
||||||
super.init(frame: .zero)
|
super.init(frame: .zero)
|
||||||
initialSetup()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public required init?(coder: NSCoder) {
|
public required init?(coder: NSCoder) {
|
||||||
super.init(coder: coder)
|
super.init(coder: coder)
|
||||||
initialSetup()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -125,17 +122,17 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
open var isOn: Bool = false { didSet { subject.send() }}
|
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() }}
|
open var inputId: String? { didSet { subject.send() }}
|
||||||
|
|
||||||
@ -173,24 +170,23 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Toggle
|
// MARK: - Toggle
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
private func updateToggle() {
|
private func constrainKnob(){
|
||||||
//private func
|
self.knobLeadingConstraint?.isActive = false
|
||||||
func constrainKnob(){
|
self.knobTrailingConstraint?.isActive = false
|
||||||
self.knobLeadingConstraint?.isActive = false
|
if isOn {
|
||||||
self.knobTrailingConstraint?.isActive = false
|
self.knobTrailingConstraint = self.toggleView.trailingAnchor.constraint(equalTo: self.knobView.trailingAnchor, constant: 2)
|
||||||
if isOn {
|
self.knobLeadingConstraint = self.knobView.leadingAnchor.constraint(greaterThanOrEqualTo: self.toggleView.leadingAnchor)
|
||||||
self.knobTrailingConstraint = self.toggleView.trailingAnchor.constraint(equalTo: self.knobView.trailingAnchor, constant: 2)
|
} else {
|
||||||
self.knobLeadingConstraint = self.knobView.leadingAnchor.constraint(greaterThanOrEqualTo: self.toggleView.leadingAnchor)
|
self.knobTrailingConstraint = self.toggleView.trailingAnchor.constraint(greaterThanOrEqualTo: self.knobView.trailingAnchor)
|
||||||
} else {
|
self.knobLeadingConstraint = self.knobView.leadingAnchor.constraint(equalTo: self.toggleView.leadingAnchor, constant: 2)
|
||||||
self.knobTrailingConstraint = self.toggleView.trailingAnchor.constraint(greaterThanOrEqualTo: self.knobView.trailingAnchor)
|
|
||||||
self.knobLeadingConstraint = self.knobView.leadingAnchor.constraint(equalTo: self.toggleView.leadingAnchor, constant: 2)
|
|
||||||
}
|
|
||||||
self.knobTrailingConstraint?.isActive = true
|
|
||||||
self.knobLeadingConstraint?.isActive = true
|
|
||||||
self.knobWidthConstraint?.constant = self.knobSize.width
|
|
||||||
self.layoutIfNeeded()
|
|
||||||
}
|
}
|
||||||
|
self.knobTrailingConstraint?.isActive = true
|
||||||
|
self.knobLeadingConstraint?.isActive = true
|
||||||
|
self.knobWidthConstraint?.constant = self.knobSize.width
|
||||||
|
self.layoutIfNeeded()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func updateToggle() {
|
||||||
let toggleColor = toggleColorConfiguration.getColor(self)
|
let toggleColor = toggleColorConfiguration.getColor(self)
|
||||||
let knobColor = knobColorConfiguration.getColor(self)
|
let knobColor = knobColorConfiguration.getColor(self)
|
||||||
|
|
||||||
@ -204,8 +200,8 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable {
|
|||||||
self.knobView.backgroundColor = knobColor
|
self.knobView.backgroundColor = knobColor
|
||||||
}, completion: nil)
|
}, completion: nil)
|
||||||
|
|
||||||
UIView.animate(withDuration: 0.33, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.5, options: [], animations: {
|
UIView.animate(withDuration: 0.33, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.5, options: [], animations: { [weak self] in
|
||||||
constrainKnob()
|
self?.constrainKnob()
|
||||||
}, completion: nil)
|
}, 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.
|
/// This will toggle the state of the Toggle and execute the actionBlock if provided.
|
||||||
open func toggle() {
|
open func toggle() {
|
||||||
isOn.toggle()
|
isOn.toggle()
|
||||||
|
isSelected = isOn
|
||||||
sendActions(for: .valueChanged)
|
sendActions(for: .valueChanged)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user