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() {
|
||||
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,24 +170,23 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Toggle
|
||||
//--------------------------------------------------
|
||||
private func updateToggle() {
|
||||
//private func
|
||||
func constrainKnob(){
|
||||
self.knobLeadingConstraint?.isActive = false
|
||||
self.knobTrailingConstraint?.isActive = false
|
||||
if isOn {
|
||||
self.knobTrailingConstraint = self.toggleView.trailingAnchor.constraint(equalTo: self.knobView.trailingAnchor, constant: 2)
|
||||
self.knobLeadingConstraint = self.knobView.leadingAnchor.constraint(greaterThanOrEqualTo: self.toggleView.leadingAnchor)
|
||||
} else {
|
||||
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()
|
||||
private func constrainKnob(){
|
||||
self.knobLeadingConstraint?.isActive = false
|
||||
self.knobTrailingConstraint?.isActive = false
|
||||
if isOn {
|
||||
self.knobTrailingConstraint = self.toggleView.trailingAnchor.constraint(equalTo: self.knobView.trailingAnchor, constant: 2)
|
||||
self.knobLeadingConstraint = self.knobView.leadingAnchor.constraint(greaterThanOrEqualTo: self.toggleView.leadingAnchor)
|
||||
} else {
|
||||
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()
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user