From 0090b686a576a96ed3bff93a74b46eabf23b629a Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 14 Jan 2020 11:11:28 -0500 Subject: [PATCH 01/10] default stryle and spacing --- MVMCoreUI/Molecules/Items/ListItemModel.swift | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Molecules/Items/ListItemModel.swift b/MVMCoreUI/Molecules/Items/ListItemModel.swift index 7208a2ce..24cb05e0 100644 --- a/MVMCoreUI/Molecules/Items/ListItemModel.swift +++ b/MVMCoreUI/Molecules/Items/ListItemModel.swift @@ -15,7 +15,7 @@ import MVMCore public var action: ActionProtocol? public var hideArrow: Bool? public var line: LineModel? - public var style: String? + public var style: String? = "standard" enum ListItemCodingKeys: String, CodingKey { case backgroundColor @@ -31,10 +31,20 @@ import MVMCore action = try typeContainer.decodeModelIfPresent(codingKey: .action, typeCodingKey: ActionCodingKey.actionType) hideArrow = try typeContainer.decodeIfPresent(Bool.self, forKey: .hideArrow) line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line) - style = try typeContainer.decodeIfPresent(String.self, forKey: .style) + if let style = try typeContainer.decodeIfPresent(String.self, forKey: .style) { + self.style = style + } + try super.init(from: decoder) + + if useHorizontalMargins == nil { + useHorizontalMargins = true + } + if useVerticalMargins == nil { + useVerticalMargins = true + } } - + public override func encode(to encoder: Encoder) throws { try super.encode(to: encoder) var container = encoder.container(keyedBy: ListItemCodingKeys.self) @@ -43,5 +53,6 @@ import MVMCore try container.encodeIfPresent(hideArrow, forKey: .hideArrow) try container.encodeIfPresent(line, forKey: .line) try container.encodeIfPresent(style, forKey: .style) - } + } } + From 2f6859f5435275d406389afa86df42ce9905c207 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 14 Jan 2020 11:17:10 -0500 Subject: [PATCH 02/10] button model fix --- MVMCoreUI.xcodeproj/project.pbxproj | 9 ++++----- .../Atoms/Buttons/MFTextButton+ModelExtension.swift | 5 +---- .../PrimaryButton+MoleculeProtocolExtension.swift | 5 +---- .../{ModelHelper.swift => MoleculeModelHelper.swift} | 2 +- MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift | 2 +- 5 files changed, 8 insertions(+), 15 deletions(-) rename MVMCoreUI/Models/Extensions/{ModelHelper.swift => MoleculeModelHelper.swift} (98%) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 1497d632..6580f328 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -93,7 +93,7 @@ 944589212385D6E900DE9FD4 /* DashLineModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 944589202385D6E900DE9FD4 /* DashLineModel.swift */; }; 944589232385DA9600DE9FD4 /* ImageViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 944589222385DA9500DE9FD4 /* ImageViewModel.swift */; }; 9455B19C234F8A0400A574DB /* MVMAnimationFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9455B19B234F8A0400A574DB /* MVMAnimationFramework.framework */; }; - 946EE1BA237B66D80036751F /* ModelHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1B9237B66D80036751F /* ModelHelper.swift */; }; + 946EE1BA237B66D80036751F /* MoleculeModelHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1B9237B66D80036751F /* MoleculeModelHelper.swift */; }; 948DB67E2326DCD90011F916 /* MultiProgress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 948DB67D2326DCD90011F916 /* MultiProgress.swift */; }; 94C2D9842386F3F80006CF46 /* LabelAttributeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94C2D9832386F3F80006CF46 /* LabelAttributeModel.swift */; }; 94C2D9A123872BCC0006CF46 /* LabelAttributeUnderlineModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94C2D9A023872BCC0006CF46 /* LabelAttributeUnderlineModel.swift */; }; @@ -364,7 +364,7 @@ 944589202385D6E900DE9FD4 /* DashLineModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashLineModel.swift; sourceTree = ""; }; 944589222385DA9500DE9FD4 /* ImageViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageViewModel.swift; sourceTree = ""; }; 9455B19B234F8A0400A574DB /* MVMAnimationFramework.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MVMAnimationFramework.framework; path = ../SharedFrameworks/MVMAnimationFramework.framework; sourceTree = ""; }; - 946EE1B9237B66D80036751F /* ModelHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelHelper.swift; sourceTree = ""; }; + 946EE1B9237B66D80036751F /* MoleculeModelHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeModelHelper.swift; sourceTree = ""; }; 948DB67D2326DCD90011F916 /* MultiProgress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiProgress.swift; sourceTree = ""; }; 94C2D9832386F3F80006CF46 /* LabelAttributeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeModel.swift; sourceTree = ""; }; 94C2D9A023872BCC0006CF46 /* LabelAttributeUnderlineModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeUnderlineModel.swift; sourceTree = ""; }; @@ -684,7 +684,7 @@ 946EE1B5237B663A0036751F /* Extensions */ = { isa = PBXGroup; children = ( - 946EE1B9237B66D80036751F /* ModelHelper.swift */, + 946EE1B9237B66D80036751F /* MoleculeModelHelper.swift */, ); path = Extensions; sourceTree = ""; @@ -1561,7 +1561,6 @@ 012A889C23889E8400FE3DA1 /* TemplateModelProtocol.swift in Sources */, D29770FC21F7C77400B2F0D0 /* MVMCoreUITextFieldView.m in Sources */, C003506123AA94CD00B6AC29 /* Button.swift in Sources */, - D29DF25121E6A177003B2FB9 /* MFDigitTextBox.m in Sources */, DBC4391B224421A0001AB423 /* CaretButton.swift in Sources */, 0198F7A82256A80B0066C936 /* MFRadioButton.m in Sources */, 0A6BF4722360C56C0028F841 /* BaseDropdownEntryField.swift in Sources */, @@ -1588,7 +1587,7 @@ 01509D912327ECE600EF99AA /* CornerLabels.swift in Sources */, D22D1F1B220341F60077CEC0 /* MVMCoreUICheckBox.m in Sources */, D29DF2CB21E7BFCC003B2FB9 /* MFSizeThreshold.m in Sources */, - 946EE1BA237B66D80036751F /* ModelHelper.swift in Sources */, + 946EE1BA237B66D80036751F /* MoleculeModelHelper.swift in Sources */, 01509D932327ECFB00EF99AA /* ProgressBar.swift in Sources */, D29770F521F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsViewController.m in Sources */, ); diff --git a/MVMCoreUI/Atoms/Buttons/MFTextButton+ModelExtension.swift b/MVMCoreUI/Atoms/Buttons/MFTextButton+ModelExtension.swift index a6df6745..a86c072e 100644 --- a/MVMCoreUI/Atoms/Buttons/MFTextButton+ModelExtension.swift +++ b/MVMCoreUI/Atoms/Buttons/MFTextButton+ModelExtension.swift @@ -16,9 +16,6 @@ extension MFTextButton: ModelMoleculeViewProtocol { setTitleColor(model.textColor.uiColor, for: .normal) isEnabled = model.enabled backgroundColor = model.backgroundColor?.uiColor - //TODO: Use object when handleAction is rewrote to handle action model - if let actionMap = model.action.toJSON() { - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) - } + set(with: model.action, delegateObject: delegateObject, additionalData: additionalData) } } diff --git a/MVMCoreUI/Atoms/Buttons/PrimaryButton+MoleculeProtocolExtension.swift b/MVMCoreUI/Atoms/Buttons/PrimaryButton+MoleculeProtocolExtension.swift index f7192fc9..6f285e19 100644 --- a/MVMCoreUI/Atoms/Buttons/PrimaryButton+MoleculeProtocolExtension.swift +++ b/MVMCoreUI/Atoms/Buttons/PrimaryButton+MoleculeProtocolExtension.swift @@ -22,9 +22,6 @@ extension PrimaryButton: ModelMoleculeViewProtocol { setAsSecondaryCustom() } } - //TODO: Use object when handleAction is rewrote to handle action model - if let actionMap = model.action.toJSON() { - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) - } + set(with: model.action, delegateObject: delegateObject, additionalData: additionalData) } } diff --git a/MVMCoreUI/Models/Extensions/ModelHelper.swift b/MVMCoreUI/Models/Extensions/MoleculeModelHelper.swift similarity index 98% rename from MVMCoreUI/Models/Extensions/ModelHelper.swift rename to MVMCoreUI/Models/Extensions/MoleculeModelHelper.swift index 72bb5f8f..e10fcc38 100644 --- a/MVMCoreUI/Models/Extensions/ModelHelper.swift +++ b/MVMCoreUI/Models/Extensions/MoleculeModelHelper.swift @@ -1,5 +1,5 @@ // -// ModelHelper.swift +// MoleculeModelHelper.swift // MVMCoreUI // // Created by Ryan on 11/12/19. diff --git a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift index 5bc59593..6a958061 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift @@ -38,7 +38,7 @@ import Foundation //need to move labelattributemodel to different method ModelRegistry.register(LabelAttributeFontModel.self) ModelRegistry.register(LabelAttributeColorModel.self) - ModelRegistry.register(LabelAttributeImageModel.self) + //ModelRegistry.register(LabelAttributeImageModel.self) // We need to separate the registry by types due to collisions... ModelRegistry.register(LabelAttributeUnderlineModel.self) ModelRegistry.register(LabelAttributeStrikeThroughModel.self) ModelRegistry.register(LabelAttributeActionModel.self) From 979718d4b8836e69323dcf24146b75dcc5d6cd79 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 14 Jan 2020 11:56:50 -0500 Subject: [PATCH 03/10] Defaults, percent fix --- MVMCoreUI/Models/Molecules/FooterModel.swift | 22 +++++++++++++ MVMCoreUI/Models/Molecules/HeaderModel.swift | 29 ++++++++++++----- MVMCoreUI/Molecules/Items/ListItemModel.swift | 31 ++++++++++++++----- .../Molecules/Items/StackItemModel.swift | 8 ++--- MVMCoreUI/Organisms/MoleculeStackView.swift | 8 ++--- 5 files changed, 75 insertions(+), 23 deletions(-) diff --git a/MVMCoreUI/Models/Molecules/FooterModel.swift b/MVMCoreUI/Models/Molecules/FooterModel.swift index 757e2fd5..e31ec1fc 100644 --- a/MVMCoreUI/Models/Molecules/FooterModel.swift +++ b/MVMCoreUI/Models/Molecules/FooterModel.swift @@ -16,11 +16,33 @@ import Foundation enum FooterCodingKeys: String, CodingKey { case backgroundColor } + + /// Defaults to set + func setDefaults() { + if useHorizontalMargins == nil { + useHorizontalMargins = true + } + if useVerticalMargins == nil { + useVerticalMargins = true + } + if topMarginPadding == nil { + topMarginPadding = PaddingDefaultVerticalSpacing + } + if bottomMarginPadding == nil { + bottomMarginPadding = PaddingDefaultVerticalSpacing + } + } + + public override init(with moleculeModel: MoleculeProtocol) { + super.init(with: moleculeModel) + setDefaults() + } required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: FooterCodingKeys.self) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) try super.init(from: decoder) + setDefaults() } public override func encode(to encoder: Encoder) throws { diff --git a/MVMCoreUI/Models/Molecules/HeaderModel.swift b/MVMCoreUI/Models/Molecules/HeaderModel.swift index 1e4ab9f2..4499d313 100644 --- a/MVMCoreUI/Models/Molecules/HeaderModel.swift +++ b/MVMCoreUI/Models/Molecules/HeaderModel.swift @@ -18,19 +18,34 @@ import Foundation case line case backgroundColor } - - required public init(from decoder: Decoder) throws { - try super.init(from: decoder) - let typeContainer = try decoder.container(keyedBy: HeaderCodingKeys.self) - line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line) - - // Default Values + + /// Defaults to set + func setDefaults() { + if useHorizontalMargins == nil { + useHorizontalMargins = true + } + if useVerticalMargins == nil { + useVerticalMargins = true + } if topMarginPadding == nil { topMarginPadding = PaddingDefaultVerticalSpacing } if bottomMarginPadding == nil { bottomMarginPadding = PaddingDefaultVerticalSpacing } + line?.type = .heavy + } + + public override init(with moleculeModel: MoleculeProtocol) { + super.init(with: moleculeModel) + setDefaults() + } + + required public init(from decoder: Decoder) throws { + try super.init(from: decoder) + let typeContainer = try decoder.container(keyedBy: HeaderCodingKeys.self) + line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line) + setDefaults() } public override func encode(to encoder: Encoder) throws { diff --git a/MVMCoreUI/Molecules/Items/ListItemModel.swift b/MVMCoreUI/Molecules/Items/ListItemModel.swift index 24cb05e0..cd0b1dc3 100644 --- a/MVMCoreUI/Molecules/Items/ListItemModel.swift +++ b/MVMCoreUI/Molecules/Items/ListItemModel.swift @@ -24,6 +24,28 @@ import MVMCore case line case style } + + /// Defaults to set + func setDefaults() { + style = "standard" + if useHorizontalMargins == nil { + useHorizontalMargins = true + } + if useVerticalMargins == nil { + useVerticalMargins = true + } + if topMarginPadding == nil { + topMarginPadding = 24 + } + if bottomMarginPadding == nil { + bottomMarginPadding = 24 + } + } + + public override init(with moleculeModel: MoleculeProtocol) { + super.init(with: moleculeModel) + setDefaults() + } required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: ListItemCodingKeys.self) @@ -34,15 +56,8 @@ import MVMCore if let style = try typeContainer.decodeIfPresent(String.self, forKey: .style) { self.style = style } - try super.init(from: decoder) - - if useHorizontalMargins == nil { - useHorizontalMargins = true - } - if useVerticalMargins == nil { - useVerticalMargins = true - } + setDefaults() } public override func encode(to encoder: Encoder) throws { diff --git a/MVMCoreUI/Molecules/Items/StackItemModel.swift b/MVMCoreUI/Molecules/Items/StackItemModel.swift index a5128f1b..d19f2401 100644 --- a/MVMCoreUI/Molecules/Items/StackItemModel.swift +++ b/MVMCoreUI/Molecules/Items/StackItemModel.swift @@ -12,12 +12,12 @@ import Foundation public static var identifier: String = "stackItem" public var backgroundColor: Color? public var spacing: CGFloat? - public var percentage: Int? = 0 + public var percent: Int? public var gone: Bool = false enum MoleculeStackItemCodingKeys: String, CodingKey { case spacing - case percentage + case percent case gone } @@ -28,7 +28,7 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: MoleculeStackItemCodingKeys.self) spacing = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .spacing) - percentage = try typeContainer.decodeIfPresent(Int.self, forKey: .percentage) + percent = try typeContainer.decodeIfPresent(Int.self, forKey: .percent) if let gone = try typeContainer.decodeIfPresent(Bool.self, forKey: .gone) { self.gone = gone } @@ -39,7 +39,7 @@ import Foundation try super.encode(to: encoder) var container = encoder.container(keyedBy: MoleculeStackItemCodingKeys.self) try container.encodeIfPresent(spacing, forKey: .spacing) - try container.encodeIfPresent(percentage, forKey: .percentage) + try container.encodeIfPresent(percent, forKey: .percent) try container.encode(gone, forKey: .gone) } } diff --git a/MVMCoreUI/Organisms/MoleculeStackView.swift b/MVMCoreUI/Organisms/MoleculeStackView.swift index 5345549c..1783e19a 100644 --- a/MVMCoreUI/Organisms/MoleculeStackView.swift +++ b/MVMCoreUI/Organisms/MoleculeStackView.swift @@ -222,8 +222,8 @@ open class MoleculeStackView: Container { stackItem.translatesAutoresizingMaskIntoConstraints = false let spacing = model.spacing ?? stackModel.spacing - let verticalAlignment = model.verticalAlignment ?? (stackItem.view as? MVMCoreUIViewConstrainingProtocol)?.verticalAlignment?() ?? (model.percentage == nil && stackModel.axis == .vertical ? .fill : (stackModel.axis == .vertical ? .leading : .center)) - let horizontalAlignment = model.horizontalAlignment ?? (stackItem.view as? MVMCoreUIViewConstrainingProtocol)?.horizontalAlignment?() ?? (stackModel.axis == .vertical || model.percentage == nil ? .fill : .leading) + let verticalAlignment = model.verticalAlignment ?? (stackItem.view as? MVMCoreUIViewConstrainingProtocol)?.verticalAlignment?() ?? (model.percent == nil && stackModel.axis == .vertical ? .fill : (stackModel.axis == .vertical ? .leading : .center)) + let horizontalAlignment = model.horizontalAlignment ?? (stackItem.view as? MVMCoreUIViewConstrainingProtocol)?.horizontalAlignment?() ?? (stackModel.axis == .vertical || model.percent == nil ? .fill : .leading) stackItem.containerHelper.alignHorizontal(horizontalAlignment) stackItem.containerHelper.alignVertical(verticalAlignment) @@ -238,7 +238,7 @@ open class MoleculeStackView: Container { } pinView(stackItem, toView: contentView, attribute: .leading, relation: .equal, priority: .required, constant: 0) pinView(contentView, toView: stackItem, attribute: .trailing, relation: .equal, priority: .required, constant: 0) - if let percent = model.percentage { + if let percent = model.percent { stackItem.heightAnchor.constraint(equalTo: contentView.heightAnchor, multiplier: CGFloat(percent)/100.0).isActive = true } if lastItem { @@ -255,7 +255,7 @@ open class MoleculeStackView: Container { } pinView(stackItem, toView: contentView, attribute: .top, relation: .equal, priority: .required, constant: 0) pinView(contentView, toView: stackItem, attribute: .bottom, relation: .equal, priority: .required, constant: 0) - if let percent = model.percentage { + if let percent = model.percent { stackItem.widthAnchor.constraint(equalTo: contentView.widthAnchor, multiplier: CGFloat(percent)/100.0).isActive = true } if lastItem { From a2046036164c05d895b1a127bbe59858aae7a580 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 14 Jan 2020 12:19:26 -0500 Subject: [PATCH 04/10] temp corner labels fix --- MVMCoreUI/Molecules/LeftRightViews/CornerLabels.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/MVMCoreUI/Molecules/LeftRightViews/CornerLabels.swift b/MVMCoreUI/Molecules/LeftRightViews/CornerLabels.swift index bde3ab6f..5c0dbfcf 100644 --- a/MVMCoreUI/Molecules/LeftRightViews/CornerLabels.swift +++ b/MVMCoreUI/Molecules/LeftRightViews/CornerLabels.swift @@ -8,7 +8,7 @@ import UIKit -@objcMembers public class CornerLabels: ViewConstrainingView { +@objcMembers public class CornerLabels: ViewConstrainingView, ModelMoleculeViewProtocol { let topLeftLabel = Label.commonLabelB1(true) let topRightLabel = Label.commonLabelB1(true) @@ -177,9 +177,7 @@ import UIKit public override class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { return 34 } -} -extension CornerLabels: MoleculeViewProtocol { public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { guard let model = model as? CornerLabelsModel, let data = try? model.encode(using: JSONEncoder()), From 3d2fd02ac54a4d3011c4298735da6b7f78742d08 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 14 Jan 2020 13:58:18 -0500 Subject: [PATCH 05/10] undo view constraining removal code fix molecule table cell fix corner labels --- MVMCoreUI/Atoms/Views/ViewConstrainingView.m | 39 +++++++++++ MVMCoreUI/BaseClasses/View.swift | 1 + .../Items/MoleculeTableViewCell.swift | 11 ++-- .../LeftRightViews/CornerLabels.swift | 66 ++++++++----------- MVMCoreUI/Molecules/MoleculeContainer.swift | 7 +- 5 files changed, 80 insertions(+), 44 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/ViewConstrainingView.m b/MVMCoreUI/Atoms/Views/ViewConstrainingView.m index 54a12612..b98e72a5 100644 --- a/MVMCoreUI/Atoms/Views/ViewConstrainingView.m +++ b/MVMCoreUI/Atoms/Views/ViewConstrainingView.m @@ -352,6 +352,45 @@ } - (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { + // Only treated as a container if we are constraining a molecule. + if (!self.constrainedView) { + [super setWithJSON:json delegateObject:delegateObject additionalData:additionalData]; + } + if (self.shouldSetupMoleculeFromJSON) { + NSDictionary *moleculeJSON = [json dict:KeyMolecule]; + if (self.molecule) { + [self.molecule setWithJSON:moleculeJSON delegateObject:delegateObject additionalData:additionalData]; + } else if (moleculeJSON) { + UIView *molecule = [[MVMCoreUIMoleculeMappingObject sharedMappingObject] createMoleculeForJSON:moleculeJSON delegateObject:delegateObject constrainIfNeeded:true]; + if (molecule) { + [self addMolecule:molecule]; + } + self.molecule = molecule; + [self setMoleculeAccessibility]; + } + } else { + [self.molecule setWithJSON:json delegateObject:delegateObject additionalData:additionalData]; + } + + NSNumber *useHorizontalMargins = [json optionalNumberForKey:@"useHorizontalMargins"]; + if (useHorizontalMargins) { + self.updateViewHorizontalDefaults = [useHorizontalMargins boolValue]; + } + NSNumber *useVerticalMargins = [json optionalNumberForKey:@"useVerticalMargins"]; + if (useVerticalMargins) { + self.updateViewVerticalDefaults = [useVerticalMargins boolValue]; + } + + // Set the alignment for the stack in the containing view. The json driven value is for the axis direction alignment. + NSString *alignment = [json string:@"horizontalAlignment"]; + if (alignment) { + [self alignHorizontal:[ViewConstrainingView getAlignmentForString:alignment defaultAlignment:UIStackViewAlignmentFill]]; + } + alignment = [json string:@"verticalAlignment"]; + if (alignment) { + [self alignVertical:[ViewConstrainingView getAlignmentForString:alignment defaultAlignment:UIStackViewAlignmentFill]]; + } + if ([self.molecule respondsToSelector:@selector(copyBackgroundColor)] && [self.molecule performSelector:@selector(copyBackgroundColor)]) { self.backgroundColor = self.molecule.backgroundColor; } diff --git a/MVMCoreUI/BaseClasses/View.swift b/MVMCoreUI/BaseClasses/View.swift index 4691f8e7..d3843f43 100644 --- a/MVMCoreUI/BaseClasses/View.swift +++ b/MVMCoreUI/BaseClasses/View.swift @@ -61,6 +61,7 @@ extension View: MVMCoreViewProtocol { open func setupView() { translatesAutoresizingMaskIntoConstraints = false insetsLayoutMarginsFromSafeArea = false + MVMCoreUIUtility.setMarginsFor(self, leading: 0, top: 0, trailing: 0, bottom: 0) } } diff --git a/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift b/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift index 1fee9e20..2b4fa0a8 100644 --- a/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift @@ -13,13 +13,12 @@ import UIKit // MARK: - MVMCoreUIMoleculeViewProtocol public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.setWithModel(model, delegateObject, additionalData) - - guard let model = model, - let moleculeModel = (model as? ListItemModel)?.molecule, - let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(moleculeModel, delegateObject, true) else { - return + guard let moleculeModel = (model as? ListItemModel)?.molecule else { return } + if molecule != nil { + (molecule as? ModelMoleculeViewProtocol)?.setWithModel(moleculeModel, delegateObject, additionalData) + } else if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(moleculeModel, delegateObject, true) { + addMolecule(moleculeView) } - addMolecule(moleculeView) } public override class func name(forReuse molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> String? { diff --git a/MVMCoreUI/Molecules/LeftRightViews/CornerLabels.swift b/MVMCoreUI/Molecules/LeftRightViews/CornerLabels.swift index 5c0dbfcf..ac9fe240 100644 --- a/MVMCoreUI/Molecules/LeftRightViews/CornerLabels.swift +++ b/MVMCoreUI/Molecules/LeftRightViews/CornerLabels.swift @@ -8,8 +8,8 @@ import UIKit -@objcMembers public class CornerLabels: ViewConstrainingView, ModelMoleculeViewProtocol { - +@objcMembers public class CornerLabels: View { + var middleView: UIView? let topLeftLabel = Label.commonLabelB1(true) let topRightLabel = Label.commonLabelB1(true) let bottomLeftLabel = Label.commonLabelB3(true) @@ -38,18 +38,19 @@ import UIKit var topLabelToMoleculeConstraint: NSLayoutConstraint? var bottomLabelToMoleculeConstraint: NSLayoutConstraint? - public override func addMolecule(_ molecule: UIView) { - insertSubview(molecule, at: 0) + public func addMiddleView(_ view: UIView) { + insertSubview(view, at: 0) topLabelToMoleculeConstraint?.isActive = false bottomLabelToMoleculeConstraint?.isActive = false - molecule.leftAnchor.constraint(equalTo: layoutMarginsGuide.leftAnchor).isActive = true - layoutMarginsGuide.rightAnchor.constraint(equalTo: molecule.rightAnchor).isActive = true + view.leftAnchor.constraint(equalTo: layoutMarginsGuide.leftAnchor).isActive = true + layoutMarginsGuide.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true - topLabelToMoleculeConstraint = molecule.topAnchor.constraint(equalTo: topLabelsView.bottomAnchor, constant: spaceAboveMolecule) + topLabelToMoleculeConstraint = view.topAnchor.constraint(equalTo: topLabelsView.bottomAnchor, constant: spaceAboveMolecule) topLabelToMoleculeConstraint?.isActive = true - bottomLabelToMoleculeConstraint = bottomLabelsView.topAnchor.constraint(equalTo: molecule.bottomAnchor, constant: spaceBelowMolecule) + bottomLabelToMoleculeConstraint = bottomLabelsView.topAnchor.constraint(equalTo: view.bottomAnchor, constant: spaceBelowMolecule) bottomLabelToMoleculeConstraint?.isActive = true + self.middleView = view } // MARK: - MVMCoreViewProtocol @@ -59,12 +60,11 @@ import UIKit topRightLabel.updateView(size) bottomLeftLabel.updateView(size) bottomRightLabel.updateView(size) + (middleView as? MVMCoreViewProtocol)?.updateView(size) } public override func setupView() { super.setupView() - shouldSetupMoleculeFromJSON = true - guard topLeftLabel.superview == nil else { return } @@ -141,17 +141,6 @@ import UIKit } // MARK: - MVMCoreUIMoleculeViewProtocol - open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - topLeftLabel.setWithJSON(json?.optionalDictionaryForKey("topLeftLabel"), delegateObject: delegateObject, additionalData: additionalData) - topRightLabel.setWithJSON(json?.optionalDictionaryForKey("topRightLabel"), delegateObject: delegateObject, additionalData: additionalData) - bottomLeftLabel.setWithJSON(json?.optionalDictionaryForKey("bottomLeftLabel"), delegateObject: delegateObject, additionalData: additionalData) - bottomRightLabel.setWithJSON(json?.optionalDictionaryForKey("bottomRightLabel"), delegateObject: delegateObject, additionalData: additionalData) - - topLabelToMoleculeConstraint?.constant = (molecule != nil && (topLeftLabel.hasText || topRightLabel.hasText)) ? spaceAboveMolecule : 0 - bottomLabelToMoleculeConstraint?.constant = (molecule != nil && (bottomLeftLabel.hasText || bottomRightLabel.hasText)) ? spaceBelowMolecule : 0 - } - public override func setAsMolecule() { super.setAsMolecule() styleDefault() @@ -163,8 +152,7 @@ import UIKit styleDefault() spaceAboveMolecule = 6.0 spaceBelowMolecule = 6.0 - - molecule?.reset?() + (middleView as? MoleculeViewProtocol)?.reset?() } func styleDefault() { @@ -174,23 +162,27 @@ import UIKit bottomRightLabel.styleB3(true) } - public override class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { + public class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { return 34 } - public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { - guard let model = model as? CornerLabelsModel, - let data = try? model.encode(using: JSONEncoder()), - let json = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any] else { - return + public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + super.setWithModel(model, delegateObject, additionalData) + guard let model = model as? CornerLabelsModel else { return } + if middleView != nil { + (middleView as? ModelMoleculeViewProtocol)?.setWithModel(model, delegateObject, additionalData) + } else { + if let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(model.molecule, delegateObject) { + addMiddleView(molecule) + } } - self.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) -// topLeftLabel.setWithModel(model.topLeftLabel, delegateObject, additionalData) -// topRightLabel.setWithModel(model.topRightLabel, delegateObject, additionalData) -// bottomLeftLabel.setWithModel(model.bottomLeftLabel, delegateObject, additionalData) -// bottomRightLabel.setWithModel(model.bottomRightLabel, delegateObject, additionalData) -// -// topLabelToMoleculeConstraint?.constant = (molecule != nil && (topLeftLabel.hasText || topRightLabel.hasText)) ? spaceAboveMolecule : 0 -// bottomLabelToMoleculeConstraint?.constant = (molecule != nil && (bottomLeftLabel.hasText || bottomRightLabel.hasText)) ? spaceBelowMolecule : 0 + + topLeftLabel.setWithModel(model.topLeftLabel, delegateObject, additionalData) + topRightLabel.setWithModel(model.topRightLabel, delegateObject, additionalData) + bottomLeftLabel.setWithModel(model.bottomLeftLabel, delegateObject, additionalData) + bottomRightLabel.setWithModel(model.bottomRightLabel, delegateObject, additionalData) + + topLabelToMoleculeConstraint?.constant = (middleView != nil && (topLeftLabel.hasText || topRightLabel.hasText)) ? spaceAboveMolecule : 0 + bottomLabelToMoleculeConstraint?.constant = (middleView != nil && (bottomLeftLabel.hasText || bottomRightLabel.hasText)) ? spaceBelowMolecule : 0 } } diff --git a/MVMCoreUI/Molecules/MoleculeContainer.swift b/MVMCoreUI/Molecules/MoleculeContainer.swift index f45ca482..e3646bcf 100644 --- a/MVMCoreUI/Molecules/MoleculeContainer.swift +++ b/MVMCoreUI/Molecules/MoleculeContainer.swift @@ -9,6 +9,11 @@ import UIKit open class MoleculeContainer: Container { + + /// Can be overriden to change how the molecule is added to the hierarchy. + public func addMolecule(_ molecule: UIView) { + addAndContain(molecule) + } override public func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { guard let moleculeJSON = json?.optionalDictionaryForKey(KeyMolecule) else { @@ -31,7 +36,7 @@ open class MoleculeContainer: Container { (view as? ModelMoleculeViewProtocol)?.setWithModel(casteModel.molecule, delegateObject, additionalData) } else { if let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(casteModel.molecule, delegateObject) { - addAndContain(molecule) + addMolecule(molecule) } } } From 147ce53c90f6a0dd771cb1ddebbb25996f4d1d60 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 14 Jan 2020 15:50:46 -0500 Subject: [PATCH 06/10] name for class --- MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift | 10 +++++----- MVMCoreUI/Molecules/Items/TableViewCell.swift | 9 ++++++--- MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift | 5 ++--- MVMCoreUI/Molecules/ModuleMolecule.swift | 2 +- MVMCoreUI/Organisms/Carousel.swift | 2 +- MVMCoreUI/Organisms/MoleculeStackView.swift | 3 ++- MVMCoreUI/Templates/MoleculeListTemplate.swift | 2 +- 7 files changed, 18 insertions(+), 15 deletions(-) diff --git a/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift b/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift index 1fee9e20..3733ea6e 100644 --- a/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift @@ -22,12 +22,12 @@ import UIKit addMolecule(moleculeView) } - public override class func name(forReuse molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> String? { - guard let moleculeModel = (molecule as? ListItemModel)?.molecule else { + public override class func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { + guard let moleculeModel = (model as? ListItemModel)?.molecule else { return "\(self)<>" } - let className = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moleculeModel) as? ModelMoleculeViewProtocol - let moleculeName = className?.nameForReuse(molecule, delegateObject) ?? moleculeModel.moleculeName ?? "" + let className = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moleculeModel) as? ModelMoleculeViewProtocol.Type + let moleculeName = className?.nameForReuse(model, delegateObject) ?? moleculeModel.moleculeName ?? "" return "\(self)<\(moleculeName)>" } @@ -39,7 +39,7 @@ import UIKit return theClass.requiredModules?(moleculeJSON, delegateObject: delegateObject, error: error) } - public static func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { + public override class func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { guard let moleculeModel = (molecule as? MoleculeContainerModel)?.molecule, let classType = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moleculeModel) as? ModelMoleculeViewProtocol.Type, let height = classType.estimatedHeight(forRow: moleculeModel, delegateObject: delegateObject) else { diff --git a/MVMCoreUI/Molecules/Items/TableViewCell.swift b/MVMCoreUI/Molecules/Items/TableViewCell.swift index 774f50d1..ffdcd85b 100644 --- a/MVMCoreUI/Molecules/Items/TableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/TableViewCell.swift @@ -179,10 +179,13 @@ import UIKit backgroundColor = .white } - public class func name(forReuse molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> String? { - return molecule?.moleculeName ?? "" + public class func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { + return model?.moleculeName } - + + public class func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { + return nil + } // MARK: - Arrow /// Adds the standard mvm style caret to the accessory view @objc public func addCaretViewAccessory() { diff --git a/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift b/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift index de8e4d4f..34f2c67b 100644 --- a/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift +++ b/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift @@ -10,13 +10,13 @@ import Foundation public protocol ModelMoleculeViewProtocol { func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) - func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? + static func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? static func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? static func requiredModules(_ molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? } extension ModelMoleculeViewProtocol { - public func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { + public static func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { return nil } public static func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { @@ -25,7 +25,6 @@ extension ModelMoleculeViewProtocol { public static func requiredModules(_ molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { return nil } - // Temporary public static func decodeJSONToModel(json: [AnyHashable: Any], type: T.Type) throws -> T where T : Decodable { let data = try JSONSerialization.data(withJSONObject: json) diff --git a/MVMCoreUI/Molecules/ModuleMolecule.swift b/MVMCoreUI/Molecules/ModuleMolecule.swift index e2411ec0..0cb0e541 100644 --- a/MVMCoreUI/Molecules/ModuleMolecule.swift +++ b/MVMCoreUI/Molecules/ModuleMolecule.swift @@ -61,7 +61,7 @@ open class ModuleMolecule: Container { public override func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { guard let moduleMolecule = model as? ModuleMoleculeModel, let moduleModel = delegateObject?.moleculeDelegate?.getModuleWithName(moduleMolecule.moduleName), - let classType = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moduleModel) as? ModelMoleculeViewProtocol, + let classType = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moduleModel) as? ModelMoleculeViewProtocol.Type, let name = classType.nameForReuse(moduleModel, delegateObject) else { // Critical error return "moduleMolecule<>" diff --git a/MVMCoreUI/Organisms/Carousel.swift b/MVMCoreUI/Organisms/Carousel.swift index 181ae372..98f1e6a2 100644 --- a/MVMCoreUI/Organisms/Carousel.swift +++ b/MVMCoreUI/Organisms/Carousel.swift @@ -169,7 +169,7 @@ open class Carousel: ViewConstrainingView, ModelMoleculeViewProtocol { /// Returns the (identifier, class) of the molecule for the given map. func getMoleculeInfo(with molecule: MoleculeProtocol, delegateObject: MVMCoreUIDelegateObject?) -> (identifier: String, class: AnyClass, molecule: MoleculeProtocol)? { guard let className = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(molecule) , - let moleculeName = (className as? ModelMoleculeViewProtocol)?.nameForReuse(molecule, delegateObject) ?? molecule.moleculeName else { + let moleculeName = (className as? ModelMoleculeViewProtocol.Type)?.nameForReuse(molecule, delegateObject) ?? molecule.moleculeName else { return nil } return (moleculeName, className, molecule) diff --git a/MVMCoreUI/Organisms/MoleculeStackView.swift b/MVMCoreUI/Organisms/MoleculeStackView.swift index 5345549c..a09ec83d 100644 --- a/MVMCoreUI/Organisms/MoleculeStackView.swift +++ b/MVMCoreUI/Organisms/MoleculeStackView.swift @@ -119,7 +119,8 @@ open class MoleculeStackView: Container { var name = "stack<" for case let item in model.molecules { if let moleculeName = item.molecule.moleculeName { - if let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping[moleculeName] as? ModelMoleculeViewProtocol, let nameForReuse = moleculeClass.nameForReuse(item.molecule, delegateObject) { + if let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping[moleculeName] as? ModelMoleculeViewProtocol.Type, + let nameForReuse = moleculeClass.nameForReuse(item.molecule, delegateObject) { name.append(nameForReuse + ",") } else { name.append(moleculeName + ",") diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index 3a551a79..5570bb1a 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -167,7 +167,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol func getMoleculeInfo(with listItem: ListItemModelProtocol?) -> (identifier: String, class: AnyClass, molecule: ListItemModelProtocol)? { guard let listItem = listItem, let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(listItem), - let moleculeName = (moleculeClass as? ModelMoleculeViewProtocol)?.nameForReuse(listItem, delegateObject() as? MVMCoreUIDelegateObject) ?? listItem.moleculeName else { + let moleculeName = (moleculeClass as? ModelMoleculeViewProtocol.Type)?.nameForReuse(listItem, delegateObject() as? MVMCoreUIDelegateObject) ?? listItem.moleculeName else { return nil } return (moleculeName, moleculeClass, listItem) From 27793931f5c1f56bccfb09ed832de3a2e10736cf Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 14 Jan 2020 15:55:18 -0500 Subject: [PATCH 07/10] fix for static functions --- MVMCoreUI/BaseClasses/View.swift | 4 ---- .../Molecules/Items/MoleculeCollectionViewCell.swift | 8 +++++--- .../Molecules/Items/MoleculeTableViewCell.swift | 12 ++++++------ MVMCoreUI/Molecules/Items/TableViewCell.swift | 4 ---- MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift | 6 +++--- MVMCoreUI/Molecules/ModuleMolecule.swift | 4 ++-- MVMCoreUI/Organisms/Carousel.swift | 2 +- MVMCoreUI/Organisms/MoleculeStackView.swift | 6 +++--- MVMCoreUI/Templates/MoleculeListTemplate.swift | 2 +- 9 files changed, 21 insertions(+), 27 deletions(-) diff --git a/MVMCoreUI/BaseClasses/View.swift b/MVMCoreUI/BaseClasses/View.swift index d3843f43..4d6e247d 100644 --- a/MVMCoreUI/BaseClasses/View.swift +++ b/MVMCoreUI/BaseClasses/View.swift @@ -40,10 +40,6 @@ import UIKit } } - public func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { - return model?.moleculeName - } - open func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { self.model = model if let backgroundColor = model?.backgroundColor { diff --git a/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift b/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift index b396dde6..93f5e039 100644 --- a/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift +++ b/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift @@ -114,11 +114,13 @@ open class MoleculeCollectionViewCell: UICollectionViewCell, MVMCoreUIMoleculeVi backgroundColor = .white } - public class func name(forReuse molecule: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? { - guard let molecule = molecule?.optionalDictionaryForKey(KeyMolecule) else { + public class func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { + guard let molecule = (model as? CarouselItemModel)?.molecule, + let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(molecule) as? ModelMoleculeViewProtocol.Type, + let name = moleculeClass.nameForReuse(molecule, delegateObject) ?? molecule.moleculeName else { return nil } - return MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: molecule)?.name?(forReuse: molecule, delegateObject: delegateObject) ?? molecule.optionalStringForKey(KeyMoleculeName) + return name } public func updateView(_ size: CGFloat) { diff --git a/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift b/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift index 2b4fa0a8..6b57c0f5 100644 --- a/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift @@ -20,16 +20,16 @@ import UIKit addMolecule(moleculeView) } } - - public override class func name(forReuse molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> String? { - guard let moleculeModel = (molecule as? ListItemModel)?.molecule else { + + public class func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { + guard let moleculeModel = (model as? ListItemModel)?.molecule else { return "\(self)<>" } - let className = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moleculeModel) as? ModelMoleculeViewProtocol - let moleculeName = className?.nameForReuse(molecule, delegateObject) ?? moleculeModel.moleculeName ?? "" + let className = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moleculeModel) as? ModelMoleculeViewProtocol.Type + let moleculeName = className?.nameForReuse(moleculeModel, delegateObject) ?? moleculeModel.moleculeName ?? "" return "\(self)<\(moleculeName)>" } - + public class func requiredModules(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { guard let moleculeJSON = json?.optionalDictionaryForKey(KeyMolecule), let theClass = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: moleculeJSON) else { diff --git a/MVMCoreUI/Molecules/Items/TableViewCell.swift b/MVMCoreUI/Molecules/Items/TableViewCell.swift index 774f50d1..dfcf7252 100644 --- a/MVMCoreUI/Molecules/Items/TableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/TableViewCell.swift @@ -178,10 +178,6 @@ import UIKit styleStandard() backgroundColor = .white } - - public class func name(forReuse molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> String? { - return molecule?.moleculeName ?? "" - } // MARK: - Arrow /// Adds the standard mvm style caret to the accessory view diff --git a/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift b/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift index de8e4d4f..fcf03ccd 100644 --- a/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift +++ b/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift @@ -10,14 +10,14 @@ import Foundation public protocol ModelMoleculeViewProtocol { func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) - func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? + static func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? static func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? static func requiredModules(_ molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? } extension ModelMoleculeViewProtocol { - public func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { - return nil + public static func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { + return model?.moleculeName } public static func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { return nil diff --git a/MVMCoreUI/Molecules/ModuleMolecule.swift b/MVMCoreUI/Molecules/ModuleMolecule.swift index e2411ec0..be13fc79 100644 --- a/MVMCoreUI/Molecules/ModuleMolecule.swift +++ b/MVMCoreUI/Molecules/ModuleMolecule.swift @@ -58,10 +58,10 @@ open class ModuleMolecule: Container { return height } - public override func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { + public class func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { guard let moduleMolecule = model as? ModuleMoleculeModel, let moduleModel = delegateObject?.moleculeDelegate?.getModuleWithName(moduleMolecule.moduleName), - let classType = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moduleModel) as? ModelMoleculeViewProtocol, + let classType = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moduleModel) as? ModelMoleculeViewProtocol.Type, let name = classType.nameForReuse(moduleModel, delegateObject) else { // Critical error return "moduleMolecule<>" diff --git a/MVMCoreUI/Organisms/Carousel.swift b/MVMCoreUI/Organisms/Carousel.swift index 181ae372..98f1e6a2 100644 --- a/MVMCoreUI/Organisms/Carousel.swift +++ b/MVMCoreUI/Organisms/Carousel.swift @@ -169,7 +169,7 @@ open class Carousel: ViewConstrainingView, ModelMoleculeViewProtocol { /// Returns the (identifier, class) of the molecule for the given map. func getMoleculeInfo(with molecule: MoleculeProtocol, delegateObject: MVMCoreUIDelegateObject?) -> (identifier: String, class: AnyClass, molecule: MoleculeProtocol)? { guard let className = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(molecule) , - let moleculeName = (className as? ModelMoleculeViewProtocol)?.nameForReuse(molecule, delegateObject) ?? molecule.moleculeName else { + let moleculeName = (className as? ModelMoleculeViewProtocol.Type)?.nameForReuse(molecule, delegateObject) ?? molecule.moleculeName else { return nil } return (moleculeName, className, molecule) diff --git a/MVMCoreUI/Organisms/MoleculeStackView.swift b/MVMCoreUI/Organisms/MoleculeStackView.swift index 1783e19a..60c6515f 100644 --- a/MVMCoreUI/Organisms/MoleculeStackView.swift +++ b/MVMCoreUI/Organisms/MoleculeStackView.swift @@ -97,7 +97,7 @@ open class MoleculeStackView: Container { removeAllItemViews() // If the items in the stack are different, clear them, create new ones. - if (previousModel == nil) || nameForReuse(previousModel, delegateObject) != nameForReuse(model, delegateObject) { + if (previousModel == nil) || MoleculeStackView.nameForReuse(previousModel, delegateObject) != MoleculeStackView.nameForReuse(model, delegateObject) { stackItems = [] createStackItemsFromModel(with: delegateObject) } else if let models = stackModel?.molecules { @@ -111,7 +111,7 @@ open class MoleculeStackView: Container { stackModel?.useVerticalMargins = moleculesShouldSetVerticalMargins } - public override func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { + public class func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { // This will aggregate names of molecules to make an id. guard let model = model as? MoleculeStackModel else { return "stack<>" @@ -119,7 +119,7 @@ open class MoleculeStackView: Container { var name = "stack<" for case let item in model.molecules { if let moleculeName = item.molecule.moleculeName { - if let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping[moleculeName] as? ModelMoleculeViewProtocol, let nameForReuse = moleculeClass.nameForReuse(item.molecule, delegateObject) { + if let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping[moleculeName] as? ModelMoleculeViewProtocol.Type, let nameForReuse = moleculeClass.nameForReuse(item.molecule, delegateObject) { name.append(nameForReuse + ",") } else { name.append(moleculeName + ",") diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index 3a551a79..5570bb1a 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -167,7 +167,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol func getMoleculeInfo(with listItem: ListItemModelProtocol?) -> (identifier: String, class: AnyClass, molecule: ListItemModelProtocol)? { guard let listItem = listItem, let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(listItem), - let moleculeName = (moleculeClass as? ModelMoleculeViewProtocol)?.nameForReuse(listItem, delegateObject() as? MVMCoreUIDelegateObject) ?? listItem.moleculeName else { + let moleculeName = (moleculeClass as? ModelMoleculeViewProtocol.Type)?.nameForReuse(listItem, delegateObject() as? MVMCoreUIDelegateObject) ?? listItem.moleculeName else { return nil } return (moleculeName, moleculeClass, listItem) From fc2326e9a8706b81bf2c2c597ba9e138e56977dc Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 14 Jan 2020 16:32:42 -0500 Subject: [PATCH 08/10] button size --- MVMCoreUI/Atoms/Buttons/ButtonModel.swift | 17 +++++++++++-- ...maryButton+MoleculeProtocolExtension.swift | 8 +++++++ MVMCoreUI/BaseClasses/View.swift | 12 ++++++++++ MVMCoreUI/Molecules/Items/ListItemModel.swift | 1 - .../SwitchMolecules/HeadlineBodySwitch.swift | 2 +- MVMCoreUI/Molecules/ModuleMolecule.swift | 6 ++--- .../EyebrowHeadlineBodyLink.swift | 2 +- MVMCoreUI/Organisms/MoleculeStackView.swift | 24 +++++++++---------- 8 files changed, 52 insertions(+), 20 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/ButtonModel.swift b/MVMCoreUI/Atoms/Buttons/ButtonModel.swift index 03eb7fc3..4329ccff 100644 --- a/MVMCoreUI/Atoms/Buttons/ButtonModel.swift +++ b/MVMCoreUI/Atoms/Buttons/ButtonModel.swift @@ -13,12 +13,18 @@ public enum ButtonStyle: String, Codable { case secondary } +public enum ButtonSize: String, Codable { + case standard + case tiny +} + public class ButtonModel: MoleculeProtocol { public static var identifier: String = "button" public var backgroundColor: Color? public var title: String public var action: ActionProtocol - public var style: ButtonStyle? + public var style: ButtonStyle? = .primary + public var size: ButtonSize? = .standard init(with title: String, action: ActionProtocol) { self.title = title @@ -30,6 +36,7 @@ public class ButtonModel: MoleculeProtocol { case title case action case style + case size } required public init(from decoder: Decoder) throws { @@ -37,7 +44,12 @@ public class ButtonModel: MoleculeProtocol { backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) title = try typeContainer.decode(String.self, forKey: .title) action = try typeContainer.decodeModel(codingKey: .action, typeCodingKey: ActionCodingKey.actionType) - style = try typeContainer.decodeIfPresent(ButtonStyle.self, forKey: .style) + if let style = try typeContainer.decodeIfPresent(ButtonStyle.self, forKey: .style) { + self.style = style + } + if let size = try typeContainer.decodeIfPresent(ButtonSize.self, forKey: .size) { + self.size = size + } } public func encode(to encoder: Encoder) throws { @@ -46,5 +58,6 @@ public class ButtonModel: MoleculeProtocol { try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeModel(action, forKey: .action) try container.encodeIfPresent(style, forKey: .style) + try container.encodeIfPresent(size, forKey: .size) } } diff --git a/MVMCoreUI/Atoms/Buttons/PrimaryButton+MoleculeProtocolExtension.swift b/MVMCoreUI/Atoms/Buttons/PrimaryButton+MoleculeProtocolExtension.swift index 6f285e19..2d7ecf40 100644 --- a/MVMCoreUI/Atoms/Buttons/PrimaryButton+MoleculeProtocolExtension.swift +++ b/MVMCoreUI/Atoms/Buttons/PrimaryButton+MoleculeProtocolExtension.swift @@ -22,6 +22,14 @@ extension PrimaryButton: ModelMoleculeViewProtocol { setAsSecondaryCustom() } } + if let size = model.size { + switch size { + case .standard: + setAsTiny(false) + case .tiny: + setAsTiny(true) + } + } set(with: model.action, delegateObject: delegateObject, additionalData: additionalData) } } diff --git a/MVMCoreUI/BaseClasses/View.swift b/MVMCoreUI/BaseClasses/View.swift index 4d6e247d..05cbef15 100644 --- a/MVMCoreUI/BaseClasses/View.swift +++ b/MVMCoreUI/BaseClasses/View.swift @@ -46,6 +46,18 @@ import UIKit self.backgroundColor = backgroundColor.uiColor } } + + public class func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { + return model?.moleculeName + } + + public class func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { + return nil + } + + public class func requiredModules(_ molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { + return nil + } } // MARK:- MVMCoreViewProtocol diff --git a/MVMCoreUI/Molecules/Items/ListItemModel.swift b/MVMCoreUI/Molecules/Items/ListItemModel.swift index cd0b1dc3..5e54a2e9 100644 --- a/MVMCoreUI/Molecules/Items/ListItemModel.swift +++ b/MVMCoreUI/Molecules/Items/ListItemModel.swift @@ -27,7 +27,6 @@ import MVMCore /// Defaults to set func setDefaults() { - style = "standard" if useHorizontalMargins == nil { useHorizontalMargins = true } diff --git a/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift b/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift index fee32b2f..1c937df1 100644 --- a/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift +++ b/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift @@ -41,7 +41,7 @@ import UIKit super.setWithModel(model, delegateObject, additionalData) } - public static func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { + public class override func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { return 30 } diff --git a/MVMCoreUI/Molecules/ModuleMolecule.swift b/MVMCoreUI/Molecules/ModuleMolecule.swift index be13fc79..04caa9da 100644 --- a/MVMCoreUI/Molecules/ModuleMolecule.swift +++ b/MVMCoreUI/Molecules/ModuleMolecule.swift @@ -46,7 +46,7 @@ open class ModuleMolecule: Container { } } - public static func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { + public override class func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { guard let moduleMolecule = molecule as? ModuleMoleculeModel, let moduleModel = delegateObject?.moleculeDelegate?.getModuleWithName(moduleMolecule.moduleName), @@ -58,7 +58,7 @@ open class ModuleMolecule: Container { return height } - public class func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { + public override class func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { guard let moduleMolecule = model as? ModuleMoleculeModel, let moduleModel = delegateObject?.moleculeDelegate?.getModuleWithName(moduleMolecule.moduleName), let classType = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moduleModel) as? ModelMoleculeViewProtocol.Type, @@ -69,7 +69,7 @@ open class ModuleMolecule: Container { return name } - public static func requiredModules(_ molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { + public override class func requiredModules(_ molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { guard let moduleName = (molecule as? ModuleMoleculeModel)?.moduleName, let _ = delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) else { diff --git a/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift b/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift index 1262994f..d5557eca 100644 --- a/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift +++ b/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift @@ -85,7 +85,7 @@ struct EyebrowHeadlineBodyLinkModel: MoleculeProtocol { body.styleB2(true) } - public static func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { + public override class func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { return 65 } } diff --git a/MVMCoreUI/Organisms/MoleculeStackView.swift b/MVMCoreUI/Organisms/MoleculeStackView.swift index c3da98ef..9f2f526f 100644 --- a/MVMCoreUI/Organisms/MoleculeStackView.swift +++ b/MVMCoreUI/Organisms/MoleculeStackView.swift @@ -111,7 +111,18 @@ open class MoleculeStackView: Container { stackModel?.useVerticalMargins = moleculesShouldSetVerticalMargins } - public class func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { + open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + if model == nil { + let data = try! JSONSerialization.data(withJSONObject: json!) + let decoder = JSONDecoder() + let model = try! decoder.decode(MoleculeStackModel.self, from: data) + setWithModel(model, delegateObject, additionalData) + } else { + setWithModel(model, delegateObject, additionalData) + } + } + + public override class func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { // This will aggregate names of molecules to make an id. guard let model = model as? MoleculeStackModel else { return "stack<>" @@ -131,17 +142,6 @@ open class MoleculeStackView: Container { return name } - open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - if model == nil { - let data = try! JSONSerialization.data(withJSONObject: json!) - let decoder = JSONDecoder() - let model = try! decoder.decode(MoleculeStackModel.self, from: data) - setWithModel(model, delegateObject, additionalData) - } else { - setWithModel(model, delegateObject, additionalData) - } - } - public class func name(forReuse molecule: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? { // This will aggregate names of molecules to make an id. guard let molecules = molecule?.optionalArrayForKey(KeyMolecules) else { From e85270d0389857eaae0f67fe941bb731e0796fea Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 14 Jan 2020 18:33:34 -0500 Subject: [PATCH 09/10] new molecules to model --- MVMCoreUI.xcodeproj/project.pbxproj | 4 ++++ .../HeadLineBodyCaretLinkImage.swift | 15 ++++++++++++--- .../HeadlineBodyCaretLinkImageModel.swift | 17 +++++++++++++++++ .../OtherHandlers/MoleculeObjectMapping.swift | 3 +++ 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyCaretLinkImageModel.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 6580f328..9c93c8dc 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -150,6 +150,7 @@ D28A838D23CCDCC200DFE4FC /* PrimaryButton+MoleculeProtocolExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A838C23CCDCC200DFE4FC /* PrimaryButton+MoleculeProtocolExtension.swift */; }; D28A838F23CCDEDE00DFE4FC /* TwoButtonViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A838E23CCDEDE00DFE4FC /* TwoButtonViewModel.swift */; }; D28A839123CD4FD400DFE4FC /* CornerLabelsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A839023CD4FD400DFE4FC /* CornerLabelsModel.swift */; }; + D28A839323CE828900DFE4FC /* HeadlineBodyCaretLinkImageModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A839223CE828900DFE4FC /* HeadlineBodyCaretLinkImageModel.swift */; }; D296E14722A5984C0051EBE7 /* MVMCoreUIViewConstrainingProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D296E14622A597490051EBE7 /* MVMCoreUIViewConstrainingProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; D29770C821F7C4AE00B2F0D0 /* TopLabelsView.m in Sources */ = {isa = PBXBuildFile; fileRef = D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */; }; D29770C921F7C4AE00B2F0D0 /* TopLabelsView.h in Headers */ = {isa = PBXBuildFile; fileRef = D29770C721F7C4AE00B2F0D0 /* TopLabelsView.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -418,6 +419,7 @@ D28A838C23CCDCC200DFE4FC /* PrimaryButton+MoleculeProtocolExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PrimaryButton+MoleculeProtocolExtension.swift"; sourceTree = ""; }; D28A838E23CCDEDE00DFE4FC /* TwoButtonViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwoButtonViewModel.swift; sourceTree = ""; }; D28A839023CD4FD400DFE4FC /* CornerLabelsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CornerLabelsModel.swift; sourceTree = ""; }; + D28A839223CE828900DFE4FC /* HeadlineBodyCaretLinkImageModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeadlineBodyCaretLinkImageModel.swift; sourceTree = ""; }; D296E14622A597490051EBE7 /* MVMCoreUIViewConstrainingProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIViewConstrainingProtocol.h; sourceTree = ""; }; D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TopLabelsView.m; sourceTree = ""; }; D29770C721F7C4AE00B2F0D0 /* TopLabelsView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TopLabelsView.h; sourceTree = ""; }; @@ -760,6 +762,7 @@ 01EB368D23609801006832FA /* HeadlineBodyModel.swift */, D22479952316AF6D003FCCF9 /* HeadlineBodyTextButton.swift */, D27CD40F2339057800C1DC07 /* EyebrowHeadlineBodyLink.swift */, + D28A839223CE828900DFE4FC /* HeadlineBodyCaretLinkImageModel.swift */, C7192E7C23C301750050C2A0 /* HeadLineBodyCaretLinkImage.swift */, ); path = VerticalCombinationViews; @@ -1536,6 +1539,7 @@ 0198F79F225679880066C936 /* FormValidationProtocol.swift in Sources */, D243859923A16B1800332775 /* Container.swift in Sources */, D29DF29821E7ADB8003B2FB9 /* MFScrollingViewController.m in Sources */, + D28A839323CE828900DFE4FC /* HeadlineBodyCaretLinkImageModel.swift in Sources */, D29770C821F7C4AE00B2F0D0 /* TopLabelsView.m in Sources */, 01EB369323609801006832FA /* HeaderModel.swift in Sources */, D2E1FADF2268B8E700AEFD8C /* ThreeLayerTableViewController.swift in Sources */, diff --git a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadLineBodyCaretLinkImage.swift b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadLineBodyCaretLinkImage.swift index 9c3dba8a..3b52e6bf 100644 --- a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadLineBodyCaretLinkImage.swift +++ b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadLineBodyCaretLinkImage.swift @@ -7,7 +7,7 @@ // import Foundation -@objcMembers public class HeadLineBodyCaretLinkImage: ViewConstrainingView { +@objcMembers public class HeadLineBodyCaretLinkImage: View { let headlineBody = HeadlineBody(frame: .zero) let caretButton = CaretButton(frame: .zero) @@ -34,7 +34,7 @@ import Foundation } let view = MVMCoreUICommonViewsUtility.commonView() addSubview(view) - pinView(toSuperView: view) + NSLayoutConstraint.constraintPinSubview(toSuperview: view) view.addSubview(headlineBody) view.addSubview(caretButton) @@ -78,7 +78,16 @@ import Foundation backgroundImageView.reset() } - public override class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { + public override class func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { return 320 } + + public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { + super.setWithModel(model, delegateObject, additionalData) + guard let model = model as? HeadlineBodyCaretLinkImageModel else { return } + headlineBody.setWithModel(model.headlineBody, delegateObject, additionalData) + caretButton.setWithModel(model.caretLink, delegateObject, additionalData) + backgroundImageView.setWithModel(model.image, delegateObject, additionalData) + } } + diff --git a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyCaretLinkImageModel.swift b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyCaretLinkImageModel.swift new file mode 100644 index 00000000..4bfa2740 --- /dev/null +++ b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyCaretLinkImageModel.swift @@ -0,0 +1,17 @@ +// +// headlineBodyCaretLinkImageModel.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 1/14/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import UIKit + +public class HeadlineBodyCaretLinkImageModel: MoleculeProtocol { + public static var identifier: String = "headlineBodyCaretLinkImageMolecule" + public var backgroundColor: Color? + public var caretLink: LinkModel? + public var headlineBody: HeadlineBodyModel + public var image: ImageViewModel +} diff --git a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift index 6a958061..e4c35777 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift @@ -25,10 +25,13 @@ import Foundation ModelRegistry.register(ScrollerModel.self) ModelRegistry.register(CornerLabelsModel.self) ModelRegistry.register(LineModel.self) + ModelRegistry.register(CircleProgressModel.self) + ModelRegistry.register(HeadlineBodyCaretLinkImageModel.self) // buttons ModelRegistry.register(ButtonModel.self) ModelRegistry.register(TwoButtonViewModel.self) ModelRegistry.register(LinkModel.self) + ModelRegistry.register(CaretLinkModel.self) // list items ModelRegistry.register(ListItemModel.self) ModelRegistry.register(DropDownListItemModel.self) From f87ddf34480333952e3847b1dd2b706cc405ba27 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 14 Jan 2020 18:41:54 -0500 Subject: [PATCH 10/10] name update --- .../HeadlineBodyCaretLinkImageModel.swift | 2 +- MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyCaretLinkImageModel.swift b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyCaretLinkImageModel.swift index 4bfa2740..8052a7db 100644 --- a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyCaretLinkImageModel.swift +++ b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyCaretLinkImageModel.swift @@ -9,7 +9,7 @@ import UIKit public class HeadlineBodyCaretLinkImageModel: MoleculeProtocol { - public static var identifier: String = "headlineBodyCaretLinkImageMolecule" + public static var identifier: String = "headlineBodyCaretLinkImage" public var backgroundColor: Color? public var caretLink: LinkModel? public var headlineBody: HeadlineBodyModel diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index b2590566..ad987229 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -73,7 +73,7 @@ @"headlineBodyButton": HeadlineBodyButton.class, @"stackItem": StackItem.class, @"eyebrowHeadlineBodyLink": EyebrowHeadlineBodyLink.class, - @"headLineBodyCaretLinkImage" : HeadLineBodyCaretLinkImage.class + @"headlineBodyCaretLinkImage" : HeadLineBodyCaretLinkImage.class } mutableCopy]; }); return mapping;