latest state

This commit is contained in:
Kevin G Christiano 2020-07-08 11:39:43 -04:00
parent b546588665
commit ad204118af
4 changed files with 53 additions and 33 deletions

View File

@ -88,8 +88,6 @@ import Foundation
MoleculeObjectMapping.shared()?.register(viewClass: Tags.self, viewModelClass: TagsModel.self) MoleculeObjectMapping.shared()?.register(viewClass: Tags.self, viewModelClass: TagsModel.self)
MoleculeObjectMapping.shared()?.register(viewClass: Tag.self, viewModelClass: TagModel.self) MoleculeObjectMapping.shared()?.register(viewClass: Tag.self, viewModelClass: TagModel.self)
// MARK:- Other Atoms // MARK:- Other Atoms
MoleculeObjectMapping.shared()?.register(viewClass: ProgressBar.self, viewModelClass: ProgressBarModel.self) MoleculeObjectMapping.shared()?.register(viewClass: ProgressBar.self, viewModelClass: ProgressBarModel.self)
MoleculeObjectMapping.shared()?.register(viewClass: MultiProgress.self, viewModelClass: MultiProgressBarModel.self) MoleculeObjectMapping.shared()?.register(viewClass: MultiProgress.self, viewModelClass: MultiProgressBarModel.self)
@ -119,6 +117,8 @@ import Foundation
MoleculeObjectMapping.shared()?.register(viewClass: HeadlineBodyButton.self, viewModelClass: HeadlineBodyButtonModel.self) MoleculeObjectMapping.shared()?.register(viewClass: HeadlineBodyButton.self, viewModelClass: HeadlineBodyButtonModel.self)
MoleculeObjectMapping.shared()?.register(viewClass: BGImageHeadlineBodyButton.self, viewModelClass: BGImageHeadlineBodyButtonModel.self) MoleculeObjectMapping.shared()?.register(viewClass: BGImageHeadlineBodyButton.self, viewModelClass: BGImageHeadlineBodyButtonModel.self)
MoleculeObjectMapping.shared()?.register(viewClass: ThreeHeadlineBodyLink.self, viewModelClass: ThreeHeadlineBodyLinkModel.self) MoleculeObjectMapping.shared()?.register(viewClass: ThreeHeadlineBodyLink.self, viewModelClass: ThreeHeadlineBodyLinkModel.self)
MoleculeObjectMapping.shared()?.register(viewClass: OrderTracker.self, viewModelClass: OrderTrackerModel.self)
MoleculeObjectMapping.shared()?.register(viewClass: Step.self, viewModelClass: StepModel.self)
// MARK:- Left Right Molecules // MARK:- Left Right Molecules
MoleculeObjectMapping.shared()?.register(viewClass: CornerLabels.self, viewModelClass: CornerLabelsModel.self) MoleculeObjectMapping.shared()?.register(viewClass: CornerLabels.self, viewModelClass: CornerLabelsModel.self)

View File

@ -33,7 +33,7 @@ open class OrderTracker: View {
// MARK: - Methods // MARK: - Methods
//-------------------------------------------------- //--------------------------------------------------
func constrain(stepModels: [StepModel]?) { func constrain(stepModels: [StepModel]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
removeSteps() removeSteps()
@ -44,7 +44,7 @@ open class OrderTracker: View {
for (i, stepModel) in stepModels.enumerated() { for (i, stepModel) in stepModels.enumerated() {
let step = Step() let step = Step()
step.set(with: stepModel, nil, nil) step.set(with: stepModel, delegateObject, additionalData)
addSubview(step) addSubview(step)
step.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true step.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
@ -86,10 +86,9 @@ open class OrderTracker: View {
context.setStrokeColor((step.state?.color() ?? .mvmCoolGray3).cgColor) context.setStrokeColor((step.state?.color() ?? .mvmCoolGray3).cgColor)
context.addLine(to: convert(step.imageCenterPoint, from: step)) context.addLine(to: convert(step.imageCenterPoint, from: step))
}
context.strokePath() context.strokePath()
} }
}
//------------------------------------------------------ //------------------------------------------------------
// MARK: - MoleculeViewProtocol // MARK: - MoleculeViewProtocol
@ -104,7 +103,8 @@ open class OrderTracker: View {
guard let model = model as? OrderTrackerModel else { return } guard let model = model as? OrderTrackerModel else { return }
constrain(stepModels: model.steps) constrain(stepModels: model.steps, delegateObject: delegateObject, additionalData: additionalData)
setNeedsLayout()
setNeedsDisplay() setNeedsDisplay()
} }
} }

View File

@ -51,6 +51,7 @@ open class Step: View {
stateImage.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true stateImage.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
stateImage.heightAnchor.constraint(equalToConstant: 18).isActive = true stateImage.heightAnchor.constraint(equalToConstant: 18).isActive = true
stateImage.widthAnchor.constraint(equalToConstant: 18).isActive = true stateImage.widthAnchor.constraint(equalToConstant: 18).isActive = true
bottomAnchor.constraint(greaterThanOrEqualTo: stateImage.bottomAnchor, constant: Padding.Five).isActive = true
headline.topAnchor.constraint(equalTo: topAnchor).isActive = true headline.topAnchor.constraint(equalTo: topAnchor).isActive = true
headline.leadingAnchor.constraint(equalTo: stateImage.trailingAnchor, constant: Padding.Four).isActive = true headline.leadingAnchor.constraint(equalTo: stateImage.trailingAnchor, constant: Padding.Four).isActive = true
@ -88,9 +89,16 @@ open class Step: View {
guard let model = model as? StepModel else { return } guard let model = model as? StepModel else { return }
headline.text = model.headline headline.set(with: model.headline, delegateObject, additionalData)
bodyTop.text = model.bodyTop
bodyBottom.text = model.bodyBottom if let bodyTopModel = model.bodyTop {
bodyTop.set(with: bodyTopModel, delegateObject, additionalData)
}
if let bodyBottomModel = model.bodyBottom {
bodyBottom.set(with: bodyBottomModel, delegateObject, additionalData)
}
stateImage.image = model.state?.image() stateImage.image = model.state?.image()
} }
} }

View File

@ -18,9 +18,13 @@ open class StepModel: MoleculeModelProtocol {
public static var identifier: String = "step" public static var identifier: String = "step"
public var state: State? public var state: State?
public var headline: String = "" public var headline: LabelModel
public var bodyTop: String? public var bodyTop: LabelModel?
public var bodyBottom: String? public var bodyBottom: LabelModel?
//--------------------------------------------------
// MARK: - Enum
//--------------------------------------------------
public enum State: String, Codable { public enum State: String, Codable {
case complete case complete
@ -31,13 +35,13 @@ open class StepModel: MoleculeModelProtocol {
switch self { switch self {
case .complete: case .complete:
return UIImage(named: "icon_tracker_complete") return MVMCoreUIUtility.imageNamed("icon_tracker_complete")
case .incomplete: case .incomplete:
return UIImage(named: "icon_tracker_incomplete") return MVMCoreUIUtility.imageNamed("icon_tracker_incomplete")
case .invalid: case .invalid:
return UIImage(named: "icon_tracker_invalid") return MVMCoreUIUtility.imageNamed("icon_tracker_invalid")
} }
} }
@ -64,6 +68,9 @@ open class StepModel: MoleculeModelProtocol {
case moleculeName case moleculeName
case backgroundColor case backgroundColor
case state case state
case headline
case bodyTop
case bodyBottom
} }
//-------------------------------------------------- //--------------------------------------------------
@ -74,12 +81,17 @@ open class StepModel: MoleculeModelProtocol {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
state = try typeContainer.decodeIfPresent(State.self, forKey: .state) state = try typeContainer.decodeIfPresent(State.self, forKey: .state)
headline = try typeContainer.decode(LabelModel.self, forKey: .headline)
bodyTop = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .bodyTop)
bodyBottom = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .bodyBottom)
} }
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(moleculeName, forKey: .moleculeName) try container.encode(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encodeIfPresent(state, forKey: .state) try container.encodeIfPresent(headline, forKey: .headline)
try container.encodeIfPresent(bodyTop, forKey: .bodyTop)
try container.encodeIfPresent(bodyBottom, forKey: .bodyBottom)
} }
} }