From 7b2fc7bfba3e35fa7e59d979742ed2af999db357 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 21 Nov 2019 11:53:26 -0500 Subject: [PATCH] some more stuff --- MVMCoreUI.xcodeproj/project.pbxproj | 28 +++++- .../MFTextField+ModelExtension.swift | 77 ++++++++++++++++ MVMCoreUI/Atoms/Views/GraphView.swift | 6 +- .../Atoms/Views/MFView+ModelExtension.swift | 23 +++++ MVMCoreUI/Atoms/Views/MFView.h | 1 + .../ViewConstrainingView+ModelExtension.swift | 88 +++++++++++++++++++ MVMCoreUI/Atoms/Views/ViewConstrainingView.h | 5 ++ MVMCoreUI/Atoms/Views/ViewConstrainingView.m | 1 - MVMCoreUI/BaseClasses/View.swift | 11 ++- .../Models/ConstrainingMoleculeProtocol.swift | 19 ++++ MVMCoreUI/Models/MoleculeProtocol.swift | 31 +++++++ MVMCoreUI/Models/Molecules/HeaderModel.swift | 3 +- MVMCoreUI/Models/Molecules/LabelModel.swift | 1 - .../Models/Molecules/SeperatorModel.swift | 14 +++ .../Models/Molecules/TextFieldModel.swift | 2 + MVMCoreUI/Molecules/StandardHeaderView.swift | 5 +- .../MVMCoreUIMoleculeMappingObject.m | 2 +- ...ping.swift => MoleculeObjectMapping.swift} | 5 +- 18 files changed, 309 insertions(+), 13 deletions(-) create mode 100644 MVMCoreUI/Atoms/TextFields/MFTextField+ModelExtension.swift create mode 100644 MVMCoreUI/Atoms/Views/MFView+ModelExtension.swift create mode 100644 MVMCoreUI/Atoms/Views/ViewConstrainingView+ModelExtension.swift create mode 100644 MVMCoreUI/Models/ConstrainingMoleculeProtocol.swift create mode 100644 MVMCoreUI/Models/Molecules/SeperatorModel.swift rename MVMCoreUI/OtherHandlers/{MVMCoreUIMoleculeMappingObject+ModelMapping.swift => MoleculeObjectMapping.swift} (80%) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index cc93db84..d8399580 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -12,6 +12,11 @@ 0105618E224BBE7700E1557D /* FormValidator+TextFields.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */; }; 0105618F224BBE7700E1557D /* FormValidator+FormParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */; }; 0116A4E5228B19640094F3ED /* RadioButtonModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0116A4E4228B19640094F3ED /* RadioButtonModel.swift */; }; + 012CA98923849699003F810F /* SeperatorModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012CA98823849699003F810F /* SeperatorModel.swift */; }; + 012CA99A2384A687003F810F /* MFTextField+ModelExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012CA9992384A687003F810F /* MFTextField+ModelExtension.swift */; }; + 012CA99C23859FDC003F810F /* ViewConstrainingView+ModelExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012CA99B23859FDC003F810F /* ViewConstrainingView+ModelExtension.swift */; }; + 012CA99E2385A2D3003F810F /* MFView+ModelExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012CA99D2385A2D3003F810F /* MFView+ModelExtension.swift */; }; + 012CA9BE2385C692003F810F /* ConstrainingMoleculeProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012CA9BD2385C692003F810F /* ConstrainingMoleculeProtocol.swift */; }; 01509D8F2327EC6F00EF99AA /* MoleculeTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01509D8E2327EC6F00EF99AA /* MoleculeTableViewCell.swift */; }; 01509D912327ECE600EF99AA /* CornerLabels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01509D902327ECE600EF99AA /* CornerLabels.swift */; }; 01509D932327ECFB00EF99AA /* ProgressBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01509D922327ECFB00EF99AA /* ProgressBar.swift */; }; @@ -25,7 +30,7 @@ 017BEB48236230DB0024EF95 /* MoleculeViewProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB47236230DB0024EF95 /* MoleculeViewProtocol.swift */; }; 017BEB4A236235BA0024EF95 /* ModelMoleculeViewProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB49236235BA0024EF95 /* ModelMoleculeViewProtocol.swift */; }; 017BEB7B236763000024EF95 /* LineModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB7A236763000024EF95 /* LineModel.swift */; }; - 017BEB7F23676E870024EF95 /* MVMCoreUIMoleculeMappingObject+ModelMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB7E23676E870024EF95 /* MVMCoreUIMoleculeMappingObject+ModelMapping.swift */; }; + 017BEB7F23676E870024EF95 /* MoleculeObjectMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB7E23676E870024EF95 /* MoleculeObjectMapping.swift */; }; 0198F79F225679880066C936 /* FormValidationProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0198F79E225679870066C936 /* FormValidationProtocol.swift */; }; 0198F7A62256A80B0066C936 /* MFRadioButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 0198F7A02256A80A0066C936 /* MFRadioButton.h */; settings = {ATTRIBUTES = (Public, ); }; }; 0198F7A82256A80B0066C936 /* MFRadioButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 0198F7A22256A80A0066C936 /* MFRadioButton.m */; }; @@ -227,6 +232,11 @@ 0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FormValidator+TextFields.swift"; sourceTree = ""; }; 0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FormValidator+FormParams.swift"; sourceTree = ""; }; 0116A4E4228B19640094F3ED /* RadioButtonModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioButtonModel.swift; sourceTree = ""; }; + 012CA98823849699003F810F /* SeperatorModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeperatorModel.swift; sourceTree = ""; }; + 012CA9992384A687003F810F /* MFTextField+ModelExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MFTextField+ModelExtension.swift"; sourceTree = ""; }; + 012CA99B23859FDC003F810F /* ViewConstrainingView+ModelExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ViewConstrainingView+ModelExtension.swift"; sourceTree = ""; }; + 012CA99D2385A2D3003F810F /* MFView+ModelExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MFView+ModelExtension.swift"; sourceTree = ""; }; + 012CA9BD2385C692003F810F /* ConstrainingMoleculeProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstrainingMoleculeProtocol.swift; sourceTree = ""; }; 01509D8E2327EC6F00EF99AA /* MoleculeTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MoleculeTableViewCell.swift; sourceTree = ""; }; 01509D902327ECE600EF99AA /* CornerLabels.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CornerLabels.swift; sourceTree = ""; }; 01509D922327ECFB00EF99AA /* ProgressBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProgressBar.swift; sourceTree = ""; }; @@ -240,7 +250,7 @@ 017BEB47236230DB0024EF95 /* MoleculeViewProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeViewProtocol.swift; sourceTree = ""; }; 017BEB49236235BA0024EF95 /* ModelMoleculeViewProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelMoleculeViewProtocol.swift; sourceTree = ""; }; 017BEB7A236763000024EF95 /* LineModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LineModel.swift; sourceTree = ""; }; - 017BEB7E23676E870024EF95 /* MVMCoreUIMoleculeMappingObject+ModelMapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreUIMoleculeMappingObject+ModelMapping.swift"; sourceTree = ""; }; + 017BEB7E23676E870024EF95 /* MoleculeObjectMapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeObjectMapping.swift; sourceTree = ""; }; 0198F79E225679870066C936 /* FormValidationProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormValidationProtocol.swift; sourceTree = ""; }; 0198F7A02256A80A0066C936 /* MFRadioButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MFRadioButton.h; sourceTree = ""; }; 0198F7A22256A80A0066C936 /* MFRadioButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MFRadioButton.m; sourceTree = ""; }; @@ -457,6 +467,7 @@ children = ( 017BEB392360EEB40024EF95 /* PageModel.swift */, 01EB3683236097C0006832FA /* MoleculeProtocol.swift */, + 012CA9BD2385C692003F810F /* ConstrainingMoleculeProtocol.swift */, 946EE1B5237B663A0036751F /* Extensions */, 01EB368723609801006832FA /* Molecules */, ); @@ -477,6 +488,7 @@ 01EB368723609801006832FA /* Molecules */ = { isa = PBXGroup; children = ( + 012CA98823849699003F810F /* SeperatorModel.swift */, 01EB368823609801006832FA /* LabelModel.swift */, 01EB368923609801006832FA /* ListItemModel.swift */, 01EB368A23609801006832FA /* MoleculeStackItemModel.swift */, @@ -798,10 +810,12 @@ DB06250A2293456500B72DD3 /* LeftRightLabelView.swift */, D29DF17E21E69E2E003B2FB9 /* MFView.h */, D29DF17F21E69E2E003B2FB9 /* MFView.m */, + 012CA99D2385A2D3003F810F /* MFView+ModelExtension.swift */, D29DF31E21ED0CBA003B2FB9 /* LabelView.h */, D29DF31F21ED0CBA003B2FB9 /* LabelView.m */, D29DF28721E7AC2B003B2FB9 /* ViewConstrainingView.h */, D29DF28821E7AC2B003B2FB9 /* ViewConstrainingView.m */, + 012CA99B23859FDC003F810F /* ViewConstrainingView+ModelExtension.swift */, D282AAB9224131D100C46919 /* MFTransparentGIFView.swift */, D282AAB3223FDDAE00C46919 /* MFLoadImageView.swift */, D29DF2AD21E7B3A4003B2FB9 /* MFTextView.h */, @@ -839,6 +853,7 @@ children = ( D29DF24C21E6A177003B2FB9 /* MFTextField.h */, D29DF24221E6A176003B2FB9 /* MFTextField.m */, + 012CA9992384A687003F810F /* MFTextField+ModelExtension.swift */, D29DF24421E6A176003B2FB9 /* MFTextField.xib */, D29DF24B21E6A177003B2FB9 /* MFTextFieldSubclassExtension.h */, D29DF24721E6A176003B2FB9 /* MFMdnTextField.h */, @@ -888,7 +903,7 @@ D2A514562211C53C00345BFB /* MVMCoreUIMoleculeMappingObject.h */, D2A514572211C53C00345BFB /* MVMCoreUIMoleculeMappingObject.m */, 017BEB432362192F0024EF95 /* MVMCoreUIMoleculeMappingObject+ModelExtension.swift */, - 017BEB7E23676E870024EF95 /* MVMCoreUIMoleculeMappingObject+ModelMapping.swift */, + 017BEB7E23676E870024EF95 /* MoleculeObjectMapping.swift */, ); path = OtherHandlers; sourceTree = ""; @@ -1123,7 +1138,9 @@ D29DF32121ED0CBA003B2FB9 /* LabelView.m in Sources */, DBC4391822442197001AB423 /* CaretView.swift in Sources */, D29770F221F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.m in Sources */, + 012CA9BE2385C692003F810F /* ConstrainingMoleculeProtocol.swift in Sources */, D29B771022C281F400D6ACE0 /* ModuleMolecule.swift in Sources */, + 012CA98923849699003F810F /* SeperatorModel.swift in Sources */, DBC4391922442197001AB423 /* DashLine.swift in Sources */, 0A7BAD74232A8DC700FB8E22 /* HeadlineBodyButton.swift in Sources */, D29DF29621E7ADB8003B2FB9 /* StackableViewController.m in Sources */, @@ -1161,6 +1178,7 @@ D29DF12B21E6851E003B2FB9 /* MVMCoreUITopAlertExpandableView.m in Sources */, D2755D7B23689C7500485468 /* TableViewCell.swift in Sources */, 01EB369223609801006832FA /* MoleculeStackModel.swift in Sources */, + 012CA99E2385A2D3003F810F /* MFView+ModelExtension.swift in Sources */, D29DF25421E6A177003B2FB9 /* MFMdnTextField.m in Sources */, D282AABA224131D100C46919 /* MFTransparentGIFView.swift in Sources */, D2A514672213885800345BFB /* StandardHeaderView.swift in Sources */, @@ -1188,7 +1206,7 @@ D29DF18321E69E54003B2FB9 /* SeparatorView.m in Sources */, D29DF17A21E69E1F003B2FB9 /* MFCustomButton.m in Sources */, 017BEB7B236763000024EF95 /* LineModel.swift in Sources */, - 017BEB7F23676E870024EF95 /* MVMCoreUIMoleculeMappingObject+ModelMapping.swift in Sources */, + 017BEB7F23676E870024EF95 /* MoleculeObjectMapping.swift in Sources */, D274CA332236A78900B01B62 /* StandardFooterView.swift in Sources */, D29DF2BF21E7BEA4003B2FB9 /* MVMCoreUITabBarPageControlViewController.m in Sources */, D29DF28321E7AB24003B2FB9 /* MVMCoreUICommonViewsUtility.m in Sources */, @@ -1211,6 +1229,7 @@ D29DF28C21E7AC2B003B2FB9 /* ViewConstrainingView.m in Sources */, D29DF17B21E69E1F003B2FB9 /* PrimaryButton.m in Sources */, 017BEB4A236235BA0024EF95 /* ModelMoleculeViewProtocol.swift in Sources */, + 012CA99A2384A687003F810F /* MFTextField+ModelExtension.swift in Sources */, 01EB3684236097C0006832FA /* MoleculeProtocol.swift in Sources */, D27CD4102339057800C1DC07 /* EyebrowHeadlineBodyLink.swift in Sources */, D29DF11D21E684A9003B2FB9 /* MVMCoreUISplitViewController.m in Sources */, @@ -1235,6 +1254,7 @@ D29DF13221E6851E003B2FB9 /* MVMCoreUITopAlertBaseView.m in Sources */, D29DF29C21E7ADB9003B2FB9 /* MFProgrammaticTableViewController.m in Sources */, 0105618E224BBE7700E1557D /* FormValidator+TextFields.swift in Sources */, + 012CA99C23859FDC003F810F /* ViewConstrainingView+ModelExtension.swift in Sources */, 0A1214A022C11A18007C7030 /* ActionDetailWithImage.swift in Sources */, 01EB369123609801006832FA /* MoleculeStackItemModel.swift in Sources */, D29DF2BE21E7BEA4003B2FB9 /* TopTabbar.m in Sources */, diff --git a/MVMCoreUI/Atoms/TextFields/MFTextField+ModelExtension.swift b/MVMCoreUI/Atoms/TextFields/MFTextField+ModelExtension.swift new file mode 100644 index 00000000..81f00282 --- /dev/null +++ b/MVMCoreUI/Atoms/TextFields/MFTextField+ModelExtension.swift @@ -0,0 +1,77 @@ +// +// MFTextField+ModelExtension.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 11/19/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +enum TextType: String { + case dropDown = "dropDown" + case password = "password" + case number = "number" + case email = "email" +} +extension MFTextField: ModelMoleculeViewProtocol { + // + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + //TODO: Need to create setWithModel in ViewConstraining View + #warning("This below call should be repaced with super.setWithModel once we get rid of ViewConstrainingView.") + //TODO: This below call should be repaced with super.setWithModel once we get rid of ViewConstrainingView. + setUpWithModel(model, delegateObject, additionalData) + + guard let textFieldModel = model as? TextFieldModel, + let delegateObject = delegateObject else { + return + } + + if let delegate = delegateObject.formValidationProtocol { + let formValidator = FormValidator.getFormValidatorFor(delegate: delegate) + mfTextFieldDelegate = formValidator + uiTextFieldDelegate = delegateObject.uiTextFieldDelegate + if let textField = textField { + MVMCoreUICommonViewsUtility.addDismissToolbar(textField, delegate: uiTextFieldDelegate) + } + } + + formText = textFieldModel.label as NSString? + text = textFieldModel.value as NSString? + enable(textFieldModel.disabled) + errMessage = textFieldModel.errorMsg + fieldKey = textFieldModel.fieldKey + groupName = textFieldModel.groupName + + + switch textFieldModel.type { + case TextType.dropDown.rawValue: + dropDownCarrotLabel?.isHidden = true + hasDropDown = true + break + case TextType.password.rawValue: + textField?.isSecureTextEntry = true + break + case TextType.number.rawValue: + textField?.keyboardType = .numberPad + break + case TextType.email.rawValue: + textField?.keyboardType = .emailAddress + break + default: + print("default") + } + + if let regex = textFieldModel.regex { + validationBlock = {(enteredValue: String?) -> Bool in + if let enteredValue = enteredValue { + return MVMCoreUIUtility.validate(enteredValue, withRegularExpression: regex) + } + return true + } + } else { + setDefaultValidationBlock() + } + } +} + diff --git a/MVMCoreUI/Atoms/Views/GraphView.swift b/MVMCoreUI/Atoms/Views/GraphView.swift index ebd074a0..e919e445 100644 --- a/MVMCoreUI/Atoms/Views/GraphView.swift +++ b/MVMCoreUI/Atoms/Views/GraphView.swift @@ -125,7 +125,11 @@ public struct GraphObject { heightConstraint?.isActive = true widthAnchor.constraint(equalTo: heightAnchor).isActive = true } - + + override open func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + super.setWithModel(model, delegateObject, additionalData) + } + override open func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) let object = GraphObject(json) diff --git a/MVMCoreUI/Atoms/Views/MFView+ModelExtension.swift b/MVMCoreUI/Atoms/Views/MFView+ModelExtension.swift new file mode 100644 index 00000000..44973370 --- /dev/null +++ b/MVMCoreUI/Atoms/Views/MFView+ModelExtension.swift @@ -0,0 +1,23 @@ +// +// MFView+ModelExtension.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 11/20/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + +extension MFView { + public func setUpDefaultWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String: AnyHashable]?) { + self.model = model + if let backgroundColorString = model?.backgroundColor { + backgroundColor = UIColor.mfGet(for: backgroundColorString) + } + } +} +extension ModelMoleculeViewProtocol where Self: MFView { + func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String: AnyHashable]?) { + setUpDefaultWithModel(model, delegateObject, additionalData) + } +} diff --git a/MVMCoreUI/Atoms/Views/MFView.h b/MVMCoreUI/Atoms/Views/MFView.h index 62683433..dd8e01a8 100644 --- a/MVMCoreUI/Atoms/Views/MFView.h +++ b/MVMCoreUI/Atoms/Views/MFView.h @@ -14,6 +14,7 @@ @interface MFView : UIView @property (nullable, nonatomic, strong) NSDictionary *json; +@property (nullable, nonatomic, strong) id model; // Called in the initialization functions. Can setup ui here. - (void)setupView; diff --git a/MVMCoreUI/Atoms/Views/ViewConstrainingView+ModelExtension.swift b/MVMCoreUI/Atoms/Views/ViewConstrainingView+ModelExtension.swift new file mode 100644 index 00000000..1e4cd849 --- /dev/null +++ b/MVMCoreUI/Atoms/Views/ViewConstrainingView+ModelExtension.swift @@ -0,0 +1,88 @@ +// +// ViewConstrainingView+ModelExtension.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 11/20/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + + +extension ViewConstrainingView { + public func setUpWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String: AnyHashable]?) { + if self.constrainedView == nil { + setUpDefaultWithModel(model, delegateObject, additionalData) + } + + if shouldSetupMoleculeFromJSON, + let moleculeObject = (model as? ConstrainingMoleculeProtocol)?.molecule { + if molecule != nil { + (molecule as? ModelMoleculeViewProtocol)?.setWithModel(moleculeObject, delegateObject, additionalData) + } else { + if let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(moleculeObject, delegateObject, true) { + addMolecule(molecule) + self.molecule = molecule + setMoleculeAccessibility() + } + } + } else { + (molecule as? ModelMoleculeViewProtocol)?.setWithModel(model, delegateObject, additionalData) + } + + if let useHorizontalMargins = model?.useHorizontalMargins { + updateViewHorizontalDefaults = useHorizontalMargins + } + if let useVerticalMargins = model?.useVerticalMargins { + updateViewVerticalDefaults = useVerticalMargins + } + + if let horizontalAlignment = model?.horizontalAlignment { + alignHorizontal(ViewConstrainingView.getAlignmentFor(horizontalAlignment, defaultAlignment: .fill)) + } + if let verticalAlignment = model?.verticalAlignment { + alignVertical(ViewConstrainingView.getAlignmentFor(verticalAlignment, defaultAlignment: .fill)) + } + + #warning("work on the below") + // let copyBackgroundColor = self.copyBackgroundColor?() + // if copyBackgroundColor { + // + // } + } +} + +extension ModelMoleculeViewProtocol where Self: ViewConstrainingView { + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String: AnyHashable]?) { + setUpWithModel(model, delegateObject, additionalData) + } +} + +/* +- (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { + // Only treated as a container if we are constraining a molecule. + + 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/Atoms/Views/ViewConstrainingView.h b/MVMCoreUI/Atoms/Views/ViewConstrainingView.h index c10768b0..30f5a552 100644 --- a/MVMCoreUI/Atoms/Views/ViewConstrainingView.h +++ b/MVMCoreUI/Atoms/Views/ViewConstrainingView.h @@ -30,6 +30,8 @@ @property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *topPinLow; @property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *bottomPinLow; +@property (weak, nullable, nonatomic) UIView *constrainedView; + /// In updateView, will set horizontal padding to default. @property (nonatomic) BOOL updateViewHorizontalDefaults; @property (nonatomic) BOOL updateViewVerticalDefaults; @@ -89,6 +91,9 @@ - (void)alignBottom; - (void)alignFillVertical; +- (void)alignHorizontal:(UIStackViewAlignment)alignment; +- (void)alignVertical:(UIStackViewAlignment)alignment; + /// Convenience function for getting the alignment from a map. + (UIStackViewAlignment)getAlignmentForString:(nullable NSString *)alignmentString defaultAlignment:(UIStackViewAlignment)defaultAlignment; diff --git a/MVMCoreUI/Atoms/Views/ViewConstrainingView.m b/MVMCoreUI/Atoms/Views/ViewConstrainingView.m index 57e54983..4983020e 100644 --- a/MVMCoreUI/Atoms/Views/ViewConstrainingView.m +++ b/MVMCoreUI/Atoms/Views/ViewConstrainingView.m @@ -18,7 +18,6 @@ #import "MVMCoreUIViewConstrainingProtocol.h" @interface ViewConstrainingView () -@property (weak, nullable, nonatomic) UIView *constrainedView; @end @implementation ViewConstrainingView diff --git a/MVMCoreUI/BaseClasses/View.swift b/MVMCoreUI/BaseClasses/View.swift index bc6e7634..de76f739 100644 --- a/MVMCoreUI/BaseClasses/View.swift +++ b/MVMCoreUI/BaseClasses/View.swift @@ -8,8 +8,9 @@ import UIKit -@objcMembers open class View: UIView { +@objcMembers open class View: UIView, ModelMoleculeViewProtocol { open var json: [AnyHashable: Any]? + open var model: MoleculeProtocol? private var initialSetupPerformed = false @@ -34,6 +35,13 @@ import UIKit setupView() } } + + open func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + self.model = model + if let backgroundColorString = model?.backgroundColor { + backgroundColor = UIColor.mfGet(for: backgroundColorString) + } + } } extension View: MVMCoreViewProtocol { @@ -59,3 +67,4 @@ extension View: MVMCoreUIMoleculeViewProtocol { backgroundColor = .clear } } + diff --git a/MVMCoreUI/Models/ConstrainingMoleculeProtocol.swift b/MVMCoreUI/Models/ConstrainingMoleculeProtocol.swift new file mode 100644 index 00000000..91d4a566 --- /dev/null +++ b/MVMCoreUI/Models/ConstrainingMoleculeProtocol.swift @@ -0,0 +1,19 @@ +// +// ConstrainingMoleculeProtocol.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 11/20/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + +public protocol ConstrainingMoleculeProtocol: MoleculeProtocol { + var molecule: MoleculeProtocol? {get} +} + +extension ConstrainingMoleculeProtocol { + public var molecule: MoleculeProtocol? { + get { return nil } + } +} diff --git a/MVMCoreUI/Models/MoleculeProtocol.swift b/MVMCoreUI/Models/MoleculeProtocol.swift index 0bb23cdf..2ddc4061 100644 --- a/MVMCoreUI/Models/MoleculeProtocol.swift +++ b/MVMCoreUI/Models/MoleculeProtocol.swift @@ -2,7 +2,14 @@ import Foundation public protocol MoleculeProtocol: Model { var moleculeName: String? {get} + var backgroundColor: String? {get} var dictionary: [AnyHashable: Any]? {get} + var molecule: MoleculeProtocol? {get} + + var useHorizontalMargins: Bool? {get} + var useVerticalMargins: Bool? {get} + var horizontalAlignment: String? {get} + var verticalAlignment: String? {get} } extension MoleculeProtocol { @@ -10,6 +17,30 @@ extension MoleculeProtocol { get { return Self.identifier } } + public var molecule: MoleculeProtocol? { + get { return nil } + } + + public var backgroundColor: String? { + get { return toJSON()?["backgroundColor"] as? String } + } + + public var useHorizontalMargins: Bool? { + get { return toJSON()?["useHorizontalMargins"] as? Bool } + } + + public var useVerticalMargins: Bool? { + get { return toJSON()?["useVerticalMargins"] as? Bool } + } + + public var horizontalAlignment: String? { + get { return toJSON()?["horizontalAlignment"] as? String } + } + + public var verticalAlignment: String? { + get { return toJSON()?["verticalAlignment"] as? String } + } + public var dictionary: [AnyHashable: Any]? { return toJSON() } diff --git a/MVMCoreUI/Models/Molecules/HeaderModel.swift b/MVMCoreUI/Models/Molecules/HeaderModel.swift index 4cbc1c82..0dca783c 100644 --- a/MVMCoreUI/Models/Molecules/HeaderModel.swift +++ b/MVMCoreUI/Models/Molecules/HeaderModel.swift @@ -8,9 +8,10 @@ import Foundation -@objcMembers public class HeaderModel: MoleculeProtocol { +@objcMembers public class HeaderModel: ConstrainingMoleculeProtocol { public static var identifier: String = "header" public var moleculeName: String? + public var backgroundColor: String? public var molecule: MoleculeProtocol? public var seperator: MoleculeProtocol? diff --git a/MVMCoreUI/Models/Molecules/LabelModel.swift b/MVMCoreUI/Models/Molecules/LabelModel.swift index e5de1ccf..0886524a 100644 --- a/MVMCoreUI/Models/Molecules/LabelModel.swift +++ b/MVMCoreUI/Models/Molecules/LabelModel.swift @@ -11,6 +11,5 @@ import Foundation @objcMembers public class LabelModel: MoleculeProtocol { public static var identifier: String = "label" - public var moleculeName: String? public var text: String? } diff --git a/MVMCoreUI/Models/Molecules/SeperatorModel.swift b/MVMCoreUI/Models/Molecules/SeperatorModel.swift new file mode 100644 index 00000000..705f904c --- /dev/null +++ b/MVMCoreUI/Models/Molecules/SeperatorModel.swift @@ -0,0 +1,14 @@ +// +// SeperatorModel.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 11/19/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +class SeperatorModel: MoleculeProtocol { + public static var identifier: String = "line" + public var type: String? +} diff --git a/MVMCoreUI/Models/Molecules/TextFieldModel.swift b/MVMCoreUI/Models/Molecules/TextFieldModel.swift index 74e7cd3e..77454895 100644 --- a/MVMCoreUI/Models/Molecules/TextFieldModel.swift +++ b/MVMCoreUI/Models/Molecules/TextFieldModel.swift @@ -12,9 +12,11 @@ import UIKit public static var identifier: String = "textField" public var editable = true + public var disabled = false public var errorMsg: String? public var label: String? public var type: String? + public var value: String? public var regex: String? public var required: Bool? diff --git a/MVMCoreUI/Molecules/StandardHeaderView.swift b/MVMCoreUI/Molecules/StandardHeaderView.swift index 9b9a5ff2..100173fc 100644 --- a/MVMCoreUI/Molecules/StandardHeaderView.swift +++ b/MVMCoreUI/Molecules/StandardHeaderView.swift @@ -57,7 +57,10 @@ public class StandardHeaderView: ViewConstrainingView, ModelMoleculeViewProtocol open func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { //TODO: Need to create setWithModel in ViewConstraining View - super.setWithJSON(model?.toJSON(), delegateObject: delegateObject, additionalData: additionalData) + + #warning("This below call should be repaced with super.setWithModel once we get rid of ViewConstrainingView.") + //TODO: This below call should be repaced with super.setWithModel once we get rid of ViewConstrainingView. + setUpWithModel(model, delegateObject, additionalData) // This molecule will by default handle margins. (molecule as? MVMCoreUIViewConstrainingProtocol)?.shouldSetHorizontalMargins?(false) diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index 388ee47e..86f69f86 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -79,7 +79,7 @@ - (instancetype)init { if (self = [super init]) { - [MVMCoreUIMoleculeMappingObject registerObjects]; + [MoleculeObjectMapping registerObjects]; } return self; } diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelMapping.swift b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift similarity index 80% rename from MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelMapping.swift rename to MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift index 67d3df02..84e0932c 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelMapping.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift @@ -8,8 +8,8 @@ import Foundation -@objc public extension MVMCoreUIMoleculeMappingObject { - @objc static func registerObjects() { +@objcMembers public class MoleculeObjectMapping: NSObject { + public static func registerObjects() { ModelRegistry.register(LabelModel.self) ModelRegistry.register(HeaderModel.self) ModelRegistry.register(HeadlineBodyModel.self) @@ -18,5 +18,6 @@ import Foundation ModelRegistry.register(ListItemModel.self) ModelRegistry.register(TextFieldModel.self) ModelRegistry.register(LineModel.self) + ModelRegistry.register(SeperatorModel.self) } }