using type now and not the old way.
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
4487f9b03b
commit
76b58ec88a
@ -305,61 +305,27 @@ extension VDS.Badge.FillColor: Codable {
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
//try legacy ones that map to real fillColor cases
|
||||
if let legacy = try? LegacyFillColor(from: decoder) {
|
||||
self = legacy.fillColor
|
||||
|
||||
} //try to convert to a color
|
||||
else if let color = try? Color(from: decoder) {
|
||||
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
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
let type = try container.decode(CustomColorType.self, forKey: .type)
|
||||
|
||||
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
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user