From c737ca134479f3e47ebd335eed951507fea47e02 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 8 Oct 2024 09:08:05 -0500 Subject: [PATCH] added textColor Signed-off-by: Matt Bruce --- MVMCoreUI/Atomic/Atoms/Views/Badge.swift | 1 + MVMCoreUI/Atomic/Atoms/Views/BadgeModel.swift | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Badge.swift b/MVMCoreUI/Atomic/Atoms/Views/Badge.swift index 81203d47..9957101f 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Badge.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Badge.swift @@ -31,6 +31,7 @@ open class Badge: VDS.Badge, VDSMoleculeViewProtocol { self.accessibilityIdentifier = accessibilityIdentifier } text = viewModel.text + textColor = viewModel.textColor maxWidth = viewModel.maxWidth numberOfLines = viewModel.numberOfLines fillColor = viewModel.fillColor diff --git a/MVMCoreUI/Atomic/Atoms/Views/BadgeModel.swift b/MVMCoreUI/Atomic/Atoms/Views/BadgeModel.swift index 34ed444c..52e43e9a 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/BadgeModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/BadgeModel.swift @@ -22,6 +22,7 @@ open class BadgeModel: MoleculeModelProtocol { // MARK: - VDS Properties //-------------------------------------------------- public var text: String = "" + public var textColor: Badge.TextColor? = nil public var accessibilityText: String? public var maxWidth: CGFloat? public var numberOfLines: Int = 1 @@ -29,7 +30,7 @@ open class BadgeModel: MoleculeModelProtocol { public var surface: Surface = .light private enum CodingKeys: String, CodingKey { - case id, accessibilityIdentifier, text, accessibilityText, fillColor, surface, numberOfLines, maxWidth + case id, accessibilityIdentifier, text, textColor, accessibilityText, fillColor, surface, numberOfLines, maxWidth } required public convenience init(from decoder: Decoder) throws { @@ -38,6 +39,9 @@ open class BadgeModel: MoleculeModelProtocol { id = try container.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString accessibilityIdentifier = try container.decodeIfPresent(String.self, forKey: .accessibilityIdentifier) text = try container.decode(String.self, forKey: .text) + if let foundTextColor = try container.decodeIfPresent(Color.self, forKey: .textColor) { + textColor = .custom(foundTextColor.uiColor) + } 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 @@ -55,6 +59,12 @@ open class BadgeModel: MoleculeModelProtocol { try container.encode(surface, forKey: .surface) try container.encode(numberOfLines, forKey: .numberOfLines) try container.encodeIfPresent(maxWidth, forKey: .maxWidth) + switch textColor { + case .custom(let color): + try container.encode(Color(uiColor: color), forKey: .textColor) + default: + break + } } public func isEqual(to model: any ModelComparisonProtocol) -> Bool {