Added numberColor, bulletColor & addressed review comments
This commit is contained in:
parent
b9267f219f
commit
77b5275a44
@ -12,23 +12,24 @@ import Foundation
|
|||||||
public override class var identifier: String {
|
public override class var identifier: String {
|
||||||
return "numberedList"
|
return "numberedList"
|
||||||
}
|
}
|
||||||
|
public var numberColor: Color?
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case moleculeName
|
case moleculeName
|
||||||
case backgroundColor
|
case backgroundColor
|
||||||
case list
|
case list
|
||||||
case stringColor
|
case numberColor
|
||||||
}
|
}
|
||||||
|
|
||||||
// Numbered list model comes in the from of list = [MoleculeModelProtocol]
|
// Numbered list model comes in the from of list = [MoleculeModelProtocol]
|
||||||
public required init(from decoder: Decoder) throws {
|
public required init(from decoder: Decoder) throws {
|
||||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
|
||||||
let stringColor = try typeContainer.decodeIfPresent(Color.self, forKey: .stringColor)
|
numberColor = try typeContainer.decodeIfPresent(Color.self, forKey: .numberColor)
|
||||||
let list: [MoleculeModelProtocol] = try typeContainer.decodeModels(codingKey: .list)
|
let list: [MoleculeModelProtocol] = try typeContainer.decodeModels(codingKey: .list)
|
||||||
var models: [MoleculeStackItemModel] = []
|
var models: [MoleculeStackItemModel] = []
|
||||||
for (index, molecule) in list.enumerated() {
|
for (index, molecule) in list.enumerated() {
|
||||||
models.append(MoleculeStackItemModel(with: StringAndMoleculeModel(string: "\(index+1).", molecule: molecule, stringColor: stringColor)))
|
models.append(MoleculeStackItemModel(with: StringAndMoleculeModel(string: "\(index+1).", molecule: molecule, stringColor: numberColor ?? Color(uiColor: .mvmBlack))))
|
||||||
}
|
}
|
||||||
super.init(molecules: models, spacing: 0)
|
super.init(molecules: models, spacing: 0)
|
||||||
}
|
}
|
||||||
@ -38,15 +39,12 @@ import Foundation
|
|||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
try container.encode(moleculeName, forKey: .moleculeName)
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
|
|
||||||
var indexColor: Color?
|
|
||||||
var models: [MoleculeModelProtocol] = []
|
var models: [MoleculeModelProtocol] = []
|
||||||
for molecule in molecules {
|
for molecule in molecules {
|
||||||
let stringAndMoleculeModel: StringAndMoleculeModel = ((molecule as! MoleculeStackItemModel).molecule as! StringAndMoleculeModel)
|
models.append(((molecule as! MoleculeStackItemModel).molecule as! StringAndMoleculeModel).molecule)
|
||||||
indexColor = stringAndMoleculeModel.stringColor
|
|
||||||
models.append(stringAndMoleculeModel.molecule)
|
|
||||||
}
|
}
|
||||||
try container.encodeModels(models, forKey: .list)
|
try container.encodeModels(models, forKey: .list)
|
||||||
try container.encodeIfPresent(indexColor, forKey: .stringColor)
|
try container.encodeIfPresent(numberColor, forKey: .numberColor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,9 +13,9 @@ public class StringAndMoleculeModel: MoleculeModelProtocol {
|
|||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
public var string: String
|
public var string: String
|
||||||
public var molecule: MoleculeModelProtocol
|
public var molecule: MoleculeModelProtocol
|
||||||
public var stringColor: Color?
|
public var stringColor: Color
|
||||||
|
|
||||||
public init(string: String, molecule: MoleculeModelProtocol, stringColor: Color?) {
|
public init(string: String, molecule: MoleculeModelProtocol, stringColor: Color) {
|
||||||
self.string = string
|
self.string = string
|
||||||
self.molecule = molecule
|
self.molecule = molecule
|
||||||
self.stringColor = stringColor
|
self.stringColor = stringColor
|
||||||
@ -34,7 +34,7 @@ public class StringAndMoleculeModel: MoleculeModelProtocol {
|
|||||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||||
string = try typeContainer.decode(String.self, forKey: .string)
|
string = try typeContainer.decode(String.self, forKey: .string)
|
||||||
molecule = try typeContainer.decodeModel(codingKey: .molecule)
|
molecule = try typeContainer.decodeModel(codingKey: .molecule)
|
||||||
stringColor = try typeContainer.decodeIfPresent(Color.self, forKey: .stringColor)
|
stringColor = try typeContainer.decode(Color.self, forKey: .stringColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func encode(to encoder: Encoder) throws {
|
public func encode(to encoder: Encoder) throws {
|
||||||
|
|||||||
@ -84,7 +84,7 @@ open class StringAndMoleculeView: View {
|
|||||||
super.set(with: model, delegateObject, additionalData)
|
super.set(with: model, delegateObject, additionalData)
|
||||||
guard let model = model as? StringAndMoleculeModel else { return }
|
guard let model = model as? StringAndMoleculeModel else { return }
|
||||||
label.text = model.string
|
label.text = model.string
|
||||||
label.textColor = model.stringColor?.uiColor
|
label.textColor = model.stringColor.uiColor
|
||||||
molecule.set(with: model.molecule, delegateObject, additionalData)
|
molecule.set(with: model.molecule, delegateObject, additionalData)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,13 +13,14 @@ import Foundation
|
|||||||
return "unOrderedList"
|
return "unOrderedList"
|
||||||
}
|
}
|
||||||
public var bulletChar = "•"
|
public var bulletChar = "•"
|
||||||
|
public var bulletColor: Color?
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case moleculeName
|
case moleculeName
|
||||||
case backgroundColor
|
case backgroundColor
|
||||||
case list
|
case list
|
||||||
case bulletChar
|
case bulletChar
|
||||||
case stringColor
|
case bulletColor
|
||||||
}
|
}
|
||||||
|
|
||||||
// Numbered list model comes in the from of list = [MoleculeModelProtocol]
|
// Numbered list model comes in the from of list = [MoleculeModelProtocol]
|
||||||
@ -29,11 +30,11 @@ import Foundation
|
|||||||
self.bulletChar = bulletChar
|
self.bulletChar = bulletChar
|
||||||
}
|
}
|
||||||
|
|
||||||
let stringColor = try typeContainer.decodeIfPresent(Color.self, forKey: .stringColor)
|
bulletColor = try typeContainer.decodeIfPresent(Color.self, forKey: .bulletColor)
|
||||||
let list: [MoleculeModelProtocol] = try typeContainer.decodeModels(codingKey: .list)
|
let list: [MoleculeModelProtocol] = try typeContainer.decodeModels(codingKey: .list)
|
||||||
var models: [MoleculeStackItemModel] = []
|
var models: [MoleculeStackItemModel] = []
|
||||||
for molecule in list {
|
for molecule in list {
|
||||||
models.append(MoleculeStackItemModel(with: StringAndMoleculeModel(string: bulletChar, molecule: molecule, stringColor: stringColor)))
|
models.append(MoleculeStackItemModel(with: StringAndMoleculeModel(string: bulletChar, molecule: molecule, stringColor: bulletColor ?? Color(uiColor: .mvmBlack))))
|
||||||
}
|
}
|
||||||
super.init(molecules: models, spacing: 0)
|
super.init(molecules: models, spacing: 0)
|
||||||
}
|
}
|
||||||
@ -44,14 +45,11 @@ import Foundation
|
|||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
try container.encode(moleculeName, forKey: .moleculeName)
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
|
|
||||||
var stringColor: Color?
|
|
||||||
var models: [MoleculeModelProtocol] = []
|
var models: [MoleculeModelProtocol] = []
|
||||||
for molecule in molecules {
|
for molecule in molecules {
|
||||||
let stringAndMoleculeModel: StringAndMoleculeModel = ((molecule as! MoleculeStackItemModel).molecule as! StringAndMoleculeModel)
|
models.append(((molecule as! MoleculeStackItemModel).molecule as! StringAndMoleculeModel).molecule)
|
||||||
stringColor = stringAndMoleculeModel.stringColor
|
|
||||||
models.append(stringAndMoleculeModel.molecule)
|
|
||||||
}
|
}
|
||||||
try container.encodeModels(models, forKey: .list)
|
try container.encodeModels(models, forKey: .list)
|
||||||
try container.encodeIfPresent(stringColor, forKey: .stringColor)
|
try container.encodeIfPresent(bulletColor, forKey: .bulletColor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user