override for accessibility new impl

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-06-19 17:17:46 -05:00
parent a2f7c03b8f
commit 6c4d428984
5 changed files with 68 additions and 20 deletions

View File

@ -135,14 +135,15 @@ open class SelectorBase: Control, SelectorControlable {
onChange = nil onChange = nil
} }
public var accessibilityDefaultAction: (() -> Void)? open override func accessibilityActivate() -> Bool {
guard isEnabled, isUserInteractionEnabled else { return false }
public override func accessibilityActivate() -> Bool {
if let accessibilityDefaultAction { if let accessibilityAction {
accessibilityDefaultAction() accessibilityAction(self)
} else { } else {
toggle() toggle()
} }
return true return true
} }
} }

View File

@ -70,6 +70,13 @@ open class SelectorGroupBase<SelectorItemType: Groupable>: Control, SelectorGrou
self?.didSelect(handler) self?.didSelect(handler)
self?.setNeedsUpdate() self?.setNeedsUpdate()
} }
selector.accessibilityAction = { [weak self] handler in
guard let handler = handler as? SelectorItemType else { return }
self?.didSelect(handler)
self?.setNeedsUpdate()
}
mainStackView.addArrangedSubview(selector) mainStackView.addArrangedSubview(selector)
} }
} }

View File

@ -147,6 +147,15 @@ open class SelectorItemBase<Selector: SelectorBase>: Control, Errorable, Changea
open var accessibilityValueText: String? open var accessibilityValueText: String?
open override var accessibilityDefaultAction: ((Control) -> Void)? {
didSet {
selectorView.accessibilityAction = { [weak self] selectorItemBase in
guard let self else { return }
accessibilityAction?(self)
}
}
}
open var accessibilityLabelText: String { open var accessibilityLabelText: String {
var accessibilityLabels = [String]() var accessibilityLabels = [String]()
@ -186,7 +195,7 @@ open class SelectorItemBase<Selector: SelectorBase>: Control, Errorable, Changea
toggle() toggle()
} }
selectorView.accessibilityDefaultAction = { [weak self] in selectorView.accessibilityAction = { [weak self] _ in
guard let self, isEnabled else { return } guard let self, isEnabled else { return }
toggle() toggle()
} }
@ -366,4 +375,15 @@ open class SelectorItemBase<Selector: SelectorBase>: Control, Errorable, Changea
/// This will change to state of the Selector. /// This will change to state of the Selector.
open func toggle() {} open func toggle() {}
open override func accessibilityActivate() -> Bool {
guard isEnabled, isUserInteractionEnabled else { return false }
if let accessibilityAction {
accessibilityAction(self)
} else {
toggle()
}
return true
}
} }

View File

@ -78,11 +78,6 @@ open class PaginationButton: ButtonBase {
tintColor = color tintColor = color
super.updateView() super.updateView()
} }
open override func accessibilityActivate() -> Bool {
sendActions(for: .touchUpInside)
return true
}
} }
extension PaginationButton { extension PaginationButton {

View File

@ -74,9 +74,7 @@ open class RadioBoxItem: Control, Changeable, FormFieldable, Groupable {
} }
/// Selector for this RadioBox. /// Selector for this RadioBox.
open var selectorView = UIView().with { open var selectorView = View()
$0.translatesAutoresizingMaskIntoConstraints = false
}
/// If provided, the RadioBox text will be rendered. /// If provided, the RadioBox text will be rendered.
open var text: String? { didSet { setNeedsUpdate() } } open var text: String? { didSet { setNeedsUpdate() } }
@ -133,20 +131,33 @@ open class RadioBoxItem: Control, Changeable, FormFieldable, Groupable {
open var accessibilityValueText: String? open var accessibilityValueText: String?
open override var accessibilityAction: ((Control) -> Void)? {
didSet {
selectorView.accessibilityAction = { [weak self] selectorItemBase in
guard let self else { return }
accessibilityAction?(self)
}
}
}
open var accessibilityLabelText: String { open var accessibilityLabelText: String {
var accessibilityLabels = [String]() var accessibilityLabels = [String]()
if isSelected {
accessibilityLabels.append("selected")
}
accessibilityLabels.append("Radiobox") accessibilityLabels.append("Radiobox")
if let text { if let text, !text.isEmpty {
accessibilityLabels.append(text) accessibilityLabels.append(text)
} }
if let text = subText { if let text = subText, !text.isEmpty {
accessibilityLabels.append(text) accessibilityLabels.append(text)
} }
if let text = subTextRight { if let text = subTextRight, !text.isEmpty {
accessibilityLabels.append(text) accessibilityLabels.append(text)
} }
@ -189,6 +200,16 @@ open class RadioBoxItem: Control, Changeable, FormFieldable, Groupable {
onClick = { control in onClick = { control in
control.toggle() control.toggle()
} }
if #available(iOS 17.0, *) {
accessibilityHintBlock = { [weak self] in
return "foo"
}
} else {
// Fallback on earlier versions
}
} }
/// 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.
@ -199,7 +220,7 @@ open class RadioBoxItem: Control, Changeable, FormFieldable, Groupable {
selectorView.isAccessibilityElement = true selectorView.isAccessibilityElement = true
selectorView.accessibilityTraits = .button selectorView.accessibilityTraits = .button
addSubview(selectorView) addSubview(selectorView)
selectorView.isUserInteractionEnabled = false selectorView.isUserInteractionEnabled = true
selectorView.addSubview(selectorStackView) selectorView.addSubview(selectorStackView)
@ -281,7 +302,7 @@ open class RadioBoxItem: Control, Changeable, FormFieldable, Groupable {
: accessibilityValueText : accessibilityValueText
} }
} }
open override var accessibilityElements: [Any]? { open override var accessibilityElements: [Any]? {
get { get {
var items = [Any]() var items = [Any]()
@ -322,7 +343,11 @@ open class RadioBoxItem: Control, Changeable, FormFieldable, Groupable {
return super.hitTest(point, with: event) return super.hitTest(point, with: event)
} }
} }
open func getSelectorView() -> UIView {
selectorView
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Private Methods // MARK: - Private Methods
//-------------------------------------------------- //--------------------------------------------------