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
}
public var accessibilityDefaultAction: (() -> Void)?
public override func accessibilityActivate() -> Bool {
if let accessibilityDefaultAction {
accessibilityDefaultAction()
open override func accessibilityActivate() -> Bool {
guard isEnabled, isUserInteractionEnabled else { return false }
if let accessibilityAction {
accessibilityAction(self)
} else {
toggle()
}
return true
}
}

View File

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

View File

@ -147,6 +147,15 @@ open class SelectorItemBase<Selector: SelectorBase>: Control, Errorable, Changea
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 {
var accessibilityLabels = [String]()
@ -186,7 +195,7 @@ open class SelectorItemBase<Selector: SelectorBase>: Control, Errorable, Changea
toggle()
}
selectorView.accessibilityDefaultAction = { [weak self] in
selectorView.accessibilityAction = { [weak self] _ in
guard let self, isEnabled else { return }
toggle()
}
@ -366,4 +375,15 @@ open class SelectorItemBase<Selector: SelectorBase>: Control, Errorable, Changea
/// This will change to state of the Selector.
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
super.updateView()
}
open override func accessibilityActivate() -> Bool {
sendActions(for: .touchUpInside)
return true
}
}
extension PaginationButton {

View File

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