Merge branch 'bugfix/wonky_toggle' into 'release/7_6_0'
Wonky toggle See merge request BPHV_MIPS/mvm_core_ui!395
This commit is contained in:
commit
7f9eea3b41
@ -131,8 +131,26 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
||||
private var widthConstraint: NSLayoutConstraint?
|
||||
|
||||
private func constrainKnob() {
|
||||
knobLeadingConstraint?.isActive = !isOn
|
||||
knobTrailingConstraint?.isActive = isOn
|
||||
|
||||
knobLeadingConstraint?.isActive = false
|
||||
knobTrailingConstraint?.isActive = false
|
||||
|
||||
_ = isOn ? constrainKnobOn() : constrainKnobOff()
|
||||
|
||||
knobTrailingConstraint?.isActive = true
|
||||
knobLeadingConstraint?.isActive = true
|
||||
}
|
||||
|
||||
private func constrainKnobOn() {
|
||||
|
||||
knobTrailingConstraint = trailingAnchor.constraint(equalTo: knobView.trailingAnchor, constant: 1)
|
||||
knobLeadingConstraint = knobView.leadingAnchor.constraint(greaterThanOrEqualTo: leadingAnchor)
|
||||
}
|
||||
|
||||
private func constrainKnobOff() {
|
||||
|
||||
knobTrailingConstraint = trailingAnchor.constraint(greaterThanOrEqualTo: knobView.trailingAnchor)
|
||||
knobLeadingConstraint = knobView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 1)
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
@ -189,6 +207,8 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
||||
|
||||
layer.cornerRadius = Self.getContainerHeight() / 2.0
|
||||
knobView.layer.cornerRadius = Self.getKnobHeight() / 2.0
|
||||
|
||||
changeStateNoAnimation(isOn)
|
||||
}
|
||||
|
||||
public override func setupView() {
|
||||
@ -218,9 +238,7 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
||||
knobView.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).isActive = true
|
||||
bottomAnchor.constraint(greaterThanOrEqualTo: knobView.bottomAnchor).isActive = true
|
||||
|
||||
knobTrailingConstraint = trailingAnchor.constraint(equalTo: knobView.trailingAnchor, constant: 1)
|
||||
knobLeadingConstraint = knobView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 1)
|
||||
knobLeadingConstraint?.isActive = true
|
||||
constrainKnobOff()
|
||||
}
|
||||
|
||||
public override func reset() {
|
||||
@ -229,8 +247,6 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
||||
backgroundColor = containerTintColor.off
|
||||
knobView.backgroundColor = knobTintColor.off
|
||||
isAnimated = true
|
||||
isOn = false
|
||||
constrainKnob()
|
||||
didToggleAction = nil
|
||||
shouldToggleAction = { return true }
|
||||
}
|
||||
@ -352,7 +368,8 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
||||
containerTintColor.off = model.offTintColor.uiColor
|
||||
knobTintColor.on = model.onKnobTintColor.uiColor
|
||||
knobTintColor.off = model.offKnobTintColor.uiColor
|
||||
changeStateNoAnimation(model.state)
|
||||
isOn = model.state
|
||||
changeStateNoAnimation(isOn)
|
||||
isAnimated = model.animated
|
||||
isEnabled = model.enabled
|
||||
|
||||
|
||||
@ -8,11 +8,19 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
|
||||
@objcMembers open class LabelToggle: View {
|
||||
public let label = Label.commonLabelB1(true)
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
|
||||
public let label = Label.createLabelBoldBodySmall(true)
|
||||
public let toggle = Toggle()
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - MVMCoreViewProtocol
|
||||
//--------------------------------------------------
|
||||
|
||||
open override func updateView(_ size: CGFloat) {
|
||||
super.updateView(size)
|
||||
label.updateView(size)
|
||||
@ -21,28 +29,26 @@ import UIKit
|
||||
|
||||
open override func setupView() {
|
||||
super.setupView()
|
||||
guard toggle.superview == nil else {
|
||||
return
|
||||
}
|
||||
|
||||
addSubview(label)
|
||||
addSubview(toggle)
|
||||
label.setContentHuggingPriority(UILayoutPriority.required, for: NSLayoutConstraint.Axis.vertical)
|
||||
label.setContentHuggingPriority(.required, for: .vertical)
|
||||
NSLayoutConstraint.pinViews(leftView: label, rightView: toggle, alignTop: false)
|
||||
}
|
||||
|
||||
// MARK:- MoleculeViewProtocol
|
||||
open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
||||
guard let model = model as? LabelToggleModel,
|
||||
let toggleHeight = Toggle.estimatedHeight(with: model.toggle, delegateObject),
|
||||
let labelHeight = Label.estimatedHeight(with: model.label, delegateObject) else { return nil }
|
||||
let labelHeight = Label.estimatedHeight(with: model.label, delegateObject)
|
||||
else { return nil }
|
||||
|
||||
return max(toggleHeight, labelHeight)
|
||||
}
|
||||
|
||||
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||
guard let labelToggleModel = model as? LabelToggleModel else {
|
||||
return
|
||||
}
|
||||
|
||||
guard let labelToggleModel = model as? LabelToggleModel else { return }
|
||||
|
||||
label.set(with: labelToggleModel.label, delegateObject, additionalData)
|
||||
toggle.set(with: labelToggleModel.toggle, delegateObject, additionalData)
|
||||
}
|
||||
@ -52,6 +58,6 @@ import UIKit
|
||||
super.reset()
|
||||
label.reset()
|
||||
toggle.reset()
|
||||
label.styleB1(true)
|
||||
label.styleBoldBodySmall(true)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user