added back deprecated coding keys to set the inverted property since we are not accepting color anymore

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-03-28 14:10:12 -05:00
parent c758e300f6
commit 86184d130c
2 changed files with 49 additions and 2 deletions

View File

@ -72,12 +72,30 @@ public class CaretLinkModel: ButtonModelProtocol, MoleculeModelProtocol, Enablea
if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) {
self.enabled = enabled
}
action = try typeContainer.decodeModel(codingKey: .action)
if let inverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) {
self.inverted = inverted
} else {
try setInverted(deprecatedFrom: decoder)
}
}
private enum DeprecatedCodingKeys: String, CodingKey {
case enabledColor
case disabledColor
}
private func setInverted(deprecatedFrom decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: DeprecatedCodingKeys.self)
if let enabledColor = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor) {
self.inverted = !enabledColor.uiColor.isDark()
}
action = try typeContainer.decodeModel(codingKey: .action)
if let disabledColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor) {
self.inverted = disabledColor.uiColor.isDark()
}
}
public func encode(to encoder: Encoder) throws {

View File

@ -76,6 +76,8 @@ open class LinkModel: ButtonModelProtocol, MoleculeModelProtocol, EnableableMode
if let inverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) {
self.inverted = inverted
} else {
try setInverted(deprecatedFrom: decoder)
}
if let size = try typeContainer.decodeIfPresent(TextLink.Size.self, forKey: .size) {
@ -84,6 +86,33 @@ open class LinkModel: ButtonModelProtocol, MoleculeModelProtocol, EnableableMode
shouldMaskRecordedView = try typeContainer.decodeIfPresent(Bool.self, forKey: .shouldMaskRecordedView) ?? shouldMaskRecordedView
}
private enum DeprecatedCodingKeys: String, CodingKey {
case enabledColor
case disabledColor
case enabledColor_inverted
case disabledColor_inverted
}
private func setInverted(deprecatedFrom decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: DeprecatedCodingKeys.self)
if let enabledColor = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor) {
self.inverted = !enabledColor.uiColor.isDark()
}
if let enabledColor_inverted = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor_inverted) {
self.inverted = enabledColor_inverted.uiColor.isDark()
}
if let disabledColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor) {
self.inverted = disabledColor.uiColor.isDark()
}
if let disabledColor_inverted = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor_inverted) {
self.inverted = !disabledColor_inverted.uiColor.isDark()
}
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)