updated base with fix

This commit is contained in:
Matt Bruce 2024-06-19 13:28:04 -05:00
parent ac816f07f0
commit ec8d4ba1d6

View File

@ -11,7 +11,7 @@ import Combine
import VDSCoreTokens import VDSCoreTokens
/// Base Class used to build out a SelectorControlable control. /// Base Class used to build out a SelectorControlable control.
open class SelectorItemBase<Selector: SelectorControlable>: Control, Errorable, Changeable, Groupable { open class SelectorItemBase<Selector: SelectorBase>: Control, Errorable, Changeable, Groupable {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializers // MARK: - Initializers
@ -149,8 +149,13 @@ open class SelectorItemBase<Selector: SelectorControlable>: Control, Errorable,
open var accessibilityLabelText: String { open var accessibilityLabelText: String {
var accessibilityLabels = [String]() var accessibilityLabels = [String]()
accessibilityLabels.append("\(Selector.self)")
if isSelected {
accessibilityLabels.append("selected")
}
accessibilityLabels.append("\(Selector.self)")
if let text = labelText, !text.isEmpty { if let text = labelText, !text.isEmpty {
accessibilityLabels.append(text) accessibilityLabels.append(text)
} }
@ -162,7 +167,7 @@ open class SelectorItemBase<Selector: SelectorControlable>: Control, Errorable,
if !isEnabled { if !isEnabled {
accessibilityLabels.append("dimmed") accessibilityLabels.append("dimmed")
} }
if let errorText, showError, !errorText.isEmpty { if let errorText, showError, !errorText.isEmpty {
accessibilityLabels.append("error, \(errorText)") accessibilityLabels.append("error, \(errorText)")
} }
@ -177,8 +182,14 @@ open class SelectorItemBase<Selector: SelectorControlable>: Control, Errorable,
open override func initialSetup() { open override func initialSetup() {
super.initialSetup() super.initialSetup()
onClick = { [weak self] control in onClick = { [weak self] control in
self?.toggle() guard let self, isEnabled else { return }
toggle()
} }
selectorView.accessibilityDefaultAction = { [weak self] in
guard let self, isEnabled else { return }
toggle()
}
} }
/// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations. /// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations.
@ -209,7 +220,6 @@ open class SelectorItemBase<Selector: SelectorControlable>: Control, Errorable,
open override func updateView() { open override func updateView() {
super.updateView() super.updateView()
updateLabels() updateLabels()
selectorView.isUserInteractionEnabled = true
selectorView.showError = showError selectorView.showError = showError
selectorView.isSelected = isSelected selectorView.isSelected = isSelected
selectorView.isHighlighted = isHighlighted selectorView.isHighlighted = isHighlighted
@ -251,14 +261,16 @@ open class SelectorItemBase<Selector: SelectorControlable>: Control, Errorable,
/// Overriden to take the hit if there is an onClickSubscriber and the view is not a UIControl /// Overriden to take the hit if there is an onClickSubscriber and the view is not a UIControl
open override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { open override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
guard isEnabled else { return super.hitTest(point, with: event) }
let labelPoint = convert(point, to: label) let labelPoint = convert(point, to: label)
let childLabelPoint = convert(point, to: childLabel) let childLabelPoint = convert(point, to: childLabel)
if label.isAction(for: labelPoint) { if label.isAction(for: labelPoint) {
return label return label
} else if childLabel.isAction(for: childLabelPoint) { } else if childLabel.isAction(for: childLabelPoint) {
return childLabel return childLabel
} else { } else {
guard !UIAccessibility.isVoiceOverRunning else { return nil }
return super.hitTest(point, with: event) return super.hitTest(point, with: event)
} }
} }