added textColor

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-10-08 09:08:05 -05:00
parent d2e841c533
commit c737ca1344
2 changed files with 12 additions and 1 deletions

View File

@ -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

View File

@ -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 {