Merge branch 'feature/CXTDT-624895-Badge-Color-Updates' into 'develop'

VDS - iOS Badge - Include ability to select custom color for Label and Background

### Summary
CXT - Defect TrackerCXTDT-624895
VDS - iOS Badge - Include ability to select custom color for Label and Background
### JIRA Ticket
https://onejira.verizon.com/browse/CXTDT-624895

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

See merge request https://gitlab.verizon.com/BPHV_MIPS/mvm_core_ui/-/merge_requests/1199
This commit is contained in:
Hedden, Kyle Matthew 2024-10-09 13:04:36 +00:00
commit f3e97ecfd4
5 changed files with 74 additions and 5 deletions

View File

@ -31,6 +31,7 @@ open class Badge: VDS.Badge, VDSMoleculeViewProtocol {
self.accessibilityIdentifier = accessibilityIdentifier self.accessibilityIdentifier = accessibilityIdentifier
} }
text = viewModel.text text = viewModel.text
textColor = viewModel.textColor
maxWidth = viewModel.maxWidth maxWidth = viewModel.maxWidth
numberOfLines = viewModel.numberOfLines numberOfLines = viewModel.numberOfLines
fillColor = viewModel.fillColor fillColor = viewModel.fillColor

View File

@ -22,6 +22,7 @@ open class BadgeModel: MoleculeModelProtocol {
// MARK: - VDS Properties // MARK: - VDS Properties
//-------------------------------------------------- //--------------------------------------------------
public var text: String = "" public var text: String = ""
public var textColor: Badge.TextColor? = nil
public var accessibilityText: String? public var accessibilityText: String?
public var maxWidth: CGFloat? public var maxWidth: CGFloat?
public var numberOfLines: Int = 1 public var numberOfLines: Int = 1
@ -29,7 +30,7 @@ open class BadgeModel: MoleculeModelProtocol {
public var surface: Surface = .light public var surface: Surface = .light
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case id, accessibilityIdentifier, text, accessibilityText, fillColor, surface, numberOfLines, maxWidth case id, accessibilityIdentifier, text, textColor, accessibilityText, fillColor, surface, numberOfLines, maxWidth
} }
required public convenience init(from decoder: Decoder) throws { required public convenience init(from decoder: Decoder) throws {
@ -38,6 +39,9 @@ open class BadgeModel: MoleculeModelProtocol {
id = try container.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString id = try container.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
accessibilityIdentifier = try container.decodeIfPresent(String.self, forKey: .accessibilityIdentifier) accessibilityIdentifier = try container.decodeIfPresent(String.self, forKey: .accessibilityIdentifier)
text = try container.decode(String.self, forKey: .text) text = try container.decode(String.self, forKey: .text)
if let foundTextColor = try container.decodeIfPresent(Color.self, forKey: .textColor) {
textColor = .custom(foundTextColor.uiColor)
}
accessibilityText = try container.decodeIfPresent(String.self, forKey: .accessibilityText) accessibilityText = try container.decodeIfPresent(String.self, forKey: .accessibilityText)
fillColor = try container.decodeIfPresent(Badge.FillColor.self, forKey: .fillColor) ?? .red fillColor = try container.decodeIfPresent(Badge.FillColor.self, forKey: .fillColor) ?? .red
surface = try container.decodeIfPresent(Surface.self, forKey: .surface) ?? .light surface = try container.decodeIfPresent(Surface.self, forKey: .surface) ?? .light
@ -55,6 +59,12 @@ open class BadgeModel: MoleculeModelProtocol {
try container.encode(surface, forKey: .surface) try container.encode(surface, forKey: .surface)
try container.encode(numberOfLines, forKey: .numberOfLines) try container.encode(numberOfLines, forKey: .numberOfLines)
try container.encodeIfPresent(maxWidth, forKey: .maxWidth) try container.encodeIfPresent(maxWidth, forKey: .maxWidth)
switch textColor {
case .custom(let color):
try container.encode(Color(uiColor: color), forKey: .textColor)
default:
break
}
} }
public func isEqual(to model: any ModelComparisonProtocol) -> Bool { public func isEqual(to model: any ModelComparisonProtocol) -> Bool {

View File

@ -51,7 +51,7 @@ open class Tilelet: VDS.Tilelet, VDSMoleculeViewProtocol{
eyebrowModel = viewModel.eyebrowModel(delegateObject: delegateObject, additionalData: additionalData) 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.badgeModel()
descriptiveIconModel = viewModel.descriptiveIcon descriptiveIconModel = viewModel.descriptiveIcon
directionalIconModel = viewModel.directionalIcon directionalIconModel = viewModel.directionalIcon
//setup action //setup action

View File

@ -18,7 +18,7 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
public var id: String = UUID().uuidString public var id: String = UUID().uuidString
public var backgroundColor: Color? public var backgroundColor: Color?
public var badge: Tilelet.BadgeModel? public var badge: BadgeModel?
public var eyebrow: LabelModel? public var eyebrow: LabelModel?
public var eyebrowColor: TitleLockup.TextColor = .primary public var eyebrowColor: TitleLockup.TextColor = .primary
public var title: LabelModel? public var title: LabelModel?
@ -49,7 +49,7 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
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)
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(BadgeModel.self, forKey: .badge)
eyebrow = try container.decodeIfPresent(LabelModel.self, forKey: .eyebrow) 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)
@ -91,6 +91,17 @@ open class TileletModel: TileContainerBaseModel<Tilelet.Padding, Tilelet>, Molec
try super.init(from: decoder) try super.init(from: decoder)
} }
public func badgeModel() -> Tilelet.BadgeModel? {
guard let badge else { return nil }
return .init(text: badge.text,
textColor: badge.textColor,
fillColor: badge.fillColor,
surface: badge.surface,
numberOfLines: badge.numberOfLines,
maxWidth: badge.maxWidth
)
}
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 }
let attrs = eyebrow.attributes?.toVDSLabelAttributeModel(delegateObject: delegateObject, additionalData: additionalData) let attrs = eyebrow.attributes?.toVDSLabelAttributeModel(delegateObject: delegateObject, additionalData: additionalData)

View File

@ -16,7 +16,6 @@ import MVMCore
//-------------------------------------------------- //--------------------------------------------------
extension VDS.Surface: Codable {} extension VDS.Surface: Codable {}
extension VDS.Badge.FillColor: Codable {}
extension VDS.BadgeIndicator.FillColor: Codable {} extension VDS.BadgeIndicator.FillColor: Codable {}
extension VDS.BadgeIndicator.Kind: Codable {} extension VDS.BadgeIndicator.Kind: Codable {}
extension VDS.BadgeIndicator.MaximumDigits: Codable {} extension VDS.BadgeIndicator.MaximumDigits: Codable {}
@ -294,6 +293,54 @@ extension VDS.TitleLockup.TextColor: Codable {
} }
} }
extension VDS.Badge.FillColor: Codable {
enum CodingKeys: String, CodingKey {
case type
case color
}
enum CustomColorType: String, Codable {
case red, yellow, green, orange, blue, black, white
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 .red:
self = .red
case .yellow:
self = .yellow
case .green:
self = .green
case .orange:
self = .orange
case .blue:
self = .blue
case .black:
self = .black
case .white:
self = .white
case .custom:
let color = try container.decode(Color.self, forKey: .color)
self = .custom(color.uiColor)
}
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
switch self {
case .custom(let color):
try container.encode(CustomColorType.custom.rawValue, forKey: .type)
try container.encode(Color(uiColor: color), forKey: .color)
default:
try container.encode("\(self)", forKey: .type)
}
}
}
extension VDS.TitleLockup.TitleTextColor: Codable { extension VDS.TitleLockup.TitleTextColor: Codable {
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {