Updated indexColor key to stringColor & data type to Color
This commit is contained in:
parent
7e175ef581
commit
b9267f219f
@ -17,18 +17,18 @@ import Foundation
|
||||
case moleculeName
|
||||
case backgroundColor
|
||||
case list
|
||||
case indexColor
|
||||
case stringColor
|
||||
}
|
||||
|
||||
// Numbered list model comes in the from of list = [MoleculeModelProtocol]
|
||||
public required init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
let indexColor = try typeContainer.decodeIfPresent(String.self, forKey: .indexColor)
|
||||
let stringColor = try typeContainer.decodeIfPresent(Color.self, forKey: .stringColor)
|
||||
let list: [MoleculeModelProtocol] = try typeContainer.decodeModels(codingKey: .list)
|
||||
var models: [MoleculeStackItemModel] = []
|
||||
for (index, molecule) in list.enumerated() {
|
||||
models.append(MoleculeStackItemModel(with: StringAndMoleculeModel(string: "\(index+1).", molecule: molecule, indexColor: indexColor)))
|
||||
models.append(MoleculeStackItemModel(with: StringAndMoleculeModel(string: "\(index+1).", molecule: molecule, stringColor: stringColor)))
|
||||
}
|
||||
super.init(molecules: models, spacing: 0)
|
||||
}
|
||||
@ -38,15 +38,15 @@ import Foundation
|
||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||
try container.encode(moleculeName, forKey: .moleculeName)
|
||||
|
||||
var indexColor: String?
|
||||
var indexColor: Color?
|
||||
var models: [MoleculeModelProtocol] = []
|
||||
for molecule in molecules {
|
||||
let stringAndMoleculeModel: StringAndMoleculeModel = ((molecule as! MoleculeStackItemModel).molecule as! StringAndMoleculeModel)
|
||||
indexColor = stringAndMoleculeModel.indexColor
|
||||
indexColor = stringAndMoleculeModel.stringColor
|
||||
models.append(stringAndMoleculeModel.molecule)
|
||||
}
|
||||
try container.encodeModels(models, forKey: .list)
|
||||
try container.encodeIfPresent(indexColor, forKey: .indexColor)
|
||||
try container.encodeIfPresent(indexColor, forKey: .stringColor)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -13,12 +13,12 @@ public class StringAndMoleculeModel: MoleculeModelProtocol {
|
||||
public var backgroundColor: Color?
|
||||
public var string: String
|
||||
public var molecule: MoleculeModelProtocol
|
||||
public var indexColor: String?
|
||||
public var stringColor: Color?
|
||||
|
||||
public init(string: String, molecule: MoleculeModelProtocol, indexColor: String?) {
|
||||
public init(string: String, molecule: MoleculeModelProtocol, stringColor: Color?) {
|
||||
self.string = string
|
||||
self.molecule = molecule
|
||||
self.indexColor = indexColor
|
||||
self.stringColor = stringColor
|
||||
}
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
@ -26,7 +26,7 @@ public class StringAndMoleculeModel: MoleculeModelProtocol {
|
||||
case backgroundColor
|
||||
case string
|
||||
case molecule
|
||||
case indexColor
|
||||
case stringColor
|
||||
}
|
||||
|
||||
public required init(from decoder: Decoder) throws {
|
||||
@ -34,7 +34,7 @@ public class StringAndMoleculeModel: MoleculeModelProtocol {
|
||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||
string = try typeContainer.decode(String.self, forKey: .string)
|
||||
molecule = try typeContainer.decodeModel(codingKey: .molecule)
|
||||
indexColor = try typeContainer.decodeIfPresent(String.self, forKey: .indexColor)
|
||||
stringColor = try typeContainer.decodeIfPresent(Color.self, forKey: .stringColor)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
@ -43,6 +43,6 @@ public class StringAndMoleculeModel: MoleculeModelProtocol {
|
||||
try container.encode(string, forKey: .string)
|
||||
try container.encodeModel(molecule, forKey: .molecule)
|
||||
try container.encode(moleculeName, forKey: .moleculeName)
|
||||
try container.encodeIfPresent(indexColor, forKey: .indexColor)
|
||||
try container.encodeIfPresent(stringColor, forKey: .stringColor)
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,9 +84,7 @@ open class StringAndMoleculeView: View {
|
||||
super.set(with: model, delegateObject, additionalData)
|
||||
guard let model = model as? StringAndMoleculeModel else { return }
|
||||
label.text = model.string
|
||||
if let indexColor = model.indexColor {
|
||||
label.textColor = try? Color(colorString: indexColor)?.uiColor ?? .black
|
||||
}
|
||||
label.textColor = model.stringColor?.uiColor
|
||||
molecule.set(with: model.molecule, delegateObject, additionalData)
|
||||
}
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ import Foundation
|
||||
case backgroundColor
|
||||
case list
|
||||
case bulletChar
|
||||
case indexColor
|
||||
case stringColor
|
||||
}
|
||||
|
||||
// Numbered list model comes in the from of list = [MoleculeModelProtocol]
|
||||
@ -29,11 +29,11 @@ import Foundation
|
||||
self.bulletChar = bulletChar
|
||||
}
|
||||
|
||||
let indexColor = try typeContainer.decodeIfPresent(String.self, forKey: .indexColor)
|
||||
let stringColor = try typeContainer.decodeIfPresent(Color.self, forKey: .stringColor)
|
||||
let list: [MoleculeModelProtocol] = try typeContainer.decodeModels(codingKey: .list)
|
||||
var models: [MoleculeStackItemModel] = []
|
||||
for molecule in list {
|
||||
models.append(MoleculeStackItemModel(with: StringAndMoleculeModel(string: bulletChar, molecule: molecule, indexColor: indexColor)))
|
||||
models.append(MoleculeStackItemModel(with: StringAndMoleculeModel(string: bulletChar, molecule: molecule, stringColor: stringColor)))
|
||||
}
|
||||
super.init(molecules: models, spacing: 0)
|
||||
}
|
||||
@ -44,14 +44,14 @@ import Foundation
|
||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||
try container.encode(moleculeName, forKey: .moleculeName)
|
||||
|
||||
var indexColor: String?
|
||||
var stringColor: Color?
|
||||
var models: [MoleculeModelProtocol] = []
|
||||
for molecule in molecules {
|
||||
let stringAndMoleculeModel: StringAndMoleculeModel = ((molecule as! MoleculeStackItemModel).molecule as! StringAndMoleculeModel)
|
||||
indexColor = stringAndMoleculeModel.indexColor
|
||||
stringColor = stringAndMoleculeModel.stringColor
|
||||
models.append(stringAndMoleculeModel.molecule)
|
||||
}
|
||||
try container.encodeModels(models, forKey: .list)
|
||||
try container.encodeIfPresent(indexColor, forKey: .indexColor)
|
||||
try container.encodeIfPresent(stringColor, forKey: .stringColor)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user