diff --git a/VDS/Components/Tilet/TiletBadgeModel.swift b/VDS/Components/Tilet/TiletBadgeModel.swift index 521958a4..43e68abb 100644 --- a/VDS/Components/Tilet/TiletBadgeModel.swift +++ b/VDS/Components/Tilet/TiletBadgeModel.swift @@ -10,10 +10,11 @@ import Foundation extension Tilet { public struct BadgeModel: Codable { public var text: String = "" - public var fillColor:Badge.FillColor - public var surface: Surface + public var fillColor: Badge.FillColor = .red + public var surface: Surface = .light public var numberOfLines: Int public var maxWidth: CGFloat? + public init(text: String, fillColor: Badge.FillColor = .red, surface: Surface = .light, numberOfLines: Int = 0, maxWidth: CGFloat? = nil) { self.text = text self.fillColor = fillColor @@ -21,5 +22,14 @@ extension Tilet { self.numberOfLines = numberOfLines self.maxWidth = maxWidth } + + public init(from decoder: Decoder) throws { + let container: KeyedDecodingContainer = try decoder.container(keyedBy: Tilet.BadgeModel.CodingKeys.self) + self.text = try container.decode(String.self, forKey: Tilet.BadgeModel.CodingKeys.text) + self.fillColor = try container.decodeIfPresent(Badge.FillColor.self, forKey: Tilet.BadgeModel.CodingKeys.fillColor) ?? .red + self.surface = try container.decodeIfPresent(Surface.self, forKey: Tilet.BadgeModel.CodingKeys.surface) ?? .light + self.numberOfLines = try container.decodeIfPresent(Int.self, forKey: Tilet.BadgeModel.CodingKeys.numberOfLines) ?? 0 + self.maxWidth = try container.decodeIfPresent(CGFloat.self, forKey: Tilet.BadgeModel.CodingKeys.maxWidth) + } } } diff --git a/VDS/Components/Tilet/TiletIconModels.swift b/VDS/Components/Tilet/TiletIconModels.swift index 36c3f5b4..a462199b 100644 --- a/VDS/Components/Tilet/TiletIconModels.swift +++ b/VDS/Components/Tilet/TiletIconModels.swift @@ -23,7 +23,7 @@ extension Tilet { public init(from decoder: Decoder) throws { let container: KeyedDecodingContainer = try decoder.container(keyedBy: Tilet.DescriptiveIcon.CodingKeys.self) - self.name = try container.decode(Icon.Name.self, forKey: Tilet.DescriptiveIcon.CodingKeys.name) + self.name = try container.decodeIfPresent(Icon.Name.self, forKey: Tilet.DescriptiveIcon.CodingKeys.name) ?? .multipleDocuments self.size = try container.decodeIfPresent(Icon.Size.self, forKey: Tilet.DescriptiveIcon.CodingKeys.size) ?? .medium self.surface = try container.decodeIfPresent(Surface.self, forKey: Tilet.DescriptiveIcon.CodingKeys.surface) ?? .dark }