added click subscriber and updateAccessibilityLabel

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-03-07 10:54:19 -06:00
parent 16ad138559
commit 58162040d3
13 changed files with 94 additions and 43 deletions

View File

@ -17,6 +17,16 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
//-------------------------------------------------- //--------------------------------------------------
public var subject = PassthroughSubject<Void, Never>() public var subject = PassthroughSubject<Void, Never>()
public var subscribers = Set<AnyCancellable>() public var subscribers = Set<AnyCancellable>()
open var onClickSubscriber: AnyCancellable? {
willSet {
if let onClickSubscriber {
onClickSubscriber.cancel()
}
}
didSet {
enabledHighlight = onClickSubscriber != nil
}
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Properties // MARK: - Properties
@ -103,7 +113,13 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Overrides // MARK: - Overrides
//-------------------------------------------------- //--------------------------------------------------
open func updateView() {} open func updateView() {
updateAccessibilityLabel()
}
open func updateAccessibilityLabel() {
}
open func reset() { open func reset() {
backgroundColor = .clear backgroundColor = .clear

View File

@ -75,7 +75,13 @@ open class View: UIView, Handlerable, ViewProtocol, Resettable, UserInfoable {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Overrides // MARK: - Overrides
//-------------------------------------------------- //--------------------------------------------------
open func updateView() {} open func updateView() {
updateAccessibilityLabel()
}
open func updateAccessibilityLabel() {
}
open func reset() { open func reset() {
backgroundColor = .clear backgroundColor = .clear

View File

@ -143,6 +143,11 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab
open func updateView() { open func updateView() {
updateLabel() updateLabel()
updateAccessibilityLabel()
}
open func updateAccessibilityLabel() {
} }
//-------------------------------------------------- //--------------------------------------------------

View File

@ -19,10 +19,10 @@ public class Checkbox: CheckboxBase{}
public class SoloCheckbox: CheckboxBase{ public class SoloCheckbox: CheckboxBase{
public override func initialSetup() { public override func initialSetup() {
super.initialSetup() super.initialSetup()
publisher(for: .touchUpInside) onClickSubscriber = publisher(for: .touchUpInside)
.sink { control in .sink { control in
control.toggle() control.toggle()
}.store(in: &subscribers) }
} }
} }
@ -289,8 +289,12 @@ open class CheckboxBase: Control, Errorable {
open override func updateView() { open override func updateView() {
updateLabels() updateLabels()
updateSelector() updateSelector()
updateAccessibilityLabel()
} }
open override func updateAccessibilityLabel() {
setAccessibilityLabel(for: [label, childLabel, errorLabel])
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Configuration Properties // MARK: - Configuration Properties

View File

@ -89,6 +89,10 @@ public class Icon: View {
} }
} }
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)

View File

@ -137,11 +137,15 @@ public class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable
//set the attributed text //set the attributed text
attributedText = mutableText attributedText = mutableText
accessibilityLabel = text updateAccessibilityLabel()
} }
} }
} }
open func updateAccessibilityLabel() {
accessibilityLabel = text
}
// MARK: - Private Attributes // MARK: - Private Attributes
private func applyAttributes(_ mutableAttributedString: NSMutableAttributedString) { private func applyAttributes(_ mutableAttributedString: NSMutableAttributedString) {
actions = [] actions = []

View File

@ -19,10 +19,10 @@ public class SoloRadioBox: RadioBoxBase{
public override func initialSetup() { public override func initialSetup() {
super.initialSetup() super.initialSetup()
publisher(for: .touchUpInside) onClickSubscriber = publisher(for: .touchUpInside)
.sink { control in .sink { control in
control.toggle() control.toggle()
}.store(in: &subscribers) }
} }
} }
@ -243,9 +243,13 @@ open class RadioBoxBase: Control{
open override func updateView() { open override func updateView() {
updateLabels() updateLabels()
updateSelector() updateSelector()
updateAccessibilityLabel()
setNeedsDisplay() setNeedsDisplay()
} }
open override func updateAccessibilityLabel() {
setAccessibilityLabel(for: [textLabel, subTextLabel, subTextRightLabel])
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Configuration Properties // MARK: - Configuration Properties

View File

@ -26,10 +26,10 @@ public class RadioButton: RadioButtonBase {
public class SoloRadioButton: RadioButtonBase { public class SoloRadioButton: RadioButtonBase {
public override func initialSetup() { public override func initialSetup() {
super.initialSetup() super.initialSetup()
publisher(for: .touchUpInside) onClickSubscriber = publisher(for: .touchUpInside)
.sink { control in .sink { control in
control.toggle() control.toggle()
}.store(in: &subscribers) }
} }
} }
@ -289,6 +289,11 @@ open class RadioButtonBase: Control, Errorable {
open override func updateView() { open override func updateView() {
updateLabels() updateLabels()
updateSelector() updateSelector()
updateAccessibilityLabel()
}
open override func updateAccessibilityLabel() {
setAccessibilityLabel(for: [label, childLabel])
} }
//-------------------------------------------------- //--------------------------------------------------

View File

@ -23,10 +23,10 @@ public class RadioSwatch: RadioSwatchBase{
public class SolorRadioSwatch: RadioSwatchBase{ public class SolorRadioSwatch: RadioSwatchBase{
public override func initialSetup() { public override func initialSetup() {
super.initialSetup() super.initialSetup()
publisher(for: .touchUpInside) onClickSubscriber = publisher(for: .touchUpInside)
.sink { control in .sink { control in
control.toggle() control.toggle()
}.store(in: &subscribers) }
} }
} }
@ -74,24 +74,6 @@ open class RadioSwatchBase: Control {
open var value: AnyHashable? { didSet { didChange() }} open var value: AnyHashable? { didSet { didChange() }}
open var dataAnalyticsTrack: String? { didSet { didChange() }}
open var dataClickStream: String? { didSet { didChange() }}
open var dataTrack: String? { didSet { didChange() }}
open var accessibilityHintEnabled: String? { didSet { didChange() }}
open var accessibilityHintDisabled: String? { didSet { didChange() }}
open var accessibilityValueEnabled: String? { didSet { didChange() }}
open var accessibilityValueDisabled: String? { didSet { didChange() }}
open var accessibilityLabelEnabled: String? { didSet { didChange() }}
open var accessibilityLabelDisabled: String? { didSet { didChange() }}
//functions //functions
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Lifecycle // MARK: - Lifecycle
@ -130,15 +112,6 @@ open class RadioSwatchBase: Control {
strikethrough = false strikethrough = false
inputId = nil inputId = nil
value = nil value = nil
dataAnalyticsTrack = nil
dataClickStream = nil
dataTrack = nil
accessibilityHintEnabled = nil
accessibilityHintDisabled = nil
accessibilityValueEnabled = nil
accessibilityValueDisabled = nil
accessibilityLabelEnabled = nil
accessibilityLabelDisabled = nil
setNeedsDisplay() setNeedsDisplay()
} }
@ -155,6 +128,10 @@ open class RadioSwatchBase: Control {
layer.setNeedsDisplay() layer.setNeedsDisplay()
} }
public override func updateAccessibilityLabel() {
accessibilityLabel = text
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Configuration Properties // MARK: - Configuration Properties
//-------------------------------------------------- //--------------------------------------------------

View File

@ -197,6 +197,10 @@ public class InputField: EntryField, UITextFieldDelegate {
} }
} }
public override func updateAccessibilityLabel() {
}
open override func updateHelperLabel(){ open override func updateHelperLabel(){
//remove first //remove first
helperLabel.removeFromSuperview() helperLabel.removeFromSuperview()

View File

@ -9,6 +9,7 @@ import Foundation
import Foundation import Foundation
import VDSColorTokens import VDSColorTokens
import UIKit import UIKit
import Combine
@objc(VDSTilelet) @objc(VDSTilelet)
open class Tilelet: TileContainer { open class Tilelet: TileContainer {
@ -61,6 +62,13 @@ open class Tilelet: TileContainer {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Public Properties // MARK: - Public Properties
//-------------------------------------------------- //--------------------------------------------------
open override var onClickSubscriber: AnyCancellable? {
didSet {
isAccessibilityElement = onClickSubscriber != nil
//updateAccessibilityLabel()
}
}
open var titleLockup = TitleLockup().with { open var titleLockup = TitleLockup().with {
let configs = [ let configs = [
TextStyle.DeviceSpacingConfig([.titleSmall, .boldTitleSmall], TextStyle.DeviceSpacingConfig([.titleSmall, .boldTitleSmall],
@ -213,6 +221,7 @@ open class Tilelet: TileContainer {
color = .black color = .black
addContentView(stackView) addContentView(stackView)
accessibilityTraits = .link
accessibilityElements = [badge, titleLockup, descriptiveIcon, directionalIcon] accessibilityElements = [badge, titleLockup, descriptiveIcon, directionalIcon]
//badge //badge
@ -332,9 +341,6 @@ open class Tilelet: TileContainer {
} else { } else {
removeFromSuperview(titleLockupContainerView) removeFromSuperview(titleLockupContainerView)
} }
accessibilityTraits = enabledHighlight ? .link : .staticText
accessibilityLabel = [titleModel?.text, subTitleModel?.text].compactMap({$0}).joined(separator: ", ")
} }
fileprivate func updateIcons() { fileprivate func updateIcons() {
@ -386,6 +392,11 @@ open class Tilelet: TileContainer {
updateIcons() updateIcons()
layoutIfNeeded() layoutIfNeeded()
updateAccessibilityLabel()
}
open override func updateAccessibilityLabel() {
setAccessibilityLabel(for: [badge.label, titleLockup.eyebrowLabel, titleLockup.titleLabel, titleLockup.subTitleLabel])
} }
} }

View File

@ -301,5 +301,10 @@ open class ToggleBase: Control {
open override func updateView() { open override func updateView() {
updateLabel() updateLabel()
updateToggle() updateToggle()
updateAccessibilityLabel()
}
open override func updateAccessibilityLabel() {
setAccessibilityLabel(for: [label])
} }
} }

View File

@ -12,6 +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()
} }
extension ViewProtocol where Self: UIView { extension ViewProtocol where Self: UIView {
@ -22,7 +23,12 @@ extension ViewProtocol where Self: UIView {
} }
} }
public func accessibilityLabel(for views: [UIView]) -> String? { public func combineAccessibilityLabel(for views: [UIView]) -> String? {
return views.compactMap({$0.accessibilityLabel}).joined(separator: " ") let labels = views.map({($0.accessibilityLabel?.isEmpty ?? true) ? nil : $0.accessibilityLabel}).compactMap({$0})
return labels.joined(separator: ", ")
}
public func setAccessibilityLabel(for views: [UIView]) {
accessibilityLabel = combineAccessibilityLabel(for: views)
} }
} }