Merge branch 'feature/vds-titleLockup-update' into 'develop'

TextColor enums for TitleLockup/Tilelet

### Summary
For TitleLockup there are enum values that pertain to what color palette is used.

### JIRA Ticket
https://onejira.verizon.com/browse/ONEAPP-7847

Co-authored-by: Matt Bruce <matt.bruce@verizon.com>

See merge request https://gitlab.verizon.com/BPHV_MIPS/mvm_core_ui/-/merge_requests/1111
This commit is contained in:
Pfeil, Scott Robert 2024-05-07 21:38:46 +00:00
commit 07db477416
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 eyebrow: LabelModel?
public var eyebrowColor: TitleLockup.TextColor = .primary
public var title: LabelModel?
public var titleColor: TitleLockup.TitleTextColor = .primary
public var subTitle: LabelModel?
public var subTitleColor: TitleLockup.TextColor = .primary
public var descriptiveIcon: Tilelet.DescriptiveIcon?
public var directionalIcon: Tilelet.DirectionalIcon?
public var textWidth: CGFloat?
@ -32,8 +35,11 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
case moleculeName
case badge
case eyebrow
case eyebrowColor
case title
case titleColor
case subTitle
case subTitleColor
case descriptiveIcon
case directionalIcon
case textWidth
@ -50,17 +56,42 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
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)
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)
}
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 {
@ -78,12 +109,6 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
public func titleModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Tilelet.TitleModel? {
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)
do {
@ -103,17 +128,11 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
public func subTitleModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Tilelet.SubTitleModel? {
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)
do {
if let style = subTitle.fontStyle {
return .init(text: subTitle.text,
otherStandardStyle: try style.vdsSubsetStyle(),
otherStandardStyle: try style.vdsSubsetStyle(),
textColor: subTitleColor,
textAttributes: attrs)
}
@ -130,8 +149,11 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
try container.encode(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(badge, forKey: .badge)
try container.encodeModelIfPresent(eyebrow, forKey: .eyebrow)
try container.encode(eyebrowColor, forKey: .eyebrowColor)
try container.encodeModelIfPresent(title, forKey: .title)
try container.encode(titleColor, forKey: .titleColor)
try container.encodeModelIfPresent(subTitle, forKey: .subTitle)
try container.encode(subTitleColor, forKey: .subTitleColor)
try container.encodeIfPresent(descriptiveIcon, forKey: .descriptiveIcon)
try container.encodeIfPresent(directionalIcon, forKey: .directionalIcon)
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 eyebrow: LabelModel?
public var eyebrowColor: TitleLockup.TextColor = .primary
public var title: LabelModel
public var titleColor: TitleLockup.TitleTextColor = .primary
public var subTitle: LabelModel?
public var subTitleColor: TitleLockup.TextColor = .primary
public var alignment: VDS.TitleLockup.TextAlignment = .left
public var inverted: Bool = false
@ -58,8 +61,11 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco
case moleculeName
case textAlignment
case eyebrow
case eyebrowColor
case title
case titleColor
case subTitle
case subTitleColor
case inverted
case alignment
}
@ -76,6 +82,36 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco
eyebrow = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .eyebrow)
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) {
alignment = newAlignment
}
@ -94,20 +130,17 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco
try container.encode(moleculeName, forKey: .moleculeName)
try container.encode(textAlignment, forKey: .textAlignment)
try container.encodeIfPresent(eyebrow, forKey: .eyebrow)
try container.encode(eyebrowColor, forKey: .eyebrowColor)
try container.encodeModel(title, forKey: .title)
try container.encode(titleColor, forKey: .titleColor)
try container.encodeIfPresent(subTitle, forKey: .subTitle)
try container.encode(subTitleColor, forKey: .subTitleColor)
try container.encode(alignment, forKey: .alignment)
try container.encode(inverted, forKey: .inverted)
}
public func eyebrowModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> VDS.TitleLockup.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 {
@ -126,12 +159,6 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco
}
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)
do {
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? {
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)
do {