added eyebrowModel

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-05-07 13:26:39 -05:00
parent 4cd43dcfbe
commit d7fd6f4465
2 changed files with 47 additions and 5 deletions

View File

@ -45,6 +45,7 @@ open class Tilelet: VDS.Tilelet, VDSMoleculeViewProtocol{
} else if let percentage = viewModel.textPercentage { } else if let percentage = viewModel.textPercentage {
textWidth = .percentage(percentage) textWidth = .percentage(percentage)
} }
eyebrowModel = viewModel.eyebrowModel(delegateObject: delegateObject, additionalData: additionalData)
titleModel = viewModel.titleModel(delegateObject: delegateObject, additionalData: additionalData) titleModel = viewModel.titleModel(delegateObject: delegateObject, additionalData: additionalData)
subTitleModel = viewModel.subTitleModel(delegateObject: delegateObject, additionalData: additionalData) subTitleModel = viewModel.subTitleModel(delegateObject: delegateObject, additionalData: additionalData)
badgeModel = viewModel.badge badgeModel = viewModel.badge

View File

@ -19,6 +19,7 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
public var backgroundColor: Color? public var backgroundColor: Color?
public var badge: Tilelet.BadgeModel? public var badge: Tilelet.BadgeModel?
public var eyebrow: LabelModel?
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?
@ -30,6 +31,7 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
case id case id
case moleculeName case moleculeName
case badge case badge
case eyebrow
case title case title
case subTitle case subTitle
case descriptiveIcon case descriptiveIcon
@ -41,6 +43,7 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
let container = try decoder.container(keyedBy: CodingKeys.self) let container = try decoder.container(keyedBy: CodingKeys.self)
id = try container.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString id = try container.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
badge = try container.decodeIfPresent(Tilelet.BadgeModel.self, forKey: .badge) badge = try container.decodeIfPresent(Tilelet.BadgeModel.self, forKey: .badge)
eyebrow = try container.decodeIfPresent(LabelModel.self, forKey: .eyebrow)
title = try container.decodeIfPresent(LabelModel.self, forKey: .title) title = try container.decodeIfPresent(LabelModel.self, forKey: .title)
subTitle = try container.decodeIfPresent(LabelModel.self, forKey: .subTitle) subTitle = try container.decodeIfPresent(LabelModel.self, forKey: .subTitle)
descriptiveIcon = try container.decodeIfPresent(Tilelet.DescriptiveIcon.self, forKey: .descriptiveIcon) descriptiveIcon = try container.decodeIfPresent(Tilelet.DescriptiveIcon.self, forKey: .descriptiveIcon)
@ -50,13 +53,43 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
try super.init(from: decoder) try super.init(from: decoder)
} }
public func eyebrowModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Tilelet.EyebrowModel? {
guard let eyebrow else { return nil }
var eyebrowColor: TitleLockup.TextColor = .primary
if let color = eyebrow.textColor?.uiColor {
eyebrowColor = .custom(color, color)
}
let attrs = eyebrow.attributes?.toVDSLabelAttributeModel(delegateObject: delegateObject, additionalData: additionalData)
do {
if let style = eyebrow.fontStyle {
return .init(text: eyebrow.text,
textColor: eyebrowColor,
textAttributes: attrs, isBold: style.isBold(),
standardStyle: try style.vdsSubsetStyle())
}
} catch MVMCoreError.errorObject(let object) {
MVMCoreLoggingHandler.shared()?.addError(toLog: object)
} catch { }
return .init(text: eyebrow.text, textColor: eyebrowColor, textAttributes: attrs)
}
public func titleModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Tilelet.TitleModel? { public func titleModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Tilelet.TitleModel? {
guard let title else { return nil } guard let title else { return nil }
var titleColor: TitleLockup.TitleTextColor = .primary
if let color = title.textColor?.uiColor {
titleColor = .custom(color, color)
}
let attrs = title.attributes?.toVDSLabelAttributeModel(delegateObject: delegateObject, additionalData: additionalData) let attrs = title.attributes?.toVDSLabelAttributeModel(delegateObject: delegateObject, additionalData: additionalData)
do { do {
if let style = title.fontStyle { if let style = title.fontStyle {
return .init(text: title.text, return .init(text: title.text,
textColor: titleColor,
textAttributes: attrs, textAttributes: attrs,
standardStyle: try style.vdsSubsetStyle()) standardStyle: try style.vdsSubsetStyle())
} }
@ -65,23 +98,30 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
MVMCoreLoggingHandler.shared()?.addError(toLog: object) MVMCoreLoggingHandler.shared()?.addError(toLog: object)
} catch { } } catch { }
return .init(text: title.text, textAttributes: attrs) return .init(text: title.text, textColor: titleColor, textAttributes: attrs)
} }
public func subTitleModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Tilelet.SubTitleModel? { public func subTitleModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Tilelet.SubTitleModel? {
guard let subTitle else { return nil } guard let subTitle else { return nil }
var subTitleColor: TitleLockup.TextColor = .primary
if let color = subTitle.textColor?.uiColor {
subTitleColor = .custom(color, color)
}
let attrs = subTitle.attributes?.toVDSLabelAttributeModel(delegateObject: delegateObject, additionalData: additionalData) let attrs = subTitle.attributes?.toVDSLabelAttributeModel(delegateObject: delegateObject, additionalData: additionalData)
do { do {
if let style = subTitle.fontStyle { if let style = subTitle.fontStyle {
return .init(text: subTitle.text, return .init(text: subTitle.text,
otherStandardStyle: try style.vdsSubsetStyle(), otherStandardStyle: try style.vdsSubsetStyle(),
textColor: subTitleColor,
textAttributes: attrs) textAttributes: attrs)
} }
} catch MVMCoreError.errorObject(let object) { } catch MVMCoreError.errorObject(let object) {
MVMCoreLoggingHandler.shared()?.addError(toLog: object) MVMCoreLoggingHandler.shared()?.addError(toLog: object)
} catch { } } catch { }
return .init(text: subTitle.text, textAttributes: attrs) return .init(text: subTitle.text, textColor: subTitleColor, textAttributes: attrs)
} }
public override func encode(to encoder: Encoder) throws { public override func encode(to encoder: Encoder) throws {
@ -89,8 +129,9 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
try container.encode(id, forKey: .id) try container.encode(id, forKey: .id)
try container.encode(moleculeName, forKey: .moleculeName) try container.encode(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(badge, forKey: .badge) try container.encodeIfPresent(badge, forKey: .badge)
try container.encodeIfPresent(title, forKey: .title) try container.encodeModelIfPresent(eyebrow, forKey: .eyebrow)
try container.encodeIfPresent(subTitle, forKey: .subTitle) try container.encodeModelIfPresent(title, forKey: .title)
try container.encodeModelIfPresent(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(textWidth, forKey: .textWidth) try container.encodeIfPresent(textWidth, forKey: .textWidth)