refactored SelectorBase/Checkbox/RadioButton
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
18ab46b1f3
commit
052a6fbe67
@ -58,12 +58,10 @@ open class SelectorBase: Control, SelectorControlable {
|
||||
|
||||
open var selectorColorConfiguration = ControlColorConfiguration() { didSet { setNeedsUpdate() }}
|
||||
|
||||
private var selectorView = View()
|
||||
//--------------------------------------------------
|
||||
// MARK: - Constraints
|
||||
//--------------------------------------------------
|
||||
private var selectorHeightConstraint: NSLayoutConstraint?
|
||||
private var selectorWidthConstraint: NSLayoutConstraint?
|
||||
|
||||
internal var shapeLayer: CAShapeLayer?
|
||||
|
||||
open override func initialSetup() {
|
||||
@ -78,35 +76,14 @@ open class SelectorBase: Control, SelectorControlable {
|
||||
|
||||
isAccessibilityElement = true
|
||||
accessibilityTraits = .button
|
||||
|
||||
let layoutGuide = UILayoutGuide()
|
||||
addLayoutGuide(layoutGuide)
|
||||
|
||||
selectorHeightConstraint = layoutGuide.heightAnchor.constraint(equalToConstant: size.height)
|
||||
selectorHeightConstraint?.isActive = true
|
||||
|
||||
selectorWidthConstraint = layoutGuide.widthAnchor.constraint(equalToConstant: size.width)
|
||||
selectorWidthConstraint?.isActive = true
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
layoutGuide.topAnchor.constraint(equalTo: topAnchor),
|
||||
layoutGuide.bottomAnchor.constraint(equalTo: bottomAnchor),
|
||||
layoutGuide.leadingAnchor.constraint(equalTo: leadingAnchor),
|
||||
layoutGuide.trailingAnchor.constraint(equalTo: trailingAnchor)])
|
||||
|
||||
layer.cornerRadius = 2.0
|
||||
layer.borderWidth = VDSFormControls.widthBorder
|
||||
|
||||
}
|
||||
|
||||
open override var intrinsicContentSize: CGSize { size }
|
||||
|
||||
open func toggle() { }
|
||||
|
||||
open override func updateView() {
|
||||
super.updateView()
|
||||
|
||||
selectorHeightConstraint?.constant = size.height
|
||||
selectorWidthConstraint?.constant = size.width
|
||||
|
||||
setNeedsLayout()
|
||||
layoutIfNeeded()
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ open class Checkbox: SelectorBase {
|
||||
isSelected.toggle()
|
||||
sendActions(for: .valueChanged)
|
||||
}
|
||||
|
||||
|
||||
open override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
|
||||
@ -123,3 +123,12 @@ open class Checkbox: SelectorBase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: AppleGuidlinesTouchable
|
||||
extension Checkbox: AppleGuidlinesTouchable {
|
||||
|
||||
override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
||||
Self.acceptablyOutsideBounds(point: point, bounds: bounds)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -36,6 +36,17 @@ open class RadioButton: SelectorBase {
|
||||
|
||||
}
|
||||
|
||||
open override func toggle() {
|
||||
guard !isSelected else { return }
|
||||
|
||||
//removed error
|
||||
if showError && isSelected == false {
|
||||
showError.toggle()
|
||||
}
|
||||
isSelected.toggle()
|
||||
sendActions(for: .valueChanged)
|
||||
}
|
||||
|
||||
open override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
|
||||
@ -71,3 +82,12 @@ open class RadioButton: SelectorBase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: AppleGuidlinesTouchable
|
||||
extension RadioButton: AppleGuidlinesTouchable {
|
||||
|
||||
override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
||||
Self.acceptablyOutsideBounds(point: point, bounds: bounds)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user