added depreciated coding keys
also reverted to non-hard typed LabelModel as done previous. Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
995bec6cb2
commit
fb2a866f14
@ -74,20 +74,33 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco
|
|||||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
id = try typeContainer.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
|
id = try typeContainer.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
|
||||||
textAlignment = try typeContainer.decodeIfPresent(TitleLockup.TextAlignment.self, forKey: .textAlignment) ?? .left
|
textAlignment = try typeContainer.decodeIfPresent(TitleLockup.TextAlignment.self, forKey: .textAlignment) ?? .left
|
||||||
title = try typeContainer.decode(LabelModel.self, forKey: .title)
|
title = try typeContainer.decodeMolecule(codingKey: .title)
|
||||||
eyebrow = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .eyebrow)
|
eyebrow = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .eyebrow)
|
||||||
subTitle = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .subTitle)
|
subTitle = try typeContainer.decodeMoleculeIfPresent(codingKey: .subTitle)
|
||||||
subTitleColor = try typeContainer.decodeIfPresent(Use.self, forKey: .subTitleColor) ?? .primary
|
|
||||||
|
/// 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) {
|
if let newAlignment = try typeContainer.decodeIfPresent(VDS.TitleLockup.TextAlignment.self, forKey: .alignment) {
|
||||||
alignment = newAlignment
|
alignment = newAlignment
|
||||||
}
|
}
|
||||||
|
|
||||||
if let invertedStatus = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) {
|
if let inverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) {
|
||||||
inverted = invertedStatus
|
self.inverted = inverted
|
||||||
|
} else {
|
||||||
|
try setInverted(deprecatedFrom: decoder)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func encode(to encoder: Encoder) throws {
|
public func encode(to encoder: Encoder) throws {
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
try container.encode(id, forKey: .id)
|
try container.encode(id, forKey: .id)
|
||||||
@ -156,6 +169,24 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco
|
|||||||
return .init(text: subTitle.text, textColor: subTitleColor, textAttributes: attrs, numberOfLines: subTitle.numberOfLines ?? 0)
|
return .init(text: subTitle.text, textColor: subTitleColor, textAttributes: attrs, numberOfLines: subTitle.numberOfLines ?? 0)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private enum DeprecatedCodingKeys: String, CodingKey {
|
||||||
|
case titleColor
|
||||||
|
case backgroundColor
|
||||||
|
}
|
||||||
|
|
||||||
|
private func setInverted(deprecatedFrom decoder: Decoder) throws {
|
||||||
|
let typeContainer = try decoder.container(keyedBy: DeprecatedCodingKeys.self)
|
||||||
|
|
||||||
|
if let titleColor = try typeContainer.decodeIfPresent(Color.self, forKey: .titleColor) {
|
||||||
|
inverted = !titleColor.uiColor.isDark()
|
||||||
|
}
|
||||||
|
|
||||||
|
if let backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) {
|
||||||
|
inverted = !backgroundColor.uiColor.isDark()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension TitleLockupModel {
|
extension TitleLockupModel {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user