From 58162040d39f898884fa972b27d85b1f84ac3ef3 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 7 Mar 2023 10:54:19 -0600 Subject: [PATCH] added click subscriber and updateAccessibilityLabel Signed-off-by: Matt Bruce --- VDS/Classes/Control.swift | 18 +++++++++- VDS/Classes/View.swift | 8 ++++- .../Buttons/Button/ButtonBase.swift | 5 +++ VDS/Components/Checkbox/Checkbox.swift | 8 +++-- VDS/Components/Icon/Icon.swift | 4 +++ VDS/Components/Label/Label.swift | 6 +++- VDS/Components/RadioBox/RadioBox.swift | 8 +++-- VDS/Components/RadioButton/RadioButton.swift | 9 +++-- VDS/Components/RadioSwatch/RadioSwatch.swift | 35 ++++--------------- .../TextFields/InputField/InputField.swift | 4 +++ VDS/Components/Tilelet/Tilelet.swift | 17 +++++++-- VDS/Components/Toggle/Toggle.swift | 5 +++ VDS/Protocols/ViewProtocol.swift | 10 ++++-- 13 files changed, 94 insertions(+), 43 deletions(-) diff --git a/VDS/Classes/Control.swift b/VDS/Classes/Control.swift index 4da338c3..9c8da789 100644 --- a/VDS/Classes/Control.swift +++ b/VDS/Classes/Control.swift @@ -17,6 +17,16 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab //-------------------------------------------------- public var subject = PassthroughSubject() public var subscribers = Set() + open var onClickSubscriber: AnyCancellable? { + willSet { + if let onClickSubscriber { + onClickSubscriber.cancel() + } + } + didSet { + enabledHighlight = onClickSubscriber != nil + } + } //-------------------------------------------------- // MARK: - Properties @@ -103,7 +113,13 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- - open func updateView() {} + open func updateView() { + updateAccessibilityLabel() + } + + open func updateAccessibilityLabel() { + + } open func reset() { backgroundColor = .clear diff --git a/VDS/Classes/View.swift b/VDS/Classes/View.swift index c00a5887..c48ff108 100644 --- a/VDS/Classes/View.swift +++ b/VDS/Classes/View.swift @@ -75,7 +75,13 @@ open class View: UIView, Handlerable, ViewProtocol, Resettable, UserInfoable { //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- - open func updateView() {} + open func updateView() { + updateAccessibilityLabel() + } + + open func updateAccessibilityLabel() { + + } open func reset() { backgroundColor = .clear diff --git a/VDS/Components/Buttons/Button/ButtonBase.swift b/VDS/Components/Buttons/Button/ButtonBase.swift index 4eeec6ee..3ced2661 100644 --- a/VDS/Components/Buttons/Button/ButtonBase.swift +++ b/VDS/Components/Buttons/Button/ButtonBase.swift @@ -143,6 +143,11 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab open func updateView() { updateLabel() + updateAccessibilityLabel() + } + + open func updateAccessibilityLabel() { + } //-------------------------------------------------- diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index 564a70a8..fc78cb7f 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -19,10 +19,10 @@ public class Checkbox: CheckboxBase{} public class SoloCheckbox: CheckboxBase{ public override func initialSetup() { super.initialSetup() - publisher(for: .touchUpInside) + onClickSubscriber = publisher(for: .touchUpInside) .sink { control in control.toggle() - }.store(in: &subscribers) + } } } @@ -289,8 +289,12 @@ open class CheckboxBase: Control, Errorable { open override func updateView() { updateLabels() updateSelector() + updateAccessibilityLabel() } + open override func updateAccessibilityLabel() { + setAccessibilityLabel(for: [label, childLabel, errorLabel]) + } //-------------------------------------------------- // MARK: - Configuration Properties diff --git a/VDS/Components/Icon/Icon.swift b/VDS/Components/Icon/Icon.swift index e988d27a..04ba9875 100644 --- a/VDS/Components/Icon/Icon.swift +++ b/VDS/Components/Icon/Icon.swift @@ -89,6 +89,10 @@ public class Icon: View { } } + 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 07680837..5f347634 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -137,11 +137,15 @@ public class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable //set the attributed text attributedText = mutableText - accessibilityLabel = text + updateAccessibilityLabel() } } } + open func updateAccessibilityLabel() { + accessibilityLabel = text + } + // MARK: - Private Attributes private func applyAttributes(_ mutableAttributedString: NSMutableAttributedString) { actions = [] diff --git a/VDS/Components/RadioBox/RadioBox.swift b/VDS/Components/RadioBox/RadioBox.swift index fcc13a2b..b655b03b 100644 --- a/VDS/Components/RadioBox/RadioBox.swift +++ b/VDS/Components/RadioBox/RadioBox.swift @@ -19,10 +19,10 @@ public class SoloRadioBox: RadioBoxBase{ public override func initialSetup() { super.initialSetup() - publisher(for: .touchUpInside) + onClickSubscriber = publisher(for: .touchUpInside) .sink { control in control.toggle() - }.store(in: &subscribers) + } } } @@ -243,9 +243,13 @@ open class RadioBoxBase: Control{ open override func updateView() { updateLabels() updateSelector() + updateAccessibilityLabel() setNeedsDisplay() } + open override func updateAccessibilityLabel() { + setAccessibilityLabel(for: [textLabel, subTextLabel, subTextRightLabel]) + } //-------------------------------------------------- // MARK: - Configuration Properties diff --git a/VDS/Components/RadioButton/RadioButton.swift b/VDS/Components/RadioButton/RadioButton.swift index 9d7d6c44..a8938ad6 100644 --- a/VDS/Components/RadioButton/RadioButton.swift +++ b/VDS/Components/RadioButton/RadioButton.swift @@ -26,10 +26,10 @@ public class RadioButton: RadioButtonBase { public class SoloRadioButton: RadioButtonBase { public override func initialSetup() { super.initialSetup() - publisher(for: .touchUpInside) + onClickSubscriber = publisher(for: .touchUpInside) .sink { control in control.toggle() - }.store(in: &subscribers) + } } } @@ -289,6 +289,11 @@ open class RadioButtonBase: Control, Errorable { open override func updateView() { updateLabels() updateSelector() + updateAccessibilityLabel() + } + + open override func updateAccessibilityLabel() { + setAccessibilityLabel(for: [label, childLabel]) } //-------------------------------------------------- diff --git a/VDS/Components/RadioSwatch/RadioSwatch.swift b/VDS/Components/RadioSwatch/RadioSwatch.swift index 7da64e22..105e0dea 100644 --- a/VDS/Components/RadioSwatch/RadioSwatch.swift +++ b/VDS/Components/RadioSwatch/RadioSwatch.swift @@ -23,10 +23,10 @@ public class RadioSwatch: RadioSwatchBase{ public class SolorRadioSwatch: RadioSwatchBase{ public override func initialSetup() { super.initialSetup() - publisher(for: .touchUpInside) + onClickSubscriber = publisher(for: .touchUpInside) .sink { control in control.toggle() - }.store(in: &subscribers) + } } } @@ -74,24 +74,6 @@ open class RadioSwatchBase: Control { 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 //-------------------------------------------------- // MARK: - Lifecycle @@ -130,15 +112,6 @@ open class RadioSwatchBase: Control { strikethrough = false inputId = nil value = nil - dataAnalyticsTrack = nil - dataClickStream = nil - dataTrack = nil - accessibilityHintEnabled = nil - accessibilityHintDisabled = nil - accessibilityValueEnabled = nil - accessibilityValueDisabled = nil - accessibilityLabelEnabled = nil - accessibilityLabelDisabled = nil setNeedsDisplay() } @@ -155,6 +128,10 @@ open class RadioSwatchBase: Control { layer.setNeedsDisplay() } + public override func updateAccessibilityLabel() { + accessibilityLabel = text + } + //-------------------------------------------------- // MARK: - Configuration Properties //-------------------------------------------------- diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index ea2f3d87..80c765ab 100644 --- a/VDS/Components/TextFields/InputField/InputField.swift +++ b/VDS/Components/TextFields/InputField/InputField.swift @@ -197,6 +197,10 @@ public 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 1b157184..f6daedc8 100644 --- a/VDS/Components/Tilelet/Tilelet.swift +++ b/VDS/Components/Tilelet/Tilelet.swift @@ -9,6 +9,7 @@ import Foundation import Foundation import VDSColorTokens import UIKit +import Combine @objc(VDSTilelet) open class Tilelet: TileContainer { @@ -61,6 +62,13 @@ open class Tilelet: TileContainer { //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- + open override var onClickSubscriber: AnyCancellable? { + didSet { + isAccessibilityElement = onClickSubscriber != nil + //updateAccessibilityLabel() + } + } + open var titleLockup = TitleLockup().with { let configs = [ TextStyle.DeviceSpacingConfig([.titleSmall, .boldTitleSmall], @@ -213,6 +221,7 @@ open class Tilelet: TileContainer { color = .black addContentView(stackView) + accessibilityTraits = .link accessibilityElements = [badge, titleLockup, descriptiveIcon, directionalIcon] //badge @@ -332,9 +341,6 @@ open class Tilelet: TileContainer { } else { removeFromSuperview(titleLockupContainerView) } - - accessibilityTraits = enabledHighlight ? .link : .staticText - accessibilityLabel = [titleModel?.text, subTitleModel?.text].compactMap({$0}).joined(separator: ", ") } fileprivate func updateIcons() { @@ -386,6 +392,11 @@ open class Tilelet: TileContainer { updateIcons() layoutIfNeeded() + updateAccessibilityLabel() + } + + open override func updateAccessibilityLabel() { + 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 6f0a53f6..499d394d 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -301,5 +301,10 @@ open class ToggleBase: Control { open override func updateView() { updateLabel() updateToggle() + updateAccessibilityLabel() + } + + open override func updateAccessibilityLabel() { + setAccessibilityLabel(for: [label]) } } diff --git a/VDS/Protocols/ViewProtocol.swift b/VDS/Protocols/ViewProtocol.swift index a6948343..a73b83c5 100644 --- a/VDS/Protocols/ViewProtocol.swift +++ b/VDS/Protocols/ViewProtocol.swift @@ -12,6 +12,7 @@ public protocol ViewProtocol { // Can setup ui here. Should be called in the initialization functions. func setup() + func updateAccessibilityLabel() } extension ViewProtocol where Self: UIView { @@ -22,7 +23,12 @@ extension ViewProtocol where Self: UIView { } } - public func accessibilityLabel(for views: [UIView]) -> String? { - return views.compactMap({$0.accessibilityLabel}).joined(separator: " ") + public func combineAccessibilityLabel(for views: [UIView]) -> String? { + 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) } }