From e97582ee1e183993ee4efabc65fc2faad5b7c233 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 21 Sep 2023 14:59:00 -0500 Subject: [PATCH] added accessibility Signed-off-by: Matt Bruce --- MVMCoreUI/Atomic/Atoms/Views/Badge.swift | 18 ++++++++++++++++-- MVMCoreUI/Atomic/Atoms/Views/BadgeModel.swift | 5 ++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Badge.swift b/MVMCoreUI/Atomic/Atoms/Views/Badge.swift index 0e6d1075..1306074f 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Badge.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Badge.swift @@ -14,7 +14,7 @@ import Combine open class Badge: VDS.Badge, VDSMoleculeViewProtocol { // public typealias ViewModel = type //-------------------------------------------------- - // MARK: - Properties + // MARK: - Public Properties //-------------------------------------------------- public var viewModel: BadgeModel! @@ -23,7 +23,7 @@ open class Badge: VDS.Badge, VDSMoleculeViewProtocol { public var additionalData: [AnyHashable : Any]? //-------------------------------------------------- - // MARK: - Public + // MARK: - Public Methods //-------------------------------------------------- public func viewModelDidUpdate() { @@ -35,6 +35,20 @@ open class Badge: VDS.Badge, VDSMoleculeViewProtocol { } public func updateView(_ size: CGFloat) {} + + //-------------------------------------------------- + // MARK: - Overrides + //-------------------------------------------------- + open override func updateAccessibility() { + super.updateAccessibility() + + if let viewModel { + if let accessibilityText = viewModel.accessibilityText { + self.accessibilityLabel = accessibilityText + } + } + } + } //to deal with how it's parent constrains this control diff --git a/MVMCoreUI/Atomic/Atoms/Views/BadgeModel.swift b/MVMCoreUI/Atomic/Atoms/Views/BadgeModel.swift index cbb9a1b9..37344dad 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/BadgeModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/BadgeModel.swift @@ -17,13 +17,14 @@ open class BadgeModel: MoleculeModelProtocol { public var id: String = UUID().uuidString public var backgroundColor: Color? public var text: String = "" + public var accessibilityText: String? public var maxWidth: CGFloat? public var numberOfLines: Int = 1 public var fillColor = Badge.FillColor.red public var surface: Surface = .light private enum CodingKeys: String, CodingKey { - case id, text, fillColor, surface, numberOfLines, maxWidth + case id, text, accessibilityText, fillColor, surface, numberOfLines, maxWidth } required public convenience init(from decoder: Decoder) throws { @@ -31,6 +32,7 @@ open class BadgeModel: MoleculeModelProtocol { let container = try decoder.container(keyedBy: CodingKeys.self) id = try container.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString text = try container.decode(String.self, forKey: .text) + accessibilityText = try container.decodeIfPresent(String.self, forKey: .accessibilityText) fillColor = try container.decodeIfPresent(Badge.FillColor.self, forKey: .fillColor) ?? .red surface = try container.decodeIfPresent(Surface.self, forKey: .surface) ?? .light numberOfLines = try container.decodeIfPresent(Int.self, forKey: .numberOfLines) ?? 1 @@ -41,6 +43,7 @@ open class BadgeModel: MoleculeModelProtocol { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(id, forKey: .id) try container.encode(text, forKey: .text) + try container.encode(accessibilityText, forKey: .accessibilityText) try container.encode(fillColor, forKey: .fillColor) try container.encode(surface, forKey: .surface) try container.encode(numberOfLines, forKey: .numberOfLines)