From ecff7b968636da1f999e32ef6e1ebc1d8df8665c Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 1 Aug 2023 10:23:24 -0500 Subject: [PATCH] refactored updateAccessibiltyLabel to updateAccessibility moved down common isEnabled/isSelected down to base classes Signed-off-by: Matt Bruce --- VDS/Classes/Control.swift | 15 +++++++++++++-- VDS/Classes/SelectorBase.swift | 15 ++------------- VDS/Classes/SelectorGroupHandlerBase.swift | 18 ++++-------------- VDS/Classes/SelectorItemBase.swift | 18 +++--------------- VDS/Classes/View.swift | 10 +++++++--- .../Buttons/Button/ButtonBase.swift | 4 ++-- VDS/Components/Icon/Icon.swift | 4 ---- VDS/Components/Label/Label.swift | 4 ++-- VDS/Components/RadioBox/RadioBoxItem.swift | 16 +++------------- VDS/Components/RadioSwatch/RadioSwatch.swift | 2 +- VDS/Components/Tabs/Tabs.swift | 6 +++++- .../TextFields/InputField/InputField.swift | 4 ---- VDS/Components/Tilelet/Tilelet.swift | 4 ++-- VDS/Components/Toggle/Toggle.swift | 19 ++++++------------- VDS/Components/Toggle/ToggleView.swift | 16 +++------------- VDS/Components/Tooltip/Tooltip.swift | 9 +++------ .../Tooltip/TooltipAlertViewController.swift | 2 +- VDS/Protocols/ViewProtocol.swift | 2 +- 18 files changed, 58 insertions(+), 110 deletions(-) diff --git a/VDS/Classes/Control.swift b/VDS/Classes/Control.swift index cf1a9100..6920ac48 100644 --- a/VDS/Classes/Control.swift +++ b/VDS/Classes/Control.swift @@ -128,12 +128,23 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab /// Update this view based off of property changes open func updateView() { - updateAccessibilityLabel() + updateAccessibility() } /// Used to update any Accessibility properties - open func updateAccessibilityLabel() { + open func updateAccessibility() { + if isSelected { + accessibilityTraits.insert(.selected) + } else { + accessibilityTraits.remove(.selected) + } + if isEnabled { + accessibilityTraits.remove(.notEnabled) + } else { + accessibilityTraits.insert(.notEnabled) + } + } /// Resets to the Controls default values diff --git a/VDS/Classes/SelectorBase.swift b/VDS/Classes/SelectorBase.swift index ffd94ccd..bf66a5c3 100644 --- a/VDS/Classes/SelectorBase.swift +++ b/VDS/Classes/SelectorBase.swift @@ -88,19 +88,8 @@ open class SelectorBase: Control, SelectorControlable { layoutIfNeeded() } - open override func updateAccessibilityLabel() { + open override func updateAccessibility() { + super.updateAccessibility() accessibilityValue = isSelected ? "1" : "0" - if isSelected { - accessibilityTraits.insert(.selected) - } else { - accessibilityTraits.remove(.selected) - } - - if isEnabled { - accessibilityTraits.remove(.notEnabled) - } else { - accessibilityTraits.insert(.notEnabled) - } - accessibilityLabel = isSelected ? "Selected" : "Not Selected" } } diff --git a/VDS/Classes/SelectorGroupHandlerBase.swift b/VDS/Classes/SelectorGroupHandlerBase.swift index d5669538..2575ca2e 100644 --- a/VDS/Classes/SelectorGroupHandlerBase.swift +++ b/VDS/Classes/SelectorGroupHandlerBase.swift @@ -69,18 +69,8 @@ open class SelectorGroupHandlerBase: Control, Changeable { selectorViews.forEach{ $0.reset() } } - open override func updateAccessibilityLabel() { - if isSelected { - accessibilityTraits.insert(.selected) - } else { - accessibilityTraits.remove(.selected) - } - - if isEnabled { - accessibilityTraits.remove(.notEnabled) - } else { - accessibilityTraits.insert(.notEnabled) - } + open override func updateAccessibility() { + super.updateAccessibility() setAccessibilityLabel(for: selectorViews) } } @@ -92,8 +82,8 @@ open class SelectorGroupSelectedHandlerBase: SelectorGroup return selectorViews.filter { $0.isSelected == true }.first } - open override func updateAccessibilityLabel() { - super.updateAccessibilityLabel() + open override func updateAccessibility() { + super.updateAccessibility() if let selectedHandler, let value = selectedHandler.accessibilityValue, let label = selectedHandler.accessibilityLabel { accessibilityValue = "\(label) \(value)" } else { diff --git a/VDS/Classes/SelectorItemBase.swift b/VDS/Classes/SelectorItemBase.swift index c98102fd..fec3eacd 100644 --- a/VDS/Classes/SelectorItemBase.swift +++ b/VDS/Classes/SelectorItemBase.swift @@ -267,24 +267,12 @@ open class SelectorItemBase: Control, Errorable, selectorView.isHighlighted = isHighlighted selectorView.disabled = disabled selectorView.surface = surface - updateAccessibilityLabel() + updateAccessibility() } - open override func updateAccessibilityLabel() { + open override func updateAccessibility() { + super.updateAccessibility() accessibilityValue = isSelected ? "1" : "0" - if isSelected { - accessibilityTraits.insert(.selected) - } else { - accessibilityTraits.remove(.selected) - } - - if isEnabled { - accessibilityTraits.remove(.notEnabled) - } else { - accessibilityTraits.insert(.notEnabled) - } setAccessibilityLabel(for: [label, childLabel, errorLabel]) - - accessibilityLabel = "\(isSelected ? "Selected" : "Not Selected"), \(accessibilityLabel ?? "")" } } diff --git a/VDS/Classes/View.swift b/VDS/Classes/View.swift index b130b56a..199fadcb 100644 --- a/VDS/Classes/View.swift +++ b/VDS/Classes/View.swift @@ -82,12 +82,16 @@ open class View: UIView, Handlerable, ViewProtocol, Resettable, UserInfoable { /// Update this view based off of property changes open func updateView() { - updateAccessibilityLabel() + updateAccessibility() } /// Used to update any Accessibility properties - open func updateAccessibilityLabel() { - + open func updateAccessibility() { + if isEnabled { + accessibilityTraits.remove(.notEnabled) + } else { + accessibilityTraits.insert(.notEnabled) + } } /// Resets to the Views default values diff --git a/VDS/Components/Buttons/Button/ButtonBase.swift b/VDS/Components/Buttons/Button/ButtonBase.swift index ea01479d..637fceb3 100644 --- a/VDS/Components/Buttons/Button/ButtonBase.swift +++ b/VDS/Components/Buttons/Button/ButtonBase.swift @@ -158,10 +158,10 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab open func updateView() { updateLabel() - updateAccessibilityLabel() + updateAccessibility() } - open func updateAccessibilityLabel() { + open func updateAccessibility() { if isEnabled { accessibilityTraits.remove(.notEnabled) } else { diff --git a/VDS/Components/Icon/Icon.swift b/VDS/Components/Icon/Icon.swift index b1cb3c0b..58a712fb 100644 --- a/VDS/Components/Icon/Icon.swift +++ b/VDS/Components/Icon/Icon.swift @@ -102,11 +102,7 @@ open class Icon: View { imageView.image = nil } } - - public override func updateAccessibilityLabel() { - } - private func getImage(for imageName: String) -> UIImage? { return BundleManager.shared.image(for: imageName) diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index 733d858b..b4e77888 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -156,7 +156,7 @@ open class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable { attributedText = mutableText //get accessibility - updateAccessibilityLabel() + updateAccessibility() //force a drawText setNeedsDisplay() @@ -164,7 +164,7 @@ open class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable { } } - open func updateAccessibilityLabel() { + open func updateAccessibility() { accessibilityLabel = text } diff --git a/VDS/Components/RadioBox/RadioBoxItem.swift b/VDS/Components/RadioBox/RadioBoxItem.swift index 9f674099..db3e03e8 100644 --- a/VDS/Components/RadioBox/RadioBoxItem.swift +++ b/VDS/Components/RadioBox/RadioBoxItem.swift @@ -243,24 +243,14 @@ open class RadioBoxItem: Control, Changeable { //-------------------------------------------------- open override func updateView() { updateLabels() - updateAccessibilityLabel() + updateAccessibility() setNeedsLayout() layoutIfNeeded() } - open override func updateAccessibilityLabel() { + open override func updateAccessibility() { + super.updateAccessibility() accessibilityValue = isSelected ? "1" : "0" - if isSelected { - accessibilityTraits.insert(.selected) - } else { - accessibilityTraits.remove(.selected) - } - - if isEnabled { - accessibilityTraits.remove(.notEnabled) - } else { - accessibilityTraits.insert(.notEnabled) - } if accessibilityLabel == nil { setAccessibilityLabel(for: [textLabel, subTextLabel, subTextRightLabel]) } diff --git a/VDS/Components/RadioSwatch/RadioSwatch.swift b/VDS/Components/RadioSwatch/RadioSwatch.swift index 465aef71..f6651bdd 100644 --- a/VDS/Components/RadioSwatch/RadioSwatch.swift +++ b/VDS/Components/RadioSwatch/RadioSwatch.swift @@ -117,7 +117,7 @@ open class RadioSwatch: Control { layer.setNeedsDisplay() } - public override func updateAccessibilityLabel() { + public override func updateAccessibility() { accessibilityLabel = text } diff --git a/VDS/Components/Tabs/Tabs.swift b/VDS/Components/Tabs/Tabs.swift index 6728700b..5c7cda8c 100644 --- a/VDS/Components/Tabs/Tabs.swift +++ b/VDS/Components/Tabs/Tabs.swift @@ -256,7 +256,11 @@ open class Tabs: View { tabItem.orientation = orientation tabItem.surface = surface tabItem.indicatorPosition = indicatorPosition - tabItem.accessibilityLabel = "\(tabItem.text) \(tabItem.selected ? "selected" : "unselected") \(index+1) of \(tabViews.count)" + tabItem.isAccessibilityElement = true + tabItem.accessibilityLabel = tabItem.text + tabItem.accessibilityHint = "Tab Item" + tabItem.accessibilityTraits = tabItem.selected ? [.button, .selected] : .button + tabItem.accessibilityValue = "\(index+1) of \(tabViews.count) Tabs" } //update the width based on rules diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index 6b25c7e1..8ee35f0e 100644 --- a/VDS/Components/TextFields/InputField/InputField.swift +++ b/VDS/Components/TextFields/InputField/InputField.swift @@ -198,10 +198,6 @@ open class InputField: EntryField, UITextFieldDelegate { } } - public override func updateAccessibilityLabel() { - - } - open override func updateHelperLabel(){ //remove first helperLabel.removeFromSuperview() diff --git a/VDS/Components/Tilelet/Tilelet.swift b/VDS/Components/Tilelet/Tilelet.swift index 9cc2e938..80c66ea0 100644 --- a/VDS/Components/Tilelet/Tilelet.swift +++ b/VDS/Components/Tilelet/Tilelet.swift @@ -376,10 +376,10 @@ open class Tilelet: TileContainer { updateIcons() layoutIfNeeded() - updateAccessibilityLabel() + updateAccessibility() } - open override func updateAccessibilityLabel() { + open override func updateAccessibility() { setAccessibilityLabel(for: [badge.label, titleLockup.eyebrowLabel, titleLockup.titleLabel, titleLockup.subTitleLabel]) } } diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index 30459205..e7b50206 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -237,23 +237,16 @@ open class Toggle: Control, Changeable { toggleView.surface = surface toggleView.disabled = disabled toggleView.isOn = isOn - updateAccessibilityLabel() + updateAccessibility() } - open override func updateAccessibilityLabel() { - accessibilityValue = isSelected ? "1" : "0" - if isSelected { - accessibilityTraits.insert(.selected) + open override func updateAccessibility() { + super.updateAccessibility() + if showText { + setAccessibilityLabel(for: [label]) } else { - accessibilityTraits.remove(.selected) + accessibilityLabel = "Toggle" } - - if isEnabled { - accessibilityTraits.remove(.notEnabled) - } else { - accessibilityTraits.insert(.notEnabled) - } - setAccessibilityLabel(for: [label]) } open override var intrinsicContentSize: CGSize { diff --git a/VDS/Components/Toggle/ToggleView.swift b/VDS/Components/Toggle/ToggleView.swift index 1608bb6c..8bc5e03f 100644 --- a/VDS/Components/Toggle/ToggleView.swift +++ b/VDS/Components/Toggle/ToggleView.swift @@ -199,23 +199,13 @@ open class ToggleView: Control, Changeable { //-------------------------------------------------- open override func updateView() { updateToggle() - updateAccessibilityLabel() + updateAccessibility() } - open override func updateAccessibilityLabel() { + open override func updateAccessibility() { + super.updateAccessibility() accessibilityLabel = "Toggle" accessibilityValue = isSelected ? "1" : "0" - if isSelected { - accessibilityTraits.insert(.selected) - } else { - accessibilityTraits.remove(.selected) - } - - if isEnabled { - accessibilityTraits.remove(.notEnabled) - } else { - accessibilityTraits.insert(.notEnabled) - } } } diff --git a/VDS/Components/Tooltip/Tooltip.swift b/VDS/Components/Tooltip/Tooltip.swift index 6d88fca2..c777ee02 100644 --- a/VDS/Components/Tooltip/Tooltip.swift +++ b/VDS/Components/Tooltip/Tooltip.swift @@ -167,12 +167,9 @@ open class Tooltip: Control, TooltipLaunchable { imageView.image = infoImage.withTintColor(imageColor) } - open override func updateAccessibilityLabel() { - if isEnabled { - accessibilityTraits.remove(.notEnabled) - } else { - accessibilityTraits.insert(.notEnabled) - } + open override func updateAccessibility() { + super.updateAccessibility() + var label = title if label == nil { label = content diff --git a/VDS/Components/Tooltip/TooltipAlertViewController.swift b/VDS/Components/Tooltip/TooltipAlertViewController.swift index da461287..cff2bdc2 100644 --- a/VDS/Components/Tooltip/TooltipAlertViewController.swift +++ b/VDS/Components/Tooltip/TooltipAlertViewController.swift @@ -299,7 +299,7 @@ open class TooltipDialog: View, UIScrollViewDelegate { heightConstraint?.constant = contentHeight } - open override func updateAccessibilityLabel() { + open override func updateAccessibility() { var label = Tooltip.accessibleText(for: titleText, content: contentText, closeButtonText: closeButtonText) if !label.isEmpty { label += "," diff --git a/VDS/Protocols/ViewProtocol.swift b/VDS/Protocols/ViewProtocol.swift index a73b83c5..63517b35 100644 --- a/VDS/Protocols/ViewProtocol.swift +++ b/VDS/Protocols/ViewProtocol.swift @@ -12,7 +12,7 @@ public protocol ViewProtocol { // Can setup ui here. Should be called in the initialization functions. func setup() - func updateAccessibilityLabel() + func updateAccessibility() } extension ViewProtocol where Self: UIView {