refactored SelectorBase/Checkbox/RadioButton

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-07-18 16:46:16 -05:00
parent 18ab46b1f3
commit 052a6fbe67
3 changed files with 33 additions and 27 deletions

View File

@ -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()
}

View File

@ -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)
}
}

View File

@ -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)
}
}