From 8d811f229f6ac2b75f7bfce45a68e615b59e5043 Mon Sep 17 00:00:00 2001 From: panxi Date: Thu, 12 Dec 2019 15:28:47 -0500 Subject: [PATCH] change from viewconstrainingview to view --- MVMCoreUI.xcodeproj/project.pbxproj | 4 ++++ MVMCoreUI/Atoms/Views/CaretView.swift | 2 ++ MVMCoreUI/Atoms/Views/CaretViewModel.swift | 4 +++- MVMCoreUI/Atoms/Views/DashLine.swift | 2 ++ MVMCoreUI/Atoms/Views/DashLineModel.swift | 8 ++++--- .../Atoms/Views/LeftRightLabelModel.swift | 19 +++++++++++++++ .../Atoms/Views/LeftRightLabelView.swift | 20 ++++++++++++++-- MVMCoreUI/Atoms/Views/MultiProgress.swift | 6 +++-- .../Atoms/Views/MultiProgressModel.swift | 4 +++- MVMCoreUI/Atoms/Views/ProgressBar.swift | 3 ++- MVMCoreUI/Atoms/Views/ProgressBarModel.swift | 4 +++- MVMCoreUI/BaseClasses/Control.swift | 7 +++++- .../SwitchMolecules/HeadlineBodySwitch.swift | 23 +++++++++++++++---- .../OtherHandlers/MoleculeObjectMapping.swift | 3 +++ 14 files changed, 92 insertions(+), 17 deletions(-) create mode 100644 MVMCoreUI/Atoms/Views/LeftRightLabelModel.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 3ae8d221..0ff03255 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -63,6 +63,7 @@ 0A7BAD74232A8DC700FB8E22 /* HeadlineBodyButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */; }; 0A7BAFA1232BE61800FB8E22 /* Checkbox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAFA0232BE61800FB8E22 /* Checkbox.swift */; }; 0AA33B34239813C50067DD0F /* UIColor+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AA33B33239813C50067DD0F /* UIColor+Extension.swift */; }; + 9402C35023A2CEA3004B974C /* LeftRightLabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9402C34F23A2CEA3004B974C /* LeftRightLabelModel.swift */; }; 943784F5236B77BB006A1E82 /* GraphView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 943784F3236B77BB006A1E82 /* GraphView.swift */; }; 943784F6236B77BB006A1E82 /* GraphViewAnimationHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 943784F4236B77BB006A1E82 /* GraphViewAnimationHandler.swift */; }; 9445890C2385BCE300DE9FD4 /* ProgressBarModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9445890B2385BCE300DE9FD4 /* ProgressBarModel.swift */; }; @@ -311,6 +312,7 @@ 0A7BAFA0232BE61800FB8E22 /* Checkbox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Checkbox.swift; sourceTree = ""; }; 0A7BAFA2232BE63400FB8E22 /* CheckboxWithLabelView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckboxWithLabelView.swift; sourceTree = ""; }; 0AA33B33239813C50067DD0F /* UIColor+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Extension.swift"; sourceTree = ""; }; + 9402C34F23A2CEA3004B974C /* LeftRightLabelModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LeftRightLabelModel.swift; sourceTree = ""; }; 943784F3236B77BB006A1E82 /* GraphView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphView.swift; sourceTree = ""; }; 943784F4236B77BB006A1E82 /* GraphViewAnimationHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphViewAnimationHandler.swift; sourceTree = ""; }; 9445890B2385BCE300DE9FD4 /* ProgressBarModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressBarModel.swift; sourceTree = ""; }; @@ -949,6 +951,7 @@ DBC4391722442197001AB423 /* DashLine.swift */, 944589202385D6E900DE9FD4 /* DashLineModel.swift */, DB06250A2293456500B72DD3 /* LeftRightLabelView.swift */, + 9402C34F23A2CEA3004B974C /* LeftRightLabelModel.swift */, 012CA99D2385A2D3003F810F /* MFView+ModelExtension.swift */, D29DF28721E7AC2B003B2FB9 /* ViewConstrainingView.h */, D29DF28821E7AC2B003B2FB9 /* ViewConstrainingView.m */, @@ -1268,6 +1271,7 @@ files = ( 943784F5236B77BB006A1E82 /* GraphView.swift in Sources */, 012CA9E423888B1B003F810F /* ThreeLayerPageTemplateModel.swift in Sources */, + 9402C35023A2CEA3004B974C /* LeftRightLabelModel.swift in Sources */, D29DF32121ED0CBA003B2FB9 /* LabelView.m in Sources */, DBC4391822442197001AB423 /* CaretView.swift in Sources */, D29770F221F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.m in Sources */, diff --git a/MVMCoreUI/Atoms/Views/CaretView.swift b/MVMCoreUI/Atoms/Views/CaretView.swift index c02db833..f34ab776 100644 --- a/MVMCoreUI/Atoms/Views/CaretView.swift +++ b/MVMCoreUI/Atoms/Views/CaretView.swift @@ -125,7 +125,9 @@ open class CaretView: View { } } + //MARK: - MVMCoreMoleculeViewProtocol override public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + super.setWithModel(model, delegateObject, additionalData) guard let caretModel = model as? CaretViewModel else { return } diff --git a/MVMCoreUI/Atoms/Views/CaretViewModel.swift b/MVMCoreUI/Atoms/Views/CaretViewModel.swift index 481d086f..37d095d8 100644 --- a/MVMCoreUI/Atoms/Views/CaretViewModel.swift +++ b/MVMCoreUI/Atoms/Views/CaretViewModel.swift @@ -10,7 +10,9 @@ import Foundation @objcMembers public class CaretViewModel: MoleculeProtocol { - public static var identifier: String = "caretView" + public static var identifier: String { + get{ return "caretView" } + } public var backgroundColor: String? public var strokeColor: String? diff --git a/MVMCoreUI/Atoms/Views/DashLine.swift b/MVMCoreUI/Atoms/Views/DashLine.swift index 937b7313..595c7605 100644 --- a/MVMCoreUI/Atoms/Views/DashLine.swift +++ b/MVMCoreUI/Atoms/Views/DashLine.swift @@ -84,7 +84,9 @@ open class DashLine: View { } } + //MARK: - MVMCoreMoleculeViewProtocol public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + super.setWithModel(model, delegateObject, additionalData) guard let dashLineModel = model as? DashLineModel else { return } diff --git a/MVMCoreUI/Atoms/Views/DashLineModel.swift b/MVMCoreUI/Atoms/Views/DashLineModel.swift index 6fff83c7..3ba46186 100644 --- a/MVMCoreUI/Atoms/Views/DashLineModel.swift +++ b/MVMCoreUI/Atoms/Views/DashLineModel.swift @@ -9,10 +9,12 @@ import Foundation @objcMembers public class DashLineModel: MoleculeProtocol { - public static var identifier: String = "dashLine" - public var moleculeName: String + public static var identifier: String { + get { return "dashLine" } + } + public var moleculeName: String = "" public var backgroundColor: String? - public var dashColor: String + public var dashColor: String = "" public var isHidden: Bool? } diff --git a/MVMCoreUI/Atoms/Views/LeftRightLabelModel.swift b/MVMCoreUI/Atoms/Views/LeftRightLabelModel.swift new file mode 100644 index 00000000..ba07fc8b --- /dev/null +++ b/MVMCoreUI/Atoms/Views/LeftRightLabelModel.swift @@ -0,0 +1,19 @@ +// +// LeftRightLabelModel.swift +// MVMCoreUI +// +// Created by Ryan on 12/12/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +@objcMembers public class LeftRightLabelModel: MoleculeProtocol { + public var backgroundColor: String? + public var leftText: LabelModel + public var rightText: LabelModel + + public static var identifier: String { + get{ return "leftRightLabel" } + } +} diff --git a/MVMCoreUI/Atoms/Views/LeftRightLabelView.swift b/MVMCoreUI/Atoms/Views/LeftRightLabelView.swift index a059aef5..979d2abb 100644 --- a/MVMCoreUI/Atoms/Views/LeftRightLabelView.swift +++ b/MVMCoreUI/Atoms/Views/LeftRightLabelView.swift @@ -9,7 +9,7 @@ import Foundation -@objcMembers open class LeftRightLabelView: ViewConstrainingView { +@objcMembers open class LeftRightLabelView: View { //------------------------------------------------------ // MARK: - Outlets //------------------------------------------------------ @@ -28,7 +28,7 @@ import Foundation // MARK: - Initialization //------------------------------------------------------ - public init() { + public override init() { super.init(frame: .zero) } @@ -176,4 +176,20 @@ import Foundation constrainLeftLabel() } } + + //MARK: - MVMCoreMoleculeViewProtocol + + open override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + super.setWithModel(model, delegateObject, additionalData) + guard let leftRightLabelModel = model as? LeftRightLabelModel else { + return + } + leftTextLabel.setWithModel(leftRightLabelModel.leftText, delegateObject, additionalData) + rightTextLabel.setWithModel(leftRightLabelModel.rightText, delegateObject, additionalData) + if !leftTextLabel.hasText { + constrainRightLabel() + } else if !rightTextLabel.hasText { + constrainLeftLabel() + } + } } diff --git a/MVMCoreUI/Atoms/Views/MultiProgress.swift b/MVMCoreUI/Atoms/Views/MultiProgress.swift index 6f35bcc5..bbe8ed76 100644 --- a/MVMCoreUI/Atoms/Views/MultiProgress.swift +++ b/MVMCoreUI/Atoms/Views/MultiProgress.swift @@ -8,7 +8,7 @@ import UIKit -@objcMembers open class MultiProgress: ViewConstrainingView, ModelMoleculeViewProtocol { +@objcMembers open class MultiProgress: View { ///passing value to progressList creates corresponding progress bars var progressList: Array? { @@ -60,7 +60,9 @@ import UIKit } } - public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + //MARK: - MVMCoreMoleculeViewProtocol + public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + super.setWithModel(model, delegateObject, additionalData) guard let multiProgressModel = model as? MultiProgressBarModel else { return } diff --git a/MVMCoreUI/Atoms/Views/MultiProgressModel.swift b/MVMCoreUI/Atoms/Views/MultiProgressModel.swift index 25522070..62397f69 100644 --- a/MVMCoreUI/Atoms/Views/MultiProgressModel.swift +++ b/MVMCoreUI/Atoms/Views/MultiProgressModel.swift @@ -15,7 +15,9 @@ import Foundation } @objcMembers public class MultiProgressBarModel: MoleculeProtocol { - public static var identifier: String = "multiProgressBar" + public static var identifier: String { + get{ return "multiProgressBar"} + } public var moleculeName: String public var backgroundColor: String? public var progressList: [SingleProgressBarModel] diff --git a/MVMCoreUI/Atoms/Views/ProgressBar.swift b/MVMCoreUI/Atoms/Views/ProgressBar.swift index 45ce85d6..0a29d62a 100644 --- a/MVMCoreUI/Atoms/Views/ProgressBar.swift +++ b/MVMCoreUI/Atoms/Views/ProgressBar.swift @@ -50,13 +50,14 @@ import Foundation public func updateView(_ size: CGFloat) { } + //MARK: - MVMCoreMoleculeViewProtocol public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String: AnyHashable]?) { guard let progressBarModel = model as? ProgressBarModel else { return } isRounded = progressBarModel.isRounded ?? false thickness = progressBarModel.thickness ?? 8 - progress = (progressBarModel.percentage ?? 0)/100.0 + progress = (progressBarModel.percentage )/100.0 if let progressColor = progressBarModel.progressColor { progressTintColor = UIColor.mfGet(forHex: progressColor) } diff --git a/MVMCoreUI/Atoms/Views/ProgressBarModel.swift b/MVMCoreUI/Atoms/Views/ProgressBarModel.swift index 3450fc87..aa5912a7 100644 --- a/MVMCoreUI/Atoms/Views/ProgressBarModel.swift +++ b/MVMCoreUI/Atoms/Views/ProgressBarModel.swift @@ -9,7 +9,9 @@ import Foundation @objcMembers public class ProgressBarModel: MoleculeProtocol { - public static var identifier: String = "progressbar" + public static var identifier: String { + get { return "progressbar" } + } public var moleculeName: String public var isRounded: Bool? diff --git a/MVMCoreUI/BaseClasses/Control.swift b/MVMCoreUI/BaseClasses/Control.swift index fdf8204f..942cda65 100644 --- a/MVMCoreUI/BaseClasses/Control.swift +++ b/MVMCoreUI/BaseClasses/Control.swift @@ -8,8 +8,9 @@ import UIKit -public class Control: UIControl { +public class Control: UIControl, ModelMoleculeViewProtocol { var json: [AnyHashable: Any]? + public var model: MoleculeProtocol? private var initialSetupPerformed = false @@ -34,6 +35,10 @@ public class Control: UIControl { setupView() } } + + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + self.model = model + } } extension Control: MVMCoreViewProtocol { diff --git a/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift b/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift index 79110460..20da726b 100644 --- a/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift +++ b/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift @@ -8,7 +8,7 @@ import UIKit -@objcMembers open class HeadlineBodySwitch: ViewConstrainingView { +@objcMembers open class HeadlineBodySwitch: View { public let headlineBody = HeadlineBody(frame: .zero) public let mvmSwitch = MVMCoreUISwitch.mvmSwitchDefault() @@ -27,13 +27,27 @@ import UIKit headlineBody.styleListItem() let view = MVMCoreUICommonViewsUtility.commonView() addSubview(view) - pinView(toSuperView: view) + NSLayoutConstraint.constraintPinSubview(toSuperview: view) view.addSubview(headlineBody) view.addSubview(mvmSwitch) NSLayoutConstraint.pinSubviewsCenter(leftView: headlineBody, rightView: mvmSwitch) } + + //MARK: - MVMCoreMoleculeViewProtocol + + open override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + super.setWithModel(model, delegateObject, additionalData) +// guard let headlineModel = model as? headlinebodyswitch +// headlineBody.setWithModel(mode, <#T##delegateObject: MVMCoreUIDelegateObject?##MVMCoreUIDelegateObject?#>, <#T##additionalData: [String : AnyHashable]?##[String : AnyHashable]?#>) + } + + public static func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { + return 30 + } + + // MARK: - MVMCoreUIMoleculeViewProtocol open override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) @@ -41,12 +55,11 @@ import UIKit mvmSwitch.setWithJSON(json?.optionalDictionaryForKey("switch"), delegateObject: delegateObject, additionalData: additionalData) } - open override class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { + open class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { return 30 } - open override func setAsMolecule() { - super.setAsMolecule() + open func setAsMolecule() { headlineBody.setAsMolecule() (mvmSwitch as MVMCoreUIMoleculeViewProtocol).setAsMolecule?() headlineBody.styleListItem() diff --git a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift index f97ed9b5..86395407 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift @@ -24,12 +24,15 @@ import Foundation ModelRegistry.register(CaretViewModel.self) ModelRegistry.register(DashLineModel.self) ModelRegistry.register(ImageViewModel.self) + //need to move labelattributemodel to different method ModelRegistry.register(LabelAttributeFontModel.self) ModelRegistry.register(LabelAttributeColorModel.self) ModelRegistry.register(LabelAttributeImageModel.self) ModelRegistry.register(LabelAttributeUnderlineModel.self) ModelRegistry.register(LabelAttributeStrikeThroughModel.self) ModelRegistry.register(LabelAttributeActionModel.self) + // ModelRegistry.register(ModuleMoleculeModel.self) + ModelRegistry.register(LeftRightLabelModel.self) } }