diff --git a/MVMCoreUI/Atomic/Atoms/Views/Tilelet.swift b/MVMCoreUI/Atomic/Atoms/Views/Tilelet.swift index 09f905e7..28ece685 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Tilelet.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Tilelet.swift @@ -39,10 +39,16 @@ open class Tilelet: VDS.Tilelet, VDSMoleculeViewProtocol{ // MARK: - Public //-------------------------------------------------- public func viewModelDidUpdate() { - color = viewModel.color + padding = viewModel.padding + color = viewModel.color + backgroundEffect = viewModel.backgroundEffect aspectRatio = viewModel.aspectRatio width = viewModel.width + height = viewModel.height + showBorder = viewModel.showBorder + showDropShadows = viewModel.showDropShadwows + if let value = viewModel.textWidth { textWidth = .value(value) } else if let percentage = viewModel.textPercentage { diff --git a/MVMCoreUI/Atomic/Atoms/Views/TileletModel.swift b/MVMCoreUI/Atomic/Atoms/Views/TileletModel.swift index 62fac7e9..2abd1eec 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/TileletModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/TileletModel.swift @@ -9,7 +9,7 @@ import Foundation import VDS -open class TileletModel: MoleculeModelProtocol { +open class TileletModel: TileContainerBaseModel, MoleculeModelProtocol { //-------------------------------------------------- // MARK: - Properties @@ -17,23 +17,23 @@ open class TileletModel: MoleculeModelProtocol { public static var identifier: String = "tilelet" public var id: String = UUID().uuidString public var backgroundColor: Color? - public var color: Tilelet.BackgroundColor - public var padding: Tilelet.Padding - public var aspectRatio: Tilelet.AspectRatio + public var color: Tilelet.BackgroundColor = .black + public var padding: Tilelet.Padding = .large + public var aspectRatio: Tilelet.AspectRatio = .ratio1x1 + public var backgroundEffect: Tilelet.BackgroundEffect = .none public var badge: Tilelet.BadgeModel? public var title: LabelModel? public var subTitle: LabelModel? public var descriptiveIcon: Tilelet.DescriptiveIcon? public var directionalIcon: Tilelet.DirectionalIcon? - public var width: CGFloat? public var textWidth: CGFloat? public var textPercentage: CGFloat? - public var action: ActionModelProtocol? private enum CodingKeys: String, CodingKey { case id case moleculeName case backgroundColor + case backgroundEffect case color case padding case aspectRatio @@ -42,27 +42,25 @@ open class TileletModel: MoleculeModelProtocol { case subTitle case descriptiveIcon case directionalIcon - case width case textWidth case textPercentage - case action } required public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) - self.id = try container.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString - self.backgroundColor = try container.decodeIfPresent(Color.self, forKey: .backgroundColor) - self.color = try container.decodeIfPresent(Tilelet.BackgroundColor.self, forKey: .color) ?? Tilelet.BackgroundColor.black - self.padding = try container.decodeIfPresent(Tilelet.Padding.self, forKey: .padding) ?? Tilelet.Padding.small - self.aspectRatio = try container.decodeIfPresent(Tilelet.AspectRatio.self, forKey: .aspectRatio) ?? Tilelet.AspectRatio.none - self.badge = try container.decodeIfPresent(Tilelet.BadgeModel.self, forKey: .badge) - self.title = try container.decodeIfPresent(LabelModel.self, forKey: .title) - self.subTitle = try container.decodeIfPresent(LabelModel.self, forKey: .subTitle) - self.descriptiveIcon = try container.decodeIfPresent(Tilelet.DescriptiveIcon.self, forKey: .descriptiveIcon) - self.directionalIcon = try container.decodeIfPresent(Tilelet.DirectionalIcon.self, forKey: .directionalIcon) - 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) - action = try container.decodeModelIfPresent(codingKey: .action) + id = try container.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString + backgroundColor = try container.decodeIfPresent(Color.self, forKey: .backgroundColor) + color = try container.decodeIfPresent(Tilelet.BackgroundColor.self, forKey: .color) ?? Tilelet.BackgroundColor.black + backgroundEffect = try container.decodeIfPresent(Tilelet.BackgroundEffect.self, forKey: .backgroundEffect) ?? .none + padding = try container.decodeIfPresent(Tilelet.Padding.self, forKey: .padding) ?? Tilelet.Padding.small + aspectRatio = try container.decodeIfPresent(Tilelet.AspectRatio.self, forKey: .aspectRatio) ?? Tilelet.AspectRatio.none + badge = try container.decodeIfPresent(Tilelet.BadgeModel.self, forKey: .badge) + title = try container.decodeIfPresent(LabelModel.self, forKey: .title) + subTitle = try container.decodeIfPresent(LabelModel.self, forKey: .subTitle) + descriptiveIcon = try container.decodeIfPresent(Tilelet.DescriptiveIcon.self, forKey: .descriptiveIcon) + directionalIcon = try container.decodeIfPresent(Tilelet.DirectionalIcon.self, forKey: .directionalIcon) + textWidth = try container.decodeIfPresent(CGFloat.self, forKey: .textWidth) + textPercentage = try container.decodeIfPresent(CGFloat.self, forKey: .textPercentage) + try super.init(from: decoder) } public func titleModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Tilelet.TitleModel? { @@ -99,7 +97,7 @@ open class TileletModel: MoleculeModelProtocol { return .init(text: subTitle.text, textAttributes: attrs) } - public func encode(to encoder: Encoder) throws { + public override func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(id, forKey: .id) try container.encode(moleculeName, forKey: .moleculeName) @@ -112,9 +110,8 @@ open class TileletModel: MoleculeModelProtocol { try container.encodeIfPresent(subTitle, forKey: .subTitle) try container.encodeIfPresent(descriptiveIcon, forKey: .descriptiveIcon) try container.encodeIfPresent(directionalIcon, forKey: .directionalIcon) - try container.encodeIfPresent(width, forKey: .width) try container.encodeIfPresent(textWidth, forKey: .textWidth) try container.encodeIfPresent(textPercentage, forKey: .textPercentage) - try container.encodeModelIfPresent(action, forKey: .action) + try super.encode(to: encoder) } }