Merge branch 'feature/vds-titleLockup-update' into 'develop'
Updated against new TitleLockup ### Summary Updated to fix issues with the VDS TitleLockup text color changes. ### JIRA Ticket Co-authored-by: Matt Bruce <matt.bruce@verizon.com> See merge request https://gitlab.verizon.com/BPHV_MIPS/mvm_core_ui/-/merge_requests/1110
This commit is contained in:
commit
208fbd4824
@ -45,6 +45,7 @@ open class Tilelet: VDS.Tilelet, VDSMoleculeViewProtocol{
|
||||
} else if let percentage = viewModel.textPercentage {
|
||||
textWidth = .percentage(percentage)
|
||||
}
|
||||
eyebrowModel = viewModel.eyebrowModel(delegateObject: delegateObject, additionalData: additionalData)
|
||||
titleModel = viewModel.titleModel(delegateObject: delegateObject, additionalData: additionalData)
|
||||
subTitleModel = viewModel.subTitleModel(delegateObject: delegateObject, additionalData: additionalData)
|
||||
badgeModel = viewModel.badge
|
||||
|
||||
@ -19,6 +19,7 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
|
||||
public var backgroundColor: Color?
|
||||
|
||||
public var badge: Tilelet.BadgeModel?
|
||||
public var eyebrow: LabelModel?
|
||||
public var title: LabelModel?
|
||||
public var subTitle: LabelModel?
|
||||
public var descriptiveIcon: Tilelet.DescriptiveIcon?
|
||||
@ -30,6 +31,7 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
|
||||
case id
|
||||
case moleculeName
|
||||
case badge
|
||||
case eyebrow
|
||||
case title
|
||||
case subTitle
|
||||
case descriptiveIcon
|
||||
@ -41,6 +43,7 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
id = try container.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
|
||||
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)
|
||||
subTitle = try container.decodeIfPresent(LabelModel.self, forKey: .subTitle)
|
||||
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)
|
||||
}
|
||||
|
||||
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? {
|
||||
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 {
|
||||
if let style = title.fontStyle {
|
||||
return .init(text: title.text,
|
||||
textColor: titleColor,
|
||||
textAttributes: attrs,
|
||||
standardStyle: try style.vdsSubsetStyle())
|
||||
}
|
||||
@ -65,23 +98,30 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
|
||||
MVMCoreLoggingHandler.shared()?.addError(toLog: object)
|
||||
} 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? {
|
||||
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)
|
||||
}
|
||||
} catch MVMCoreError.errorObject(let object) {
|
||||
MVMCoreLoggingHandler.shared()?.addError(toLog: object)
|
||||
} 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 {
|
||||
@ -89,8 +129,9 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
|
||||
try container.encode(id, forKey: .id)
|
||||
try container.encode(moleculeName, forKey: .moleculeName)
|
||||
try container.encodeIfPresent(badge, forKey: .badge)
|
||||
try container.encodeIfPresent(title, forKey: .title)
|
||||
try container.encodeIfPresent(subTitle, forKey: .subTitle)
|
||||
try container.encodeModelIfPresent(eyebrow, forKey: .eyebrow)
|
||||
try container.encodeModelIfPresent(title, forKey: .title)
|
||||
try container.encodeModelIfPresent(subTitle, forKey: .subTitle)
|
||||
try container.encodeIfPresent(descriptiveIcon, forKey: .descriptiveIcon)
|
||||
try container.encodeIfPresent(directionalIcon, forKey: .directionalIcon)
|
||||
try container.encodeIfPresent(textWidth, forKey: .textWidth)
|
||||
|
||||
@ -75,7 +75,7 @@ extension VDS.TileContainerBase.BackgroundColor: Codable {
|
||||
var container = encoder.singleValueContainer()
|
||||
switch self {
|
||||
case .custom(let value):
|
||||
try container.encode(value)
|
||||
try container.encode(Color(uiColor: value))
|
||||
default:
|
||||
try container.encode(String(reflecting: self))
|
||||
}
|
||||
@ -96,9 +96,9 @@ extension VDS.TileContainerBase.BackgroundColor: Codable {
|
||||
self = .black
|
||||
default:
|
||||
if let color = try? Color(from: decoder) {
|
||||
self = .custom(color.hex)
|
||||
self = .custom(color.uiColor)
|
||||
} else {
|
||||
self = .custom(type)
|
||||
self = .custom(UIColor(hexString: type))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -128,9 +128,9 @@ extension VDS.TileContainerBase.BackgroundEffect: Codable {
|
||||
case .none:
|
||||
self = .none
|
||||
case .gradient:
|
||||
let firstColor = try container.decode(String.self, forKey: .firstColor)
|
||||
let secondColor = try container.decode(String.self, forKey: .secondColor)
|
||||
self = .gradient(firstColor, secondColor)
|
||||
let firstColor = try container.decode(Color.self, forKey: .firstColor)
|
||||
let secondColor = try container.decode(Color.self, forKey: .secondColor)
|
||||
self = .gradient(firstColor.uiColor, secondColor.uiColor)
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,8 +143,8 @@ extension VDS.TileContainerBase.BackgroundEffect: Codable {
|
||||
try container.encode(BackgroundEffectType.none.rawValue, forKey: .type)
|
||||
case .gradient(let firstColor, let secondColor):
|
||||
try container.encode(BackgroundEffectType.gradient.rawValue, forKey: .type)
|
||||
try container.encode(firstColor, forKey: .firstColor)
|
||||
try container.encode(secondColor, forKey: .secondColor)
|
||||
try container.encode(Color(uiColor: firstColor), forKey: .firstColor)
|
||||
try container.encode(Color(uiColor: secondColor), forKey: .secondColor)
|
||||
@unknown default:
|
||||
break
|
||||
}
|
||||
|
||||
@ -23,7 +23,6 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco
|
||||
public var eyebrow: LabelModel?
|
||||
public var title: LabelModel
|
||||
public var subTitle: LabelModel?
|
||||
public var subTitleColor: Use = .primary
|
||||
|
||||
public var alignment: VDS.TitleLockup.TextAlignment = .left
|
||||
public var inverted: Bool = false
|
||||
@ -61,7 +60,6 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco
|
||||
case eyebrow
|
||||
case title
|
||||
case subTitle
|
||||
case subTitleColor
|
||||
case inverted
|
||||
case alignment
|
||||
}
|
||||
@ -78,17 +76,6 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco
|
||||
eyebrow = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .eyebrow)
|
||||
subTitle = try typeContainer.decodeMoleculeIfPresent(codingKey: .subTitle)
|
||||
|
||||
/// look for color hex code
|
||||
if let color = try? typeContainer.decodeIfPresent(Color.self, forKey: .subTitleColor) {
|
||||
self.subTitleColor = color.uiColor.isDark() ? .primary : .secondary
|
||||
|
||||
} else if let subTitleColor = try? typeContainer.decodeIfPresent(Use.self, forKey: .subTitleColor) {
|
||||
self.subTitleColor = subTitleColor
|
||||
|
||||
} else {
|
||||
subTitleColor = .primary
|
||||
}
|
||||
|
||||
if let newAlignment = try typeContainer.decodeIfPresent(VDS.TitleLockup.TextAlignment.self, forKey: .alignment) {
|
||||
alignment = newAlignment
|
||||
}
|
||||
@ -109,17 +96,23 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco
|
||||
try container.encodeIfPresent(eyebrow, forKey: .eyebrow)
|
||||
try container.encodeModel(title, forKey: .title)
|
||||
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 {
|
||||
return .init(text: eyebrow.text,
|
||||
textColor: eyebrowColor,
|
||||
isBold: style.isBold(),
|
||||
standardStyle: try style.vdsSubsetStyle(),
|
||||
textAttributes: attrs,
|
||||
@ -129,14 +122,21 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco
|
||||
MVMCoreLoggingHandler.shared()?.addError(toLog: object)
|
||||
} catch { }
|
||||
|
||||
return .init(text: eyebrow.text, textAttributes: attrs, numberOfLines: eyebrow.numberOfLines ?? 0)
|
||||
return .init(text: eyebrow.text, textColor: eyebrowColor, textAttributes: attrs, numberOfLines: eyebrow.numberOfLines ?? 0)
|
||||
}
|
||||
|
||||
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 {
|
||||
return .init(text: title.text,
|
||||
textColor: titleColor,
|
||||
textAttributes: attrs,
|
||||
isBold: style.isBold(),
|
||||
standardStyle: try style.vdsSubsetStyle(),
|
||||
@ -147,11 +147,17 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco
|
||||
MVMCoreLoggingHandler.shared()?.addError(toLog: object)
|
||||
} catch { }
|
||||
|
||||
return .init(text: title.text, textAttributes: attrs, numberOfLines: title.numberOfLines ?? 0)
|
||||
return .init(text: title.text, textColor: titleColor, textAttributes: attrs, numberOfLines: title.numberOfLines ?? 0)
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
@ -86,11 +86,14 @@ public final class Color: Codable {
|
||||
let colorString = try container.decode(String.self)
|
||||
|
||||
if let vdsColor = UIColor.VDSColor(rawValue: colorString) {
|
||||
self.uiColor = vdsColor.uiColor
|
||||
uiColor = vdsColor.uiColor
|
||||
hex = uiColor.hexString ?? ""
|
||||
} else if let color = Color(name: colorString) {
|
||||
uiColor = color.uiColor
|
||||
hex = color.hex
|
||||
} else {
|
||||
let components = try Color.getColorComponents(for: colorString)
|
||||
self.uiColor = components.color
|
||||
uiColor = components.color
|
||||
hex = components.hex
|
||||
name = components.name ?? ""
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user