fixed the vds color breaking changes for monarch

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-06-05 13:40:01 -05:00
parent f3e2263048
commit 037a52d379
4 changed files with 26 additions and 28 deletions

View File

@ -58,7 +58,7 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
textPercentage = try container.decodeIfPresent(CGFloat.self, forKey: .textPercentage) textPercentage = try container.decodeIfPresent(CGFloat.self, forKey: .textPercentage)
if let color = eyebrow?.textColor?.uiColor { if let color = eyebrow?.textColor?.uiColor {
self.eyebrowColor = .custom(color, color) self.eyebrowColor = .custom(color)
} else if let eyebrowColor = try? container.decodeIfPresent(TitleLockup.TextColor.self, forKey: .eyebrowColor) { } else if let eyebrowColor = try? container.decodeIfPresent(TitleLockup.TextColor.self, forKey: .eyebrowColor) {
self.eyebrowColor = eyebrowColor self.eyebrowColor = eyebrowColor
@ -68,7 +68,7 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
} }
if let color = title?.textColor?.uiColor { if let color = title?.textColor?.uiColor {
self.titleColor = .custom(color, color) self.titleColor = .custom(color)
} else if let titleColor = try? container.decodeIfPresent(TitleLockup.TitleTextColor.self, forKey: .titleColor) { } else if let titleColor = try? container.decodeIfPresent(TitleLockup.TitleTextColor.self, forKey: .titleColor) {
self.titleColor = titleColor self.titleColor = titleColor
@ -78,7 +78,7 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
} }
if let color = subTitle?.textColor?.uiColor { if let color = subTitle?.textColor?.uiColor {
self.subTitleColor = .custom(color, color) self.subTitleColor = .custom(color)
} else if let subTitleColor = try? container.decodeIfPresent(TitleLockup.TextColor.self, forKey: .subTitleColor) { } else if let subTitleColor = try? container.decodeIfPresent(TitleLockup.TextColor.self, forKey: .subTitleColor) {
self.subTitleColor = subTitleColor self.subTitleColor = subTitleColor

View File

@ -197,8 +197,7 @@ extension VDS.TitleLockup.TextColor: Codable {
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case type case type
case lightColor case color
case darkColor
} }
enum CustomColorType: String, Codable { enum CustomColorType: String, Codable {
@ -217,9 +216,8 @@ extension VDS.TitleLockup.TextColor: Codable {
case .secondary: case .secondary:
self = .secondary self = .secondary
case .custom: case .custom:
let lightColor = try container.decode(Color.self, forKey: .lightColor) let color = try container.decode(Color.self, forKey: .color)
let darkColor = try container.decode(Color.self, forKey: .darkColor) self = .custom(color.uiColor)
self = .custom(lightColor.uiColor, darkColor.uiColor)
} }
} }
@ -230,11 +228,10 @@ extension VDS.TitleLockup.TextColor: Codable {
try container.encode(CustomColorType.primary.rawValue, forKey: .type) try container.encode(CustomColorType.primary.rawValue, forKey: .type)
case .secondary: case .secondary:
try container.encode(CustomColorType.secondary.rawValue, forKey: .type) try container.encode(CustomColorType.secondary.rawValue, forKey: .type)
case .custom(let lightColor, let darkColor): case .custom(let color):
try container.encode(CustomColorType.custom.rawValue, forKey: .type) try container.encode(CustomColorType.custom.rawValue, forKey: .type)
try container.encode(Color(uiColor: lightColor), forKey: .lightColor) try container.encode(Color(uiColor: color), forKey: .color)
try container.encode(Color(uiColor: darkColor), forKey: .darkColor) default:
@unknown default:
break break
} }
} }
@ -244,8 +241,7 @@ extension VDS.TitleLockup.TitleTextColor: Codable {
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case type case type
case lightColor case color
case darkColor
} }
enum CustomColorType: String, Codable { enum CustomColorType: String, Codable {
@ -261,9 +257,8 @@ extension VDS.TitleLockup.TitleTextColor: Codable {
case .primary: case .primary:
self = .primary self = .primary
case .custom: case .custom:
let lightColor = try container.decode(Color.self, forKey: .lightColor) let color = try container.decode(Color.self, forKey: .color)
let darkColor = try container.decode(Color.self, forKey: .darkColor) self = .custom(color.uiColor)
self = .custom(lightColor.uiColor, darkColor.uiColor)
} }
} }
@ -272,11 +267,10 @@ extension VDS.TitleLockup.TitleTextColor: Codable {
switch self { switch self {
case .primary: case .primary:
try container.encode(CustomColorType.primary.rawValue, forKey: .type) try container.encode(CustomColorType.primary.rawValue, forKey: .type)
case .custom(let lightColor, let darkColor): case .custom(let color):
try container.encode(CustomColorType.custom.rawValue, forKey: .type) try container.encode(CustomColorType.custom.rawValue, forKey: .type)
try container.encode(Color(uiColor: lightColor), forKey: .lightColor) try container.encode(Color(uiColor: color), forKey: .color)
try container.encode(Color(uiColor: darkColor), forKey: .darkColor) default:
@unknown default:
break break
} }
} }

View File

@ -46,7 +46,7 @@ extension Tilelet.DescriptiveIcon: Codable {
let accessibleText = try container.decodeIfPresent(String.self, forKey: .accessibleText) let accessibleText = try container.decodeIfPresent(String.self, forKey: .accessibleText)
if let uiColor = color?.uiColor { if let uiColor = color?.uiColor {
self.init(name: name, self.init(name: name,
colorConfiguration: .init(uiColor, uiColor), iconColor: .custom(uiColor),
size: size, size: size,
accessibleText: accessibleText) accessibleText: accessibleText)
} else { } else {
@ -61,7 +61,9 @@ extension Tilelet.DescriptiveIcon: Codable {
try container.encode(name, forKey: .name) try container.encode(name, forKey: .name)
try container.encode(size, forKey: .size) try container.encode(size, forKey: .size)
try container.encodeIfPresent(accessibleText, forKey: .accessibleText) try container.encodeIfPresent(accessibleText, forKey: .accessibleText)
try container.encodeIfPresent(colorConfiguration.lightColor.hexString, forKey: .color) if let color = iconColor?.uiColor {
try container.encode(Color(uiColor: color), forKey: .color)
}
} }
} }
@ -81,7 +83,7 @@ extension Tilelet.DirectionalIcon: Codable {
let accessibleText = try container.decodeIfPresent(String.self, forKey: .accessibleText) let accessibleText = try container.decodeIfPresent(String.self, forKey: .accessibleText)
if let uiColor = color?.uiColor { if let uiColor = color?.uiColor {
self.init(iconType: iconType, self.init(iconType: iconType,
colorConfiguration: .init(uiColor, uiColor), iconColor: .custom(uiColor),
size: size, size: size,
accessibleText: accessibleText) accessibleText: accessibleText)
} else { } else {
@ -96,6 +98,8 @@ extension Tilelet.DirectionalIcon: Codable {
try container.encode(iconType, forKey: .name) try container.encode(iconType, forKey: .name)
try container.encode(size, forKey: .size) try container.encode(size, forKey: .size)
try container.encodeIfPresent(accessibleText, forKey: .accessibleText) try container.encodeIfPresent(accessibleText, forKey: .accessibleText)
try container.encodeIfPresent(colorConfiguration.lightColor.hexString, forKey: .color) if let color = iconColor?.uiColor {
try container.encode(Color(uiColor: color), forKey: .color)
}
} }
} }

View File

@ -99,7 +99,7 @@ public class TitleLockupModel: ParentMoleculeModelProtocol {
subTitle = try typeContainer.decodeMoleculeIfPresent(codingKey: .subTitle) subTitle = try typeContainer.decodeMoleculeIfPresent(codingKey: .subTitle)
if let color = eyebrow?.textColor?.uiColor { if let color = eyebrow?.textColor?.uiColor {
self.eyebrowColor = .custom(color, color) self.eyebrowColor = .custom(color)
} else if let eyebrowColor = try? typeContainer.decodeIfPresent(TitleLockup.TextColor.self, forKey: .eyebrowColor) { } else if let eyebrowColor = try? typeContainer.decodeIfPresent(TitleLockup.TextColor.self, forKey: .eyebrowColor) {
self.eyebrowColor = eyebrowColor self.eyebrowColor = eyebrowColor
@ -109,7 +109,7 @@ public class TitleLockupModel: ParentMoleculeModelProtocol {
} }
if let color = title.textColor?.uiColor { if let color = title.textColor?.uiColor {
self.titleColor = .custom(color, color) self.titleColor = .custom(color)
} else if let titleColor = try? typeContainer.decodeIfPresent(TitleLockup.TitleTextColor.self, forKey: .titleColor) { } else if let titleColor = try? typeContainer.decodeIfPresent(TitleLockup.TitleTextColor.self, forKey: .titleColor) {
self.titleColor = titleColor self.titleColor = titleColor
@ -119,7 +119,7 @@ public class TitleLockupModel: ParentMoleculeModelProtocol {
} }
if let color = subTitle?.textColor?.uiColor { if let color = subTitle?.textColor?.uiColor {
self.subTitleColor = .custom(color, color) self.subTitleColor = .custom(color)
} else if let subTitleColor = try? typeContainer.decodeIfPresent(TitleLockup.TextColor.self, forKey: .subTitleColor) { } else if let subTitleColor = try? typeContainer.decodeIfPresent(TitleLockup.TextColor.self, forKey: .subTitleColor) {
self.subTitleColor = subTitleColor self.subTitleColor = subTitleColor