using type now and not the old way.

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-10-14 15:57:25 -05:00
parent 4487f9b03b
commit 76b58ec88a

View File

@ -305,61 +305,27 @@ extension VDS.Badge.FillColor: Codable {
} }
public init(from decoder: Decoder) throws { public init(from decoder: Decoder) throws {
//try legacy ones that map to real fillColor cases let container = try decoder.container(keyedBy: CodingKeys.self)
if let legacy = try? LegacyFillColor(from: decoder) { let type = try container.decode(CustomColorType.self, forKey: .type)
self = legacy.fillColor
} //try to convert to a color switch type {
else if let color = try? Color(from: decoder) { case .red:
self = .red
case .yellow:
self = .yellow
case .green:
self = .green
case .orange:
self = .orange
case .blue:
self = .blue
case .black:
self = .black
case .white:
self = .white
case .custom:
let color = try container.decode(Color.self, forKey: .color)
self = .custom(color.uiColor) self = .custom(color.uiColor)
} //try to use new format
else {
let container = try decoder.container(keyedBy: CodingKeys.self)
let type = try container.decode(CustomColorType.self, forKey: .type)
switch type {
case .red:
self = .red
case .yellow:
self = .yellow
case .green:
self = .green
case .orange:
self = .orange
case .blue:
self = .blue
case .black:
self = .black
case .white:
self = .white
case .custom:
let color = try container.decode(Color.self, forKey: .color)
self = .custom(color.uiColor)
}
}
}
private enum LegacyFillColor: String, Decodable {
case red, yellow, green, orange, blue, black, white
var fillColor: Badge.FillColor {
switch self {
case .red:
return .red
case .yellow:
return .yellow
case .green:
return .green
case .orange:
return .orange
case .blue:
return .blue
case .black:
return .black
case .white:
return .white
}
} }
} }