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,11 +128,22 @@ 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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,18 +69,8 @@ open class SelectorGroupHandlerBase<HandlerType: Control>: 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<HandlerType: Control>: 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 {
|
||||
|
||||
@ -267,24 +267,12 @@ open class SelectorItemBase<Selector: SelectorControlable>: 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 ?? "")"
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -103,10 +103,6 @@ open class Icon: View {
|
||||
}
|
||||
}
|
||||
|
||||
public override func updateAccessibilityLabel() {
|
||||
|
||||
}
|
||||
|
||||
private func getImage(for imageName: String) -> UIImage? {
|
||||
|
||||
return BundleManager.shared.image(for: imageName)
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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])
|
||||
}
|
||||
|
||||
@ -117,7 +117,7 @@ open class RadioSwatch: Control {
|
||||
layer.setNeedsDisplay()
|
||||
}
|
||||
|
||||
public override func updateAccessibilityLabel() {
|
||||
public override func updateAccessibility() {
|
||||
accessibilityLabel = text
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -198,10 +198,6 @@ open class InputField: EntryField, UITextFieldDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
public override func updateAccessibilityLabel() {
|
||||
|
||||
}
|
||||
|
||||
open override func updateHelperLabel(){
|
||||
//remove first
|
||||
helperLabel.removeFromSuperview()
|
||||
|
||||
@ -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])
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 += ","
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user