added defaults into decode func
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
394c78f065
commit
60e4b6f2c2
@ -16,9 +16,9 @@ open class TiletModel: MoleculeModelProtocol {
|
||||
//--------------------------------------------------
|
||||
public static var identifier: String = "tilet"
|
||||
public var backgroundColor: Color?
|
||||
public var color: TileContainer.BackgroundColor = .black
|
||||
public var padding: TileContainer.Padding = .padding4X
|
||||
public var aspectRatio: TileContainer.AspectRatio = .none
|
||||
public var color: TileContainer.BackgroundColor
|
||||
public var padding: TileContainer.Padding
|
||||
public var aspectRatio: TileContainer.AspectRatio
|
||||
public var badge: Tilet.BadgeModel?
|
||||
public var title: Tilet.TitleModel?
|
||||
public var subTitle: Tilet.SubTitleModel?
|
||||
@ -27,4 +27,20 @@ open class TiletModel: MoleculeModelProtocol {
|
||||
public var width: CGFloat?
|
||||
public var textWidth: CGFloat?
|
||||
public var textPercentage: CGFloat?
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.backgroundColor = try container.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||
self.color = try container.decodeIfPresent(TileContainer.BackgroundColor.self, forKey: .color) ?? TileContainer.BackgroundColor.black
|
||||
self.padding = try container.decodeIfPresent(TileContainer.Padding.self, forKey: .padding) ?? TileContainer.Padding.padding4X
|
||||
self.aspectRatio = try container.decodeIfPresent(TileContainer.AspectRatio.self, forKey: .aspectRatio) ?? TileContainer.AspectRatio.none
|
||||
self.badge = try container.decodeIfPresent(Tilet.BadgeModel.self, forKey: .badge)
|
||||
self.title = try container.decodeIfPresent(Tilet.TitleModel.self, forKey: .title)
|
||||
self.subTitle = try container.decodeIfPresent(Tilet.SubTitleModel.self, forKey: .subTitle)
|
||||
self.descriptiveIcon = try container.decodeIfPresent(Tilet.DescriptiveIcon.self, forKey: .descriptiveIcon)
|
||||
self.directionalIcon = try container.decodeIfPresent(Tilet.DirectionalIcon.self, forKey: .directionalIcon) ?? Tilet.DirectionalIcon.init(size: .medium, surface: .dark)
|
||||
self.width = try container.decodeIfPresent(CGFloat.self, forKey: .width)
|
||||
self.textWidth = try container.decodeIfPresent(CGFloat.self, forKey: .textWidth)
|
||||
self.textPercentage = try container.decodeIfPresent(CGFloat.self, forKey: .textPercentage)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user