laets state

This commit is contained in:
Kevin G Christiano 2020-07-07 13:24:37 -04:00
parent 0b1c599930
commit b00e9bcf03
3 changed files with 33 additions and 14 deletions

View File

@ -17,7 +17,7 @@ open class OrderTrackerModel: MoleculeModelProtocol {
public var backgroundColor: Color?
public static var identifier: String = "orderTracker"
public var steps: [StepModel]?
public var steps: [StepModel]
//--------------------------------------------------
// MARK: - Keys
@ -36,13 +36,13 @@ open class OrderTrackerModel: MoleculeModelProtocol {
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
steps = try typeContainer.decodeIfPresent([StepModel].self, forKey: .steps)
steps = try typeContainer.decode([StepModel].self, forKey: .steps)
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encodeIfPresent(steps, forKey: .steps)
try container.encode(steps, forKey: .steps)
}
}

View File

@ -42,9 +42,28 @@ open class Step: View {
open override func setupView() {
super.setupView()
addSubview(stateImage)
addSubview(headline)
addSubview(bodyTop)
addSubview(bodyBottom)
stateImage.topAnchor.constraint(equalTo: topAnchor).isActive = true
stateImage.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
stateImage.heightAnchor.constraint(equalToConstant: 18).isActive = true
stateImage.widthAnchor.constraint(equalToConstant: 18).isActive = true
headline.topAnchor.constraint(equalTo: topAnchor).isActive = true
headline.leadingAnchor.constraint(equalTo: stateImage.trailingAnchor, constant: Padding.Four).isActive = true
trailingAnchor.constraint(equalTo: headline.trailingAnchor).isActive = true
bodyTop.topAnchor.constraint(equalTo: headline.bottomAnchor).isActive = true
bodyTop.leadingAnchor.constraint(equalTo: stateImage.trailingAnchor, constant: Padding.Four).isActive = true
trailingAnchor.constraint(equalTo: bodyTop.trailingAnchor).isActive = true
bodyBottom.topAnchor.constraint(equalTo: bodyTop.bottomAnchor).isActive = true
bodyBottom.leadingAnchor.constraint(equalTo: stateImage.trailingAnchor, constant: Padding.Four).isActive = true
trailingAnchor.constraint(equalTo: bodyBottom.trailingAnchor).isActive = true
bottomAnchor.constraint(greaterThanOrEqualTo: bodyBottom.bottomAnchor).isActive = true
}
public override func reset() {

View File

@ -51,6 +51,17 @@ open class ImageView: UIImageView, MoleculeViewProtocol {
}
}
/// Will be called only once.
open func setupView() {
translatesAutoresizingMaskIntoConstraints = false
insetsLayoutMarginsFromSafeArea = false
MVMCoreUIUtility.setMarginsFor(self, leading: 0, top: 0, trailing: 0, bottom: 0)
}
open func reset() {
backgroundColor = .clear
}
//--------------------------------------------------
// MARK: - MoleculeViewProtocol
//--------------------------------------------------
@ -76,16 +87,5 @@ open class ImageView: UIImageView, MoleculeViewProtocol {
open func updateView(_ size: CGFloat) { }
/// Will be called only once.
open func setupView() {
translatesAutoresizingMaskIntoConstraints = false
insetsLayoutMarginsFromSafeArea = false
MVMCoreUIUtility.setMarginsFor(self, leading: 0, top: 0, trailing: 0, bottom: 0)
}
open func reset() {
backgroundColor = .clear
}
open func setAsMolecule() { }
}