refactored updateAccessibiltyLabel to updateAccessibility
moved down common isEnabled/isSelected down to base classes Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
05543e7c89
commit
ecff7b9686
@ -128,12 +128,23 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
|
|||||||
|
|
||||||
/// Update this view based off of property changes
|
/// Update this view based off of property changes
|
||||||
open func updateView() {
|
open func updateView() {
|
||||||
updateAccessibilityLabel()
|
updateAccessibility()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used to update any Accessibility properties
|
/// 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
|
/// Resets to the Controls default values
|
||||||
|
|||||||
@ -88,19 +88,8 @@ open class SelectorBase: Control, SelectorControlable {
|
|||||||
layoutIfNeeded()
|
layoutIfNeeded()
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func updateAccessibilityLabel() {
|
open override func updateAccessibility() {
|
||||||
|
super.updateAccessibility()
|
||||||
accessibilityValue = isSelected ? "1" : "0"
|
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"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,18 +69,8 @@ open class SelectorGroupHandlerBase<HandlerType: Control>: Control, Changeable {
|
|||||||
selectorViews.forEach{ $0.reset() }
|
selectorViews.forEach{ $0.reset() }
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func updateAccessibilityLabel() {
|
open override func updateAccessibility() {
|
||||||
if isSelected {
|
super.updateAccessibility()
|
||||||
accessibilityTraits.insert(.selected)
|
|
||||||
} else {
|
|
||||||
accessibilityTraits.remove(.selected)
|
|
||||||
}
|
|
||||||
|
|
||||||
if isEnabled {
|
|
||||||
accessibilityTraits.remove(.notEnabled)
|
|
||||||
} else {
|
|
||||||
accessibilityTraits.insert(.notEnabled)
|
|
||||||
}
|
|
||||||
setAccessibilityLabel(for: selectorViews)
|
setAccessibilityLabel(for: selectorViews)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,8 +82,8 @@ open class SelectorGroupSelectedHandlerBase<HandlerType: Control>: SelectorGroup
|
|||||||
return selectorViews.filter { $0.isSelected == true }.first
|
return selectorViews.filter { $0.isSelected == true }.first
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func updateAccessibilityLabel() {
|
open override func updateAccessibility() {
|
||||||
super.updateAccessibilityLabel()
|
super.updateAccessibility()
|
||||||
if let selectedHandler, let value = selectedHandler.accessibilityValue, let label = selectedHandler.accessibilityLabel {
|
if let selectedHandler, let value = selectedHandler.accessibilityValue, let label = selectedHandler.accessibilityLabel {
|
||||||
accessibilityValue = "\(label) \(value)"
|
accessibilityValue = "\(label) \(value)"
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -267,24 +267,12 @@ open class SelectorItemBase<Selector: SelectorControlable>: Control, Errorable,
|
|||||||
selectorView.isHighlighted = isHighlighted
|
selectorView.isHighlighted = isHighlighted
|
||||||
selectorView.disabled = disabled
|
selectorView.disabled = disabled
|
||||||
selectorView.surface = surface
|
selectorView.surface = surface
|
||||||
updateAccessibilityLabel()
|
updateAccessibility()
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func updateAccessibilityLabel() {
|
open override func updateAccessibility() {
|
||||||
|
super.updateAccessibility()
|
||||||
accessibilityValue = isSelected ? "1" : "0"
|
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])
|
setAccessibilityLabel(for: [label, childLabel, errorLabel])
|
||||||
|
|
||||||
accessibilityLabel = "\(isSelected ? "Selected" : "Not Selected"), \(accessibilityLabel ?? "")"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -82,12 +82,16 @@ open class View: UIView, Handlerable, ViewProtocol, Resettable, UserInfoable {
|
|||||||
|
|
||||||
/// Update this view based off of property changes
|
/// Update this view based off of property changes
|
||||||
open func updateView() {
|
open func updateView() {
|
||||||
updateAccessibilityLabel()
|
updateAccessibility()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used to update any Accessibility properties
|
/// 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
|
/// Resets to the Views default values
|
||||||
|
|||||||
@ -158,10 +158,10 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab
|
|||||||
|
|
||||||
open func updateView() {
|
open func updateView() {
|
||||||
updateLabel()
|
updateLabel()
|
||||||
updateAccessibilityLabel()
|
updateAccessibility()
|
||||||
}
|
}
|
||||||
|
|
||||||
open func updateAccessibilityLabel() {
|
open func updateAccessibility() {
|
||||||
if isEnabled {
|
if isEnabled {
|
||||||
accessibilityTraits.remove(.notEnabled)
|
accessibilityTraits.remove(.notEnabled)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -102,11 +102,7 @@ open class Icon: View {
|
|||||||
imageView.image = nil
|
imageView.image = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func updateAccessibilityLabel() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private func getImage(for imageName: String) -> UIImage? {
|
private func getImage(for imageName: String) -> UIImage? {
|
||||||
|
|
||||||
return BundleManager.shared.image(for: imageName)
|
return BundleManager.shared.image(for: imageName)
|
||||||
|
|||||||
@ -156,7 +156,7 @@ open class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable {
|
|||||||
attributedText = mutableText
|
attributedText = mutableText
|
||||||
|
|
||||||
//get accessibility
|
//get accessibility
|
||||||
updateAccessibilityLabel()
|
updateAccessibility()
|
||||||
|
|
||||||
//force a drawText
|
//force a drawText
|
||||||
setNeedsDisplay()
|
setNeedsDisplay()
|
||||||
@ -164,7 +164,7 @@ open class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open func updateAccessibilityLabel() {
|
open func updateAccessibility() {
|
||||||
accessibilityLabel = text
|
accessibilityLabel = text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -243,24 +243,14 @@ open class RadioBoxItem: Control, Changeable {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
open override func updateView() {
|
open override func updateView() {
|
||||||
updateLabels()
|
updateLabels()
|
||||||
updateAccessibilityLabel()
|
updateAccessibility()
|
||||||
setNeedsLayout()
|
setNeedsLayout()
|
||||||
layoutIfNeeded()
|
layoutIfNeeded()
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func updateAccessibilityLabel() {
|
open override func updateAccessibility() {
|
||||||
|
super.updateAccessibility()
|
||||||
accessibilityValue = isSelected ? "1" : "0"
|
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 {
|
if accessibilityLabel == nil {
|
||||||
setAccessibilityLabel(for: [textLabel, subTextLabel, subTextRightLabel])
|
setAccessibilityLabel(for: [textLabel, subTextLabel, subTextRightLabel])
|
||||||
}
|
}
|
||||||
|
|||||||
@ -117,7 +117,7 @@ open class RadioSwatch: Control {
|
|||||||
layer.setNeedsDisplay()
|
layer.setNeedsDisplay()
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func updateAccessibilityLabel() {
|
public override func updateAccessibility() {
|
||||||
accessibilityLabel = text
|
accessibilityLabel = text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -256,7 +256,11 @@ open class Tabs: View {
|
|||||||
tabItem.orientation = orientation
|
tabItem.orientation = orientation
|
||||||
tabItem.surface = surface
|
tabItem.surface = surface
|
||||||
tabItem.indicatorPosition = indicatorPosition
|
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
|
//update the width based on rules
|
||||||
|
|||||||
@ -198,10 +198,6 @@ open class InputField: EntryField, UITextFieldDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func updateAccessibilityLabel() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
open override func updateHelperLabel(){
|
open override func updateHelperLabel(){
|
||||||
//remove first
|
//remove first
|
||||||
helperLabel.removeFromSuperview()
|
helperLabel.removeFromSuperview()
|
||||||
|
|||||||
@ -376,10 +376,10 @@ open class Tilelet: TileContainer {
|
|||||||
updateIcons()
|
updateIcons()
|
||||||
|
|
||||||
layoutIfNeeded()
|
layoutIfNeeded()
|
||||||
updateAccessibilityLabel()
|
updateAccessibility()
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func updateAccessibilityLabel() {
|
open override func updateAccessibility() {
|
||||||
setAccessibilityLabel(for: [badge.label, titleLockup.eyebrowLabel, titleLockup.titleLabel, titleLockup.subTitleLabel])
|
setAccessibilityLabel(for: [badge.label, titleLockup.eyebrowLabel, titleLockup.titleLabel, titleLockup.subTitleLabel])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -237,23 +237,16 @@ open class Toggle: Control, Changeable {
|
|||||||
toggleView.surface = surface
|
toggleView.surface = surface
|
||||||
toggleView.disabled = disabled
|
toggleView.disabled = disabled
|
||||||
toggleView.isOn = isOn
|
toggleView.isOn = isOn
|
||||||
updateAccessibilityLabel()
|
updateAccessibility()
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func updateAccessibilityLabel() {
|
open override func updateAccessibility() {
|
||||||
accessibilityValue = isSelected ? "1" : "0"
|
super.updateAccessibility()
|
||||||
if isSelected {
|
if showText {
|
||||||
accessibilityTraits.insert(.selected)
|
setAccessibilityLabel(for: [label])
|
||||||
} else {
|
} else {
|
||||||
accessibilityTraits.remove(.selected)
|
accessibilityLabel = "Toggle"
|
||||||
}
|
}
|
||||||
|
|
||||||
if isEnabled {
|
|
||||||
accessibilityTraits.remove(.notEnabled)
|
|
||||||
} else {
|
|
||||||
accessibilityTraits.insert(.notEnabled)
|
|
||||||
}
|
|
||||||
setAccessibilityLabel(for: [label])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open override var intrinsicContentSize: CGSize {
|
open override var intrinsicContentSize: CGSize {
|
||||||
|
|||||||
@ -199,23 +199,13 @@ open class ToggleView: Control, Changeable {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
open override func updateView() {
|
open override func updateView() {
|
||||||
updateToggle()
|
updateToggle()
|
||||||
updateAccessibilityLabel()
|
updateAccessibility()
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func updateAccessibilityLabel() {
|
open override func updateAccessibility() {
|
||||||
|
super.updateAccessibility()
|
||||||
accessibilityLabel = "Toggle"
|
accessibilityLabel = "Toggle"
|
||||||
accessibilityValue = isSelected ? "1" : "0"
|
accessibilityValue = isSelected ? "1" : "0"
|
||||||
if isSelected {
|
|
||||||
accessibilityTraits.insert(.selected)
|
|
||||||
} else {
|
|
||||||
accessibilityTraits.remove(.selected)
|
|
||||||
}
|
|
||||||
|
|
||||||
if isEnabled {
|
|
||||||
accessibilityTraits.remove(.notEnabled)
|
|
||||||
} else {
|
|
||||||
accessibilityTraits.insert(.notEnabled)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -167,12 +167,9 @@ open class Tooltip: Control, TooltipLaunchable {
|
|||||||
imageView.image = infoImage.withTintColor(imageColor)
|
imageView.image = infoImage.withTintColor(imageColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func updateAccessibilityLabel() {
|
open override func updateAccessibility() {
|
||||||
if isEnabled {
|
super.updateAccessibility()
|
||||||
accessibilityTraits.remove(.notEnabled)
|
|
||||||
} else {
|
|
||||||
accessibilityTraits.insert(.notEnabled)
|
|
||||||
}
|
|
||||||
var label = title
|
var label = title
|
||||||
if label == nil {
|
if label == nil {
|
||||||
label = content
|
label = content
|
||||||
|
|||||||
@ -299,7 +299,7 @@ open class TooltipDialog: View, UIScrollViewDelegate {
|
|||||||
heightConstraint?.constant = contentHeight
|
heightConstraint?.constant = contentHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func updateAccessibilityLabel() {
|
open override func updateAccessibility() {
|
||||||
var label = Tooltip.accessibleText(for: titleText, content: contentText, closeButtonText: closeButtonText)
|
var label = Tooltip.accessibleText(for: titleText, content: contentText, closeButtonText: closeButtonText)
|
||||||
if !label.isEmpty {
|
if !label.isEmpty {
|
||||||
label += ","
|
label += ","
|
||||||
|
|||||||
@ -12,7 +12,7 @@ public protocol ViewProtocol {
|
|||||||
|
|
||||||
// Can setup ui here. Should be called in the initialization functions.
|
// Can setup ui here. Should be called in the initialization functions.
|
||||||
func setup()
|
func setup()
|
||||||
func updateAccessibilityLabel()
|
func updateAccessibility()
|
||||||
}
|
}
|
||||||
|
|
||||||
extension ViewProtocol where Self: UIView {
|
extension ViewProtocol where Self: UIView {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user