Merge branch 'develop' of https://gitlab.verizon.com/BPHV_MIPS/mvm_core_ui.git into feature/monarch

This commit is contained in:
Matt Bruce 2024-05-07 16:48:58 -05:00
commit 7e722c07d4
3 changed files with 169 additions and 37 deletions

View File

@ -20,8 +20,11 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
public var badge: Tilelet.BadgeModel? public var badge: Tilelet.BadgeModel?
public var eyebrow: LabelModel? public var eyebrow: LabelModel?
public var eyebrowColor: TitleLockup.TextColor = .primary
public var title: LabelModel? public var title: LabelModel?
public var titleColor: TitleLockup.TitleTextColor = .primary
public var subTitle: LabelModel? public var subTitle: LabelModel?
public var subTitleColor: TitleLockup.TextColor = .primary
public var descriptiveIcon: Tilelet.DescriptiveIcon? public var descriptiveIcon: Tilelet.DescriptiveIcon?
public var directionalIcon: Tilelet.DirectionalIcon? public var directionalIcon: Tilelet.DirectionalIcon?
public var textWidth: CGFloat? public var textWidth: CGFloat?
@ -32,8 +35,11 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
case moleculeName case moleculeName
case badge case badge
case eyebrow case eyebrow
case eyebrowColor
case title case title
case titleColor
case subTitle case subTitle
case subTitleColor
case descriptiveIcon case descriptiveIcon
case directionalIcon case directionalIcon
case textWidth case textWidth
@ -50,17 +56,42 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
directionalIcon = try container.decodeIfPresent(Tilelet.DirectionalIcon.self, forKey: .directionalIcon) directionalIcon = try container.decodeIfPresent(Tilelet.DirectionalIcon.self, forKey: .directionalIcon)
textWidth = try container.decodeIfPresent(CGFloat.self, forKey: .textWidth) textWidth = try container.decodeIfPresent(CGFloat.self, forKey: .textWidth)
textPercentage = try container.decodeIfPresent(CGFloat.self, forKey: .textPercentage) textPercentage = try container.decodeIfPresent(CGFloat.self, forKey: .textPercentage)
if let color = eyebrow?.textColor?.uiColor {
self.eyebrowColor = .custom(color, color)
} else if let eyebrowColor = try? container.decodeIfPresent(TitleLockup.TextColor.self, forKey: .eyebrowColor) {
self.eyebrowColor = eyebrowColor
} else {
eyebrowColor = .primary
}
if let color = title?.textColor?.uiColor {
self.titleColor = .custom(color, color)
} else if let titleColor = try? container.decodeIfPresent(TitleLockup.TitleTextColor.self, forKey: .titleColor) {
self.titleColor = titleColor
} else {
titleColor = .primary
}
if let color = subTitle?.textColor?.uiColor {
self.subTitleColor = .custom(color, color)
} else if let subTitleColor = try? container.decodeIfPresent(TitleLockup.TextColor.self, forKey: .subTitleColor) {
self.subTitleColor = subTitleColor
} else {
subTitleColor = .primary
}
try super.init(from: decoder) try super.init(from: decoder)
} }
public func eyebrowModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Tilelet.EyebrowModel? { public func eyebrowModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Tilelet.EyebrowModel? {
guard let eyebrow else { return nil } 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) let attrs = eyebrow.attributes?.toVDSLabelAttributeModel(delegateObject: delegateObject, additionalData: additionalData)
do { do {
if let style = eyebrow.fontStyle { if let style = eyebrow.fontStyle {
@ -78,12 +109,6 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
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 {
@ -103,17 +128,11 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
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, textColor: subTitleColor,
textAttributes: attrs) textAttributes: attrs)
} }
@ -130,8 +149,11 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
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.encodeModelIfPresent(eyebrow, forKey: .eyebrow) try container.encodeModelIfPresent(eyebrow, forKey: .eyebrow)
try container.encode(eyebrowColor, forKey: .eyebrowColor)
try container.encodeModelIfPresent(title, forKey: .title) try container.encodeModelIfPresent(title, forKey: .title)
try container.encode(titleColor, forKey: .titleColor)
try container.encodeModelIfPresent(subTitle, forKey: .subTitle) try container.encodeModelIfPresent(subTitle, forKey: .subTitle)
try container.encode(subTitleColor, forKey: .subTitleColor)
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)

View File

@ -192,3 +192,92 @@ extension VDS.TileContainer.Padding: Codable {
} }
} }
} }
extension VDS.TitleLockup.TextColor: Codable {
enum CodingKeys: String, CodingKey {
case type
case lightColor
case darkColor
}
enum CustomColorType: String, Codable {
case primary
case secondary
case custom
}
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let type = try container.decode(CustomColorType.self, forKey: .type)
switch type {
case .primary:
self = .primary
case .secondary:
self = .secondary
case .custom:
let lightColor = try container.decode(Color.self, forKey: .lightColor)
let darkColor = try container.decode(Color.self, forKey: .darkColor)
self = .custom(lightColor.uiColor, darkColor.uiColor)
}
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
switch self {
case .primary:
try container.encode(CustomColorType.primary.rawValue, forKey: .type)
case .secondary:
try container.encode(CustomColorType.secondary.rawValue, forKey: .type)
case .custom(let lightColor, let darkColor):
try container.encode(CustomColorType.custom.rawValue, forKey: .type)
try container.encode(Color(uiColor: lightColor), forKey: .lightColor)
try container.encode(Color(uiColor: darkColor), forKey: .darkColor)
@unknown default:
break
}
}
}
extension VDS.TitleLockup.TitleTextColor: Codable {
enum CodingKeys: String, CodingKey {
case type
case lightColor
case darkColor
}
enum CustomColorType: String, Codable {
case primary
case custom
}
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let type = try container.decode(CustomColorType.self, forKey: .type)
switch type {
case .primary:
self = .primary
case .custom:
let lightColor = try container.decode(Color.self, forKey: .lightColor)
let darkColor = try container.decode(Color.self, forKey: .darkColor)
self = .custom(lightColor.uiColor, darkColor.uiColor)
}
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
switch self {
case .primary:
try container.encode(CustomColorType.primary.rawValue, forKey: .type)
case .custom(let lightColor, let darkColor):
try container.encode(CustomColorType.custom.rawValue, forKey: .type)
try container.encode(Color(uiColor: lightColor), forKey: .lightColor)
try container.encode(Color(uiColor: darkColor), forKey: .darkColor)
@unknown default:
break
}
}
}

View File

@ -21,8 +21,11 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco
public var textAlignment: TitleLockup.TextAlignment = .left public var textAlignment: TitleLockup.TextAlignment = .left
public var eyebrow: LabelModel? public var eyebrow: LabelModel?
public var eyebrowColor: TitleLockup.TextColor = .primary
public var title: LabelModel public var title: LabelModel
public var titleColor: TitleLockup.TitleTextColor = .primary
public var subTitle: LabelModel? public var subTitle: LabelModel?
public var subTitleColor: TitleLockup.TextColor = .primary
public var alignment: VDS.TitleLockup.TextAlignment = .left public var alignment: VDS.TitleLockup.TextAlignment = .left
public var inverted: Bool = false public var inverted: Bool = false
@ -58,8 +61,11 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco
case moleculeName case moleculeName
case textAlignment case textAlignment
case eyebrow case eyebrow
case eyebrowColor
case title case title
case titleColor
case subTitle case subTitle
case subTitleColor
case inverted case inverted
case alignment case alignment
} }
@ -76,6 +82,36 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco
eyebrow = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .eyebrow) eyebrow = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .eyebrow)
subTitle = try typeContainer.decodeMoleculeIfPresent(codingKey: .subTitle) subTitle = try typeContainer.decodeMoleculeIfPresent(codingKey: .subTitle)
if let color = eyebrow?.textColor?.uiColor {
self.eyebrowColor = .custom(color, color)
} else if let eyebrowColor = try? typeContainer.decodeIfPresent(TitleLockup.TextColor.self, forKey: .eyebrowColor) {
self.eyebrowColor = eyebrowColor
} else {
eyebrowColor = .primary
}
if let color = title.textColor?.uiColor {
self.titleColor = .custom(color, color)
} else if let titleColor = try? typeContainer.decodeIfPresent(TitleLockup.TitleTextColor.self, forKey: .titleColor) {
self.titleColor = titleColor
} else {
titleColor = .primary
}
if let color = subTitle?.textColor?.uiColor {
self.subTitleColor = .custom(color, color)
} else if let subTitleColor = try? typeContainer.decodeIfPresent(TitleLockup.TextColor.self, forKey: .subTitleColor) {
self.subTitleColor = subTitleColor
} else {
subTitleColor = .primary
}
if let newAlignment = try typeContainer.decodeIfPresent(VDS.TitleLockup.TextAlignment.self, forKey: .alignment) { if let newAlignment = try typeContainer.decodeIfPresent(VDS.TitleLockup.TextAlignment.self, forKey: .alignment) {
alignment = newAlignment alignment = newAlignment
} }
@ -94,20 +130,17 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco
try container.encode(moleculeName, forKey: .moleculeName) try container.encode(moleculeName, forKey: .moleculeName)
try container.encode(textAlignment, forKey: .textAlignment) try container.encode(textAlignment, forKey: .textAlignment)
try container.encodeIfPresent(eyebrow, forKey: .eyebrow) try container.encodeIfPresent(eyebrow, forKey: .eyebrow)
try container.encode(eyebrowColor, forKey: .eyebrowColor)
try container.encodeModel(title, forKey: .title) try container.encodeModel(title, forKey: .title)
try container.encode(titleColor, forKey: .titleColor)
try container.encodeIfPresent(subTitle, forKey: .subTitle) try container.encodeIfPresent(subTitle, forKey: .subTitle)
try container.encode(subTitleColor, forKey: .subTitleColor)
try container.encode(alignment, forKey: .alignment) try container.encode(alignment, forKey: .alignment)
try container.encode(inverted, forKey: .inverted) try container.encode(inverted, forKey: .inverted)
} }
public func eyebrowModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> VDS.TitleLockup.EyebrowModel? { public func eyebrowModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> VDS.TitleLockup.EyebrowModel? {
guard let eyebrow else { return nil } 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) let attrs = eyebrow.attributes?.toVDSLabelAttributeModel(delegateObject: delegateObject, additionalData: additionalData)
do { do {
if let style = eyebrow.fontStyle { if let style = eyebrow.fontStyle {
@ -126,12 +159,6 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco
} }
public func titleModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> VDS.TitleLockup.TitleModel { public func titleModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> VDS.TitleLockup.TitleModel {
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 {
@ -152,12 +179,6 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco
public func subTitleModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> VDS.TitleLockup.SubTitleModel? { public func subTitleModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> VDS.TitleLockup.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 {