latest state
This commit is contained in:
parent
b546588665
commit
ad204118af
@ -38,7 +38,7 @@ import Foundation
|
||||
public func getMoleculeModelForJSON(_ json: [String: Any]) throws -> MoleculeModelProtocol? {
|
||||
guard let moleculeName = json.optionalStringForKey(KeyMoleculeName),
|
||||
let type = ModelRegistry.getType(for: moleculeName, with: MoleculeModelProtocol.self) else {
|
||||
throw ModelRegistry.Error.decoderErrorModelNotMapped()
|
||||
throw ModelRegistry.Error.decoderErrorModelNotMapped()
|
||||
}
|
||||
guard let model = try type.decode(jsonDict: json) as? MoleculeModelProtocol else {
|
||||
throw ModelRegistry.Error.decoderError
|
||||
@ -88,8 +88,6 @@ import Foundation
|
||||
MoleculeObjectMapping.shared()?.register(viewClass: Tags.self, viewModelClass: TagsModel.self)
|
||||
MoleculeObjectMapping.shared()?.register(viewClass: Tag.self, viewModelClass: TagModel.self)
|
||||
|
||||
|
||||
|
||||
// MARK:- Other Atoms
|
||||
MoleculeObjectMapping.shared()?.register(viewClass: ProgressBar.self, viewModelClass: ProgressBarModel.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: BGImageHeadlineBodyButton.self, viewModelClass: BGImageHeadlineBodyButtonModel.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
|
||||
MoleculeObjectMapping.shared()?.register(viewClass: CornerLabels.self, viewModelClass: CornerLabelsModel.self)
|
||||
|
||||
@ -33,7 +33,7 @@ open class OrderTracker: View {
|
||||
// MARK: - Methods
|
||||
//--------------------------------------------------
|
||||
|
||||
func constrain(stepModels: [StepModel]?) {
|
||||
func constrain(stepModels: [StepModel]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||
|
||||
removeSteps()
|
||||
|
||||
@ -44,7 +44,7 @@ open class OrderTracker: View {
|
||||
for (i, stepModel) in stepModels.enumerated() {
|
||||
|
||||
let step = Step()
|
||||
step.set(with: stepModel, nil, nil)
|
||||
step.set(with: stepModel, delegateObject, additionalData)
|
||||
addSubview(step)
|
||||
|
||||
step.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
|
||||
@ -86,9 +86,8 @@ open class OrderTracker: View {
|
||||
|
||||
context.setStrokeColor((step.state?.color() ?? .mvmCoolGray3).cgColor)
|
||||
context.addLine(to: convert(step.imageCenterPoint, from: step))
|
||||
context.strokePath()
|
||||
}
|
||||
|
||||
context.strokePath()
|
||||
}
|
||||
|
||||
//------------------------------------------------------
|
||||
@ -104,7 +103,8 @@ open class OrderTracker: View {
|
||||
|
||||
guard let model = model as? OrderTrackerModel else { return }
|
||||
|
||||
constrain(stepModels: model.steps)
|
||||
constrain(stepModels: model.steps, delegateObject: delegateObject, additionalData: additionalData)
|
||||
setNeedsLayout()
|
||||
setNeedsDisplay()
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,6 +51,7 @@ open class Step: View {
|
||||
stateImage.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
|
||||
stateImage.heightAnchor.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.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 }
|
||||
|
||||
headline.text = model.headline
|
||||
bodyTop.text = model.bodyTop
|
||||
bodyBottom.text = model.bodyBottom
|
||||
headline.set(with: model.headline, delegateObject, additionalData)
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,9 +18,13 @@ open class StepModel: MoleculeModelProtocol {
|
||||
|
||||
public static var identifier: String = "step"
|
||||
public var state: State?
|
||||
public var headline: String = ""
|
||||
public var bodyTop: String?
|
||||
public var bodyBottom: String?
|
||||
public var headline: LabelModel
|
||||
public var bodyTop: LabelModel?
|
||||
public var bodyBottom: LabelModel?
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Enum
|
||||
//--------------------------------------------------
|
||||
|
||||
public enum State: String, Codable {
|
||||
case complete
|
||||
@ -31,13 +35,13 @@ open class StepModel: MoleculeModelProtocol {
|
||||
|
||||
switch self {
|
||||
case .complete:
|
||||
return UIImage(named: "icon_tracker_complete")
|
||||
return MVMCoreUIUtility.imageNamed("icon_tracker_complete")
|
||||
|
||||
case .incomplete:
|
||||
return UIImage(named: "icon_tracker_incomplete")
|
||||
return MVMCoreUIUtility.imageNamed("icon_tracker_incomplete")
|
||||
|
||||
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 backgroundColor
|
||||
case state
|
||||
case headline
|
||||
case bodyTop
|
||||
case bodyBottom
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
@ -74,12 +81,17 @@ open class StepModel: MoleculeModelProtocol {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||
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 {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(moleculeName, forKey: .moleculeName)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user