redid the values
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
76b58ec88a
commit
7eb1a4ff4b
@ -27,11 +27,13 @@ open class BadgeModel: MoleculeModelProtocol {
|
|||||||
public var maxWidth: CGFloat?
|
public var maxWidth: CGFloat?
|
||||||
public var numberOfLines: Int = 1
|
public var numberOfLines: Int = 1
|
||||||
public var fillColorStyle = Badge.FillColor.red
|
public var fillColorStyle = Badge.FillColor.red
|
||||||
public var fillColor: Color?
|
|
||||||
public var surface: Surface = .light
|
public var surface: Surface = .light
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case id, accessibilityIdentifier, text, textColor, textColorStyle, accessibilityText, fillColor, fillColorStyle, surface, numberOfLines, maxWidth
|
case id, accessibilityIdentifier, accessibilityText
|
||||||
|
case surface, numberOfLines, maxWidth
|
||||||
|
case text, textColor
|
||||||
|
case fillColor, fillColorStyle
|
||||||
}
|
}
|
||||||
|
|
||||||
required public convenience init(from decoder: Decoder) throws {
|
required public convenience init(from decoder: Decoder) throws {
|
||||||
@ -48,7 +50,7 @@ open class BadgeModel: MoleculeModelProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//look for a style
|
//look for a style
|
||||||
fillColorStyle = try container.decodeIfPresent(Badge.FillColor.self, forKey: .fillColor) ?? .red
|
fillColorStyle = try container.decodeIfPresent(Badge.FillColor.self, forKey: .fillColorStyle) ?? .red
|
||||||
|
|
||||||
//look for a color and set the style
|
//look for a color and set the style
|
||||||
if let fillColor = try container.decodeIfPresent(Color.self, forKey: .fillColor) {
|
if let fillColor = try container.decodeIfPresent(Color.self, forKey: .fillColor) {
|
||||||
@ -65,10 +67,10 @@ open class BadgeModel: MoleculeModelProtocol {
|
|||||||
try container.encode(text, forKey: .text)
|
try container.encode(text, forKey: .text)
|
||||||
try container.encode(accessibilityText, forKey: .accessibilityText)
|
try container.encode(accessibilityText, forKey: .accessibilityText)
|
||||||
try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier)
|
try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier)
|
||||||
try container.encode(fillColor, forKey: .fillColor)
|
|
||||||
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)
|
||||||
|
try container.encode(fillColorStyle, forKey: .fillColorStyle)
|
||||||
switch textColorStyle {
|
switch textColorStyle {
|
||||||
case .custom(let color):
|
case .custom(let color):
|
||||||
try container.encode(Color(uiColor: color), forKey: .textColor)
|
try container.encode(Color(uiColor: color), forKey: .textColor)
|
||||||
@ -80,7 +82,8 @@ open class BadgeModel: MoleculeModelProtocol {
|
|||||||
public func isEqual(to model: any ModelComparisonProtocol) -> Bool {
|
public func isEqual(to model: any ModelComparisonProtocol) -> Bool {
|
||||||
guard let model = model as? BadgeModel else { return false }
|
guard let model = model as? BadgeModel else { return false }
|
||||||
return self.backgroundColor == model.backgroundColor
|
return self.backgroundColor == model.backgroundColor
|
||||||
&& self.fillColor == model.fillColor
|
&& self.fillColorStyle == model.fillColorStyle
|
||||||
|
&& self.textColorStyle == model.textColorStyle
|
||||||
&& self.numberOfLines == model.numberOfLines
|
&& self.numberOfLines == model.numberOfLines
|
||||||
&& self.text == model.text
|
&& self.text == model.text
|
||||||
&& self.surface == model.surface
|
&& self.surface == model.surface
|
||||||
|
|||||||
@ -294,49 +294,40 @@ extension VDS.TitleLockup.TextColor: Codable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension VDS.Badge.FillColor: 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 {
|
public init(from decoder: Decoder) throws {
|
||||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
let container = try decoder.singleValueContainer()
|
||||||
let type = try container.decode(CustomColorType.self, forKey: .type)
|
let type = try container.decode(String.self)
|
||||||
|
|
||||||
switch type {
|
switch type {
|
||||||
case .red:
|
case "red":
|
||||||
self = .red
|
self = .red
|
||||||
case .yellow:
|
case "yellow":
|
||||||
self = .yellow
|
self = .yellow
|
||||||
case .green:
|
case "green":
|
||||||
self = .green
|
self = .green
|
||||||
case .orange:
|
case "orange":
|
||||||
self = .orange
|
self = .orange
|
||||||
case .blue:
|
case "blue":
|
||||||
self = .blue
|
self = .blue
|
||||||
case .black:
|
case "black":
|
||||||
self = .black
|
self = .black
|
||||||
case .white:
|
case "white":
|
||||||
self = .white
|
self = .white
|
||||||
case .custom:
|
default:
|
||||||
let color = try container.decode(Color.self, forKey: .color)
|
if let color = try? Color(from: decoder) {
|
||||||
self = .custom(color.uiColor)
|
self = .custom(color.uiColor)
|
||||||
|
} else {
|
||||||
|
self = .custom(UIColor(hexString: type))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func encode(to encoder: Encoder) throws {
|
public func encode(to encoder: Encoder) throws {
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.singleValueContainer()
|
||||||
switch self {
|
switch self {
|
||||||
case .custom(let color):
|
case .custom(let value):
|
||||||
try container.encode(CustomColorType.custom.rawValue, forKey: .type)
|
try container.encode(Color(uiColor: value))
|
||||||
try container.encode(Color(uiColor: color), forKey: .color)
|
|
||||||
default:
|
default:
|
||||||
try container.encode("\(self)", forKey: .type)
|
try container.encode(String(reflecting: self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user