refactored the Tilelet with missing tilecontainer properties

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-04-15 15:16:28 -05:00
parent 61a5f4d7d1
commit 44cbeeb695
2 changed files with 29 additions and 26 deletions

View File

@ -39,10 +39,16 @@ open class Tilelet: VDS.Tilelet, VDSMoleculeViewProtocol{
// MARK: - Public // MARK: - Public
//-------------------------------------------------- //--------------------------------------------------
public func viewModelDidUpdate() { public func viewModelDidUpdate() {
color = viewModel.color
padding = viewModel.padding padding = viewModel.padding
color = viewModel.color
backgroundEffect = viewModel.backgroundEffect
aspectRatio = viewModel.aspectRatio aspectRatio = viewModel.aspectRatio
width = viewModel.width width = viewModel.width
height = viewModel.height
showBorder = viewModel.showBorder
showDropShadows = viewModel.showDropShadwows
if let value = viewModel.textWidth { if let value = viewModel.textWidth {
textWidth = .value(value) textWidth = .value(value)
} else if let percentage = viewModel.textPercentage { } else if let percentage = viewModel.textPercentage {

View File

@ -9,7 +9,7 @@
import Foundation import Foundation
import VDS import VDS
open class TileletModel: MoleculeModelProtocol { open class TileletModel: TileContainerBaseModel, MoleculeModelProtocol {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Properties // MARK: - Properties
@ -17,23 +17,23 @@ open class TileletModel: MoleculeModelProtocol {
public static var identifier: String = "tilelet" public static var identifier: String = "tilelet"
public var id: String = UUID().uuidString public var id: String = UUID().uuidString
public var backgroundColor: Color? public var backgroundColor: Color?
public var color: Tilelet.BackgroundColor public var color: Tilelet.BackgroundColor = .black
public var padding: Tilelet.Padding public var padding: Tilelet.Padding = .large
public var aspectRatio: Tilelet.AspectRatio public var aspectRatio: Tilelet.AspectRatio = .ratio1x1
public var backgroundEffect: Tilelet.BackgroundEffect = .none
public var badge: Tilelet.BadgeModel? public var badge: Tilelet.BadgeModel?
public var title: LabelModel? public var title: LabelModel?
public var subTitle: LabelModel? public var subTitle: LabelModel?
public var descriptiveIcon: Tilelet.DescriptiveIcon? public var descriptiveIcon: Tilelet.DescriptiveIcon?
public var directionalIcon: Tilelet.DirectionalIcon? public var directionalIcon: Tilelet.DirectionalIcon?
public var width: CGFloat?
public var textWidth: CGFloat? public var textWidth: CGFloat?
public var textPercentage: CGFloat? public var textPercentage: CGFloat?
public var action: ActionModelProtocol?
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case id case id
case moleculeName case moleculeName
case backgroundColor case backgroundColor
case backgroundEffect
case color case color
case padding case padding
case aspectRatio case aspectRatio
@ -42,27 +42,25 @@ open class TileletModel: MoleculeModelProtocol {
case subTitle case subTitle
case descriptiveIcon case descriptiveIcon
case directionalIcon case directionalIcon
case width
case textWidth case textWidth
case textPercentage case textPercentage
case action
} }
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self) let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString id = try container.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
self.backgroundColor = try container.decodeIfPresent(Color.self, forKey: .backgroundColor) backgroundColor = try container.decodeIfPresent(Color.self, forKey: .backgroundColor)
self.color = try container.decodeIfPresent(Tilelet.BackgroundColor.self, forKey: .color) ?? Tilelet.BackgroundColor.black 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 backgroundEffect = try container.decodeIfPresent(Tilelet.BackgroundEffect.self, forKey: .backgroundEffect) ?? .none
self.aspectRatio = try container.decodeIfPresent(Tilelet.AspectRatio.self, forKey: .aspectRatio) ?? Tilelet.AspectRatio.none padding = try container.decodeIfPresent(Tilelet.Padding.self, forKey: .padding) ?? Tilelet.Padding.small
self.badge = try container.decodeIfPresent(Tilelet.BadgeModel.self, forKey: .badge) aspectRatio = try container.decodeIfPresent(Tilelet.AspectRatio.self, forKey: .aspectRatio) ?? Tilelet.AspectRatio.none
self.title = try container.decodeIfPresent(LabelModel.self, forKey: .title) badge = try container.decodeIfPresent(Tilelet.BadgeModel.self, forKey: .badge)
self.subTitle = try container.decodeIfPresent(LabelModel.self, forKey: .subTitle) title = try container.decodeIfPresent(LabelModel.self, forKey: .title)
self.descriptiveIcon = try container.decodeIfPresent(Tilelet.DescriptiveIcon.self, forKey: .descriptiveIcon) subTitle = try container.decodeIfPresent(LabelModel.self, forKey: .subTitle)
self.directionalIcon = try container.decodeIfPresent(Tilelet.DirectionalIcon.self, forKey: .directionalIcon) descriptiveIcon = try container.decodeIfPresent(Tilelet.DescriptiveIcon.self, forKey: .descriptiveIcon)
self.width = try container.decodeIfPresent(CGFloat.self, forKey: .width) directionalIcon = try container.decodeIfPresent(Tilelet.DirectionalIcon.self, forKey: .directionalIcon)
self.textWidth = try container.decodeIfPresent(CGFloat.self, forKey: .textWidth) textWidth = try container.decodeIfPresent(CGFloat.self, forKey: .textWidth)
self.textPercentage = try container.decodeIfPresent(CGFloat.self, forKey: .textPercentage) textPercentage = try container.decodeIfPresent(CGFloat.self, forKey: .textPercentage)
action = try container.decodeModelIfPresent(codingKey: .action) try super.init(from: decoder)
} }
public func titleModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Tilelet.TitleModel? { 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) 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) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id) try container.encode(id, forKey: .id)
try container.encode(moleculeName, forKey: .moleculeName) try container.encode(moleculeName, forKey: .moleculeName)
@ -112,9 +110,8 @@ open class TileletModel: MoleculeModelProtocol {
try container.encodeIfPresent(subTitle, forKey: .subTitle) try container.encodeIfPresent(subTitle, forKey: .subTitle)
try container.encodeIfPresent(descriptiveIcon, forKey: .descriptiveIcon) try container.encodeIfPresent(descriptiveIcon, forKey: .descriptiveIcon)
try container.encodeIfPresent(directionalIcon, forKey: .directionalIcon) try container.encodeIfPresent(directionalIcon, forKey: .directionalIcon)
try container.encodeIfPresent(width, forKey: .width)
try container.encodeIfPresent(textWidth, forKey: .textWidth) try container.encodeIfPresent(textWidth, forKey: .textWidth)
try container.encodeIfPresent(textPercentage, forKey: .textPercentage) try container.encodeIfPresent(textPercentage, forKey: .textPercentage)
try container.encodeModelIfPresent(action, forKey: .action) try super.encode(to: encoder)
} }
} }