From ad204118afb411caf40ff4c85dd530b2b125696a Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 8 Jul 2020 11:39:43 -0400 Subject: [PATCH] latest state --- MVMCoreUI/Atomic/MoleculeObjectMapping.swift | 34 +++++++++---------- .../Order Tracker/OrderTracker.swift | 10 +++--- .../Order Tracker/Step.swift | 14 ++++++-- .../Order Tracker/StepModel.swift | 28 ++++++++++----- 4 files changed, 53 insertions(+), 33 deletions(-) diff --git a/MVMCoreUI/Atomic/MoleculeObjectMapping.swift b/MVMCoreUI/Atomic/MoleculeObjectMapping.swift index 5a3a3a1f..09ff554f 100644 --- a/MVMCoreUI/Atomic/MoleculeObjectMapping.swift +++ b/MVMCoreUI/Atomic/MoleculeObjectMapping.swift @@ -11,7 +11,7 @@ import Foundation @objcMembers public class MoleculeObjectMapping: NSObject { public var moleculeMapping: [String: MoleculeViewProtocol.Type] = [:] - + /// Returns the mapping object stored in the singleton public static func shared() -> Self? { return MVMCoreActionUtility.initializerClassCheck(CoreUIObject.sharedInstance()?.moleculeMap, classToVerify: self) as? Self @@ -22,12 +22,12 @@ import Foundation try? ModelRegistry.register(viewModelClass) moleculeMapping.updateValue(viewClass, forKey: viewModelClass.identifier) } - + /// Returns the type of molecule view for the given model public func getMoleculeClass(_ model: MoleculeModelProtocol) -> MoleculeViewProtocol.Type? { return moleculeMapping[model.moleculeName] } - + /// Creates a molecule with the given model. public func createMolecule(_ model: MoleculeModelProtocol, delegateObject: MVMCoreUIDelegateObject? = nil, additionalData: [AnyHashable: Any]? = nil) -> MoleculeViewProtocol? { guard let type = moleculeMapping[model.moleculeName] else { return nil } @@ -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 @@ -87,9 +87,7 @@ import Foundation MoleculeObjectMapping.shared()?.register(viewClass: RadioSwatches.self, viewModelClass: RadioSwatchesModel.self) 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,7 +117,9 @@ 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) MoleculeObjectMapping.shared()?.register(viewClass: LeftRightLabelView.self, viewModelClass: LeftRightLabelModel.self) @@ -127,7 +127,7 @@ import Foundation MoleculeObjectMapping.shared()?.register(viewClass: HeadlineBodyToggle.self, viewModelClass: HeadlineBodyToggleModel.self) MoleculeObjectMapping.shared()?.register(viewClass: HeadlineBodyLinkToggle.self, viewModelClass: HeadlineBodyLinkToggleModel.self) MoleculeObjectMapping.shared()?.register(viewClass: ActionDetailWithImage.self, viewModelClass: ActionDetailWithImageModel.self) - + // MARK:- List items MoleculeObjectMapping.shared()?.register(viewClass: MoleculeTableViewCell.self, viewModelClass: MoleculeListItemModel.self) MoleculeObjectMapping.shared()?.register(viewClass: DropDownFilterTableViewCell.self, viewModelClass: DropDownListItemModel.self) @@ -140,8 +140,8 @@ import Foundation MoleculeObjectMapping.shared()?.register(viewClass: StackItem.self, viewModelClass: StackItemModel.self) MoleculeObjectMapping.shared()?.register(viewClass: MoleculeCollectionViewCell.self, viewModelClass: MoleculeCollectionItemModel.self) MoleculeObjectMapping.shared()?.register(viewClass: CarouselItem.self, viewModelClass: CarouselItemModel.self) - - + + // MARK:- Other Container Molecules MoleculeObjectMapping.shared()?.register(viewClass: MoleculeContainer.self, viewModelClass: MoleculeContainerModel.self) MoleculeObjectMapping.shared()?.register(viewClass: MoleculeHeaderView.self, viewModelClass: MoleculeHeaderModel.self) @@ -149,7 +149,7 @@ import Foundation MoleculeObjectMapping.shared()?.register(viewClass: Scroller.self, viewModelClass: ScrollerModel.self) MoleculeObjectMapping.shared()?.register(viewClass: ModuleMolecule.self, viewModelClass: ModuleMoleculeModel.self) MoleculeObjectMapping.shared()?.register(viewClass: BGImageMolecule.self, viewModelClass: BGImageMoleculeModel.self) - + // MARK:- Other Molecules MoleculeObjectMapping.shared()?.register(viewClass: DoughnutChartView.self, viewModelClass: DoughnutChartModel.self) @@ -157,7 +157,7 @@ import Foundation try? ModelRegistry.register(NavigationItemModel.self) try? ModelRegistry.register(NavigationImageButtonModel.self) try? ModelRegistry.register(NavigationLabelButtonModel.self) - + // MARK:- Other Organisms MoleculeObjectMapping.shared()?.register(viewClass: Carousel.self, viewModelClass: CarouselModel.self) MoleculeObjectMapping.shared()?.register(viewClass: BarsIndicatorView.self, viewModelClass: BarsCarouselIndicatorModel.self) @@ -204,7 +204,7 @@ import Foundation MoleculeObjectMapping.shared()?.register(viewClass: ListThreeColumnSpeedTestDivider.self, viewModelClass: ListThreeColumnSpeedTestDividerModel.self) MoleculeObjectMapping.shared()?.register(viewClass: ListThreeColumnBillChangesDivider.self, viewModelClass: ListThreeColumnBillChangesDividerModel.self) MoleculeObjectMapping.shared()?.register(viewClass: ListThreeColumnDataUsageDivider.self, viewModelClass: ListThreeColumnDataUsageDividerModel.self) - + // MARK:- Designed Headers MoleculeObjectMapping.shared()?.register(viewClass: HeadersH1Button.self, viewModelClass: HeadersH1ButtonModel.self) MoleculeObjectMapping.shared()?.register(viewClass: HeadersH1LandingPageHeader.self, viewModelClass: HeadersH1LandingPageHeaderModel.self) @@ -218,10 +218,10 @@ import Foundation // MARK:- Device Items MoleculeObjectMapping.shared()?.register(viewClass: ListDeviceComplexButtonMedium.self, viewModelClass: ListDeviceComplexButtonMediumModel.self) MoleculeObjectMapping.shared()?.register(viewClass: ListDeviceComplexButtonSmall.self, viewModelClass: ListDeviceComplexButtonSmallModel.self) - + MoleculeObjectMapping.shared()?.register(viewClass: ListDeviceComplexLinkSmall.self, viewModelClass: ListDeviceComplexLinkSmallModel.self) MoleculeObjectMapping.shared()?.register(viewClass: ListDeviceComplexLinkMedium.self, viewModelClass: ListDeviceComplexLinkMediumModel.self) - + // MARK:- Helper models try? ModelRegistry.register(RuleRequiredModel.self) try? ModelRegistry.register(RuleAnyRequiredModel.self) @@ -245,7 +245,7 @@ import Foundation guard let model = model else { return nil } return MoleculeObjectMapping.shared()?.getMoleculeClass(model)?.requiredModules(with: model, delegateObject, error: error) } - + /// Convenience function to add require modules for the given model to the passed in array. public static func addRequiredModules(for model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, moduleList: inout [String]?, errorList: inout [MVMCoreErrorObject]?) { guard let model = model else { return } diff --git a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/Order Tracker/OrderTracker.swift b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/Order Tracker/OrderTracker.swift index 71dd8171..15bd4cfa 100644 --- a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/Order Tracker/OrderTracker.swift +++ b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/Order Tracker/OrderTracker.swift @@ -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() } } diff --git a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/Order Tracker/Step.swift b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/Order Tracker/Step.swift index 06a8a94a..de08f4a9 100644 --- a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/Order Tracker/Step.swift +++ b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/Order Tracker/Step.swift @@ -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() } } diff --git a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/Order Tracker/StepModel.swift b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/Order Tracker/StepModel.swift index 7c2d719b..3af0f49d 100644 --- a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/Order Tracker/StepModel.swift +++ b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/Order Tracker/StepModel.swift @@ -18,26 +18,30 @@ 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 case incomplete case invalid - + func image() -> UIImage? { 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) } }