migrated codable to extension
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
d2d8140b70
commit
cb9ca6236b
@ -8,7 +8,7 @@
|
||||
import Foundation
|
||||
|
||||
extension Tilelet {
|
||||
public struct BadgeModel: Codable {
|
||||
public struct BadgeModel {
|
||||
public var text: String = ""
|
||||
public var fillColor: Badge.FillColor = .red
|
||||
public var surface: Surface = .light
|
||||
@ -22,14 +22,16 @@ extension Tilelet {
|
||||
self.numberOfLines = numberOfLines
|
||||
self.maxWidth = maxWidth
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container: KeyedDecodingContainer<Tilelet.BadgeModel.CodingKeys> = try decoder.container(keyedBy: Tilelet.BadgeModel.CodingKeys.self)
|
||||
self.text = try container.decode(String.self, forKey: Tilelet.BadgeModel.CodingKeys.text)
|
||||
self.fillColor = try container.decodeIfPresent(Badge.FillColor.self, forKey: Tilelet.BadgeModel.CodingKeys.fillColor) ?? .red
|
||||
self.surface = try container.decodeIfPresent(Surface.self, forKey: Tilelet.BadgeModel.CodingKeys.surface) ?? .light
|
||||
self.numberOfLines = try container.decodeIfPresent(Int.self, forKey: Tilelet.BadgeModel.CodingKeys.numberOfLines) ?? 0
|
||||
self.maxWidth = try container.decodeIfPresent(CGFloat.self, forKey: Tilelet.BadgeModel.CodingKeys.maxWidth)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Tilelet.BadgeModel: Codable {
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container: KeyedDecodingContainer<Tilelet.BadgeModel.CodingKeys> = try decoder.container(keyedBy: Tilelet.BadgeModel.CodingKeys.self)
|
||||
self.text = try container.decode(String.self, forKey: Tilelet.BadgeModel.CodingKeys.text)
|
||||
self.fillColor = try container.decodeIfPresent(Badge.FillColor.self, forKey: Tilelet.BadgeModel.CodingKeys.fillColor) ?? .red
|
||||
self.surface = try container.decodeIfPresent(Surface.self, forKey: Tilelet.BadgeModel.CodingKeys.surface) ?? .light
|
||||
self.numberOfLines = try container.decodeIfPresent(Int.self, forKey: Tilelet.BadgeModel.CodingKeys.numberOfLines) ?? 0
|
||||
self.maxWidth = try container.decodeIfPresent(CGFloat.self, forKey: Tilelet.BadgeModel.CodingKeys.maxWidth)
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ import UIKit
|
||||
|
||||
extension Tilelet {
|
||||
|
||||
public struct DescriptiveIcon: Codable {
|
||||
public struct DescriptiveIcon {
|
||||
public var name: Icon.Name = .multipleDocuments
|
||||
public var size: Icon.Size = .medium
|
||||
public var surface: Surface = .dark
|
||||
@ -20,16 +20,9 @@ extension Tilelet {
|
||||
self.size = size
|
||||
self.surface = surface
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container: KeyedDecodingContainer<Tilelet.DescriptiveIcon.CodingKeys> = try decoder.container(keyedBy: Tilelet.DescriptiveIcon.CodingKeys.self)
|
||||
self.name = try container.decodeIfPresent(Icon.Name.self, forKey: Tilelet.DescriptiveIcon.CodingKeys.name) ?? .multipleDocuments
|
||||
self.size = try container.decodeIfPresent(Icon.Size.self, forKey: Tilelet.DescriptiveIcon.CodingKeys.size) ?? .medium
|
||||
self.surface = try container.decodeIfPresent(Surface.self, forKey: Tilelet.DescriptiveIcon.CodingKeys.surface) ?? .dark
|
||||
}
|
||||
}
|
||||
|
||||
public struct DirectionalIcon: Codable {
|
||||
public struct DirectionalIcon {
|
||||
public var size: Icon.Size = .medium
|
||||
public var surface: Surface = .dark
|
||||
|
||||
@ -37,11 +30,30 @@ extension Tilelet {
|
||||
self.size = size
|
||||
self.surface = surface
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container: KeyedDecodingContainer<Tilelet.DirectionalIcon.CodingKeys> = try decoder.container(keyedBy: Tilelet.DirectionalIcon.CodingKeys.self)
|
||||
self.size = try container.decodeIfPresent(Icon.Size.self, forKey: Tilelet.DirectionalIcon.CodingKeys.size) ?? .medium
|
||||
self.surface = try container.decodeIfPresent(Surface.self, forKey: Tilelet.DirectionalIcon.CodingKeys.surface) ?? .dark
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Tilelet.DescriptiveIcon: Codable {
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case name, size, surface
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.name = try container.decodeIfPresent(Icon.Name.self, forKey: .name) ?? .multipleDocuments
|
||||
self.size = try container.decodeIfPresent(Icon.Size.self, forKey: .size) ?? .medium
|
||||
self.surface = try container.decodeIfPresent(Surface.self, forKey: .surface) ?? .dark
|
||||
}
|
||||
}
|
||||
|
||||
extension Tilelet.DirectionalIcon: Codable {
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case size, surface
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.size = try container.decodeIfPresent(Icon.Size.self, forKey: .size) ?? .medium
|
||||
self.surface = try container.decodeIfPresent(Surface.self, forKey: .surface) ?? .dark
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,11 +8,11 @@
|
||||
import Foundation
|
||||
|
||||
extension Tilelet {
|
||||
public struct SubTitleModel: Codable {
|
||||
public struct SubTitleModel {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Enums
|
||||
//--------------------------------------------------
|
||||
public enum TextStyle: String, Codable, EnumSubset {
|
||||
public enum TextStyle: String, EnumSubset, Codable {
|
||||
case bodyLarge
|
||||
case boldBodyLarge
|
||||
case bodyMedium
|
||||
@ -22,12 +22,12 @@ extension Tilelet {
|
||||
|
||||
public var defaultValue: TitleLockup.OtherTextStyle { .bodySmall }
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Public Properties
|
||||
//--------------------------------------------------
|
||||
public var text: String = ""
|
||||
public var textStyle: TextStyle = .bodySmall
|
||||
public var textAttributes: [any LabelAttributeModel]?
|
||||
public var textColor: Use = .primary
|
||||
|
||||
//--------------------------------------------------
|
||||
@ -38,6 +38,7 @@ extension Tilelet {
|
||||
textAttributes: [any LabelAttributeModel]? = nil,
|
||||
textStyle: TextStyle = .bodySmall) {
|
||||
self.text = text
|
||||
self.textAttributes = textAttributes
|
||||
self.textColor = textColor
|
||||
self.textStyle = textStyle
|
||||
}
|
||||
@ -50,12 +51,25 @@ extension Tilelet {
|
||||
textColor: textColor,
|
||||
textAttributes: nil)
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container: KeyedDecodingContainer<Tilelet.SubTitleModel.CodingKeys> = try decoder.container(keyedBy: Tilelet.SubTitleModel.CodingKeys.self)
|
||||
self.text = try container.decode(String.self, forKey: Tilelet.SubTitleModel.CodingKeys.text)
|
||||
self.textStyle = try container.decodeIfPresent(Tilelet.SubTitleModel.TextStyle.self, forKey: Tilelet.SubTitleModel.CodingKeys.textStyle) ?? .bodySmall
|
||||
self.textColor = try container.decodeIfPresent(Use.self, forKey: Tilelet.SubTitleModel.CodingKeys.textColor) ?? .primary
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Tilelet.SubTitleModel: Codable {
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case text, textStyle, textColor
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.text = try container.decode(String.self, forKey: .text)
|
||||
self.textStyle = try container.decodeIfPresent(TextStyle.self, forKey: .textStyle) ?? .bodySmall
|
||||
self.textColor = try container.decodeIfPresent(Use.self, forKey: .textColor) ?? .primary
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(text, forKey: .text)
|
||||
try container.encode(textStyle, forKey: .textStyle)
|
||||
try container.encode(textColor, forKey: .textColor)
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
import Foundation
|
||||
|
||||
extension Tilelet {
|
||||
public struct TitleModel: Codable {
|
||||
public struct TitleModel {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Enums
|
||||
//--------------------------------------------------
|
||||
@ -24,21 +24,24 @@ extension Tilelet {
|
||||
|
||||
public var defaultValue: TitleLockup.TitleTextStyle { .boldTitleSmall }
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Public Properties
|
||||
//--------------------------------------------------
|
||||
public var text: String = ""
|
||||
public var textAttributes: [any LabelAttributeModel]?
|
||||
public var textStyle: TextStyle = .boldTitleSmall
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
//--------------------------------------------------
|
||||
public init(text: String,
|
||||
textAttributes: [any LabelAttributeModel]? = nil,
|
||||
textStyle: TextStyle = .boldTitleSmall) {
|
||||
self.text = text
|
||||
self.textAttributes = textAttributes
|
||||
self.textStyle = textStyle
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Public Functions
|
||||
@ -48,11 +51,25 @@ extension Tilelet {
|
||||
textAttributes: nil,
|
||||
textStyle: textStyle.value)
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container: KeyedDecodingContainer<Tilelet.TitleModel.CodingKeys> = try decoder.container(keyedBy: Tilelet.TitleModel.CodingKeys.self)
|
||||
self.text = try container.decode(String.self, forKey: Tilelet.TitleModel.CodingKeys.text)
|
||||
self.textStyle = try container.decodeIfPresent(Tilelet.TitleModel.TextStyle.self, forKey: Tilelet.TitleModel.CodingKeys.textStyle) ?? .boldTitleSmall
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Tilelet.TitleModel: Codable {
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case text, textStyle
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.text = try container.decode(String.self, forKey: .text)
|
||||
self.textStyle = try container.decodeIfPresent(TextStyle.self, forKey: .textStyle) ?? .boldTitleSmall
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(text, forKey: .text)
|
||||
try container.encode(textStyle, forKey: .textStyle)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user