From 5446fb0785a7b9b570768cb03d0343fc30c6b200 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 26 Nov 2019 19:20:38 -0500 Subject: [PATCH 01/51] WIP --- MVMCoreUI.xcodeproj/project.pbxproj | 58 ++++++++- MVMCoreUI/Atoms/Views/ViewConstrainingView.m | 40 ------- .../MFViewController+Model.swift | 25 ++-- .../CollectionCellMoleculeProtocol.swift | 14 +++ MVMCoreUI/Models/Extensions/ModelHelper.swift | 2 +- .../Models/Molecules/CarouselItemModel.swift | 42 +++++++ .../Models/Molecules/CarouselModel.swift | 74 ++++++++++++ .../Models/Molecules/ListItemModel.swift | 20 +++- .../Molecules/ModuleMoleculeModel.swift | 14 +++ .../Molecules/MoleculeStackItemModel.swift | 33 ++++- .../Models/Molecules/MoleculeStackModel.swift | 7 +- .../Models/Molecules/SeperatorModel.swift | 2 +- MVMCoreUI/Models/PagingMoleculeProtocol.swift | 13 ++ .../Template/ListPageTemplateModel.swift | 24 ++++ .../Models/{ => Template}/PageModel.swift | 0 .../StackCenteredPageTemplateModel.swift | 21 ++++ .../Template/StackPageTemplateModel.swift | 24 ++++ .../Template/TemplateModelProtocol.swift | 22 ++++ .../ThreeLayerPageTemplateModel.swift | 24 ++++ MVMCoreUI/Models/TemplateProtocol.swift | 29 +++++ .../Items/MoleculeCollectionViewCell.swift | 40 ++++--- .../Items/MoleculeTableViewCell.swift | 33 +++-- MVMCoreUI/Molecules/Items/TableViewCell.swift | 73 ++++++----- .../Molecules/Items/TabsTableViewCell.swift | 19 +-- .../Molecules/MVMCoreUIMoleculeViewProtocol.h | 9 +- .../Molecules/ModelMoleculeViewProtocol.swift | 11 ++ MVMCoreUI/Molecules/ModuleMolecule.swift | 88 +++++++++----- MVMCoreUI/Molecules/Scroller.swift | 32 ++++- MVMCoreUI/Molecules/StandardHeaderView.swift | 1 - MVMCoreUI/Organisms/Carousel.swift | 101 +++++++++------- MVMCoreUI/Organisms/MoleculeStackView.swift | 77 +++++++----- ...MoleculeMappingObject+ModelExtension.swift | 10 +- .../MVMCoreUIMoleculeMappingObject.h | 8 +- .../ModelMoleculeDelegateProtocol.swift | 14 +++ .../Templates/MoleculeListTemplate.swift | 113 ++++++++++-------- .../Templates/MoleculeStackTemplate.swift | 40 +++++-- MVMCoreUI/Templates/ThreeLayerTemplate.swift | 36 ++++-- 37 files changed, 866 insertions(+), 327 deletions(-) create mode 100644 MVMCoreUI/Models/CollectionCellMoleculeProtocol.swift create mode 100644 MVMCoreUI/Models/Molecules/CarouselItemModel.swift create mode 100644 MVMCoreUI/Models/Molecules/CarouselModel.swift create mode 100644 MVMCoreUI/Models/Molecules/ModuleMoleculeModel.swift create mode 100644 MVMCoreUI/Models/PagingMoleculeProtocol.swift create mode 100644 MVMCoreUI/Models/Template/ListPageTemplateModel.swift rename MVMCoreUI/Models/{ => Template}/PageModel.swift (100%) create mode 100644 MVMCoreUI/Models/Template/StackCenteredPageTemplateModel.swift create mode 100644 MVMCoreUI/Models/Template/StackPageTemplateModel.swift create mode 100644 MVMCoreUI/Models/Template/TemplateModelProtocol.swift create mode 100644 MVMCoreUI/Models/Template/ThreeLayerPageTemplateModel.swift create mode 100644 MVMCoreUI/Models/TemplateProtocol.swift create mode 100644 MVMCoreUI/OtherHandlers/ModelMoleculeDelegateProtocol.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index d8399580..ffa63ba7 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -12,11 +12,23 @@ 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 */; }; + 012A889C23889E8400FE3DA1 /* TemplateModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A889B23889E8400FE3DA1 /* TemplateModelProtocol.swift */; }; + 012A88AD238C418100FE3DA1 /* TemplateProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88AC238C418100FE3DA1 /* TemplateProtocol.swift */; }; + 012A88AF238C626E00FE3DA1 /* CarouselModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88AE238C626E00FE3DA1 /* CarouselModel.swift */; }; + 012A88B1238C880100FE3DA1 /* PagingMoleculeProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88B0238C880100FE3DA1 /* PagingMoleculeProtocol.swift */; }; + 012A88C2238D7BCA00FE3DA1 /* CarouselItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88C1238D7BCA00FE3DA1 /* CarouselItemModel.swift */; }; + 012A88C4238D86E600FE3DA1 /* CollectionCellMoleculeProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88C3238D86E600FE3DA1 /* CollectionCellMoleculeProtocol.swift */; }; + 012A88C6238DA34000FE3DA1 /* ModuleMoleculeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88C5238DA34000FE3DA1 /* ModuleMoleculeModel.swift */; }; + 012A88C8238DB02000FE3DA1 /* ModelMoleculeDelegateProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88C7238DB02000FE3DA1 /* ModelMoleculeDelegateProtocol.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 */; }; + 012CA9DE2388723E003F810F /* ListPageTemplateModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012CA9DD2388723E003F810F /* ListPageTemplateModel.swift */; }; + 012CA9E023888AC8003F810F /* StackPageTemplateModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012CA9DF23888AC8003F810F /* StackPageTemplateModel.swift */; }; + 012CA9E223888AED003F810F /* StackCenteredPageTemplateModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012CA9E123888AED003F810F /* StackCenteredPageTemplateModel.swift */; }; + 012CA9E423888B1B003F810F /* ThreeLayerPageTemplateModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012CA9E323888B1B003F810F /* ThreeLayerPageTemplateModel.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 */; }; @@ -232,11 +244,23 @@ 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 = ""; }; + 012A889B23889E8400FE3DA1 /* TemplateModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemplateModelProtocol.swift; sourceTree = ""; }; + 012A88AC238C418100FE3DA1 /* TemplateProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemplateProtocol.swift; sourceTree = ""; }; + 012A88AE238C626E00FE3DA1 /* CarouselModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CarouselModel.swift; sourceTree = ""; }; + 012A88B0238C880100FE3DA1 /* PagingMoleculeProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PagingMoleculeProtocol.swift; sourceTree = ""; }; + 012A88C1238D7BCA00FE3DA1 /* CarouselItemModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CarouselItemModel.swift; sourceTree = ""; }; + 012A88C3238D86E600FE3DA1 /* CollectionCellMoleculeProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionCellMoleculeProtocol.swift; sourceTree = ""; }; + 012A88C5238DA34000FE3DA1 /* ModuleMoleculeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModuleMoleculeModel.swift; sourceTree = ""; }; + 012A88C7238DB02000FE3DA1 /* ModelMoleculeDelegateProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelMoleculeDelegateProtocol.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 = ""; }; + 012CA9DD2388723E003F810F /* ListPageTemplateModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListPageTemplateModel.swift; sourceTree = ""; }; + 012CA9DF23888AC8003F810F /* StackPageTemplateModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StackPageTemplateModel.swift; sourceTree = ""; }; + 012CA9E123888AED003F810F /* StackCenteredPageTemplateModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StackCenteredPageTemplateModel.swift; sourceTree = ""; }; + 012CA9E323888B1B003F810F /* ThreeLayerPageTemplateModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreeLayerPageTemplateModel.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 = ""; }; @@ -462,11 +486,27 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 012A889A238898C600FE3DA1 /* Template */ = { + isa = PBXGroup; + children = ( + 012A889B23889E8400FE3DA1 /* TemplateModelProtocol.swift */, + 017BEB392360EEB40024EF95 /* PageModel.swift */, + 012CA9DD2388723E003F810F /* ListPageTemplateModel.swift */, + 012CA9DF23888AC8003F810F /* StackPageTemplateModel.swift */, + 012CA9E123888AED003F810F /* StackCenteredPageTemplateModel.swift */, + 012CA9E323888B1B003F810F /* ThreeLayerPageTemplateModel.swift */, + ); + path = Template; + sourceTree = ""; + }; 01509D96232803B200EF99AA /* Models */ = { isa = PBXGroup; children = ( - 017BEB392360EEB40024EF95 /* PageModel.swift */, + 012A88AC238C418100FE3DA1 /* TemplateProtocol.swift */, 01EB3683236097C0006832FA /* MoleculeProtocol.swift */, + 012A88B0238C880100FE3DA1 /* PagingMoleculeProtocol.swift */, + 012A88C3238D86E600FE3DA1 /* CollectionCellMoleculeProtocol.swift */, + 012A889A238898C600FE3DA1 /* Template */, 012CA9BD2385C692003F810F /* ConstrainingMoleculeProtocol.swift */, 946EE1B5237B663A0036751F /* Extensions */, 01EB368723609801006832FA /* Molecules */, @@ -498,6 +538,9 @@ 017BEB3F23620A230024EF95 /* TextFieldModel.swift */, 017BEB4123620AD20024EF95 /* FormModelProtocol.swift */, 017BEB7A236763000024EF95 /* LineModel.swift */, + 012A88AE238C626E00FE3DA1 /* CarouselModel.swift */, + 012A88C1238D7BCA00FE3DA1 /* CarouselItemModel.swift */, + 012A88C5238DA34000FE3DA1 /* ModuleMoleculeModel.swift */, ); path = Molecules; sourceTree = ""; @@ -900,6 +943,7 @@ D2C5001721F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m */, D296E14622A597490051EBE7 /* MVMCoreUIViewConstrainingProtocol.h */, D296E1402295EBBA0051EBE7 /* MoleculeDelegateProtocol.h */, + 012A88C7238DB02000FE3DA1 /* ModelMoleculeDelegateProtocol.swift */, D2A514562211C53C00345BFB /* MVMCoreUIMoleculeMappingObject.h */, D2A514572211C53C00345BFB /* MVMCoreUIMoleculeMappingObject.m */, 017BEB432362192F0024EF95 /* MVMCoreUIMoleculeMappingObject+ModelExtension.swift */, @@ -1135,6 +1179,7 @@ buildActionMask = 2147483647; files = ( 943784F5236B77BB006A1E82 /* GraphView.swift in Sources */, + 012CA9E423888B1B003F810F /* ThreeLayerPageTemplateModel.swift in Sources */, D29DF32121ED0CBA003B2FB9 /* LabelView.m in Sources */, DBC4391822442197001AB423 /* CaretView.swift in Sources */, D29770F221F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.m in Sources */, @@ -1157,11 +1202,13 @@ D29DF25321E6A177003B2FB9 /* MFDigitTextField.m in Sources */, D2B18B7F2360913400A9AEDC /* Control.swift in Sources */, D29DF12F21E6851E003B2FB9 /* MVMCoreUITopAlertMainView.m in Sources */, + 012A88C8238DB02000FE3DA1 /* ModelMoleculeDelegateProtocol.swift in Sources */, DBC4392122491730001AB423 /* LabelWithInternalButton.swift in Sources */, D224798C231450C8003FCCF9 /* HeadlineBodySwitch.swift in Sources */, 017BEB442362192F0024EF95 /* MVMCoreUIMoleculeMappingObject+ModelExtension.swift in Sources */, D29DF17C21E69E1F003B2FB9 /* MFTextButton.m in Sources */, D29DF2C521E7BF57003B2FB9 /* MFTabBarSwipeAnimator.m in Sources */, + 012A88AD238C418100FE3DA1 /* TemplateProtocol.swift in Sources */, D29DF2B421E7B76D003B2FB9 /* MFLoadingSpinner.m in Sources */, 01EB369423609801006832FA /* HeadlineBodyModel.swift in Sources */, D2C5001921F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m in Sources */, @@ -1173,6 +1220,7 @@ D2A5145F2211DDC100345BFB /* MoleculeStackView.swift in Sources */, D29DF27621E79E81003B2FB9 /* MVMCoreUILoggingHandler.m in Sources */, D29DF24D21E6A177003B2FB9 /* MFTextField.m in Sources */, + 012A88C4238D86E600FE3DA1 /* CollectionCellMoleculeProtocol.swift in Sources */, 017BEB4023620A230024EF95 /* TextFieldModel.swift in Sources */, D29DF2A221E7AF4E003B2FB9 /* MVMCoreUIUtility.m in Sources */, D29DF12B21E6851E003B2FB9 /* MVMCoreUITopAlertExpandableView.m in Sources */, @@ -1181,6 +1229,8 @@ 012CA99E2385A2D3003F810F /* MFView+ModelExtension.swift in Sources */, D29DF25421E6A177003B2FB9 /* MFMdnTextField.m in Sources */, D282AABA224131D100C46919 /* MFTransparentGIFView.swift in Sources */, + 012A88AF238C626E00FE3DA1 /* CarouselModel.swift in Sources */, + 012CA9E023888AC8003F810F /* StackPageTemplateModel.swift in Sources */, D2A514672213885800345BFB /* StandardHeaderView.swift in Sources */, 01EB369023609801006832FA /* ListItemModel.swift in Sources */, DBEFFA04225A829700230692 /* Label.swift in Sources */, @@ -1198,6 +1248,7 @@ D2D6CD4222E78FAB00D701B8 /* ThreeLayerTemplate.swift in Sources */, 01EB368F23609801006832FA /* LabelModel.swift in Sources */, 0105618F224BBE7700E1557D /* FormValidator+FormParams.swift in Sources */, + 012CA9E223888AED003F810F /* StackCenteredPageTemplateModel.swift in Sources */, 0A7BAFA1232BE61800FB8E22 /* Checkbox.swift in Sources */, D22479962316AF6E003FCCF9 /* HeadlineBodyTextButton.swift in Sources */, D29DF2AE21E7B3A4003B2FB9 /* MFTextView.m in Sources */, @@ -1214,12 +1265,14 @@ D29DF27A21E7A533003B2FB9 /* MVMCoreUISession.m in Sources */, 01DF55E021F8FAA800CC099B /* MFTextFieldListView.swift in Sources */, D2A5146B2214905000345BFB /* ThreeLayerViewController.swift in Sources */, + 012A88B1238C880100FE3DA1 /* PagingMoleculeProtocol.swift in Sources */, D29DF2C921E7BFC6003B2FB9 /* MFSizeObject.m in Sources */, D2A6390522CBCE160052ED1F /* MoleculeCollectionViewCell.swift in Sources */, D2A6390122CBB1820052ED1F /* Carousel.swift in Sources */, D29DF2C721E7BF57003B2FB9 /* MFTabBarInteractor.m in Sources */, D29DF29521E7ADB8003B2FB9 /* ProgrammaticScrollViewController.m in Sources */, D2A638FD22CA98280052ED1F /* HeadlineBody.swift in Sources */, + 012CA9DE2388723E003F810F /* ListPageTemplateModel.swift in Sources */, D29DF16121E69996003B2FB9 /* MFViewController.m in Sources */, D2E1FAE12268E81D00AEFD8C /* MoleculeListTemplate.swift in Sources */, DB06250B2293456500B72DD3 /* LeftRightLabelView.swift in Sources */, @@ -1238,6 +1291,7 @@ D29770C821F7C4AE00B2F0D0 /* TopLabelsView.m in Sources */, 01EB369323609801006832FA /* HeaderModel.swift in Sources */, D2E1FADF2268B8E700AEFD8C /* ThreeLayerTableViewController.swift in Sources */, + 012A88C6238DA34000FE3DA1 /* ModuleMoleculeModel.swift in Sources */, D20A9A5E2243D3E300ADE781 /* TwoButtonView.swift in Sources */, D2B1E3E522F37D6A0065F95C /* ImageHeadlineBody.swift in Sources */, 943784F6236B77BB006A1E82 /* GraphViewAnimationHandler.swift in Sources */, @@ -1246,6 +1300,7 @@ D2A5146122121FBF00345BFB /* MoleculeStackTemplate.swift in Sources */, D29DF11821E6805F003B2FB9 /* NSLayoutConstraint+MFConvenience.m in Sources */, D29DF26C21E6AA0B003B2FB9 /* FLAnimatedImage.m in Sources */, + 012A889C23889E8400FE3DA1 /* TemplateModelProtocol.swift in Sources */, D29770FC21F7C77400B2F0D0 /* MVMCoreUITextFieldView.m in Sources */, D29DF25121E6A177003B2FB9 /* MFDigitTextBox.m in Sources */, DBC4391B224421A0001AB423 /* CaretButton.swift in Sources */, @@ -1260,6 +1315,7 @@ D29DF2BE21E7BEA4003B2FB9 /* TopTabbar.m in Sources */, D2A514632213643100345BFB /* MoleculeStackCenteredTemplate.swift in Sources */, D29DF32421ED0DA2003B2FB9 /* TextButtonView.m in Sources */, + 012A88C2238D7BCA00FE3DA1 /* CarouselItemModel.swift in Sources */, D29DF29E21E7AE3B003B2FB9 /* MFStyler.m in Sources */, D2A514592211C53C00345BFB /* MVMCoreUIMoleculeMappingObject.m in Sources */, 01509D8F2327EC6F00EF99AA /* MoleculeTableViewCell.swift in Sources */, diff --git a/MVMCoreUI/Atoms/Views/ViewConstrainingView.m b/MVMCoreUI/Atoms/Views/ViewConstrainingView.m index 4983020e..29f2c9be 100644 --- a/MVMCoreUI/Atoms/Views/ViewConstrainingView.m +++ b/MVMCoreUI/Atoms/Views/ViewConstrainingView.m @@ -352,46 +352,6 @@ } - (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]; - } - [self.molecule 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/BaseControllers/MFViewController+Model.swift b/MVMCoreUI/BaseControllers/MFViewController+Model.swift index 924ce4c7..159a3260 100644 --- a/MVMCoreUI/BaseControllers/MFViewController+Model.swift +++ b/MVMCoreUI/BaseControllers/MFViewController+Model.swift @@ -11,16 +11,19 @@ import Foundation public extension MFViewController { @objc func parsePageJSON() { - guard let pageJSON = loadObject?.pageJSON as? [String: AnyHashable] else { - return - } - do { - let pageData = try JSONSerialization.data(withJSONObject: pageJSON) - let decoder = JSONDecoder() - let pageModel = try decoder.decode(PageModel.self, from: pageData) - self.pageModel = pageModel - } catch { - MVMCoreUILoggingHandler.logDebugMessage(withDelegate: "error: \(error)") - } + + (self as? TemplateProtocol)?.parseTemplateJSON() +// guard let pageJSON = loadObject?.pageJSON as? [String: AnyHashable] else { +// return +// } +// do { +// let pageData = try JSONSerialization.data(withJSONObject: pageJSON) +// let decoder = JSONDecoder() +// +// let pageModel = try decoder.decode(PageModel.self, from: pageData) +// self.pageModel = pageModel +// } catch { +// MVMCoreUILoggingHandler.logDebugMessage(withDelegate: "error: \(error)") +// } } } diff --git a/MVMCoreUI/Models/CollectionCellMoleculeProtocol.swift b/MVMCoreUI/Models/CollectionCellMoleculeProtocol.swift new file mode 100644 index 00000000..a6a6d95d --- /dev/null +++ b/MVMCoreUI/Models/CollectionCellMoleculeProtocol.swift @@ -0,0 +1,14 @@ +// +// CollectionCellMoleculeProtocol.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 11/26/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + +public protocol CollectionCellMoleculeProtocol: MoleculeProtocol { + var peakingUI: Bool? {get} + var peakingArrowColor: String? {get} +} diff --git a/MVMCoreUI/Models/Extensions/ModelHelper.swift b/MVMCoreUI/Models/Extensions/ModelHelper.swift index 661280a9..da5e0d56 100644 --- a/MVMCoreUI/Models/Extensions/ModelHelper.swift +++ b/MVMCoreUI/Models/Extensions/ModelHelper.swift @@ -8,7 +8,7 @@ import Foundation -extension KeyedDecodingContainer where Key : CodingKey{ +extension KeyedDecodingContainer where Key : CodingKey { private enum TypeCodingKey: String, CodingKey { case moleculeName } diff --git a/MVMCoreUI/Models/Molecules/CarouselItemModel.swift b/MVMCoreUI/Models/Molecules/CarouselItemModel.swift new file mode 100644 index 00000000..a2359f03 --- /dev/null +++ b/MVMCoreUI/Models/Molecules/CarouselItemModel.swift @@ -0,0 +1,42 @@ +// +// CarouselItemModel.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 11/26/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + + +@objcMembers public class CarouselItemModel: MoleculeProtocol { + public static var identifier: String = "carouselItem" + public var moleculeName: String + public var backgroundColor: String? + public var molecule: MoleculeProtocol? + + public init(molecule: MoleculeProtocol?, backgroundColor: String?) { + self.molecule = molecule + self.moleculeName = Self.identifier + self.backgroundColor = backgroundColor + } + enum CodingKeys: String, CodingKey { + case moleculeName + case molecule + case backgroundColor + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName) + self.molecule = try typeContainer.decodeIfPresent(codingKey: .molecule) + self.backgroundColor = try typeContainer.decode(String.self, forKey: .backgroundColor) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(moleculeName, forKey: .moleculeName) + try container.encode(backgroundColor, forKey: .backgroundColor) + try container.encodeIfPresent(self.molecule, forKey: .molecule) + } +} diff --git a/MVMCoreUI/Models/Molecules/CarouselModel.swift b/MVMCoreUI/Models/Molecules/CarouselModel.swift new file mode 100644 index 00000000..9fce489a --- /dev/null +++ b/MVMCoreUI/Models/Molecules/CarouselModel.swift @@ -0,0 +1,74 @@ +// +// CarouselModel.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 11/25/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +@objcMembers public class CarouselModel: MoleculeProtocol { + + public static var identifier: String = "carousel" + public var moleculeName: String + public var molecules: [CarouselItemModel] + + public var spacing: Float? + public var border: Bool? + public var loop: Bool? + public var height: Float? + public var itemWidthPercent: Float? + public var itemAlignment: String? + public var pagingMolecule: PagingMoleculeProtocol? + + public init(molecules: [CarouselItemModel], spacing: Float?, border: Bool?, loop: Bool?, height: Float?, itemWidthPercent: Float?, itemAlignment: String?, pagingMolecule: PagingMoleculeProtocol?){ + self.moleculeName = Self.identifier + self.molecules = molecules + self.spacing = spacing + self.border = border + self.loop = loop + self.height = height + self.itemWidthPercent = itemWidthPercent + self.itemAlignment = itemAlignment + self.pagingMolecule = pagingMolecule + } + + enum CodingKeys: String, CodingKey { + case moleculeName + case molecules + case spacing + case border + case loop + case height + case itemWidthPercent + case itemAlignment + case pagingMolecule + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName) + self.molecules = try typeContainer.decode([CarouselItemModel].self, forKey: .molecules) + self.spacing = try typeContainer.decode(Float.self, forKey: .spacing) + self.border = try typeContainer.decode(Bool.self, forKey: .border) + self.loop = try typeContainer.decode(Bool.self, forKey: .loop) + self.height = try typeContainer.decode(Float.self, forKey: .height) + self.itemWidthPercent = try typeContainer.decode(Float.self, forKey: .itemWidthPercent) + self.itemAlignment = try typeContainer.decode(String.self, forKey: .itemAlignment) + self.pagingMolecule = try typeContainer.decodeIfPresent(codingKey: .pagingMolecule) as? PagingMoleculeProtocol + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(moleculeName, forKey: .moleculeName) + try container.encode(molecules, forKey: .molecules) + try container.encode(spacing, forKey: .spacing) + try container.encode(border, forKey: .border) + try container.encode(loop, forKey: .loop) + try container.encode(height, forKey: .height) + try container.encode(itemWidthPercent, forKey: .itemWidthPercent) + try container.encode(itemAlignment, forKey: .itemAlignment) + try container.encodeIfPresent(self.pagingMolecule, forKey: .pagingMolecule) + } +} diff --git a/MVMCoreUI/Models/Molecules/ListItemModel.swift b/MVMCoreUI/Models/Molecules/ListItemModel.swift index a903299a..b2da3db1 100644 --- a/MVMCoreUI/Models/Molecules/ListItemModel.swift +++ b/MVMCoreUI/Models/Molecules/ListItemModel.swift @@ -14,16 +14,26 @@ import Foundation public var molecule: MoleculeProtocol? public var actionMap: ActionMapModel? - public init(molecule: MoleculeProtocol?, actionMap: ActionMapModel?) { + public var hideArrow: Bool? + public var separator: SeperatorModel? + public var style: String? + + public init(molecule: MoleculeProtocol?, actionMap: ActionMapModel?, hideArrow: Bool?, separator: SeperatorModel?, style: String?) { self.molecule = molecule self.actionMap = actionMap self.moleculeName = Self.identifier + self.hideArrow = hideArrow + self.separator = separator + self.style = style } enum CodingKeys: String, CodingKey { case moleculeName case molecule case actionMap + case hideArrow + case separator + case style } required public init(from decoder: Decoder) throws { @@ -31,6 +41,10 @@ import Foundation self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName) self.molecule = try typeContainer.decodeIfPresent(codingKey: .molecule) self.actionMap = try typeContainer.decodeIfPresent(ActionMapModel.self, forKey: .actionMap) + + self.hideArrow = try typeContainer.decode(Bool.self, forKey: .hideArrow) + self.separator = try typeContainer.decode(SeperatorModel.self, forKey: .hideArrow) + self.style = try typeContainer.decode(String.self, forKey: .style) } public func encode(to encoder: Encoder) throws { @@ -38,5 +52,9 @@ import Foundation try container.encode(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(self.molecule, forKey: .molecule) try container.encodeIfPresent(actionMap, forKey: .actionMap) + + try container.encodeIfPresent(hideArrow, forKey: .hideArrow) + try container.encodeIfPresent(separator, forKey: .separator) + try container.encodeIfPresent(style, forKey: .style) } } diff --git a/MVMCoreUI/Models/Molecules/ModuleMoleculeModel.swift b/MVMCoreUI/Models/Molecules/ModuleMoleculeModel.swift new file mode 100644 index 00000000..15ce347f --- /dev/null +++ b/MVMCoreUI/Models/Molecules/ModuleMoleculeModel.swift @@ -0,0 +1,14 @@ +// +// ModuleMoleculeModel.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 11/26/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + +class ModuleMoleculeModel: MoleculeProtocol { + public static var identifier: String = "moduleMolecule" + public var moduleName: String +} diff --git a/MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift b/MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift index 5bceda3e..9c75b582 100644 --- a/MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift +++ b/MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift @@ -10,27 +10,56 @@ import Foundation @objcMembers public class MoleculeStackItemModel: MoleculeProtocol { public static var identifier: String = "stackItem" - public var moleculeName: String? + public var moleculeName: String public var molecule: MoleculeProtocol? - public init(molecule: MoleculeProtocol?) { + public var spacing: CGFloat? + public var percentage: Int? + public var verticalAlignment: String? + public var horizontalAlignment: String? + public var gone = false + + public init(molecule: MoleculeProtocol?, spacing: CGFloat?, percentage: Int?, verticalAlignment: String?, horizontalAlignment: String?, gone: Bool = false) { self.molecule = molecule self.moleculeName = Self.identifier + + self.spacing = spacing + self.percentage = percentage + self.verticalAlignment = verticalAlignment + self.horizontalAlignment = horizontalAlignment + self.gone = gone } enum CodingKeys: String, CodingKey { case moleculeName case molecule + case spacing + case percentage + case verticalAlignment + case horizontalAlignment + case gone } required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName) self.molecule = try typeContainer.decodeIfPresent(codingKey: .molecule) + + self.spacing = try typeContainer.decode(CGFloat.self, forKey: .spacing) + self.percentage = try typeContainer.decode(Int.self, forKey: .percentage) + self.verticalAlignment = try typeContainer.decode(String.self, forKey: .verticalAlignment) + self.horizontalAlignment = try typeContainer.decode(String.self, forKey: .horizontalAlignment) + self.gone = try typeContainer.decode(Bool.self, forKey: .gone) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(self.molecule, forKey: .molecule) + + try container.encode(spacing, forKey: .spacing) + try container.encode(percentage, forKey: .percentage) + try container.encode(verticalAlignment, forKey: .verticalAlignment) + try container.encode(horizontalAlignment, forKey: .horizontalAlignment) + try container.encode(gone, forKey: .gone) } } diff --git a/MVMCoreUI/Models/Molecules/MoleculeStackModel.swift b/MVMCoreUI/Models/Molecules/MoleculeStackModel.swift index 30c15822..bad35824 100644 --- a/MVMCoreUI/Models/Molecules/MoleculeStackModel.swift +++ b/MVMCoreUI/Models/Molecules/MoleculeStackModel.swift @@ -14,17 +14,20 @@ import Foundation public var moleculeName: String? public var molecules: [MoleculeStackItemModel]? public var axis: String? + public var spacing: Float? - public init(axis: String?, molecules: [MoleculeStackItemModel]?) { + public init(axis: String?, molecules: [MoleculeStackItemModel]?, spacing: Float?) { self.axis = axis self.molecules = molecules self.moleculeName = Self.identifier + self.spacing = spacing } enum CodingKeys: String, CodingKey { case moleculeName case molecules case axis + case spacing } required public init(from decoder: Decoder) throws { @@ -32,6 +35,7 @@ import Foundation self.moleculeName = try typeContainer.decodeIfPresent(String.self, forKey: .moleculeName) self.molecules = try typeContainer.decode([MoleculeStackItemModel].self, forKey: .molecules) self.axis = try typeContainer.decodeIfPresent(String.self, forKey: .axis) + self.spacing = try typeContainer.decodeIfPresent(Float.self, forKey: .spacing) } public func encode(to encoder: Encoder) throws { @@ -39,5 +43,6 @@ import Foundation try container.encode(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(molecules, forKey: .molecules) try container.encode(axis, forKey: .axis) + try container.encode(spacing, forKey: .spacing) } } diff --git a/MVMCoreUI/Models/Molecules/SeperatorModel.swift b/MVMCoreUI/Models/Molecules/SeperatorModel.swift index 705f904c..cdc1cb3c 100644 --- a/MVMCoreUI/Models/Molecules/SeperatorModel.swift +++ b/MVMCoreUI/Models/Molecules/SeperatorModel.swift @@ -8,7 +8,7 @@ import UIKit -class SeperatorModel: MoleculeProtocol { +@objcMembers public class SeperatorModel: MoleculeProtocol { public static var identifier: String = "line" public var type: String? } diff --git a/MVMCoreUI/Models/PagingMoleculeProtocol.swift b/MVMCoreUI/Models/PagingMoleculeProtocol.swift new file mode 100644 index 00000000..af1ce14a --- /dev/null +++ b/MVMCoreUI/Models/PagingMoleculeProtocol.swift @@ -0,0 +1,13 @@ +// +// PagingMoleculeProtocol.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 11/25/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + +public protocol PagingMoleculeProtocol: MoleculeProtocol { + var position: Float? {get} +} diff --git a/MVMCoreUI/Models/Template/ListPageTemplateModel.swift b/MVMCoreUI/Models/Template/ListPageTemplateModel.swift new file mode 100644 index 00000000..2ad31cdc --- /dev/null +++ b/MVMCoreUI/Models/Template/ListPageTemplateModel.swift @@ -0,0 +1,24 @@ +// +// ListPageTemplate.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 11/22/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + +@objcMembers public class ListPageTemplateModel: TemplateModelProtocol { + + public static var identifier: String = "listTemplate" + + public var pageType: String + + public var screenHeading: String + + public var isAtomicTabs: Bool? + + public var header: MoleculeStackModel? + public var molecules: [ListItemModel]? + public var footer: MoleculeStackModel? +} diff --git a/MVMCoreUI/Models/PageModel.swift b/MVMCoreUI/Models/Template/PageModel.swift similarity index 100% rename from MVMCoreUI/Models/PageModel.swift rename to MVMCoreUI/Models/Template/PageModel.swift diff --git a/MVMCoreUI/Models/Template/StackCenteredPageTemplateModel.swift b/MVMCoreUI/Models/Template/StackCenteredPageTemplateModel.swift new file mode 100644 index 00000000..27eaa362 --- /dev/null +++ b/MVMCoreUI/Models/Template/StackCenteredPageTemplateModel.swift @@ -0,0 +1,21 @@ +// +// StackCenteredPageTemplate.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 11/22/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + +@objcMembers public class StackCenteredPageTemplateModel: TemplateModelProtocol { + + public static var identifier: String = "stackCenterTemplate" + + public var pageType: String + + public var screenHeading: String + + public var isAtomicTabs: Bool? + +} diff --git a/MVMCoreUI/Models/Template/StackPageTemplateModel.swift b/MVMCoreUI/Models/Template/StackPageTemplateModel.swift new file mode 100644 index 00000000..e1030f35 --- /dev/null +++ b/MVMCoreUI/Models/Template/StackPageTemplateModel.swift @@ -0,0 +1,24 @@ +// +// StackPageTemplate.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 11/22/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + + +@objcMembers public class StackPageTemplateModel: TemplateModelProtocol { + public static var identifier: String = "moleculeStack" + + public var pageType: String + + public var screenHeading: String + + public var isAtomicTabs: Bool? + + public var header: MoleculeStackModel? + public var moleculeStack: MoleculeStackModel? + public var footer: MoleculeStackModel? +} diff --git a/MVMCoreUI/Models/Template/TemplateModelProtocol.swift b/MVMCoreUI/Models/Template/TemplateModelProtocol.swift new file mode 100644 index 00000000..3eeb9673 --- /dev/null +++ b/MVMCoreUI/Models/Template/TemplateModelProtocol.swift @@ -0,0 +1,22 @@ +// +// TemplateModelProtocol.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 11/22/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + +public protocol TemplateModelProtocol: Model { + var template: String { get } + var pageType: String { get set } + var screenHeading: String { get set } + var isAtomicTabs: Bool? { get set } +} + +extension TemplateModelProtocol { + public var template: String { + get { return Self.identifier } + } +} diff --git a/MVMCoreUI/Models/Template/ThreeLayerPageTemplateModel.swift b/MVMCoreUI/Models/Template/ThreeLayerPageTemplateModel.swift new file mode 100644 index 00000000..658a021f --- /dev/null +++ b/MVMCoreUI/Models/Template/ThreeLayerPageTemplateModel.swift @@ -0,0 +1,24 @@ +// +// ThreeLayerPageTemplateModel.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 11/22/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + +@objcMembers public class ThreeLayerPageTemplateModel: TemplateModelProtocol { + + public static var identifier: String = "threeLayer" + + public var pageType: String + + public var screenHeading: String + + public var isAtomicTabs: Bool? + + public var header: MoleculeStackModel? + public var middle: MoleculeStackModel? + public var footer: MoleculeStackModel? +} diff --git a/MVMCoreUI/Models/TemplateProtocol.swift b/MVMCoreUI/Models/TemplateProtocol.swift new file mode 100644 index 00000000..90e3e635 --- /dev/null +++ b/MVMCoreUI/Models/TemplateProtocol.swift @@ -0,0 +1,29 @@ +// +// ModelTemplateProtocol.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 11/25/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + +public protocol TemplateProtocol { + var templateModel: TemplateModelProtocol? {get} + func parseTemplateJSON() + func templateData() -> Data? +} + +extension TemplateProtocol where Self: MFViewController { + public func templateData() -> Data? { + guard let pageJSON = loadObject?.pageJSON as? [String: AnyHashable] else { + return nil + } + do { + return try JSONSerialization.data(withJSONObject: pageJSON) + } catch { + MVMCoreUILoggingHandler.logDebugMessage(withDelegate: "error: \(error)") + return nil + } + } +} diff --git a/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift b/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift index 75249f7d..bc97be16 100644 --- a/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift +++ b/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift @@ -8,7 +8,8 @@ import UIKit -open class MoleculeCollectionViewCell: UICollectionViewCell, MVMCoreUIMoleculeViewProtocol, MoleculeListCellProtocol { +open class MoleculeCollectionViewCell: UICollectionViewCell, MVMCoreUIMoleculeViewProtocol, MoleculeListCellProtocol, ModelMoleculeViewProtocol { + open var molecule: (UIView & MVMCoreUIMoleculeViewProtocol)? open var json: [AnyHashable: Any]? @@ -64,47 +65,50 @@ open class MoleculeCollectionViewCell: UICollectionViewCell, MVMCoreUIMoleculeVi peakingRightArrow.centerYAnchor.constraint(equalTo: contentView.centerYAnchor).isActive = true NSLayoutConstraint.scalingPinViewRight(toSuper: peakingRightArrow, ratio: ratio, anchor: contentView.widthAnchor) } - - public func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { - self.json = json - - if let useHorizontalMargins = json?.optionalBoolForKey("useHorizontalMargins") { + + + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + guard let collectionModel = model as? CollectionCellMoleculeProtocol else { + return + } + + if let useHorizontalMargins = collectionModel.useHorizontalMargins { updateViewHorizontalDefaults = useHorizontalMargins } - if let useVerticalMargins = json?.optionalBoolForKey("useVerticalMargins") { + if let useVerticalMargins = collectionModel.useVerticalMargins { updateViewVerticalDefaults = useVerticalMargins } - // Handles peaking. - allowsPeaking = json?.optionalBoolForKey("peakingUI") ?? true - if let peakingArrowColor = json?.optionalStringForKey("peakingArrowColor") { + allowsPeaking = collectionModel.peakingUI ?? false + if let peakingArrowColor = collectionModel.peakingArrowColor { let color = UIColor.mfGet(forHex: peakingArrowColor) peakingLeftArrow.tintColor = color peakingRightArrow.tintColor = color } - - if let backgroundColorString = json?.optionalStringForKey(KeyBackgroundColor) { - backgroundColor = UIColor.mfGet(forHex: backgroundColorString) + + if let backgroundColorString = collectionModel.backgroundColor { + backgroundColor = UIColor.mfGet(forHex: backgroundColorString) } - - guard let moleculeJSON = json?.optionalDictionaryForKey(KeyMolecule) else { + + guard let moleculeModel = collectionModel.molecule else { return } + if molecule == nil { - if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject, constrainIfNeeded: true) { + if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(moleculeModel, delegateObject, true) { contentView.insertSubview(moleculeView, at: 0) NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: moleculeView, useMargins: true).values)) molecule = moleculeView } } else { - molecule?.setWithJSON(moleculeJSON, delegateObject: delegateObject, additionalData: additionalData) + (molecule as? ModelMoleculeViewProtocol)?.setWithModel(moleculeModel, delegateObject, additionalData) } + // This molecule will handle spacing by default. if let castView = molecule as? MVMCoreUIViewConstrainingProtocol { castView.shouldSetHorizontalMargins?(false) castView.shouldSetVerticalMargins?(false) } - accessibilityElements = molecule?.subviews } diff --git a/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift b/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift index 4769b7e5..7963b819 100644 --- a/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift @@ -9,30 +9,27 @@ import UIKit @objcMembers open class MoleculeTableViewCell: TableViewCell { - - // MARK: - MVMCoreUIMoleculeViewProtocol - public override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - - guard molecule == nil, let json = json, let moleculeJSON = json.optionalDictionaryForKey(KeyMolecule), let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject, constrainIfNeeded: true) else { return } + + public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + super.setWithModel(model, delegateObject, additionalData) + + guard let model = model, + let moleculeModel = (model as? ConstrainingMoleculeProtocol)?.molecule, + let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(moleculeModel, delegateObject, true) else { + return + } addMolecule(moleculeView) } - - public override class func estimatedHeight(forRow json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { - guard let moleculeJSON = json?.optionalDictionaryForKey(KeyMolecule), let height = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: moleculeJSON)?.estimatedHeight?(forRow: moleculeJSON, delegateObject: delegateObject) else { - return 80 - } - return max(2 * PaddingDefaultVerticalSpacing3, height) - } - - public override class func name(forReuse molecule: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? { - guard let molecule = molecule?.optionalDictionaryForKey(KeyMolecule) else { + + public override class func name(forReuse molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> String? { + guard let moleculeModel = molecule?.molecule else { return "\(self)<>" } - let moleculeName = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: molecule)?.name?(forReuse: molecule, delegateObject: delegateObject) ?? molecule.optionalStringForKey(KeyMoleculeName) ?? "" + let className = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moleculeModel) as? ModelMoleculeViewProtocol + let moleculeName = (className as? ModelMoleculeViewProtocol.Type)?.name(forReuse: molecule, delegateObject: 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 cc531d75..7a097b5e 100644 --- a/MVMCoreUI/Molecules/Items/TableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/TableViewCell.swift @@ -8,9 +8,11 @@ import UIKit -@objcMembers open class TableViewCell: UITableViewCell, MVMCoreUIMoleculeViewProtocol, MoleculeListCellProtocol { +@objcMembers open class TableViewCell: UITableViewCell, MVMCoreUIMoleculeViewProtocol, MoleculeListCellProtocol, ModelMoleculeViewProtocol { + open var molecule: (UIView & MVMCoreUIMoleculeViewProtocol)? - open var json: [AnyHashable: Any]? + open var listItemModel: ListItemModel? + open var json: [String: Any]? // In updateView, will set padding to default. open var updateViewHorizontalDefaults = true @@ -136,46 +138,47 @@ import UIKit contentView.insetsLayoutMarginsFromSafeArea = false contentView.preservesSuperviewLayoutMargins = false } - - // MARK: - MVMCoreUIMoleculeViewProtocol - public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - self.json = json - - guard let json = json else { return } - - style(with: json.optionalStringForKey("style")) - - if let useHorizontalMargins = json.optionalBoolForKey("useHorizontalMargins") { + + //TODO: Model, Change to model + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + guard let model = model as? ListItemModel else { + return + } + + self.listItemModel = model + style(with: model.style) + + if let useHorizontalMargins = model.useHorizontalMargins { updateViewHorizontalDefaults = useHorizontalMargins } - - if (json.optionalBoolForKey("useVerticalMargins") ?? true) == false { + + if (model.useVerticalMargins ?? true) == false { topMarginPadding = 0 bottomMarginPadding = 0 } - - if let backgroundColorString = json.optionalStringForKey(KeyBackgroundColor) { + + if let backgroundColorString = model.backgroundColor { backgroundColor = UIColor.mfGet(forHex: backgroundColorString) } - + // Add the caret if there is an action and it's not declared hidden. if !customAccessoryView { - if let _ = json.optionalDictionaryForKey("actionMap"), !json.boolForKey("hideArrow") { + if let _ = model.actionMap, !(model.hideArrow ?? false) { addCaretViewAccessory() } else { accessoryView = nil } } - + // override the separator - if let separator = json.optionalDictionaryForKey("separator") { + if let separator = model.separator { addSeparatorsIfNeeded() - bottomSeparatorView?.setWithJSON(separator, delegateObject: delegateObject, additionalData: additionalData) + (bottomSeparatorView as? ModelMoleculeViewProtocol)?.setWithModel(separator, nil, nil) } - - guard let moleculeJSON = json.optionalDictionaryForKey(KeyMolecule) else { return } - molecule?.setWithJSON(moleculeJSON, delegateObject: delegateObject, additionalData: additionalData) - + + guard let moleculeModel = model.molecule else { return } + (molecule as? ModelMoleculeViewProtocol)?.setWithModel(moleculeModel, delegateObject, additionalData) + // This molecule will by default handle margins. if let castView = molecule as? MVMCoreUIViewConstrainingProtocol { castView.shouldSetHorizontalMargins?(false) @@ -189,18 +192,20 @@ import UIKit styleStandard() backgroundColor = .white } - - public class func estimatedHeight(forRow json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { - guard let moleculeJSON = json?.optionalDictionaryForKey(KeyMolecule), let height = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: moleculeJSON)?.estimatedHeight?(forRow: moleculeJSON, delegateObject: delegateObject) else { + + public static func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { + guard let moleculeModel = molecule?.molecule, + let classType = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moleculeModel) as? ModelMoleculeViewProtocol.Type, + let height = classType.estimatedHeight(forRow: moleculeModel, delegateObject: delegateObject) else { return 80 } return max(2 * PaddingDefaultVerticalSpacing3, height) } - - public class func name(forReuse molecule: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? { - return molecule?.optionalStringForKey(KeyMoleculeName) ?? "" + + + 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 @objc public func addCaretViewAccessory() { @@ -247,6 +252,7 @@ import UIKit // MARK: - MoleculeListCellProtocol /// For when the separator between cells shows using json and frequency. Default is type: standard, frequency: allExceptTop. + //TODO: Change to model public func setSeparatorWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?, indexPath: IndexPath) { addSeparatorsIfNeeded() if let json = json { @@ -263,7 +269,8 @@ import UIKit } public func didSelectCell(atIndex indexPath: IndexPath, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - if let actionMap = json?.optionalDictionaryForKey("actionMap") { + //TODO: Use object when handleAction is rewrote to handle action model + if let actionMap = self.listItemModel?.actionMap?.toJSON() { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) } } diff --git a/MVMCoreUI/Molecules/Items/TabsTableViewCell.swift b/MVMCoreUI/Molecules/Items/TabsTableViewCell.swift index 1a1796cd..b75f4600 100644 --- a/MVMCoreUI/Molecules/Items/TabsTableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/TabsTableViewCell.swift @@ -38,12 +38,13 @@ import UIKit } // MARK: - MoleculeDelegateProtocol - public override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { - super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) + + public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + super.setWithModel(model, delegateObject, additionalData) self.delegateObject = delegateObject tabs.reloadData() } - + public override func reset() { super.reset() topMarginPadding = 8 @@ -51,17 +52,21 @@ import UIKit } } +//TODO: Models changes + extension TabsTableViewCell: TopTabbarDelegate { public func shouldSelectItem(at index: Int, topTabbar: TopTabbar) -> Bool { - if let moleculesArrays = json?.arrayForKey(KeyMolecules), let molecules = moleculesArrays[topTabbar.selectedIndex] as? [[AnyHashable: Any]] { + if let moleculesArrays = json?.arrayForKey(KeyMolecules), + let molecules = moleculesArrays[topTabbar.selectedIndex] as? [[AnyHashable: Any]] { delegateObject?.moleculeDelegate?.removeMolecules?(molecules, sender: self, animation: index < tabs.selectedIndex ? .right : .left) } previousTabIndex = tabs.selectedIndex return true } - + public func topTabbar(_ topTabbar: TopTabbar, didSelectItemAt index: Int) { - if let moleculesArrays = json?.arrayForKey(KeyMolecules), let molecules = moleculesArrays[index] as? [[AnyHashable: Any]] { + if let moleculesArrays = json?.arrayForKey(KeyMolecules), + let molecules = moleculesArrays[index] as? [[AnyHashable: Any]] { delegateObject?.moleculeDelegate?.addMolecules?(molecules, sender: self, animation: index < previousTabIndex ? .left : .right) } } @@ -71,7 +76,7 @@ extension TabsTableViewCell: TopTabbarDataSource { public func number(ofTopTabbarItems topTabbar: TopTabbar) -> Int { return json?.optionalDictionaryForKey("tabs")?.optionalArrayForKey("tabs")?.count ?? 0 } - + public func topTabbar(_ topTabbar: TopTabbar, titleForItemAt index: Int) -> String? { guard let tabs = json?.optionalDictionaryForKey("tabs")?.arrayForKey("tabs"), let label = tabs[index] as? [AnyHashable: Any], let title = label.optionalStringForKey(KeyText) else { return "Select" diff --git a/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h b/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h index 2c52324b..e67dc964 100644 --- a/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h +++ b/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h @@ -14,15 +14,10 @@ @protocol MVMCoreUIMoleculeViewProtocol -/// Sets up the ui based on the json -- (void)setWithJSON:(nullable NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject additionalData:(nullable NSDictionary *)additionalData; - @optional -// optional func setWithModel(_ model: MoleculeProtocol, _ delegateObject: MVMCoreUIDelegateObject, _ additionalData: [String: AnyHashable]) -//Type arguments cannot be applied to non-parameterized class 'NSObject' -//- (void)setWithModel:(nullable NSObject*)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject additionalData:(nullable NSDictionary *)additionalData; - +/// Sets up the ui based on the json +- (void)setWithJSON:(nullable NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject additionalData:(nullable NSDictionary *)additionalData; /// Called after init to provide an early setter for any molecule specific logic - (void)setAsMolecule; diff --git a/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift b/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift index 98c1818c..fa1b30a8 100644 --- a/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift +++ b/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift @@ -10,4 +10,15 @@ import Foundation public protocol ModelMoleculeViewProtocol { func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String: AnyHashable]?) + static func name(forReuse molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> String? + static func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? +} + +extension ModelMoleculeViewProtocol { + public static func name(forReuse molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> String? { + return nil + } + 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 77acc007..ab252b5e 100644 --- a/MVMCoreUI/Molecules/ModuleMolecule.swift +++ b/MVMCoreUI/Molecules/ModuleMolecule.swift @@ -8,7 +8,7 @@ import UIKit -open class ModuleMolecule: ViewConstrainingView { +open class ModuleMolecule: ViewConstrainingView, ModelMoleculeViewProtocol { open var moduleMolecule: (UIView & MVMCoreUIMoleculeViewProtocol)? @@ -16,33 +16,65 @@ open class ModuleMolecule: ViewConstrainingView { super.updateView(size) moduleMolecule?.updateView(size) } - - // MARK: - MVMCoreUIMoleculeViewProtocol - open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - - guard let moduleName = json?.optionalStringForKey("moduleName"), let module = delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) else { - // Critical error - return + + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String: AnyHashable]?) { + #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 moduleMoleculeModel = model as? ModuleMoleculeModel, + let module = delegateObject?.moleculeDelegate?.getModuleWithName(moduleMoleculeModel.moduleName) else { + // Critical error + return } - if moduleMolecule == nil { - if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: module, delegateObject: delegateObject, constrainIfNeeded: true) { - addSubview(moleculeView) - NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: moleculeView, useMargins: false).values)) - moduleMolecule = moleculeView - - isAccessibilityElement = false - if moleculeView.accessibilityElements != nil { - accessibilityElements = moleculeView.accessibilityElements - } else { - accessibilityElements = [moleculeView] - } - } - } else { - moduleMolecule?.setWithJSON(module, delegateObject: delegateObject, additionalData: additionalData) - } +// if moduleMolecule == nil { +// MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(<#T##model: MoleculeProtocol##MoleculeProtocol#>, <#T##delegateObject: MVMCoreUIDelegateObject?##MVMCoreUIDelegateObject?#>, <#T##constrainIfNeeded: Bool##Bool#>) +// if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: module, delegateObject: delegateObject, constrainIfNeeded: true) { +// addSubview(moleculeView) +// NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: moleculeView, useMargins: false).values)) +// moduleMolecule = moleculeView +// +// isAccessibilityElement = false +// if moleculeView.accessibilityElements != nil { +// accessibilityElements = moleculeView.accessibilityElements +// } else { +// accessibilityElements = [moleculeView] +// } +// } +// } else { +// moduleMolecule?.setWithJSON(module, delegateObject: delegateObject, additionalData: additionalData) +// } + } + +// // MARK: - MVMCoreUIMoleculeViewProtocol +// open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { +// super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) +// +// guard let moduleName = json?.optionalStringForKey("moduleName"), +// let module = delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) else { +// // Critical error +// return +// } +// +// if moduleMolecule == nil { +// if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: module, delegateObject: delegateObject, constrainIfNeeded: true) { +// addSubview(moleculeView) +// NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: moleculeView, useMargins: false).values)) +// moduleMolecule = moleculeView +// +// isAccessibilityElement = false +// if moleculeView.accessibilityElements != nil { +// accessibilityElements = moleculeView.accessibilityElements +// } else { +// accessibilityElements = [moleculeView] +// } +// } +// } else { +// moduleMolecule?.setWithJSON(module, delegateObject: delegateObject, additionalData: additionalData) +// } +// } open override func setAsMolecule() { super.setAsMolecule() @@ -55,7 +87,8 @@ open class ModuleMolecule: ViewConstrainingView { } public override class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { - guard let moduleName = json?.optionalStringForKey("moduleName"), let module = delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) else { + guard let moduleName = json?.optionalStringForKey("moduleName"), + let module = delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) else { // Critical error return 0 } @@ -63,7 +96,8 @@ open class ModuleMolecule: ViewConstrainingView { } public override class func name(forReuse molecule: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? { - guard let moduleName = molecule?.optionalStringForKey("moduleName"), let module = delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) else { + guard let moduleName = molecule?.optionalStringForKey("moduleName"), + let module = delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) else { // Critical error return "moduleMolecule<>" } diff --git a/MVMCoreUI/Molecules/Scroller.swift b/MVMCoreUI/Molecules/Scroller.swift index e4289bc3..7f179a07 100644 --- a/MVMCoreUI/Molecules/Scroller.swift +++ b/MVMCoreUI/Molecules/Scroller.swift @@ -27,19 +27,41 @@ import UIKit constraint.priority = UILayoutPriority(rawValue: 999) constraint.isActive = true } - - open override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { - guard let json = json, let moleculeJSON = json.optionalDictionaryForKey(KeyMolecule) else { + + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + //super.setWithModel(model, delegateObject, 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) + + guard let model = model, + let moleculeModel = (model as? ConstrainingMoleculeProtocol)?.molecule else { return } + if molecule == nil { - if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject, constrainIfNeeded: true) { + if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(moleculeModel, delegateObject, true) { contentView.addSubview(moleculeView) pinView(toSuperView: moleculeView) molecule = moleculeView } } else { - molecule?.setWithJSON(moleculeJSON, delegateObject: delegateObject, additionalData: additionalData) + (molecule as? ModelMoleculeViewProtocol)?.setWithModel(moleculeModel, delegateObject, additionalData) } } + +// open override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { +// guard let json = json, let moleculeJSON = json.optionalDictionaryForKey(KeyMolecule) else { +// return +// } +// if molecule == nil { +// if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject, constrainIfNeeded: true) { +// contentView.addSubview(moleculeView) +// pinView(toSuperView: moleculeView) +// molecule = moleculeView +// } +// } else { +// molecule?.setWithJSON(moleculeJSON, delegateObject: delegateObject, additionalData: additionalData) +// } +// } } diff --git a/MVMCoreUI/Molecules/StandardHeaderView.swift b/MVMCoreUI/Molecules/StandardHeaderView.swift index 100173fc..32b14bb2 100644 --- a/MVMCoreUI/Molecules/StandardHeaderView.swift +++ b/MVMCoreUI/Molecules/StandardHeaderView.swift @@ -56,7 +56,6 @@ public class StandardHeaderView: ViewConstrainingView, ModelMoleculeViewProtocol } open 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. diff --git a/MVMCoreUI/Organisms/Carousel.swift b/MVMCoreUI/Organisms/Carousel.swift index d0efcce3..116f1135 100644 --- a/MVMCoreUI/Organisms/Carousel.swift +++ b/MVMCoreUI/Organisms/Carousel.swift @@ -8,7 +8,8 @@ import UIKit -open class Carousel: ViewConstrainingView { +open class Carousel: ViewConstrainingView, ModelMoleculeViewProtocol { + let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()) /// The current index of the collection view. Includes dummy cells when looping. @@ -28,7 +29,7 @@ open class Carousel: ViewConstrainingView { var numberOfPages = 0 /// The json for the molecules. - var molecules: [[AnyHashable: Any]]? + var molecules: [MoleculeProtocol]? /// The horizontal alignment of the cell in the collection view. Only noticeable if the itemWidthPercent is less than 100%. var itemAlignment = UICollectionView.ScrollPosition.left @@ -79,25 +80,37 @@ open class Carousel: ViewConstrainingView { } // MARK: - MVMCoreUIMoleculeViewProtocol - open override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { - super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) + //TODO: Model, Change to model + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + guard let caroselModel = model as? CarouselModel else { + return + } + + #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(caroselModel, delegateObject, additionalData) + collectionView.backgroundColor = backgroundColor collectionView.layer.borderColor = backgroundColor?.cgColor - collectionView.layer.borderWidth = (json?.boolForKey("border") ?? false) ? 1 : 0 + collectionView.layer.borderWidth = (caroselModel.border ?? false) ? 1 : 0 backgroundColor = .white - registerCells(with: json, delegateObject: delegateObject) - setupLayout(with: json) - prepareMolecules(with: json) - itemWidthPercent = (json?.optionalCGFloatForKey("itemWidthPercent") ?? 100) / 100 - setAlignment(with: json?.optionalStringForKey("itemAlignment")) - if let height = json?.optionalCGFloatForKey("height") { - collectionViewHeight?.constant = height + + registerCells(with: caroselModel, delegateObject: delegateObject) + setupLayout(with: caroselModel) + prepareMolecules(with: caroselModel) + itemWidthPercent = CGFloat((caroselModel.itemWidthPercent ?? 100) / 100) + setAlignment(with: caroselModel.itemAlignment) + + if let height = caroselModel.height { + collectionViewHeight?.constant = CGFloat(height) collectionViewHeight?.isActive = true } - setupPagingMolecule(json: json?.optionalDictionaryForKey("pagingMolecule"), delegateObject: delegateObject) + + setupPagingMolecule(caroselModel.pagingMolecule, delegateObject: delegateObject) collectionView.reloadData() } - + + open override func shouldSetHorizontalMargins(_ shouldSet: Bool) { super.shouldSetHorizontalMargins(shouldSet) updateViewHorizontalDefaults = false @@ -105,24 +118,25 @@ open class Carousel: ViewConstrainingView { // MARK: - JSON Setters /// Updates the layout being used - func setupLayout(with json:[AnyHashable: Any]?) { + + func setupLayout(with carouselModel: CarouselModel?) { let layout = UICollectionViewFlowLayout() layout.scrollDirection = .horizontal - layout.minimumLineSpacing = json?["spacing"] as? CGFloat ?? 1 + layout.minimumLineSpacing = CGFloat(carouselModel?.spacing ?? 1) layout.minimumInteritemSpacing = 0 collectionView.collectionViewLayout = layout } - - func prepareMolecules(with json: [AnyHashable: Any]?) { - guard let newMolecules = json?.optionalArrayForKey(KeyMolecules) as? [[AnyHashable: Any]] else { + + func prepareMolecules(with carouselModel: CarouselModel?) { + guard let newMolecules = carouselModel?.molecules else { numberOfPages = 0 molecules = nil return } - + numberOfPages = newMolecules.count molecules = newMolecules - if json?.boolForKey("loop") ?? false && newMolecules.count > 2 { + if carouselModel?.loop ?? false && newMolecules.count > 2 { // Sets up the row data with buffer cells on each side (for illusion of endless scroll... also has one more buffer cell on each side in case we can peek that cell). loop = true molecules?.insert(newMolecules.last!, at: 0) @@ -132,36 +146,33 @@ open class Carousel: ViewConstrainingView { } pageIndex = 0 } - + + /// Sets up the paging molecule + open func setupPagingMolecule(_ molecule: PagingMoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) { + var pagingView: (UIView & MVMCoreUIPagingProtocol)? = nil + if let molecule = molecule { + pagingView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(molecule, delegateObject, true) as? (UIView & MVMCoreUIPagingProtocol) + } + addPaging(view: pagingView, position: (CGFloat(molecule?.position ?? 20))) + } + /// Registers the cells with the collection view - func registerCells(with json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) { - if let molecules = json?.optionalArrayForKey(KeyMolecules) as? [[AnyHashable: Any]] { - for molecule in molecules { - if let info = getMoleculeInfo(with: molecule, delegateObject: delegateObject) { - collectionView.register(info.class, forCellWithReuseIdentifier: info.identifier) - } + func registerCells(with carouselModel: CarouselModel, delegateObject: MVMCoreUIDelegateObject?) { + for molecule in carouselModel.molecules { + if let info = getMoleculeInfo(with: molecule, delegateObject: delegateObject) { + collectionView.register(info.class, forCellWithReuseIdentifier: info.identifier) } } } - - /// Sets up the paging molecule - open func setupPagingMolecule(json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) { - var pagingView: (UIView & MVMCoreUIPagingProtocol)? = nil - if let json = json { - pagingView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: json, delegateObject: delegateObject, constrainIfNeeded: true) as? (UIView & MVMCoreUIPagingProtocol) - } - addPaging(view: pagingView, position: (json?.optionalCGFloatForKey("position") ?? 20)) - } // MARK: - Convenience /// Returns the (identifier, class) of the molecule for the given map. - func getMoleculeInfo(with molecule: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> (identifier: String, class: AnyClass, molecule: [AnyHashable: Any])? { - guard let molecule = molecule, - let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: molecule), - let moleculeName = moleculeClass.name?(forReuse: molecule, delegateObject: delegateObject) ?? molecule.optionalStringForKey(KeyMoleculeName) else { - return nil + 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.Type)?.name(forReuse: molecule, delegateObject: delegateObject) ?? molecule.moleculeName else { + return nil } - return (moleculeName, moleculeClass, molecule) + return (moleculeName, className, molecule) } /// Sets the alignment from the string. @@ -272,9 +283,9 @@ extension Carousel: UICollectionViewDataSource { return UICollectionViewCell() } let cell = collectionView.dequeueReusableCell(withReuseIdentifier: moleculeInfo.identifier, for: indexPath) - if let protocolCell = cell as? MVMCoreUIMoleculeViewProtocol { + if let protocolCell = cell as? MVMCoreUIMoleculeViewProtocol & ModelMoleculeViewProtocol { protocolCell.reset?() - protocolCell.setWithJSON(moleculeInfo.molecule, delegateObject: nil, additionalData: nil) + protocolCell.setWithModel(moleculeInfo.molecule, nil, nil) protocolCell.updateView(collectionView.bounds.width) } setAccessiblity(cell, index: indexPath.row) diff --git a/MVMCoreUI/Organisms/MoleculeStackView.swift b/MVMCoreUI/Organisms/MoleculeStackView.swift index cafe21b0..c47ca142 100644 --- a/MVMCoreUI/Organisms/MoleculeStackView.swift +++ b/MVMCoreUI/Organisms/MoleculeStackView.swift @@ -20,21 +20,22 @@ public class StackItem { self.view = view } - init(with view: UIView, json: [AnyHashable: Any]?) { + init(with view: UIView, stackItemModel: MoleculeStackItemModel?) { self.view = view - update(with: json) + update(with: stackItemModel) } - func update(with json: [AnyHashable: Any]?) { - gone = json?.boolForKey("gone") ?? (json == nil) - spacing = json?.optionalCGFloatForKey("spacing") - percentage = json?["percent"] as? Int - if let alignment = json?.stringOptionalWithChainOfKeysOrIndexes([KeyMolecule,"verticalAlignment"]) { + func update(with stackItemModel: MoleculeStackItemModel?) { + gone = stackItemModel?.gone ?? false + spacing = stackItemModel?.spacing + percentage = stackItemModel?.percentage + + if let alignment = stackItemModel?.verticalAlignment { verticalAlignment = ViewConstrainingView.getAlignmentFor(alignment, defaultAlignment: .fill) } else { verticalAlignment = nil } - if let alignment = json?.stringOptionalWithChainOfKeysOrIndexes([KeyMolecule,"horizontalAlignment"]) { + if let alignment = stackItemModel?.horizontalAlignment { horizontalAlignment = ViewConstrainingView.getAlignmentFor(alignment, defaultAlignment: .fill) } else { horizontalAlignment = nil @@ -42,10 +43,11 @@ public class StackItem { } } -public class MoleculeStackView: ViewConstrainingView { +public class MoleculeStackView: ViewConstrainingView, ModelMoleculeViewProtocol { var contentView: UIView = MVMCoreUICommonViewsUtility.commonView() var items: [StackItem] = [] var useStackSpacingBeforeFirstItem = false + var moleculeStackModel: MoleculeStackModel? private var moleculesShouldSetHorizontalMargins = false private var moleculesShouldSetVerticalMargins = false @@ -144,44 +146,53 @@ public class MoleculeStackView: ViewConstrainingView { } } } - - open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - let previousJSON = self.json - super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) + + //TODO: Model, Change to model + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + guard let model = model as? MoleculeStackModel else { + return + } + let previousModel = self.moleculeStackModel + self.moleculeStackModel = model + + #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) removeAllItemViews() // If the items in the stack are the same, just update previous items instead of re-allocating. var items: [StackItem]? - if MoleculeStackView.name(forReuse: previousJSON, delegateObject: delegateObject) == MoleculeStackView.name(forReuse: json, delegateObject: delegateObject) { + + if MoleculeStackView.name(forReuse: previousModel, delegateObject: delegateObject) == MoleculeStackView.name(forReuse: model, delegateObject: delegateObject) { items = self.items } self.items = [] - guard let molecules = json?.arrayForKey(KeyMolecules) as? [[String: Any]] else { + guard let molecules = model.molecules else { return } - + // Sets the stack attributes - setAxisWithJSON(json) - spacing = json?.optionalCGFloatForKey("spacing") ?? 16 - - // Adds the molecules and sets the json. - for (index, map) in molecules.enumerated() { - if let moleculeJSON = map.optionalDictionaryForKey(KeyMolecule) { + //setAxisWithJSON(json) + spacing = CGFloat(model.spacing ?? 16) + + for (index, moleculeContainer) in molecules.enumerated() { + if let stackItemModel = moleculeContainer.molecule as? MoleculeStackItemModel { var view: UIView? - if let item = items?[index] { - item.update(with: map) - view = item.view - (view as? MVMCoreUIMoleculeViewProtocol)?.setWithJSON(moleculeJSON, delegateObject: delegateObject, additionalData: nil) - addStackItem(item, lastItem: index == molecules.count - 1) - } else if let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject, constrainIfNeeded: true) { - view = molecule - addStackItem(StackItem(with: molecule, json: map), lastItem: index == molecules.count - 1) - } - (view as? MVMCoreUIViewConstrainingProtocol)?.shouldSetHorizontalMargins?(moleculesShouldSetHorizontalMargins) - (view as? MVMCoreUIViewConstrainingProtocol)?.shouldSetVerticalMargins?(moleculesShouldSetVerticalMargins) + if let item = items?[index] { + item.update(with: stackItemModel) + view = item.view + (view as? ModelMoleculeViewProtocol)?.setWithModel(stackItemModel, delegateObject, nil) + addStackItem(item, lastItem: index == molecules.count - 1) + } else if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(stackItemModel, delegateObject, true) { + view = moleculeView + addStackItem(StackItem(with: moleculeView, stackItemModel: stackItemModel), lastItem: index == molecules.count - 1) + } + (view as? MVMCoreUIViewConstrainingProtocol)?.shouldSetHorizontalMargins?(moleculesShouldSetHorizontalMargins) + (view as? MVMCoreUIViewConstrainingProtocol)?.shouldSetVerticalMargins?(moleculesShouldSetVerticalMargins) } } + } public override class func name(forReuse molecule: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? { diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelExtension.swift b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelExtension.swift index 650264fc..0fb7370e 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelExtension.swift +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelExtension.swift @@ -8,9 +8,15 @@ import Foundation - public extension MVMCoreUIMoleculeMappingObject { + func getMoleculeClass(_ model: MoleculeProtocol) -> AnyClass? { + if let moleculeName = model.moleculeName { + return moleculeMapping.object(forKey: moleculeName) as? AnyClass + } + return nil + } + func createMolecule(_ model: MoleculeProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> (UIView & MVMCoreUIMoleculeViewProtocol)? { return createMolecule(model, delegateObject, false) } @@ -25,7 +31,7 @@ public extension MVMCoreUIMoleculeMappingObject { if let molecule = molecule as? ModelMoleculeViewProtocol { molecule.setWithModel(model, delegateObject, nil) } else { - molecule.setWithJSON(model.dictionary, delegateObject: delegateObject, additionalData: nil) + molecule.setWithJSON?(model.dictionary, delegateObject: delegateObject, additionalData: nil) } } diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.h b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.h index 776566c8..6c1a84b2 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.h +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.h @@ -29,10 +29,10 @@ - (nullable UIView *)createMoleculeForName:(nonnull NSString *)name; /// Creates the molecule for the molecule json. -- (nullable UIView *)createMoleculeForJSON:(nonnull NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject; - -/// Creates the molecule for the molecule json. Also checks if the molecule needs to be constrained for a stack/list style situation. -- (nullable UIView *)createMoleculeForJSON:(nonnull NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject constrainIfNeeded:(BOOL)constrainIfNeeded; +//- (nullable UIView *)createMoleculeForJSON:(nonnull NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject; +// +///// Creates the molecule for the molecule json. Also checks if the molecule needs to be constrained for a stack/list style situation. +//- (nullable UIView *)createMoleculeForJSON:(nonnull NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject constrainIfNeeded:(BOOL)constrainIfNeeded; #pragma mark - Convenience diff --git a/MVMCoreUI/OtherHandlers/ModelMoleculeDelegateProtocol.swift b/MVMCoreUI/OtherHandlers/ModelMoleculeDelegateProtocol.swift new file mode 100644 index 00000000..2120333e --- /dev/null +++ b/MVMCoreUI/OtherHandlers/ModelMoleculeDelegateProtocol.swift @@ -0,0 +1,14 @@ +// +// MoleculeDelegateProtocol.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 11/26/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + +public protocol ModelMoleculeDelegateProtocol { + func addMolecules(_ molecules: [MoleculeProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) + func removeMolecules(_ molecules: [MoleculeProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) +} diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index e6182bf7..0d645e35 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -8,9 +8,26 @@ import UIKit -open class MoleculeListTemplate: ThreeLayerTableViewController { - public var moleculesInfo: [(identifier: String, class: AnyClass, molecule: [AnyHashable: Any])]? +open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol, ModelMoleculeDelegateProtocol { + + public var moleculesInfo: [(identifier: String, class: AnyClass, molecule: MoleculeProtocol)]? var observer: NSKeyValueObservation? + + public var templateModel: TemplateModelProtocol? + + public func parseTemplateJSON() { + guard let templateData = templateData() else { + return + } + + do { + let decoder = JSONDecoder() + let templateModel = try decoder.decode(ListPageTemplateModel.self, from: templateData) + self.templateModel = templateModel + } catch { + MVMCoreUILoggingHandler.logDebugMessage(withDelegate: "error: \(error)") + } + } open override var loadObject: MVMCoreLoadObject? { didSet { @@ -27,21 +44,17 @@ open class MoleculeListTemplate: ThreeLayerTableViewController { } open override func viewForTop() -> UIView { -// guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("header"), -// let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, constrainIfNeeded: true) else { -// return super.viewForTop() -// } - guard let moleculeModel = pageModel?.header, - let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(moleculeModel, delegateObject() as? MVMCoreUIDelegateObject, true) else { - return super.viewForTop() + guard let headerModel = (templateModel as? ListPageTemplateModel)?.header, + let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(headerModel, delegateObject() as? MVMCoreUIDelegateObject, true) else { + return super.viewForTop() } return molecule } override open func viewForBottom() -> UIView { - guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("footer"), - let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, constrainIfNeeded: true) else { - return super.viewForBottom() + guard let footerModel = (templateModel as? ListPageTemplateModel)?.footer, + let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(footerModel, delegateObject() as? MVMCoreUIDelegateObject, true) else { + return super.viewForBottom() } return molecule } @@ -64,7 +77,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController { open override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { guard let moleculeInfo = moleculesInfo?[indexPath.row], - let estimatedHeight = moleculeInfo.class.estimatedHeight?(forRow: moleculeInfo.molecule, delegateObject: delegateObject() as? MVMCoreUIDelegateObject) else { + let estimatedHeight = (moleculeInfo.class as? ModelMoleculeViewProtocol.Type)?.estimatedHeight(forRow: moleculeInfo.molecule, delegateObject: delegateObject() as? MVMCoreUIDelegateObject) else { return 0 } return estimatedHeight @@ -85,7 +98,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController { } if let protocolCell = cell as? MVMCoreUIMoleculeViewProtocol { protocolCell.reset?() - protocolCell.setWithJSON(moleculeInfo.molecule, delegateObject: delegate, additionalData: nil) + (protocolCell as? ModelMoleculeViewProtocol)?.setWithModel(moleculeInfo.molecule, delegate, nil) protocolCell.updateView(tableView.bounds.width) } return cell @@ -126,56 +139,58 @@ open class MoleculeListTemplate: ThreeLayerTableViewController { } } } - - open override func addMolecules(_ molecules: [[AnyHashable : Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) { + + public func addMolecules(_ molecules: [MoleculeProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) { // This dispatch is needed to fix a race condition that can occur if this function is called during the table setup. - DispatchQueue.main.async { - guard let indexPath = self.tableView?.indexPath(for: sender) else { return } - var indexPaths: [IndexPath] = [] - for molecule in molecules { - if let info = self.getMoleculeInfo(with: molecule) { - self.tableView?.register(info.class, forCellReuseIdentifier: info.identifier) - let index = indexPath.row + 1 + indexPaths.count - self.moleculesInfo?.insert(info, at: index) - indexPaths.append(IndexPath(row: index, section: 0)) - } - } - self.tableView?.insertRows(at: indexPaths, with: animation) - self.updateViewConstraints() - self.view.layoutIfNeeded() - } + DispatchQueue.main.async { + guard let indexPath = self.tableView?.indexPath(for: sender) else { return } + var indexPaths: [IndexPath] = [] + for molecule in molecules { + if let info = self.getMoleculeInfo(with: molecule) { + self.tableView?.register(info.class, forCellReuseIdentifier: info.identifier) + let index = indexPath.row + 1 + indexPaths.count + self.moleculesInfo?.insert(info, at: index) + indexPaths.append(IndexPath(row: index, section: 0)) + } + } + self.tableView?.insertRows(at: indexPaths, with: animation) + self.updateViewConstraints() + self.view.layoutIfNeeded() + } } - - open override func removeMolecules(_ molecules: [[AnyHashable : Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) { + public func removeMolecules(_ molecules: [MoleculeProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) { var indexPaths: [IndexPath] = [] - for molecule in molecules { - if let removeIndex = moleculesInfo?.firstIndex(where: { (moleculeInfo) -> Bool in - return NSDictionary(dictionary: molecule).isEqual(to: moleculeInfo.molecule) - }) { - moleculesInfo?.remove(at: removeIndex) - indexPaths.append(IndexPath(row: removeIndex + indexPaths.count, section: 0)) - } - } + //TODO: cehck for molecule protocola eqality +// for molecule in molecules { +// if let removeIndex = moleculesInfo?.firstIndex(where: { (moleculeInfo) -> Bool in +// return molecule == moleculeInfo.molecule +// }) { +// moleculesInfo?.remove(at: removeIndex) +// indexPaths.append(IndexPath(row: removeIndex + indexPaths.count, section: 0)) +// } +// } self.tableView?.deleteRows(at: indexPaths, with: animation) self.updateViewConstraints() self.view.layoutIfNeeded() } + + // MARK: - Convenience /// Returns the (identifier, class) of the molecule for the given map. - func getMoleculeInfo(with molecule: [AnyHashable: Any]?) -> (identifier: String, class: AnyClass, molecule: [AnyHashable: Any])? { + func getMoleculeInfo(with molecule: MoleculeProtocol?) -> (identifier: String, class: AnyClass, molecule: MoleculeProtocol)? { guard let molecule = molecule, - let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: molecule), - let moleculeName = moleculeClass.name?(forReuse: molecule, delegateObject: delegateObject() as? MVMCoreUIDelegateObject) ?? molecule.optionalStringForKey(KeyMoleculeName) else { + let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(molecule), + let moleculeName = (moleculeClass as? ModelMoleculeViewProtocol.Type)?.name(forReuse: molecule, delegateObject: delegateObject() as? MVMCoreUIDelegateObject) ?? molecule.moleculeName else { return nil } return (moleculeName, moleculeClass, molecule) } /// Sets up the molecule list and ensures no errors loading all content. - func getMoleculeInfoList() -> [(identifier: String, class: AnyClass, molecule: [AnyHashable: Any])]? { - var moleculeList: [(identifier: String, class: AnyClass, molecule: [AnyHashable: Any])] = [] - if let molecules = loadObject?.pageJSON?.optionalArrayForKey(KeyMolecules) as? [[AnyHashable: Any]] { + func getMoleculeInfoList() -> [(identifier: String, class: AnyClass, molecule: MoleculeProtocol)]? { + var moleculeList: [(identifier: String, class: AnyClass, molecule: MoleculeProtocol)] = [] + if let molecules = (templateModel as? ListPageTemplateModel)?.molecules { for molecule in molecules { if let info = getMoleculeInfo(with: molecule) { moleculeList.append(info) @@ -187,8 +202,8 @@ open class MoleculeListTemplate: ThreeLayerTableViewController { /// Sets up the header, footer, molecule list and ensures no errors loading all content. func setup() { - var moleculeList: [(identifier: String, class: AnyClass, molecule: [AnyHashable: Any])] = [] - if let molecules = loadObject?.pageJSON?.optionalArrayForKey(KeyMolecules) as? [[AnyHashable: Any]] { + var moleculeList: [(identifier: String, class: AnyClass, molecule: MoleculeProtocol)] = [] + if let molecules = loadObject?.pageJSON?.optionalArrayForKey(KeyMolecules) as? [MoleculeProtocol] { for molecule in molecules { if let info = getMoleculeInfo(with: molecule) { moleculeList.append(info) diff --git a/MVMCoreUI/Templates/MoleculeStackTemplate.swift b/MVMCoreUI/Templates/MoleculeStackTemplate.swift index dad4d5ef..dacbd2cb 100644 --- a/MVMCoreUI/Templates/MoleculeStackTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeStackTemplate.swift @@ -8,8 +8,24 @@ import UIKit -open class MoleculeStackTemplate: ThreeLayerViewController { +open class MoleculeStackTemplate: ThreeLayerViewController, TemplateProtocol { + var observer: NSKeyValueObservation? + public var templateModel: TemplateModelProtocol? + + public func parseTemplateJSON() { + guard let templateData = templateData() else { + return + } + + do { + let decoder = JSONDecoder() + let templateModel = try decoder.decode(StackPageTemplateModel.self, from: templateData) + self.templateModel = templateModel + } catch { + MVMCoreUILoggingHandler.logDebugMessage(withDelegate: "error: \(error)") + } + } open override var loadObject: MVMCoreLoadObject? { didSet { @@ -30,29 +46,29 @@ open class MoleculeStackTemplate: ThreeLayerViewController { } open override func viewForTop() -> UIView? { - guard let moleculeModel = pageModel?.header, - let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(moleculeModel, delegateObject() as? MVMCoreUIDelegateObject, true) else { - return nil + guard let headerModel = (templateModel as? StackPageTemplateModel)?.header, + let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(headerModel, delegateObject() as? MVMCoreUIDelegateObject, true) else { + return nil } -// guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("header"), let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, constrainIfNeeded: true) else { -// return nil -// } return molecule } open override func viewForMiddle() -> UIView? { - guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("moleculeStack") else { - return nil + + guard let moleculeStackModel = (templateModel as? StackPageTemplateModel)?.moleculeStack else { + return nil } + let stack = MoleculeStackView(frame: .zero) stack.useStackSpacingBeforeFirstItem = true - stack.setWithJSON(moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, additionalData: nil) + stack.setWithModel(moleculeStackModel, delegateObject() as? MVMCoreUIDelegateObject, nil) return stack } override open func viewForBottom() -> UIView? { - guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("footer"), let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, constrainIfNeeded: true) else { - return nil + guard let footerModel = (templateModel as? StackPageTemplateModel)?.footer, + let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(footerModel, delegateObject() as? MVMCoreUIDelegateObject, true) else { + return nil } return molecule } diff --git a/MVMCoreUI/Templates/ThreeLayerTemplate.swift b/MVMCoreUI/Templates/ThreeLayerTemplate.swift index 20475a6b..f87a1e29 100644 --- a/MVMCoreUI/Templates/ThreeLayerTemplate.swift +++ b/MVMCoreUI/Templates/ThreeLayerTemplate.swift @@ -8,7 +8,23 @@ import UIKit -@objcMembers open class ThreeLayerTemplate: ThreeLayerViewController { +@objcMembers open class ThreeLayerTemplate: ThreeLayerViewController, TemplateProtocol { + + public var templateModel: TemplateModelProtocol? + + public func parseTemplateJSON() { + guard let templateData = templateData() else { + return + } + + do { + let decoder = JSONDecoder() + let templateModel = try decoder.decode(StackPageTemplateModel.self, from: templateData) + self.templateModel = templateModel + } catch { + MVMCoreUILoggingHandler.logDebugMessage(withDelegate: "error: \(error)") + } + } override open func viewDidLoad() { super.viewDidLoad() @@ -20,24 +36,28 @@ import UIKit super.newDataBuildScreen() heightConstraint?.isActive = true } - + + open override func viewForTop() -> UIView? { - guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("header"), let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, constrainIfNeeded: true) else { - return nil + guard let headerModel = (templateModel as? ThreeLayerPageTemplateModel)?.header, + let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(headerModel, delegateObject() as? MVMCoreUIDelegateObject, true) else { + return nil } return molecule } open override func viewForMiddle() -> UIView? { - guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("middle"), let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, constrainIfNeeded: true) else { - return nil + guard let middleModel = (templateModel as? ThreeLayerPageTemplateModel)?.middle, + let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(middleModel, delegateObject() as? MVMCoreUIDelegateObject, true) else { + return nil } return molecule } override open func viewForBottom() -> UIView? { - guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("footer"), let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, constrainIfNeeded: true) else { - return nil + guard let footerModel = (templateModel as? ThreeLayerPageTemplateModel)?.footer, + let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(footerModel, delegateObject() as? MVMCoreUIDelegateObject, true) else { + return nil } return molecule } From 9195f96a687ab56b7d4d0a21cb1c101c8c34e3fd Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 27 Nov 2019 14:29:20 -0500 Subject: [PATCH 02/51] fixes --- MVMCoreUI/Models/Molecules/HeaderModel.swift | 9 +++- MVMCoreUI/Models/Molecules/LabelModel.swift | 2 + .../Molecules/MoleculeStackItemModel.swift | 12 +++--- .../Models/Molecules/MoleculeStackModel.swift | 4 +- .../EyebrowHeadlineBodyLink.swift | 8 ++-- MVMCoreUI/Organisms/MoleculeStackView.swift | 41 +++++++++++-------- 6 files changed, 45 insertions(+), 31 deletions(-) diff --git a/MVMCoreUI/Models/Molecules/HeaderModel.swift b/MVMCoreUI/Models/Molecules/HeaderModel.swift index 0dca783c..b907b353 100644 --- a/MVMCoreUI/Models/Molecules/HeaderModel.swift +++ b/MVMCoreUI/Models/Molecules/HeaderModel.swift @@ -15,27 +15,34 @@ import Foundation public var molecule: MoleculeProtocol? public var seperator: MoleculeProtocol? - public init(molecule: MoleculeProtocol?){ + public init(molecule: MoleculeProtocol?, backgroundColor: String?, seperator: MoleculeProtocol?){ self.molecule = molecule self.moleculeName = Self.identifier + self.backgroundColor = backgroundColor + self.seperator = seperator } enum CodingKeys: String, CodingKey { case moleculeName case molecule + case backgroundColor case separator } required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName) + self.backgroundColor = try typeContainer.decode(String.self, forKey: .backgroundColor) self.molecule = try typeContainer.decodeIfPresent(codingKey: .molecule) + self.seperator = try typeContainer.decodeIfPresent(codingKey: .separator) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(self.molecule, forKey: .molecule) + try container.encode(backgroundColor, forKey: .backgroundColor) + try container.encodeIfPresent(self.seperator, forKey: .separator) } } diff --git a/MVMCoreUI/Models/Molecules/LabelModel.swift b/MVMCoreUI/Models/Molecules/LabelModel.swift index 0886524a..859627d5 100644 --- a/MVMCoreUI/Models/Molecules/LabelModel.swift +++ b/MVMCoreUI/Models/Molecules/LabelModel.swift @@ -11,5 +11,7 @@ import Foundation @objcMembers public class LabelModel: MoleculeProtocol { public static var identifier: String = "label" + public var moleculeName: String? public var text: String? + public var spacing: Int? } diff --git a/MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift b/MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift index 9c75b582..ea01c844 100644 --- a/MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift +++ b/MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift @@ -17,7 +17,7 @@ import Foundation public var percentage: Int? public var verticalAlignment: String? public var horizontalAlignment: String? - public var gone = false + public var gone: Bool? = false public init(molecule: MoleculeProtocol?, spacing: CGFloat?, percentage: Int?, verticalAlignment: String?, horizontalAlignment: String?, gone: Bool = false) { self.molecule = molecule @@ -44,11 +44,11 @@ import Foundation self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName) self.molecule = try typeContainer.decodeIfPresent(codingKey: .molecule) - self.spacing = try typeContainer.decode(CGFloat.self, forKey: .spacing) - self.percentage = try typeContainer.decode(Int.self, forKey: .percentage) - self.verticalAlignment = try typeContainer.decode(String.self, forKey: .verticalAlignment) - self.horizontalAlignment = try typeContainer.decode(String.self, forKey: .horizontalAlignment) - self.gone = try typeContainer.decode(Bool.self, forKey: .gone) + self.spacing = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .spacing) + self.percentage = try typeContainer.decodeIfPresent(Int.self, forKey: .percentage) + self.verticalAlignment = try typeContainer.decodeIfPresent(String.self, forKey: .verticalAlignment) + self.horizontalAlignment = try typeContainer.decodeIfPresent(String.self, forKey: .horizontalAlignment) + self.gone = try typeContainer.decodeIfPresent(Bool.self, forKey: .gone) } public func encode(to encoder: Encoder) throws { diff --git a/MVMCoreUI/Models/Molecules/MoleculeStackModel.swift b/MVMCoreUI/Models/Molecules/MoleculeStackModel.swift index bad35824..088a2733 100644 --- a/MVMCoreUI/Models/Molecules/MoleculeStackModel.swift +++ b/MVMCoreUI/Models/Molecules/MoleculeStackModel.swift @@ -32,8 +32,8 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - self.moleculeName = try typeContainer.decodeIfPresent(String.self, forKey: .moleculeName) - self.molecules = try typeContainer.decode([MoleculeStackItemModel].self, forKey: .molecules) + self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName) + self.molecules = try typeContainer.decodeIfPresent([MoleculeStackItemModel].self, forKey: .molecules) self.axis = try typeContainer.decodeIfPresent(String.self, forKey: .axis) self.spacing = try typeContainer.decodeIfPresent(Float.self, forKey: .spacing) } diff --git a/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift b/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift index a7d96a34..c9f2299f 100644 --- a/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift +++ b/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift @@ -44,13 +44,13 @@ import UIKit open override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) eyebrow.setWithJSON(json?.optionalDictionaryForKey("eyebrow"), delegateObject: delegateObject, additionalData: additionalData) - stack.items[0].gone = !eyebrow.hasText + stack.stackItems[0].gone = !eyebrow.hasText headline.setWithJSON(json?.optionalDictionaryForKey("headline"), delegateObject: delegateObject, additionalData: additionalData) - stack.items[1].gone = !headline.hasText + stack.stackItems[1].gone = !headline.hasText body.setWithJSON(json?.optionalDictionaryForKey("body"), delegateObject: delegateObject, additionalData: additionalData) - stack.items[2].gone = !body.hasText + stack.stackItems[2].gone = !body.hasText link.setWithJSON(json?.optionalDictionaryForKey("link"), delegateObject: delegateObject, additionalData: additionalData) - stack.items[3].gone = link.titleLabel?.text?.count ?? 0 == 0 + stack.stackItems[3].gone = link.titleLabel?.text?.count ?? 0 == 0 stack.restack() } diff --git a/MVMCoreUI/Organisms/MoleculeStackView.swift b/MVMCoreUI/Organisms/MoleculeStackView.swift index c47ca142..fd6896e4 100644 --- a/MVMCoreUI/Organisms/MoleculeStackView.swift +++ b/MVMCoreUI/Organisms/MoleculeStackView.swift @@ -45,7 +45,7 @@ public class StackItem { public class MoleculeStackView: ViewConstrainingView, ModelMoleculeViewProtocol { var contentView: UIView = MVMCoreUICommonViewsUtility.commonView() - var items: [StackItem] = [] + var stackItems: [StackItem] = [] var useStackSpacingBeforeFirstItem = false var moleculeStackModel: MoleculeStackModel? @@ -88,12 +88,12 @@ public class MoleculeStackView: ViewConstrainingView, ModelMoleculeViewProtocol /// Restacks the existing items. func restack() { - setWithStackItems(items) + setWithStackItems(stackItems) } /// Removes all stack items views from the view. func removeAllItemViews() { - for item in items { + for item in stackItems { item.view.removeFromSuperview() } } @@ -130,7 +130,7 @@ public class MoleculeStackView: ViewConstrainingView, ModelMoleculeViewProtocol public override func updateView(_ size: CGFloat) { super.updateView(size) - for item in items { + for item in stackItems { (item.view as? MVMCoreViewProtocol)?.updateView(size) } } @@ -140,7 +140,7 @@ public class MoleculeStackView: ViewConstrainingView, ModelMoleculeViewProtocol super.reset() backgroundColor = .clear updateViewHorizontalDefaults = true - for item in items { + for item in stackItems { if let view = item.view as? MVMCoreUIMoleculeViewProtocol { view.reset?() } @@ -163,10 +163,15 @@ public class MoleculeStackView: ViewConstrainingView, ModelMoleculeViewProtocol // If the items in the stack are the same, just update previous items instead of re-allocating. var items: [StackItem]? - if MoleculeStackView.name(forReuse: previousModel, delegateObject: delegateObject) == MoleculeStackView.name(forReuse: model, delegateObject: delegateObject) { - items = self.items + if let previousModel = previousModel { + let previoudReuseName = MoleculeStackView.name(forReuse: previousModel, delegateObject: delegateObject) + let currentReuseName = MoleculeStackView.name(forReuse: model, delegateObject: delegateObject) + if previoudReuseName == currentReuseName { + items = self.stackItems + } } - self.items = [] + + self.stackItems = [] guard let molecules = model.molecules else { return @@ -176,15 +181,15 @@ public class MoleculeStackView: ViewConstrainingView, ModelMoleculeViewProtocol //setAxisWithJSON(json) spacing = CGFloat(model.spacing ?? 16) - for (index, moleculeContainer) in molecules.enumerated() { - if let stackItemModel = moleculeContainer.molecule as? MoleculeStackItemModel { + for (index, stackItemModel) in molecules.enumerated() { + if let moleculeModel = stackItemModel.molecule { var view: UIView? if let item = items?[index] { item.update(with: stackItemModel) view = item.view - (view as? ModelMoleculeViewProtocol)?.setWithModel(stackItemModel, delegateObject, nil) + (view as? ModelMoleculeViewProtocol)?.setWithModel(moleculeModel, delegateObject, nil) addStackItem(item, lastItem: index == molecules.count - 1) - } else if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(stackItemModel, delegateObject, true) { + } else if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(moleculeModel, delegateObject, true) { view = moleculeView addStackItem(StackItem(with: moleculeView, stackItemModel: stackItemModel), lastItem: index == molecules.count - 1) } @@ -254,7 +259,7 @@ public class MoleculeStackView: ViewConstrainingView, ModelMoleculeViewProtocol /// Adds the stack item to the stack. func addStackItem(_ stackItem: StackItem, lastItem: Bool) { guard !stackItem.gone else { - items.append(stackItem) + stackItems.append(stackItem) return } let view = stackItem.view @@ -268,11 +273,11 @@ public class MoleculeStackView: ViewConstrainingView, ModelMoleculeViewProtocol view.alignHorizontal?(horizontalAlignment) view.alignVertical?(verticalAlignment) } - let first = items.first { !$0.gone } == nil + let first = stackItems.first { !$0.gone } == nil if axis == .vertical { if first { pinView(view, toView: contentView, attribute: .top, relation: .equal, priority: .required, constant: useStackSpacingBeforeFirstItem ? spacing : stackItem.spacing ?? 0) - } else if let previousView = items.last(where: { stackItem in + } else if let previousView = stackItems.last(where: { stackItem in return !stackItem.gone })?.view { _ = NSLayoutConstraint(pinFirstView: previousView, toSecondView: view, withConstant: spacing, directionVertical: true) @@ -289,7 +294,7 @@ public class MoleculeStackView: ViewConstrainingView, ModelMoleculeViewProtocol if first { // First horizontal item has no spacing by default unless told otherwise. pinView(view, toView: contentView, attribute: .leading, relation: .equal, priority: .required, constant: useStackSpacingBeforeFirstItem ? spacing : stackItem.spacing ?? 0) - } else if let previousView = items.last(where: { stackItem in + } else if let previousView = stackItems.last(where: { stackItem in return !stackItem.gone })?.view { _ = NSLayoutConstraint(pinFirstView: previousView, toSecondView: view, withConstant: spacing, directionVertical: false) @@ -303,12 +308,12 @@ public class MoleculeStackView: ViewConstrainingView, ModelMoleculeViewProtocol if lastItem { pinView(contentView, toView: view, attribute: .right, relation: .equal, priority: .required, constant: 0) } - items.append(stackItem) + stackItems.append(stackItem) } func setWithStackItems(_ items: [StackItem]) { removeAllItemViews() - self.items.removeAll() + self.stackItems.removeAll() var previousPresentItem: StackItem? = nil for item in items { if !item.gone { From 0648ec0191057ae9e70f7bfa017a1e945f8c85f6 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 27 Nov 2019 17:25:23 -0500 Subject: [PATCH 03/51] fixes --- MVMCoreUI.xcodeproj/project.pbxproj | 4 ++ MVMCoreUI/Models/Molecules/FooterModel.swift | 44 +++++++++++++++++++ MVMCoreUI/Models/Molecules/HeaderModel.swift | 10 ++--- .../Models/Molecules/HeadlineBodyModel.swift | 17 +++++++ .../Models/Molecules/SeperatorModel.swift | 2 +- .../Template/StackPageTemplateModel.swift | 4 +- 6 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 MVMCoreUI/Models/Molecules/FooterModel.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index f3d044ed..fc52bc65 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ 012A88C8238DB02000FE3DA1 /* ModelMoleculeDelegateProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88C7238DB02000FE3DA1 /* ModelMoleculeDelegateProtocol.swift */; }; 012A88DA238ED42E00FE3DA1 /* StackPageTemplateModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012CA9DF23888AC8003F810F /* StackPageTemplateModel.swift */; }; 012A88DB238ED45900FE3DA1 /* CarouselModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88AE238C626E00FE3DA1 /* CarouselModel.swift */; }; + 012A88EC238F084D00FE3DA1 /* FooterModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88EB238F084D00FE3DA1 /* FooterModel.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 */; }; @@ -263,6 +264,7 @@ 012A88C3238D86E600FE3DA1 /* CollectionCellMoleculeProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionCellMoleculeProtocol.swift; sourceTree = ""; }; 012A88C5238DA34000FE3DA1 /* ModuleMoleculeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModuleMoleculeModel.swift; sourceTree = ""; }; 012A88C7238DB02000FE3DA1 /* ModelMoleculeDelegateProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelMoleculeDelegateProtocol.swift; sourceTree = ""; }; + 012A88EB238F084D00FE3DA1 /* FooterModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FooterModel.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 = ""; }; @@ -556,6 +558,7 @@ 01EB368A23609801006832FA /* MoleculeStackItemModel.swift */, 01EB368B23609801006832FA /* MoleculeStackModel.swift */, 01EB368C23609801006832FA /* HeaderModel.swift */, + 012A88EB238F084D00FE3DA1 /* FooterModel.swift */, 01EB368D23609801006832FA /* HeadlineBodyModel.swift */, 017BEB3F23620A230024EF95 /* TextFieldModel.swift */, 017BEB4123620AD20024EF95 /* FormModelProtocol.swift */, @@ -1301,6 +1304,7 @@ D282AABA224131D100C46919 /* MFTransparentGIFView.swift in Sources */, 944589232385DA9600DE9FD4 /* ImageViewModel.swift in Sources */, D213347723843825008E41B3 /* Line.swift in Sources */, + 012A88EC238F084D00FE3DA1 /* FooterModel.swift in Sources */, D2A514672213885800345BFB /* StandardHeaderView.swift in Sources */, 01EB369023609801006832FA /* ListItemModel.swift in Sources */, D268C70C2386DFFD007F2C1C /* MoleculeStackItemModel.swift in Sources */, diff --git a/MVMCoreUI/Models/Molecules/FooterModel.swift b/MVMCoreUI/Models/Molecules/FooterModel.swift new file mode 100644 index 00000000..38d55edd --- /dev/null +++ b/MVMCoreUI/Models/Molecules/FooterModel.swift @@ -0,0 +1,44 @@ +// +// FooterModel.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 11/27/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + + +@objcMembers public class FooterModel: ConstrainingMoleculeProtocol { + public static var identifier: String = "footer" + public var moleculeName: String? + public var backgroundColor: String? + public var molecule: MoleculeProtocol? + + public init(molecule: MoleculeProtocol?, backgroundColor: String?){ + self.molecule = molecule + self.moleculeName = Self.identifier + self.backgroundColor = backgroundColor + } + + enum CodingKeys: String, CodingKey { + case moleculeName + case molecule + case backgroundColor + case separator + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName) + self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) + self.molecule = try typeContainer.decodeIfPresent(codingKey: .molecule) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(moleculeName, forKey: .moleculeName) + try container.encodeIfPresent(self.molecule, forKey: .molecule) + try container.encodeIfPresent(self.backgroundColor, forKey: .backgroundColor) + } +} diff --git a/MVMCoreUI/Models/Molecules/HeaderModel.swift b/MVMCoreUI/Models/Molecules/HeaderModel.swift index b907b353..a1cd7cec 100644 --- a/MVMCoreUI/Models/Molecules/HeaderModel.swift +++ b/MVMCoreUI/Models/Molecules/HeaderModel.swift @@ -13,9 +13,9 @@ import Foundation public var moleculeName: String? public var backgroundColor: String? public var molecule: MoleculeProtocol? - public var seperator: MoleculeProtocol? + public var seperator: SeperatorModel? - public init(molecule: MoleculeProtocol?, backgroundColor: String?, seperator: MoleculeProtocol?){ + public init(molecule: MoleculeProtocol?, backgroundColor: String?, seperator: SeperatorModel?){ self.molecule = molecule self.moleculeName = Self.identifier self.backgroundColor = backgroundColor @@ -32,16 +32,16 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName) - self.backgroundColor = try typeContainer.decode(String.self, forKey: .backgroundColor) + self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) self.molecule = try typeContainer.decodeIfPresent(codingKey: .molecule) - self.seperator = try typeContainer.decodeIfPresent(codingKey: .separator) + self.seperator = try typeContainer.decodeIfPresent(SeperatorModel.self, forKey: .separator) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(self.molecule, forKey: .molecule) - try container.encode(backgroundColor, forKey: .backgroundColor) + try container.encodeIfPresent(self.backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(self.seperator, forKey: .separator) } } diff --git a/MVMCoreUI/Models/Molecules/HeadlineBodyModel.swift b/MVMCoreUI/Models/Molecules/HeadlineBodyModel.swift index 557e74ba..571edd5b 100644 --- a/MVMCoreUI/Models/Molecules/HeadlineBodyModel.swift +++ b/MVMCoreUI/Models/Molecules/HeadlineBodyModel.swift @@ -17,5 +17,22 @@ import Foundation self.headline = headline self.moleculeName = Self.identifier } + + enum CodingKeys: String, CodingKey { + case moleculeName + case headline + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName) + self.headline = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .headline) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(moleculeName, forKey: .moleculeName) + try container.encodeIfPresent(self.headline, forKey: .headline) + } } diff --git a/MVMCoreUI/Models/Molecules/SeperatorModel.swift b/MVMCoreUI/Models/Molecules/SeperatorModel.swift index cdc1cb3c..55f2ae75 100644 --- a/MVMCoreUI/Models/Molecules/SeperatorModel.swift +++ b/MVMCoreUI/Models/Molecules/SeperatorModel.swift @@ -10,5 +10,5 @@ import UIKit @objcMembers public class SeperatorModel: MoleculeProtocol { public static var identifier: String = "line" - public var type: String? + public var type: String } diff --git a/MVMCoreUI/Models/Template/StackPageTemplateModel.swift b/MVMCoreUI/Models/Template/StackPageTemplateModel.swift index e1030f35..d05d91f3 100644 --- a/MVMCoreUI/Models/Template/StackPageTemplateModel.swift +++ b/MVMCoreUI/Models/Template/StackPageTemplateModel.swift @@ -18,7 +18,7 @@ import Foundation public var isAtomicTabs: Bool? - public var header: MoleculeStackModel? + public var header: HeaderModel? public var moleculeStack: MoleculeStackModel? - public var footer: MoleculeStackModel? + public var footer: FooterModel? } From d00a04831d183587c72765e17ddb7f98809cefa5 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 3 Dec 2019 09:19:55 -0500 Subject: [PATCH 04/51] fixes --- .../Models/Molecules/HeadlineBodyModel.swift | 20 +++++++--- .../HeadlineBody.swift | 37 +++++++++++++------ 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/MVMCoreUI/Models/Molecules/HeadlineBodyModel.swift b/MVMCoreUI/Models/Molecules/HeadlineBodyModel.swift index 571edd5b..f4a8a0f3 100644 --- a/MVMCoreUI/Models/Molecules/HeadlineBodyModel.swift +++ b/MVMCoreUI/Models/Molecules/HeadlineBodyModel.swift @@ -11,28 +11,38 @@ import Foundation @objcMembers public class HeadlineBodyModel: MoleculeProtocol { public static var identifier: String = "headlineBody" public var moleculeName: String? - public var headline: LabelModel? + public var style: String? + public var headline: LabelModel + public var body: LabelModel - public init(headline: LabelModel?) { - self.headline = headline + public init(style: String?, headline: LabelModel, body: LabelModel) { self.moleculeName = Self.identifier + self.style = style + self.headline = headline + self.body = body } enum CodingKeys: String, CodingKey { case moleculeName + case style case headline + case body } required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName) - self.headline = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .headline) + self.headline = try typeContainer.decode(LabelModel.self, forKey: .headline) + self.body = try typeContainer.decode(LabelModel.self, forKey: .body) + self.style = try typeContainer.decodeIfPresent(String.self, forKey: .style) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) - try container.encodeIfPresent(self.headline, forKey: .headline) + try container.encode(headline, forKey: .headline) + try container.encode(body, forKey: .body) + try container.encodeIfPresent(self.style, forKey: .style) } } diff --git a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBody.swift b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBody.swift index d236fc37..cc313d59 100644 --- a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBody.swift +++ b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBody.swift @@ -8,7 +8,7 @@ import UIKit -open class HeadlineBody: ViewConstrainingView { +open class HeadlineBody: ViewConstrainingView, ModelMoleculeViewProtocol { let headlineLabel = Label.commonLabelH2(true) let messageLabel = Label.commonLabelB2(true) var spaceBetweenLabelsConstant = PaddingTwo @@ -118,18 +118,31 @@ open class HeadlineBody: ViewConstrainingView { spaceBetweenLabels?.constant = 0 } } - - // MARK: - MVMCoreUIMoleculeViewProtocol - open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - - style(with: json?.optionalStringForKey("style")) - - let headlineJSON = json?.optionalDictionaryForKey("headline") - headlineLabel.setWithJSON(headlineJSON, delegateObject: delegateObject, additionalData: additionalData) - let bodyJSON = json?.optionalDictionaryForKey("body") - messageLabel.setWithJSON(bodyJSON, delegateObject: delegateObject, additionalData: additionalData) + + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + + setUpWithModel(model, delegateObject, additionalData) + guard let headlineBodyModel = model as? HeadlineBodyModel else { + return + } + + style(with: headlineBodyModel.style) + + headlineLabel.setWithModel(headlineBodyModel.headline, delegateObject, additionalData) + messageLabel.setWithModel(headlineBodyModel.body, delegateObject, additionalData) } +// // MARK: - MVMCoreUIMoleculeViewProtocol +// open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { +// super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) +// +// style(with: json?.optionalStringForKey("style")) +// +// let headlineJSON = json?.optionalDictionaryForKey("headline") +// headlineLabel.setWithJSON(headlineJSON, delegateObject: delegateObject, additionalData: additionalData) +// +// let bodyJSON = json?.optionalDictionaryForKey("body") +// messageLabel.setWithJSON(bodyJSON, delegateObject: delegateObject, additionalData: additionalData) +// } open override func reset() { super.reset() From 0288943746d9dc2a0d6772e6008b13802cea8d53 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 4 Dec 2019 14:27:45 -0500 Subject: [PATCH 05/51] fixes --- .../MVMCoreUIMoleculeMappingObject+ModelExtension.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelExtension.swift b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelExtension.swift index 0fb7370e..070c8680 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelExtension.swift +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelExtension.swift @@ -27,7 +27,7 @@ public extension MVMCoreUIMoleculeMappingObject { return nil } - let setData = {(molecule: UIView & MVMCoreUIMoleculeViewProtocol) in + let setData = {() in if let molecule = molecule as? ModelMoleculeViewProtocol { molecule.setWithModel(model, delegateObject, nil) } else { @@ -38,10 +38,10 @@ public extension MVMCoreUIMoleculeMappingObject { if constrainIfNeeded, let castMolecule = molecule as? MVMCoreUIViewConstrainingProtocol, castMolecule.needsToBeConstrained?() ?? false { let view = ViewConstrainingView(molecule: molecule, alignment: castMolecule.alignment?() ?? .fill) - setData(view) + setData() return view } else { - setData(molecule) + setData() return molecule } } From 3a1e3356bf148c9c7d647a10ecb8e871b7ac13df Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Fri, 6 Dec 2019 14:30:19 -0500 Subject: [PATCH 06/51] module molecule --- MVMCoreUI.xcodeproj/project.pbxproj | 4 ++ .../MFViewController+Model.swift | 16 +++++ .../Molecules/ModuleMoleculeModel.swift | 2 +- MVMCoreUI/Molecules/ModuleMolecule.swift | 64 +++++-------------- .../MVMCoreUIDelegateObject.swift | 3 + .../MVMCoreUIMoleculeMappingObject.h | 8 +-- .../ModuleDelegateProtocol.swift | 14 ++++ .../OtherHandlers/MoleculeObjectMapping.swift | 1 + 8 files changed, 60 insertions(+), 52 deletions(-) create mode 100644 MVMCoreUI/OtherHandlers/ModuleDelegateProtocol.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 88dc904d..f022ef91 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -45,6 +45,7 @@ 017BEB4A236235BA0024EF95 /* ModelMoleculeViewProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB49236235BA0024EF95 /* ModelMoleculeViewProtocol.swift */; }; 017BEB7B236763000024EF95 /* LineModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB7A236763000024EF95 /* LineModel.swift */; }; 017BEB7F23676E870024EF95 /* MoleculeObjectMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB7E23676E870024EF95 /* MoleculeObjectMapping.swift */; }; + 0189255C239AA7EB004E8AFF /* ModuleDelegateProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0189255B239AA7EB004E8AFF /* ModuleDelegateProtocol.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 */; }; @@ -293,6 +294,7 @@ 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 /* MoleculeObjectMapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeObjectMapping.swift; sourceTree = ""; }; + 0189255B239AA7EB004E8AFF /* ModuleDelegateProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModuleDelegateProtocol.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 = ""; }; @@ -1038,6 +1040,7 @@ D2A514572211C53C00345BFB /* MVMCoreUIMoleculeMappingObject.m */, 017BEB432362192F0024EF95 /* MVMCoreUIMoleculeMappingObject+ModelExtension.swift */, 017BEB7E23676E870024EF95 /* MoleculeObjectMapping.swift */, + 0189255B239AA7EB004E8AFF /* ModuleDelegateProtocol.swift */, ); path = OtherHandlers; sourceTree = ""; @@ -1313,6 +1316,7 @@ D29DF27621E79E81003B2FB9 /* MVMCoreUILoggingHandler.m in Sources */, D29DF24D21E6A177003B2FB9 /* MFTextField.m in Sources */, 012A88C4238D86E600FE3DA1 /* CollectionCellMoleculeProtocol.swift in Sources */, + 0189255C239AA7EB004E8AFF /* ModuleDelegateProtocol.swift in Sources */, 94C2D9AB23872EB50006CF46 /* LabelAttributeActionModel.swift in Sources */, 017BEB4023620A230024EF95 /* TextFieldModel.swift in Sources */, D29DF2A221E7AF4E003B2FB9 /* MVMCoreUIUtility.m in Sources */, diff --git a/MVMCoreUI/BaseControllers/MFViewController+Model.swift b/MVMCoreUI/BaseControllers/MFViewController+Model.swift index 159a3260..fcdde9c3 100644 --- a/MVMCoreUI/BaseControllers/MFViewController+Model.swift +++ b/MVMCoreUI/BaseControllers/MFViewController+Model.swift @@ -8,8 +8,24 @@ import Foundation +extension MFViewController: ModuleDelegateProtocol { + public func getModuleWithName(_ moleculeName: String) -> Model? { + guard let moduleJSON = loadObject?.modulesJSON?.optionalDictionaryForKey(moleculeName), + let moleculeName = moduleJSON.optionalStringForKey("moleculeName"), + let modelType = ModelRegistry.getType(for: moleculeName) else { + return nil + } + do { + return try modelType.decode(jsonDict: moduleJSON) + } catch { + MVMCoreUILoggingHandler.logDebugMessage(withDelegate: "error: \(error)") + } + return nil + } +} public extension MFViewController { + @objc func parsePageJSON() { (self as? TemplateProtocol)?.parseTemplateJSON() diff --git a/MVMCoreUI/Models/Molecules/ModuleMoleculeModel.swift b/MVMCoreUI/Models/Molecules/ModuleMoleculeModel.swift index e01d3def..9b7ebf01 100644 --- a/MVMCoreUI/Models/Molecules/ModuleMoleculeModel.swift +++ b/MVMCoreUI/Models/Molecules/ModuleMoleculeModel.swift @@ -8,7 +8,7 @@ import Foundation -class ModuleMoleculeModel: MoleculeProtocol { +public class ModuleMoleculeModel: MoleculeProtocol { public static var identifier: String = "moduleMolecule" public var moduleName: String public var backgroundColor: String? diff --git a/MVMCoreUI/Molecules/ModuleMolecule.swift b/MVMCoreUI/Molecules/ModuleMolecule.swift index ab252b5e..2087dff5 100644 --- a/MVMCoreUI/Molecules/ModuleMolecule.swift +++ b/MVMCoreUI/Molecules/ModuleMolecule.swift @@ -10,7 +10,7 @@ import UIKit open class ModuleMolecule: ViewConstrainingView, ModelMoleculeViewProtocol { - open var moduleMolecule: (UIView & MVMCoreUIMoleculeViewProtocol)? + open var moduleMolecule: (UIView & MVMCoreUIMoleculeViewProtocol & ModelMoleculeViewProtocol)? open override func updateView(_ size: CGFloat) { super.updateView(size) @@ -23,58 +23,28 @@ open class ModuleMolecule: ViewConstrainingView, ModelMoleculeViewProtocol { setUpWithModel(model, delegateObject, additionalData) guard let moduleMoleculeModel = model as? ModuleMoleculeModel, - let module = delegateObject?.moleculeDelegate?.getModuleWithName(moduleMoleculeModel.moduleName) else { + let moduleModel = delegateObject?.moduleProtocol?.getModuleWithName(moduleMoleculeModel.moduleName) as? MoleculeProtocol else { // Critical error return } -// if moduleMolecule == nil { -// MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(<#T##model: MoleculeProtocol##MoleculeProtocol#>, <#T##delegateObject: MVMCoreUIDelegateObject?##MVMCoreUIDelegateObject?#>, <#T##constrainIfNeeded: Bool##Bool#>) -// if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: module, delegateObject: delegateObject, constrainIfNeeded: true) { -// addSubview(moleculeView) -// NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: moleculeView, useMargins: false).values)) -// moduleMolecule = moleculeView -// -// isAccessibilityElement = false -// if moleculeView.accessibilityElements != nil { -// accessibilityElements = moleculeView.accessibilityElements -// } else { -// accessibilityElements = [moleculeView] -// } -// } -// } else { -// moduleMolecule?.setWithJSON(module, delegateObject: delegateObject, additionalData: additionalData) -// } + if moduleMolecule == nil { + if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(moduleModel, delegateObject, true) { + addSubview(moleculeView) + NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: moleculeView, useMargins: false).values)) + moduleMolecule = moleculeView as? (UIView & MVMCoreUIMoleculeViewProtocol & ModelMoleculeViewProtocol) + isAccessibilityElement = false + if moleculeView.accessibilityElements != nil { + accessibilityElements = moleculeView.accessibilityElements + } else { + accessibilityElements = [moleculeView] + } + } + } else { + moduleMolecule?.setWithModel(model, delegateObject, additionalData) + } } - -// // MARK: - MVMCoreUIMoleculeViewProtocol -// open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { -// super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) -// -// guard let moduleName = json?.optionalStringForKey("moduleName"), -// let module = delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) else { -// // Critical error -// return -// } -// -// if moduleMolecule == nil { -// if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: module, delegateObject: delegateObject, constrainIfNeeded: true) { -// addSubview(moleculeView) -// NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: moleculeView, useMargins: false).values)) -// moduleMolecule = moleculeView -// -// isAccessibilityElement = false -// if moleculeView.accessibilityElements != nil { -// accessibilityElements = moleculeView.accessibilityElements -// } else { -// accessibilityElements = [moleculeView] -// } -// } -// } else { -// moduleMolecule?.setWithJSON(module, delegateObject: delegateObject, additionalData: additionalData) -// } -// } open override func setAsMolecule() { super.setAsMolecule() diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIDelegateObject.swift b/MVMCoreUI/OtherHandlers/MVMCoreUIDelegateObject.swift index c0c8211f..6a7fbc05 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIDelegateObject.swift +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIDelegateObject.swift @@ -13,6 +13,7 @@ open class MVMCoreUIDelegateObject: DelegateObject { public weak var buttonDelegate: ButtonDelegateProtocol? public weak var uiTextFieldDelegate: UITextFieldDelegate? public weak var moleculeDelegate: MoleculeDelegateProtocol? + public var moduleProtocol: ModuleDelegateProtocol? open override func setAll(withDelegate delegate: Any) { super.setAll(withDelegate: delegate) @@ -20,9 +21,11 @@ open class MVMCoreUIDelegateObject: DelegateObject { buttonDelegate = delegate as? ButtonDelegateProtocol uiTextFieldDelegate = delegate as? UITextFieldDelegate moleculeDelegate = delegate as? MoleculeDelegateProtocol + moduleProtocol = delegate as? ModuleDelegateProtocol } class func delegateObject(from controller: MVMCoreViewControllerProtocol?) -> MVMCoreUIDelegateObject? { return controller?.delegateObject?() as? MVMCoreUIDelegateObject } } + diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.h b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.h index 6c1a84b2..776566c8 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.h +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.h @@ -29,10 +29,10 @@ - (nullable UIView *)createMoleculeForName:(nonnull NSString *)name; /// Creates the molecule for the molecule json. -//- (nullable UIView *)createMoleculeForJSON:(nonnull NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject; -// -///// Creates the molecule for the molecule json. Also checks if the molecule needs to be constrained for a stack/list style situation. -//- (nullable UIView *)createMoleculeForJSON:(nonnull NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject constrainIfNeeded:(BOOL)constrainIfNeeded; +- (nullable UIView *)createMoleculeForJSON:(nonnull NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject; + +/// Creates the molecule for the molecule json. Also checks if the molecule needs to be constrained for a stack/list style situation. +- (nullable UIView *)createMoleculeForJSON:(nonnull NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject constrainIfNeeded:(BOOL)constrainIfNeeded; #pragma mark - Convenience diff --git a/MVMCoreUI/OtherHandlers/ModuleDelegateProtocol.swift b/MVMCoreUI/OtherHandlers/ModuleDelegateProtocol.swift new file mode 100644 index 00000000..70c271ce --- /dev/null +++ b/MVMCoreUI/OtherHandlers/ModuleDelegateProtocol.swift @@ -0,0 +1,14 @@ +// +// ModuleDelegateProtocol.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 12/6/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + + +public protocol ModuleDelegateProtocol { + func getModuleWithName(_ moleculeName: String) -> Model? +} diff --git a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift index 983fac13..f97ed9b5 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift @@ -30,5 +30,6 @@ import Foundation ModelRegistry.register(LabelAttributeUnderlineModel.self) ModelRegistry.register(LabelAttributeStrikeThroughModel.self) ModelRegistry.register(LabelAttributeActionModel.self) + ModelRegistry.register(ModuleMoleculeModel.self) } } From 7c7232fe6a2f326c761e177b5288548c0a170e1f Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Mon, 9 Dec 2019 14:36:14 -0500 Subject: [PATCH 07/51] remove PageModel --- MVMCoreUI.xcodeproj/project.pbxproj | 4 ---- MVMCoreUI/BaseControllers/MFViewController.h | 3 --- MVMCoreUI/Models/Template/PageModel.swift | 19 ------------------- 3 files changed, 26 deletions(-) delete mode 100644 MVMCoreUI/Models/Template/PageModel.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index f022ef91..3ae8d221 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -36,7 +36,6 @@ 01509D932327ECFB00EF99AA /* ProgressBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01509D922327ECFB00EF99AA /* ProgressBar.swift */; }; 01509D952327ED1900EF99AA /* HeadlineBodyTextButtonSwitch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01509D942327ED1900EF99AA /* HeadlineBodyTextButtonSwitch.swift */; }; 017BEB382360C6AC0024EF95 /* RadioButtonLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB372360C6AC0024EF95 /* RadioButtonLabel.swift */; }; - 017BEB3A2360EEB40024EF95 /* PageModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB392360EEB40024EF95 /* PageModel.swift */; }; 017BEB3C2361EA1D0024EF95 /* MFViewController+Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB3B2361EA1D0024EF95 /* MFViewController+Model.swift */; }; 017BEB4023620A230024EF95 /* TextFieldModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB3F23620A230024EF95 /* TextFieldModel.swift */; }; 017BEB4223620AD20024EF95 /* FormModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB4123620AD20024EF95 /* FormModelProtocol.swift */; }; @@ -285,7 +284,6 @@ 01509D922327ECFB00EF99AA /* ProgressBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProgressBar.swift; sourceTree = ""; }; 01509D942327ED1900EF99AA /* HeadlineBodyTextButtonSwitch.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HeadlineBodyTextButtonSwitch.swift; sourceTree = ""; }; 017BEB372360C6AC0024EF95 /* RadioButtonLabel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RadioButtonLabel.swift; sourceTree = ""; }; - 017BEB392360EEB40024EF95 /* PageModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageModel.swift; sourceTree = ""; }; 017BEB3B2361EA1D0024EF95 /* MFViewController+Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MFViewController+Model.swift"; sourceTree = ""; }; 017BEB3F23620A230024EF95 /* TextFieldModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextFieldModel.swift; sourceTree = ""; }; 017BEB4123620AD20024EF95 /* FormModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormModelProtocol.swift; sourceTree = ""; }; @@ -525,7 +523,6 @@ isa = PBXGroup; children = ( 012A889B23889E8400FE3DA1 /* TemplateModelProtocol.swift */, - 017BEB392360EEB40024EF95 /* PageModel.swift */, 012CA9DD2388723E003F810F /* ListPageTemplateModel.swift */, 012CA9DF23888AC8003F810F /* StackPageTemplateModel.swift */, 012CA9E123888AED003F810F /* StackCenteredPageTemplateModel.swift */, @@ -1308,7 +1305,6 @@ 01EB369423609801006832FA /* HeadlineBodyModel.swift in Sources */, D2C5001921F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m in Sources */, D29DF12E21E6851E003B2FB9 /* MVMCoreUITopAlertView.m in Sources */, - 017BEB3A2360EEB40024EF95 /* PageModel.swift in Sources */, D29DF2CF21E7C104003B2FB9 /* MFLoadingViewController.m in Sources */, D22D1F572204CE5D0077CEC0 /* MVMCoreUIStackableViewController.m in Sources */, 01DF567021FA5AB300CC099B /* TextFieldListFormViewController.swift in Sources */, diff --git a/MVMCoreUI/BaseControllers/MFViewController.h b/MVMCoreUI/BaseControllers/MFViewController.h index be8c3bd2..c1415df4 100644 --- a/MVMCoreUI/BaseControllers/MFViewController.h +++ b/MVMCoreUI/BaseControllers/MFViewController.h @@ -33,15 +33,12 @@ @class MVMCoreUITabBarPageControlViewController; @class MVMAnimationManager; @class DelegateObject; -@class PageModel; @interface MFViewController : UIViewController // Stores the load object that this screen was loaded with. @property (nullable, strong, nonatomic) MVMCoreLoadObject *loadObject; -@property (nullable, strong, nonatomic) PageModel *pageModel; - // The current selected text field. @property (nullable, weak, nonatomic) __block id selectedField; diff --git a/MVMCoreUI/Models/Template/PageModel.swift b/MVMCoreUI/Models/Template/PageModel.swift deleted file mode 100644 index a47c78e1..00000000 --- a/MVMCoreUI/Models/Template/PageModel.swift +++ /dev/null @@ -1,19 +0,0 @@ -// -// Page.swift -// MVMCoreUI -// -// Created by Suresh, Kamlesh on 10/23/19. -// Copyright © 2019 Verizon Wireless. All rights reserved. -// - -import UIKit - -@objcMembers public class PageModel: Codable { - public var template: String? - public var pageType: String? - public var screenHeading: String? - public var isAtomicTabs: Bool? = false - public var header: HeaderModel? - public var molecules: [ListItemModel]? - public var moleculeStack: MoleculeStackModel? -} From 9a4a5139ed56a6910ba4ec98bbe2ba0f13045368 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 12 Dec 2019 11:47:33 -0500 Subject: [PATCH 08/51] fixes --- .../Items/DropDownFilterTableViewCell.swift | 20 +++++++++---------- MVMCoreUI/Molecules/Items/TableViewCell.swift | 2 +- .../Templates/MoleculeListTemplate.swift | 16 +++++++-------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/MVMCoreUI/Molecules/Items/DropDownFilterTableViewCell.swift b/MVMCoreUI/Molecules/Items/DropDownFilterTableViewCell.swift index 99b14870..2f856074 100644 --- a/MVMCoreUI/Molecules/Items/DropDownFilterTableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/DropDownFilterTableViewCell.swift @@ -51,16 +51,16 @@ import UIKit super.updateView(size) dropDown?.updateView(size) } - -// // MARK: - MoleculeDelegateProtocol -// public override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { -// bottomSeparatorView?.style = .none -// self.delegateObject = delegateObject -// super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) -// dropDown?.mfTextFieldDelegate = delegateObject?.uiTextFieldDelegate as? MFTextFieldDelegate -// dropDown?.uiTextFieldDelegate = delegateObject?.uiTextFieldDelegate -// dropDown?.setWithJSON(json?.optionalDictionaryForKey("dropDown"), delegateObject: delegateObject, additionalData: additionalData) -// } + + public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + bottomSeparatorView?.style = .none + self.delegateObject = delegateObject + super.setWithModel(model, delegateObject, additionalData) + + dropDown?.mfTextFieldDelegate = delegateObject?.uiTextFieldDelegate as? MFTextFieldDelegate + dropDown?.uiTextFieldDelegate = delegateObject?.uiTextFieldDelegate + dropDown?.setWithJSON(json?.optionalDictionaryForKey("dropDown"), delegateObject: delegateObject, additionalData: additionalData) + } public override func reset() { super.reset() diff --git a/MVMCoreUI/Molecules/Items/TableViewCell.swift b/MVMCoreUI/Molecules/Items/TableViewCell.swift index ffaefcb5..20c48487 100644 --- a/MVMCoreUI/Molecules/Items/TableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/TableViewCell.swift @@ -176,7 +176,7 @@ import UIKit // override the separator if let separator = model.separator { addSeparatorsIfNeeded() - (bottomSeparatorView as? ModelMoleculeViewProtocol)?.setWithModel(separator, nil, nil) + bottomSeparatorView?.setWithModel(separator, nil, nil) } guard let moleculeModel = model.molecule else { return } diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index fd1885cc..534d3228 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -160,14 +160,14 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol public func removeMolecules(_ molecules: [MoleculeProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) { var indexPaths: [IndexPath] = [] //TODO: cehck for molecule protocola eqality -// for molecule in molecules { -// if let removeIndex = moleculesInfo?.firstIndex(where: { (moleculeInfo) -> Bool in -// return molecule == moleculeInfo.molecule -// }) { -// moleculesInfo?.remove(at: removeIndex) -// indexPaths.append(IndexPath(row: removeIndex + indexPaths.count, section: 0)) -// } -// } + for molecule in molecules { + if let removeIndex = moleculesInfo?.firstIndex(where: { (moleculeInfo) -> Bool in + return molecule.toJSONString() == moleculeInfo.molecule.toJSONString() + }) { + moleculesInfo?.remove(at: removeIndex) + indexPaths.append(IndexPath(row: removeIndex + indexPaths.count, section: 0)) + } + } self.tableView?.deleteRows(at: indexPaths, with: animation) self.updateViewConstraints() self.view.layoutIfNeeded() From 8d811f229f6ac2b75f7bfce45a68e615b59e5043 Mon Sep 17 00:00:00 2001 From: panxi Date: Thu, 12 Dec 2019 15:28:47 -0500 Subject: [PATCH 09/51] change from viewconstrainingview to view --- MVMCoreUI.xcodeproj/project.pbxproj | 4 ++++ MVMCoreUI/Atoms/Views/CaretView.swift | 2 ++ MVMCoreUI/Atoms/Views/CaretViewModel.swift | 4 +++- MVMCoreUI/Atoms/Views/DashLine.swift | 2 ++ MVMCoreUI/Atoms/Views/DashLineModel.swift | 8 ++++--- .../Atoms/Views/LeftRightLabelModel.swift | 19 +++++++++++++++ .../Atoms/Views/LeftRightLabelView.swift | 20 ++++++++++++++-- MVMCoreUI/Atoms/Views/MultiProgress.swift | 6 +++-- .../Atoms/Views/MultiProgressModel.swift | 4 +++- MVMCoreUI/Atoms/Views/ProgressBar.swift | 3 ++- MVMCoreUI/Atoms/Views/ProgressBarModel.swift | 4 +++- MVMCoreUI/BaseClasses/Control.swift | 7 +++++- .../SwitchMolecules/HeadlineBodySwitch.swift | 23 +++++++++++++++---- .../OtherHandlers/MoleculeObjectMapping.swift | 3 +++ 14 files changed, 92 insertions(+), 17 deletions(-) create mode 100644 MVMCoreUI/Atoms/Views/LeftRightLabelModel.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 3ae8d221..0ff03255 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -63,6 +63,7 @@ 0A7BAD74232A8DC700FB8E22 /* HeadlineBodyButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */; }; 0A7BAFA1232BE61800FB8E22 /* Checkbox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAFA0232BE61800FB8E22 /* Checkbox.swift */; }; 0AA33B34239813C50067DD0F /* UIColor+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AA33B33239813C50067DD0F /* UIColor+Extension.swift */; }; + 9402C35023A2CEA3004B974C /* LeftRightLabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9402C34F23A2CEA3004B974C /* LeftRightLabelModel.swift */; }; 943784F5236B77BB006A1E82 /* GraphView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 943784F3236B77BB006A1E82 /* GraphView.swift */; }; 943784F6236B77BB006A1E82 /* GraphViewAnimationHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 943784F4236B77BB006A1E82 /* GraphViewAnimationHandler.swift */; }; 9445890C2385BCE300DE9FD4 /* ProgressBarModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9445890B2385BCE300DE9FD4 /* ProgressBarModel.swift */; }; @@ -311,6 +312,7 @@ 0A7BAFA0232BE61800FB8E22 /* Checkbox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Checkbox.swift; sourceTree = ""; }; 0A7BAFA2232BE63400FB8E22 /* CheckboxWithLabelView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckboxWithLabelView.swift; sourceTree = ""; }; 0AA33B33239813C50067DD0F /* UIColor+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Extension.swift"; sourceTree = ""; }; + 9402C34F23A2CEA3004B974C /* LeftRightLabelModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LeftRightLabelModel.swift; sourceTree = ""; }; 943784F3236B77BB006A1E82 /* GraphView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphView.swift; sourceTree = ""; }; 943784F4236B77BB006A1E82 /* GraphViewAnimationHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphViewAnimationHandler.swift; sourceTree = ""; }; 9445890B2385BCE300DE9FD4 /* ProgressBarModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressBarModel.swift; sourceTree = ""; }; @@ -949,6 +951,7 @@ DBC4391722442197001AB423 /* DashLine.swift */, 944589202385D6E900DE9FD4 /* DashLineModel.swift */, DB06250A2293456500B72DD3 /* LeftRightLabelView.swift */, + 9402C34F23A2CEA3004B974C /* LeftRightLabelModel.swift */, 012CA99D2385A2D3003F810F /* MFView+ModelExtension.swift */, D29DF28721E7AC2B003B2FB9 /* ViewConstrainingView.h */, D29DF28821E7AC2B003B2FB9 /* ViewConstrainingView.m */, @@ -1268,6 +1271,7 @@ files = ( 943784F5236B77BB006A1E82 /* GraphView.swift in Sources */, 012CA9E423888B1B003F810F /* ThreeLayerPageTemplateModel.swift in Sources */, + 9402C35023A2CEA3004B974C /* LeftRightLabelModel.swift in Sources */, D29DF32121ED0CBA003B2FB9 /* LabelView.m in Sources */, DBC4391822442197001AB423 /* CaretView.swift in Sources */, D29770F221F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.m in Sources */, diff --git a/MVMCoreUI/Atoms/Views/CaretView.swift b/MVMCoreUI/Atoms/Views/CaretView.swift index c02db833..f34ab776 100644 --- a/MVMCoreUI/Atoms/Views/CaretView.swift +++ b/MVMCoreUI/Atoms/Views/CaretView.swift @@ -125,7 +125,9 @@ open class CaretView: View { } } + //MARK: - MVMCoreMoleculeViewProtocol override public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + super.setWithModel(model, delegateObject, additionalData) guard let caretModel = model as? CaretViewModel else { return } diff --git a/MVMCoreUI/Atoms/Views/CaretViewModel.swift b/MVMCoreUI/Atoms/Views/CaretViewModel.swift index 481d086f..37d095d8 100644 --- a/MVMCoreUI/Atoms/Views/CaretViewModel.swift +++ b/MVMCoreUI/Atoms/Views/CaretViewModel.swift @@ -10,7 +10,9 @@ import Foundation @objcMembers public class CaretViewModel: MoleculeProtocol { - public static var identifier: String = "caretView" + public static var identifier: String { + get{ return "caretView" } + } public var backgroundColor: String? public var strokeColor: String? diff --git a/MVMCoreUI/Atoms/Views/DashLine.swift b/MVMCoreUI/Atoms/Views/DashLine.swift index 937b7313..595c7605 100644 --- a/MVMCoreUI/Atoms/Views/DashLine.swift +++ b/MVMCoreUI/Atoms/Views/DashLine.swift @@ -84,7 +84,9 @@ open class DashLine: View { } } + //MARK: - MVMCoreMoleculeViewProtocol public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + super.setWithModel(model, delegateObject, additionalData) guard let dashLineModel = model as? DashLineModel else { return } diff --git a/MVMCoreUI/Atoms/Views/DashLineModel.swift b/MVMCoreUI/Atoms/Views/DashLineModel.swift index 6fff83c7..3ba46186 100644 --- a/MVMCoreUI/Atoms/Views/DashLineModel.swift +++ b/MVMCoreUI/Atoms/Views/DashLineModel.swift @@ -9,10 +9,12 @@ import Foundation @objcMembers public class DashLineModel: MoleculeProtocol { - public static var identifier: String = "dashLine" - public var moleculeName: String + public static var identifier: String { + get { return "dashLine" } + } + public var moleculeName: String = "" public var backgroundColor: String? - public var dashColor: String + public var dashColor: String = "" public var isHidden: Bool? } diff --git a/MVMCoreUI/Atoms/Views/LeftRightLabelModel.swift b/MVMCoreUI/Atoms/Views/LeftRightLabelModel.swift new file mode 100644 index 00000000..ba07fc8b --- /dev/null +++ b/MVMCoreUI/Atoms/Views/LeftRightLabelModel.swift @@ -0,0 +1,19 @@ +// +// LeftRightLabelModel.swift +// MVMCoreUI +// +// Created by Ryan on 12/12/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +@objcMembers public class LeftRightLabelModel: MoleculeProtocol { + public var backgroundColor: String? + public var leftText: LabelModel + public var rightText: LabelModel + + public static var identifier: String { + get{ return "leftRightLabel" } + } +} diff --git a/MVMCoreUI/Atoms/Views/LeftRightLabelView.swift b/MVMCoreUI/Atoms/Views/LeftRightLabelView.swift index a059aef5..979d2abb 100644 --- a/MVMCoreUI/Atoms/Views/LeftRightLabelView.swift +++ b/MVMCoreUI/Atoms/Views/LeftRightLabelView.swift @@ -9,7 +9,7 @@ import Foundation -@objcMembers open class LeftRightLabelView: ViewConstrainingView { +@objcMembers open class LeftRightLabelView: View { //------------------------------------------------------ // MARK: - Outlets //------------------------------------------------------ @@ -28,7 +28,7 @@ import Foundation // MARK: - Initialization //------------------------------------------------------ - public init() { + public override init() { super.init(frame: .zero) } @@ -176,4 +176,20 @@ import Foundation constrainLeftLabel() } } + + //MARK: - MVMCoreMoleculeViewProtocol + + open override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + super.setWithModel(model, delegateObject, additionalData) + guard let leftRightLabelModel = model as? LeftRightLabelModel else { + return + } + leftTextLabel.setWithModel(leftRightLabelModel.leftText, delegateObject, additionalData) + rightTextLabel.setWithModel(leftRightLabelModel.rightText, delegateObject, additionalData) + if !leftTextLabel.hasText { + constrainRightLabel() + } else if !rightTextLabel.hasText { + constrainLeftLabel() + } + } } diff --git a/MVMCoreUI/Atoms/Views/MultiProgress.swift b/MVMCoreUI/Atoms/Views/MultiProgress.swift index 6f35bcc5..bbe8ed76 100644 --- a/MVMCoreUI/Atoms/Views/MultiProgress.swift +++ b/MVMCoreUI/Atoms/Views/MultiProgress.swift @@ -8,7 +8,7 @@ import UIKit -@objcMembers open class MultiProgress: ViewConstrainingView, ModelMoleculeViewProtocol { +@objcMembers open class MultiProgress: View { ///passing value to progressList creates corresponding progress bars var progressList: Array? { @@ -60,7 +60,9 @@ import UIKit } } - public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + //MARK: - MVMCoreMoleculeViewProtocol + public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + super.setWithModel(model, delegateObject, additionalData) guard let multiProgressModel = model as? MultiProgressBarModel else { return } diff --git a/MVMCoreUI/Atoms/Views/MultiProgressModel.swift b/MVMCoreUI/Atoms/Views/MultiProgressModel.swift index 25522070..62397f69 100644 --- a/MVMCoreUI/Atoms/Views/MultiProgressModel.swift +++ b/MVMCoreUI/Atoms/Views/MultiProgressModel.swift @@ -15,7 +15,9 @@ import Foundation } @objcMembers public class MultiProgressBarModel: MoleculeProtocol { - public static var identifier: String = "multiProgressBar" + public static var identifier: String { + get{ return "multiProgressBar"} + } public var moleculeName: String public var backgroundColor: String? public var progressList: [SingleProgressBarModel] diff --git a/MVMCoreUI/Atoms/Views/ProgressBar.swift b/MVMCoreUI/Atoms/Views/ProgressBar.swift index 45ce85d6..0a29d62a 100644 --- a/MVMCoreUI/Atoms/Views/ProgressBar.swift +++ b/MVMCoreUI/Atoms/Views/ProgressBar.swift @@ -50,13 +50,14 @@ import Foundation public func updateView(_ size: CGFloat) { } + //MARK: - MVMCoreMoleculeViewProtocol public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String: AnyHashable]?) { guard let progressBarModel = model as? ProgressBarModel else { return } isRounded = progressBarModel.isRounded ?? false thickness = progressBarModel.thickness ?? 8 - progress = (progressBarModel.percentage ?? 0)/100.0 + progress = (progressBarModel.percentage )/100.0 if let progressColor = progressBarModel.progressColor { progressTintColor = UIColor.mfGet(forHex: progressColor) } diff --git a/MVMCoreUI/Atoms/Views/ProgressBarModel.swift b/MVMCoreUI/Atoms/Views/ProgressBarModel.swift index 3450fc87..aa5912a7 100644 --- a/MVMCoreUI/Atoms/Views/ProgressBarModel.swift +++ b/MVMCoreUI/Atoms/Views/ProgressBarModel.swift @@ -9,7 +9,9 @@ import Foundation @objcMembers public class ProgressBarModel: MoleculeProtocol { - public static var identifier: String = "progressbar" + public static var identifier: String { + get { return "progressbar" } + } public var moleculeName: String public var isRounded: Bool? diff --git a/MVMCoreUI/BaseClasses/Control.swift b/MVMCoreUI/BaseClasses/Control.swift index fdf8204f..942cda65 100644 --- a/MVMCoreUI/BaseClasses/Control.swift +++ b/MVMCoreUI/BaseClasses/Control.swift @@ -8,8 +8,9 @@ import UIKit -public class Control: UIControl { +public class Control: UIControl, ModelMoleculeViewProtocol { var json: [AnyHashable: Any]? + public var model: MoleculeProtocol? private var initialSetupPerformed = false @@ -34,6 +35,10 @@ public class Control: UIControl { setupView() } } + + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + self.model = model + } } extension Control: MVMCoreViewProtocol { diff --git a/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift b/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift index 79110460..20da726b 100644 --- a/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift +++ b/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift @@ -8,7 +8,7 @@ import UIKit -@objcMembers open class HeadlineBodySwitch: ViewConstrainingView { +@objcMembers open class HeadlineBodySwitch: View { public let headlineBody = HeadlineBody(frame: .zero) public let mvmSwitch = MVMCoreUISwitch.mvmSwitchDefault() @@ -27,13 +27,27 @@ import UIKit headlineBody.styleListItem() let view = MVMCoreUICommonViewsUtility.commonView() addSubview(view) - pinView(toSuperView: view) + NSLayoutConstraint.constraintPinSubview(toSuperview: view) view.addSubview(headlineBody) view.addSubview(mvmSwitch) NSLayoutConstraint.pinSubviewsCenter(leftView: headlineBody, rightView: mvmSwitch) } + + //MARK: - MVMCoreMoleculeViewProtocol + + open override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + super.setWithModel(model, delegateObject, additionalData) +// guard let headlineModel = model as? headlinebodyswitch +// headlineBody.setWithModel(mode, <#T##delegateObject: MVMCoreUIDelegateObject?##MVMCoreUIDelegateObject?#>, <#T##additionalData: [String : AnyHashable]?##[String : AnyHashable]?#>) + } + + public static func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { + return 30 + } + + // MARK: - MVMCoreUIMoleculeViewProtocol open override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) @@ -41,12 +55,11 @@ import UIKit mvmSwitch.setWithJSON(json?.optionalDictionaryForKey("switch"), delegateObject: delegateObject, additionalData: additionalData) } - open override class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { + open class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { return 30 } - open override func setAsMolecule() { - super.setAsMolecule() + open func setAsMolecule() { headlineBody.setAsMolecule() (mvmSwitch as MVMCoreUIMoleculeViewProtocol).setAsMolecule?() headlineBody.styleListItem() diff --git a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift index f97ed9b5..86395407 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift @@ -24,12 +24,15 @@ import Foundation ModelRegistry.register(CaretViewModel.self) ModelRegistry.register(DashLineModel.self) ModelRegistry.register(ImageViewModel.self) + //need to move labelattributemodel to different method ModelRegistry.register(LabelAttributeFontModel.self) ModelRegistry.register(LabelAttributeColorModel.self) ModelRegistry.register(LabelAttributeImageModel.self) ModelRegistry.register(LabelAttributeUnderlineModel.self) ModelRegistry.register(LabelAttributeStrikeThroughModel.self) ModelRegistry.register(LabelAttributeActionModel.self) + // ModelRegistry.register(ModuleMoleculeModel.self) + ModelRegistry.register(LeftRightLabelModel.self) } } From 52186bf0898a00240b646c7ea8a21f2af2ea79e8 Mon Sep 17 00:00:00 2001 From: panxi Date: Thu, 12 Dec 2019 17:22:26 -0500 Subject: [PATCH 10/51] add protocol func into view --- MVMCoreUI.xcodeproj/project.pbxproj | 2 +- MVMCoreUI/Atoms/Views/CaretView.swift | 2 +- MVMCoreUI/Atoms/Views/DashLine.swift | 2 +- MVMCoreUI/Atoms/Views/DashLineModel.swift | 7 ++-- MVMCoreUI/BaseClasses/View.swift | 4 +++ MVMCoreUI/Molecules/HeadlineBodyButton.swift | 4 +-- .../SwitchMolecules/HeadlineBodySwitch.swift | 2 +- .../HeadlineBody.swift | 35 ++++++++++--------- .../HeadlineBodyModel.swift | 4 +-- 9 files changed, 34 insertions(+), 28 deletions(-) rename MVMCoreUI/{Models/Molecules => Molecules/VerticalCombinationViews}/HeadlineBodyModel.swift (74%) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 0ff03255..61ee1780 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -577,7 +577,6 @@ 01EB368B23609801006832FA /* MoleculeStackModel.swift */, 01EB368C23609801006832FA /* HeaderModel.swift */, 012A88EB238F084D00FE3DA1 /* FooterModel.swift */, - 01EB368D23609801006832FA /* HeadlineBodyModel.swift */, 017BEB3F23620A230024EF95 /* TextFieldModel.swift */, 017BEB4123620AD20024EF95 /* FormModelProtocol.swift */, 017BEB7A236763000024EF95 /* LineModel.swift */, @@ -664,6 +663,7 @@ isa = PBXGroup; children = ( D2A638FC22CA98280052ED1F /* HeadlineBody.swift */, + 01EB368D23609801006832FA /* HeadlineBodyModel.swift */, D22479952316AF6D003FCCF9 /* HeadlineBodyTextButton.swift */, D27CD40F2339057800C1DC07 /* EyebrowHeadlineBodyLink.swift */, ); diff --git a/MVMCoreUI/Atoms/Views/CaretView.swift b/MVMCoreUI/Atoms/Views/CaretView.swift index f34ab776..3a2c5561 100644 --- a/MVMCoreUI/Atoms/Views/CaretView.swift +++ b/MVMCoreUI/Atoms/Views/CaretView.swift @@ -99,7 +99,7 @@ open class CaretView: View { //------------------------------------------------------ // Default values for view. - @objc open func setAsMolecule() { + @objc open override func setAsMolecule() { defaultState() } diff --git a/MVMCoreUI/Atoms/Views/DashLine.swift b/MVMCoreUI/Atoms/Views/DashLine.swift index 595c7605..52ed9a65 100644 --- a/MVMCoreUI/Atoms/Views/DashLine.swift +++ b/MVMCoreUI/Atoms/Views/DashLine.swift @@ -64,7 +64,7 @@ open class DashLine: View { //------------------------------------------------------ // Default values for view. - @objc open func setAsMolecule() { + @objc open override func setAsMolecule() { backgroundColor = .clear isHidden = false } diff --git a/MVMCoreUI/Atoms/Views/DashLineModel.swift b/MVMCoreUI/Atoms/Views/DashLineModel.swift index 3ba46186..79367f35 100644 --- a/MVMCoreUI/Atoms/Views/DashLineModel.swift +++ b/MVMCoreUI/Atoms/Views/DashLineModel.swift @@ -12,9 +12,12 @@ import Foundation public static var identifier: String { get { return "dashLine" } } - public var moleculeName: String = "" public var backgroundColor: String? - public var dashColor: String = "" + public var dashColor: String public var isHidden: Bool? + + public init(dashColor: String) { + self.dashColor = dashColor + } } diff --git a/MVMCoreUI/BaseClasses/View.swift b/MVMCoreUI/BaseClasses/View.swift index de76f739..ec029b96 100644 --- a/MVMCoreUI/BaseClasses/View.swift +++ b/MVMCoreUI/BaseClasses/View.swift @@ -66,5 +66,9 @@ extension View: MVMCoreUIMoleculeViewProtocol { open func reset() { backgroundColor = .clear } + + open func setAsMolecule() { + + } } diff --git a/MVMCoreUI/Molecules/HeadlineBodyButton.swift b/MVMCoreUI/Molecules/HeadlineBodyButton.swift index 87efc9b6..02852d51 100644 --- a/MVMCoreUI/Molecules/HeadlineBodyButton.swift +++ b/MVMCoreUI/Molecules/HeadlineBodyButton.swift @@ -9,7 +9,7 @@ import UIKit -@objcMembers open class HeadlineBodyButton: ViewConstrainingView { +@objcMembers open class HeadlineBodyButton: View { //------------------------------------------------------ // MARK: - Outlets //------------------------------------------------------ @@ -33,7 +33,7 @@ import UIKit // MARK: - Initialization //------------------------------------------------------ - public init() { + public override init() { super.init(frame: .zero) } diff --git a/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift b/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift index 20da726b..7e5fcda8 100644 --- a/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift +++ b/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift @@ -59,7 +59,7 @@ import UIKit return 30 } - open func setAsMolecule() { + open override func setAsMolecule() { headlineBody.setAsMolecule() (mvmSwitch as MVMCoreUIMoleculeViewProtocol).setAsMolecule?() headlineBody.styleListItem() diff --git a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBody.swift b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBody.swift index cc313d59..a70b106d 100644 --- a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBody.swift +++ b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBody.swift @@ -8,7 +8,7 @@ import UIKit -open class HeadlineBody: ViewConstrainingView, ModelMoleculeViewProtocol { +open class HeadlineBody: View { let headlineLabel = Label.commonLabelH2(true) let messageLabel = Label.commonLabelB2(true) var spaceBetweenLabelsConstant = PaddingTwo @@ -81,7 +81,7 @@ open class HeadlineBody: ViewConstrainingView, ModelMoleculeViewProtocol { let view = MVMCoreUICommonViewsUtility.commonView() addSubview(view) - pinView(toSuperView: view) + NSLayoutConstraint.constraintPinSubview(toSuperview: view) view.addSubview(headlineLabel) view.addSubview(messageLabel) @@ -119,9 +119,9 @@ open class HeadlineBody: ViewConstrainingView, ModelMoleculeViewProtocol { } } - public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { - setUpWithModel(model, delegateObject, additionalData) + super.setWithModel(model, delegateObject, additionalData) guard let headlineBodyModel = model as? HeadlineBodyModel else { return } @@ -131,25 +131,26 @@ open class HeadlineBody: ViewConstrainingView, ModelMoleculeViewProtocol { headlineLabel.setWithModel(headlineBodyModel.headline, delegateObject, additionalData) messageLabel.setWithModel(headlineBodyModel.body, delegateObject, additionalData) } -// // MARK: - MVMCoreUIMoleculeViewProtocol -// open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { -// super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) -// -// style(with: json?.optionalStringForKey("style")) -// -// let headlineJSON = json?.optionalDictionaryForKey("headline") -// headlineLabel.setWithJSON(headlineJSON, delegateObject: delegateObject, additionalData: additionalData) -// -// let bodyJSON = json?.optionalDictionaryForKey("body") -// messageLabel.setWithJSON(bodyJSON, delegateObject: delegateObject, additionalData: additionalData) -// } + + // MARK: - MVMCoreUIMoleculeViewProtocol + open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) + + style(with: json?.optionalStringForKey("style")) + + let headlineJSON = json?.optionalDictionaryForKey("headline") + headlineLabel.setWithJSON(headlineJSON, delegateObject: delegateObject, additionalData: additionalData) + + let bodyJSON = json?.optionalDictionaryForKey("body") + messageLabel.setWithJSON(bodyJSON, delegateObject: delegateObject, additionalData: additionalData) + } open override func reset() { super.reset() stylePageHeader() } - public override class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { + public class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { return 58 } } diff --git a/MVMCoreUI/Models/Molecules/HeadlineBodyModel.swift b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyModel.swift similarity index 74% rename from MVMCoreUI/Models/Molecules/HeadlineBodyModel.swift rename to MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyModel.swift index 0e4f22f6..c6dbd059 100644 --- a/MVMCoreUI/Models/Molecules/HeadlineBodyModel.swift +++ b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyModel.swift @@ -15,11 +15,9 @@ import Foundation public var style: String? public var backgroundColor: String? - public init(headline: LabelModel, body: LabelModel, style: String?, backgroundColor: String?) { + public init(headline: LabelModel, body: LabelModel) { self.headline = headline self.body = body - self.style = style - self.backgroundColor = backgroundColor } } From 58ec1abcfed85af45484dc8f2ad4f16a66cb9deb Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Fri, 13 Dec 2019 11:07:32 -0500 Subject: [PATCH 11/51] list model protocol --- MVMCoreUI.xcodeproj/project.pbxproj | 34 ++++++++++--- .../CollectionCellMoleculeProtocol.swift | 0 .../ContainerMoleculeProtocol.swift | 0 .../FormModelProtocol.swift | 0 .../ListItemModelProtocol.swift | 14 ++++++ .../MoleculeProtocol.swift | 0 .../PagingMoleculeProtocol.swift | 0 .../TemplateModelProtocol.swift | 0 .../TemplateProtocol.swift | 0 .../Molecules/DropDownListItemModel.swift | 46 +++++++++++++++++ .../Models/Molecules/DropDownModel.swift | 17 +++++++ .../Models/Molecules/ListItemModel.swift | 9 ++-- .../Template/ListPageTemplateModel.swift | 49 +++++++++++++++++-- 13 files changed, 153 insertions(+), 16 deletions(-) rename MVMCoreUI/Models/{ => ModelProtocols}/CollectionCellMoleculeProtocol.swift (100%) rename MVMCoreUI/Models/{ => ModelProtocols}/ContainerMoleculeProtocol.swift (100%) rename MVMCoreUI/Models/{Molecules => ModelProtocols}/FormModelProtocol.swift (100%) create mode 100644 MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift rename MVMCoreUI/Models/{ => ModelProtocols}/MoleculeProtocol.swift (100%) rename MVMCoreUI/Models/{ => ModelProtocols}/PagingMoleculeProtocol.swift (100%) rename MVMCoreUI/Models/{Template => ModelProtocols}/TemplateModelProtocol.swift (100%) rename MVMCoreUI/Models/{ => ModelProtocols}/TemplateProtocol.swift (100%) create mode 100644 MVMCoreUI/Models/Molecules/DropDownListItemModel.swift create mode 100644 MVMCoreUI/Models/Molecules/DropDownModel.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 61ee1780..d9f4c2ff 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -12,6 +12,9 @@ 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 */; }; + 011B58F023A2AA980085F53C /* ListItemModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011B58EF23A2AA980085F53C /* ListItemModelProtocol.swift */; }; + 011B58F223A2AE2C0085F53C /* DropDownListItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011B58F123A2AE2C0085F53C /* DropDownListItemModel.swift */; }; + 011B58F423A2CCC80085F53C /* DropDownModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011B58F323A2CCC80085F53C /* DropDownModel.swift */; }; 012A889C23889E8400FE3DA1 /* TemplateModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A889B23889E8400FE3DA1 /* TemplateModelProtocol.swift */; }; 012A88AD238C418100FE3DA1 /* TemplateProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88AC238C418100FE3DA1 /* TemplateProtocol.swift */; }; 012A88B1238C880100FE3DA1 /* PagingMoleculeProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88B0238C880100FE3DA1 /* PagingMoleculeProtocol.swift */; }; @@ -261,6 +264,9 @@ 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 = ""; }; + 011B58EF23A2AA980085F53C /* ListItemModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListItemModelProtocol.swift; sourceTree = ""; }; + 011B58F123A2AE2C0085F53C /* DropDownListItemModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropDownListItemModel.swift; sourceTree = ""; }; + 011B58F323A2CCC80085F53C /* DropDownModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropDownModel.swift; sourceTree = ""; }; 012A889B23889E8400FE3DA1 /* TemplateModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemplateModelProtocol.swift; sourceTree = ""; }; 012A88AC238C418100FE3DA1 /* TemplateProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemplateProtocol.swift; sourceTree = ""; }; 012A88AE238C626E00FE3DA1 /* CarouselModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CarouselModel.swift; sourceTree = ""; }; @@ -521,10 +527,24 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 011B58EE23A2AA850085F53C /* ModelProtocols */ = { + isa = PBXGroup; + children = ( + 017BEB4123620AD20024EF95 /* FormModelProtocol.swift */, + 012A88C3238D86E600FE3DA1 /* CollectionCellMoleculeProtocol.swift */, + 012A88B0238C880100FE3DA1 /* PagingMoleculeProtocol.swift */, + 01EB3683236097C0006832FA /* MoleculeProtocol.swift */, + 012A88AC238C418100FE3DA1 /* TemplateProtocol.swift */, + 012A889B23889E8400FE3DA1 /* TemplateModelProtocol.swift */, + 012A88ED239858E300FE3DA1 /* ContainerMoleculeProtocol.swift */, + 011B58EF23A2AA980085F53C /* ListItemModelProtocol.swift */, + ); + path = ModelProtocols; + sourceTree = ""; + }; 012A889A238898C600FE3DA1 /* Template */ = { isa = PBXGroup; children = ( - 012A889B23889E8400FE3DA1 /* TemplateModelProtocol.swift */, 012CA9DD2388723E003F810F /* ListPageTemplateModel.swift */, 012CA9DF23888AC8003F810F /* StackPageTemplateModel.swift */, 012CA9E123888AED003F810F /* StackCenteredPageTemplateModel.swift */, @@ -544,12 +564,8 @@ 01509D96232803B200EF99AA /* Models */ = { isa = PBXGroup; children = ( + 011B58EE23A2AA850085F53C /* ModelProtocols */, 012A88EF23985E0100FE3DA1 /* Primitive Models */, - 012A88AC238C418100FE3DA1 /* TemplateProtocol.swift */, - 01EB3683236097C0006832FA /* MoleculeProtocol.swift */, - 012A88ED239858E300FE3DA1 /* ContainerMoleculeProtocol.swift */, - 012A88B0238C880100FE3DA1 /* PagingMoleculeProtocol.swift */, - 012A88C3238D86E600FE3DA1 /* CollectionCellMoleculeProtocol.swift */, 012A889A238898C600FE3DA1 /* Template */, 946EE1B5237B663A0036751F /* Extensions */, 01EB368723609801006832FA /* Molecules */, @@ -573,12 +589,13 @@ children = ( 012CA98823849699003F810F /* SeperatorModel.swift */, 01EB368923609801006832FA /* ListItemModel.swift */, + 011B58F323A2CCC80085F53C /* DropDownModel.swift */, + 011B58F123A2AE2C0085F53C /* DropDownListItemModel.swift */, 01EB368A23609801006832FA /* MoleculeStackItemModel.swift */, 01EB368B23609801006832FA /* MoleculeStackModel.swift */, 01EB368C23609801006832FA /* HeaderModel.swift */, 012A88EB238F084D00FE3DA1 /* FooterModel.swift */, 017BEB3F23620A230024EF95 /* TextFieldModel.swift */, - 017BEB4123620AD20024EF95 /* FormModelProtocol.swift */, 017BEB7A236763000024EF95 /* LineModel.swift */, 012A88AE238C626E00FE3DA1 /* CarouselModel.swift */, 012A88C1238D7BCA00FE3DA1 /* CarouselItemModel.swift */, @@ -1352,6 +1369,7 @@ 012CA9E223888AED003F810F /* StackCenteredPageTemplateModel.swift in Sources */, 012A88DA238ED42E00FE3DA1 /* StackPageTemplateModel.swift in Sources */, 0A7BAFA1232BE61800FB8E22 /* Checkbox.swift in Sources */, + 011B58F023A2AA980085F53C /* ListItemModelProtocol.swift in Sources */, D22479962316AF6E003FCCF9 /* HeadlineBodyTextButton.swift in Sources */, D29DF2AE21E7B3A4003B2FB9 /* MFTextView.m in Sources */, 017BEB382360C6AC0024EF95 /* RadioButtonLabel.swift in Sources */, @@ -1364,6 +1382,7 @@ D274CA332236A78900B01B62 /* StandardFooterView.swift in Sources */, D29DF2BF21E7BEA4003B2FB9 /* MVMCoreUITabBarPageControlViewController.m in Sources */, D29DF28321E7AB24003B2FB9 /* MVMCoreUICommonViewsUtility.m in Sources */, + 011B58F223A2AE2C0085F53C /* DropDownListItemModel.swift in Sources */, 94C2D9842386F3F80006CF46 /* LabelAttributeModel.swift in Sources */, 944589212385D6E900DE9FD4 /* DashLineModel.swift in Sources */, D29DF27A21E7A533003B2FB9 /* MVMCoreUISession.m in Sources */, @@ -1407,6 +1426,7 @@ D2A5146122121FBF00345BFB /* MoleculeStackTemplate.swift in Sources */, D29DF11821E6805F003B2FB9 /* NSLayoutConstraint+MFConvenience.m in Sources */, 94C2D9A323872C110006CF46 /* LabelAttributeStrikeThroughModel.swift in Sources */, + 011B58F423A2CCC80085F53C /* DropDownModel.swift in Sources */, D29DF26C21E6AA0B003B2FB9 /* FLAnimatedImage.m in Sources */, 012A88F123985E0100FE3DA1 /* Color.swift in Sources */, 012A889C23889E8400FE3DA1 /* TemplateModelProtocol.swift in Sources */, diff --git a/MVMCoreUI/Models/CollectionCellMoleculeProtocol.swift b/MVMCoreUI/Models/ModelProtocols/CollectionCellMoleculeProtocol.swift similarity index 100% rename from MVMCoreUI/Models/CollectionCellMoleculeProtocol.swift rename to MVMCoreUI/Models/ModelProtocols/CollectionCellMoleculeProtocol.swift diff --git a/MVMCoreUI/Models/ContainerMoleculeProtocol.swift b/MVMCoreUI/Models/ModelProtocols/ContainerMoleculeProtocol.swift similarity index 100% rename from MVMCoreUI/Models/ContainerMoleculeProtocol.swift rename to MVMCoreUI/Models/ModelProtocols/ContainerMoleculeProtocol.swift diff --git a/MVMCoreUI/Models/Molecules/FormModelProtocol.swift b/MVMCoreUI/Models/ModelProtocols/FormModelProtocol.swift similarity index 100% rename from MVMCoreUI/Models/Molecules/FormModelProtocol.swift rename to MVMCoreUI/Models/ModelProtocols/FormModelProtocol.swift diff --git a/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift b/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift new file mode 100644 index 00000000..ccd8884b --- /dev/null +++ b/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift @@ -0,0 +1,14 @@ +// +// ListItemModelProtocol.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 12/12/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + +public protocol ListItemModelProtocol: ContainerMoleculeProtocol { + var molecule: MoleculeProtocol? { get } + var separator: SeperatorModel? { get set } +} diff --git a/MVMCoreUI/Models/MoleculeProtocol.swift b/MVMCoreUI/Models/ModelProtocols/MoleculeProtocol.swift similarity index 100% rename from MVMCoreUI/Models/MoleculeProtocol.swift rename to MVMCoreUI/Models/ModelProtocols/MoleculeProtocol.swift diff --git a/MVMCoreUI/Models/PagingMoleculeProtocol.swift b/MVMCoreUI/Models/ModelProtocols/PagingMoleculeProtocol.swift similarity index 100% rename from MVMCoreUI/Models/PagingMoleculeProtocol.swift rename to MVMCoreUI/Models/ModelProtocols/PagingMoleculeProtocol.swift diff --git a/MVMCoreUI/Models/Template/TemplateModelProtocol.swift b/MVMCoreUI/Models/ModelProtocols/TemplateModelProtocol.swift similarity index 100% rename from MVMCoreUI/Models/Template/TemplateModelProtocol.swift rename to MVMCoreUI/Models/ModelProtocols/TemplateModelProtocol.swift diff --git a/MVMCoreUI/Models/TemplateProtocol.swift b/MVMCoreUI/Models/ModelProtocols/TemplateProtocol.swift similarity index 100% rename from MVMCoreUI/Models/TemplateProtocol.swift rename to MVMCoreUI/Models/ModelProtocols/TemplateProtocol.swift diff --git a/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift b/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift new file mode 100644 index 00000000..c6c109fe --- /dev/null +++ b/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift @@ -0,0 +1,46 @@ +// +// DropDownListItemModel.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 12/12/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + +@objcMembers public class DropDownListItemModel: ListItemModelProtocol { + public static var identifier: String = "dropDownListItem" + public var molecules: [[ListItemModel]] + public var backgroundColor: String? + public var separator: SeperatorModel? + public var dropDown: DropDownModel + + public init(molecules: [[ListItemModel]], dropDown: DropDownModel) { + self.molecules = molecules + self.dropDown = dropDown + } + + enum CodingKeys: String, CodingKey { + case moleculeName + case molecules + case separator + case backgroundColor + case dropDown + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + self.molecules = try typeContainer.decode([[ListItemModel]].self, forKey: .molecules) + self.separator = try typeContainer.decode(SeperatorModel.self, forKey: .separator) + self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) + self.dropDown = try typeContainer.decode(DropDownModel.self, forKey: .dropDown) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(moleculeName, forKey: .moleculeName) + try container.encode(molecules, forKey: .molecules) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encode(dropDown, forKey: .dropDown) + } +} diff --git a/MVMCoreUI/Models/Molecules/DropDownModel.swift b/MVMCoreUI/Models/Molecules/DropDownModel.swift new file mode 100644 index 00000000..b28eda5d --- /dev/null +++ b/MVMCoreUI/Models/Molecules/DropDownModel.swift @@ -0,0 +1,17 @@ +// +// DropDownModel.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 12/12/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + + +@objcMembers public class DropDownModel: MoleculeProtocol { + public static var identifier: String = "dropDownModel" + public var backgroundColor: String? + public var label: String + public var options: [String] +} diff --git a/MVMCoreUI/Models/Molecules/ListItemModel.swift b/MVMCoreUI/Models/Molecules/ListItemModel.swift index 9bfe704a..72556dae 100644 --- a/MVMCoreUI/Models/Molecules/ListItemModel.swift +++ b/MVMCoreUI/Models/Molecules/ListItemModel.swift @@ -8,7 +8,7 @@ import Foundation -@objcMembers public class ListItemModel: ContainerMoleculeProtocol { +@objcMembers public class ListItemModel: ListItemModelProtocol { public static var identifier: String = "listItem" public var molecule: MoleculeProtocol? public var backgroundColor: String? @@ -40,9 +40,9 @@ import Foundation self.molecule = try typeContainer.decodeIfPresent(codingKey: .molecule) action = try typeContainer.decodeIfPresent(ActionModel.self, forKey: .action) - self.hideArrow = try typeContainer.decode(Bool.self, forKey: .hideArrow) - self.separator = try typeContainer.decode(SeperatorModel.self, forKey: .hideArrow) - self.style = try typeContainer.decode(String.self, forKey: .style) + self.hideArrow = try typeContainer.decodeIfPresent(Bool.self, forKey: .hideArrow) + self.separator = try typeContainer.decodeIfPresent(SeperatorModel.self, forKey: .separator) + self.style = try typeContainer.decodeIfPresent(String.self, forKey: .style) } public func encode(to encoder: Encoder) throws { @@ -50,5 +50,6 @@ import Foundation try container.encode(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(self.molecule, forKey: .molecule) try container.encodeIfPresent(action, forKey: .action) + try container.encodeIfPresent(hideArrow, forKey: .hideArrow) } } diff --git a/MVMCoreUI/Models/Template/ListPageTemplateModel.swift b/MVMCoreUI/Models/Template/ListPageTemplateModel.swift index 2ad31cdc..fa8b96a2 100644 --- a/MVMCoreUI/Models/Template/ListPageTemplateModel.swift +++ b/MVMCoreUI/Models/Template/ListPageTemplateModel.swift @@ -11,14 +11,53 @@ import Foundation @objcMembers public class ListPageTemplateModel: TemplateModelProtocol { public static var identifier: String = "listTemplate" - + public var pageType: String - public var screenHeading: String - public var isAtomicTabs: Bool? - public var header: MoleculeStackModel? - public var molecules: [ListItemModel]? + public var header: HeaderModel? + public var molecules: [ListItemModelProtocol] public var footer: MoleculeStackModel? + + public init(pageType: String, screenHeading: String, molecules: [ListItemModelProtocol]) { + self.pageType = pageType + self.screenHeading = screenHeading + self.molecules = molecules + } + + enum CodingKeys: String, CodingKey { + case moleculeName + case pageType + case screenHeading + case molecules + case header + case footer + case isAtomicTabs + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + self.pageType = try typeContainer.decode(String.self, forKey: .pageType) + self.screenHeading = try typeContainer.decode(String.self, forKey: .screenHeading) + guard let list = try typeContainer.decodeArray(codingKey: .molecules) as? [ListItemModelProtocol] else { + throw JSONError.pathNotFound + } + self.molecules = list + self.isAtomicTabs = try typeContainer.decodeIfPresent(Bool.self, forKey: .isAtomicTabs) + self.header = try typeContainer.decodeIfPresent(HeaderModel.self, forKey: .header) + self.footer = try typeContainer.decodeIfPresent(MoleculeStackModel.self, forKey: .footer) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(pageType, forKey: .pageType) + try container.encode(screenHeading, forKey: .screenHeading) + + try container.encodeArray(molecules, forKey: .molecules) + try container.encodeIfPresent(isAtomicTabs, forKey: .isAtomicTabs) + try container.encodeIfPresent(header, forKey: .header) + try container.encodeIfPresent(footer, forKey: .footer) + } } + From 8612b34ac7c3fabe98ebfadd4d6e1cb8d9c9c290 Mon Sep 17 00:00:00 2001 From: panxi Date: Fri, 13 Dec 2019 11:26:48 -0500 Subject: [PATCH 12/51] update listitem --- MVMCoreUI.xcodeproj/project.pbxproj | 6 +---- MVMCoreUI/Atoms/Views/DashLineModel.swift | 4 +--- .../Atoms/Views/LeftRightLabelModel.swift | 6 ++--- .../Atoms/Views/MultiProgressModel.swift | 4 +--- MVMCoreUI/Atoms/Views/ProgressBarModel.swift | 4 +--- .../ListItemModelProtocol.swift | 2 +- .../Molecules/DropDownListItemModel.swift | 4 ++-- MVMCoreUI/Models/Molecules/HeaderModel.swift | 6 ++--- MVMCoreUI/Models/Molecules/LineModel.swift | 4 ---- .../Models/Molecules/SeperatorModel.swift | 15 ------------ .../Items}/ListItemModel.swift | 24 +++++++------------ .../OtherHandlers/MoleculeObjectMapping.swift | 1 - 12 files changed, 20 insertions(+), 60 deletions(-) delete mode 100644 MVMCoreUI/Models/Molecules/SeperatorModel.swift rename MVMCoreUI/{Models/Molecules => Molecules/Items}/ListItemModel.swift (61%) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index d9f4c2ff..f50573f6 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -27,7 +27,6 @@ 012A88EC238F084D00FE3DA1 /* FooterModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88EB238F084D00FE3DA1 /* FooterModel.swift */; }; 012A88EE239858E300FE3DA1 /* ContainerMoleculeProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88ED239858E300FE3DA1 /* ContainerMoleculeProtocol.swift */; }; 012A88F123985E0100FE3DA1 /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88F023985E0100FE3DA1 /* Color.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 */; }; @@ -278,7 +277,6 @@ 012A88EB238F084D00FE3DA1 /* FooterModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FooterModel.swift; sourceTree = ""; }; 012A88ED239858E300FE3DA1 /* ContainerMoleculeProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerMoleculeProtocol.swift; sourceTree = ""; }; 012A88F023985E0100FE3DA1 /* Color.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Color.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 = ""; }; @@ -587,8 +585,6 @@ 01EB368723609801006832FA /* Molecules */ = { isa = PBXGroup; children = ( - 012CA98823849699003F810F /* SeperatorModel.swift */, - 01EB368923609801006832FA /* ListItemModel.swift */, 011B58F323A2CCC80085F53C /* DropDownModel.swift */, 011B58F123A2AE2C0085F53C /* DropDownListItemModel.swift */, 01EB368A23609801006832FA /* MoleculeStackItemModel.swift */, @@ -719,6 +715,7 @@ children = ( D2755D7A23689C7500485468 /* TableViewCell.swift */, 01509D8E2327EC6F00EF99AA /* MoleculeTableViewCell.swift */, + 01EB368923609801006832FA /* ListItemModel.swift */, D2A6390422CBCE160052ED1F /* MoleculeCollectionViewCell.swift */, D224799A231965AD003FCCF9 /* AccordionMoleculeTableViewCell.swift */, D27CD40D2322EEAF00C1DC07 /* TabsTableViewCell.swift */, @@ -1294,7 +1291,6 @@ D29770F221F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.m in Sources */, D29B771022C281F400D6ACE0 /* ModuleMolecule.swift in Sources */, 94C2D9A923872E5E0006CF46 /* LabelAttributeImageModel.swift in Sources */, - 012CA98923849699003F810F /* SeperatorModel.swift in Sources */, DBC4391922442197001AB423 /* DashLine.swift in Sources */, 0AA33B34239813C50067DD0F /* UIColor+Extension.swift in Sources */, 0A7BAD74232A8DC700FB8E22 /* HeadlineBodyButton.swift in Sources */, diff --git a/MVMCoreUI/Atoms/Views/DashLineModel.swift b/MVMCoreUI/Atoms/Views/DashLineModel.swift index 79367f35..172e5dd6 100644 --- a/MVMCoreUI/Atoms/Views/DashLineModel.swift +++ b/MVMCoreUI/Atoms/Views/DashLineModel.swift @@ -9,9 +9,7 @@ import Foundation @objcMembers public class DashLineModel: MoleculeProtocol { - public static var identifier: String { - get { return "dashLine" } - } + public static var identifier: String = "dashLine" public var backgroundColor: String? public var dashColor: String diff --git a/MVMCoreUI/Atoms/Views/LeftRightLabelModel.swift b/MVMCoreUI/Atoms/Views/LeftRightLabelModel.swift index ba07fc8b..30015d70 100644 --- a/MVMCoreUI/Atoms/Views/LeftRightLabelModel.swift +++ b/MVMCoreUI/Atoms/Views/LeftRightLabelModel.swift @@ -9,11 +9,9 @@ import UIKit @objcMembers public class LeftRightLabelModel: MoleculeProtocol { + public static var identifier: String = "leftRightLabel" public var backgroundColor: String? public var leftText: LabelModel public var rightText: LabelModel - - public static var identifier: String { - get{ return "leftRightLabel" } - } + } diff --git a/MVMCoreUI/Atoms/Views/MultiProgressModel.swift b/MVMCoreUI/Atoms/Views/MultiProgressModel.swift index 62397f69..25522070 100644 --- a/MVMCoreUI/Atoms/Views/MultiProgressModel.swift +++ b/MVMCoreUI/Atoms/Views/MultiProgressModel.swift @@ -15,9 +15,7 @@ import Foundation } @objcMembers public class MultiProgressBarModel: MoleculeProtocol { - public static var identifier: String { - get{ return "multiProgressBar"} - } + public static var identifier: String = "multiProgressBar" public var moleculeName: String public var backgroundColor: String? public var progressList: [SingleProgressBarModel] diff --git a/MVMCoreUI/Atoms/Views/ProgressBarModel.swift b/MVMCoreUI/Atoms/Views/ProgressBarModel.swift index aa5912a7..3450fc87 100644 --- a/MVMCoreUI/Atoms/Views/ProgressBarModel.swift +++ b/MVMCoreUI/Atoms/Views/ProgressBarModel.swift @@ -9,9 +9,7 @@ import Foundation @objcMembers public class ProgressBarModel: MoleculeProtocol { - public static var identifier: String { - get { return "progressbar" } - } + public static var identifier: String = "progressbar" public var moleculeName: String public var isRounded: Bool? diff --git a/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift b/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift index ccd8884b..59e51708 100644 --- a/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift +++ b/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift @@ -10,5 +10,5 @@ import Foundation public protocol ListItemModelProtocol: ContainerMoleculeProtocol { var molecule: MoleculeProtocol? { get } - var separator: SeperatorModel? { get set } + var separator: LineModel? { get set } } diff --git a/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift b/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift index c6c109fe..7a7770df 100644 --- a/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift +++ b/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift @@ -12,7 +12,7 @@ import Foundation public static var identifier: String = "dropDownListItem" public var molecules: [[ListItemModel]] public var backgroundColor: String? - public var separator: SeperatorModel? + public var separator: LineModel? public var dropDown: DropDownModel public init(molecules: [[ListItemModel]], dropDown: DropDownModel) { @@ -31,7 +31,7 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) self.molecules = try typeContainer.decode([[ListItemModel]].self, forKey: .molecules) - self.separator = try typeContainer.decode(SeperatorModel.self, forKey: .separator) + self.separator = try typeContainer.decode(LineModel.self, forKey: .separator) self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) self.dropDown = try typeContainer.decode(DropDownModel.self, forKey: .dropDown) } diff --git a/MVMCoreUI/Models/Molecules/HeaderModel.swift b/MVMCoreUI/Models/Molecules/HeaderModel.swift index 9016184b..adbfca47 100644 --- a/MVMCoreUI/Models/Molecules/HeaderModel.swift +++ b/MVMCoreUI/Models/Molecules/HeaderModel.swift @@ -13,9 +13,9 @@ import Foundation public var moleculeName: String? public var backgroundColor: String? public var molecule: MoleculeProtocol? - public var seperator: SeperatorModel? + public var seperator: LineModel? - public init(molecule: MoleculeProtocol?, backgroundColor: String?, seperator: SeperatorModel?){ + public init(molecule: MoleculeProtocol?, backgroundColor: String?, seperator: LineModel?){ self.molecule = molecule self.backgroundColor = backgroundColor self.seperator = seperator @@ -33,7 +33,7 @@ import Foundation self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName) self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) self.molecule = try typeContainer.decodeIfPresent(codingKey: .molecule) - self.seperator = try typeContainer.decodeIfPresent(SeperatorModel.self, forKey: .separator) + self.seperator = try typeContainer.decodeIfPresent(LineModel.self, forKey: .separator) } public func encode(to encoder: Encoder) throws { diff --git a/MVMCoreUI/Models/Molecules/LineModel.swift b/MVMCoreUI/Models/Molecules/LineModel.swift index e00ba1fc..c6a22c62 100644 --- a/MVMCoreUI/Models/Molecules/LineModel.swift +++ b/MVMCoreUI/Models/Molecules/LineModel.swift @@ -12,8 +12,4 @@ import UIKit public static var identifier: String = "line" public var backgroundColor: String? public var type: String? - - public init(type: String?) { - self.type = type - } } diff --git a/MVMCoreUI/Models/Molecules/SeperatorModel.swift b/MVMCoreUI/Models/Molecules/SeperatorModel.swift deleted file mode 100644 index b58c7602..00000000 --- a/MVMCoreUI/Models/Molecules/SeperatorModel.swift +++ /dev/null @@ -1,15 +0,0 @@ -// -// SeperatorModel.swift -// MVMCoreUI -// -// Created by Suresh, Kamlesh on 11/19/19. -// Copyright © 2019 Verizon Wireless. All rights reserved. -// - -import UIKit - -@objcMembers public class SeperatorModel: MoleculeProtocol { - public static var identifier: String = "line" - public var backgroundColor: String? - public var type: String? -} diff --git a/MVMCoreUI/Models/Molecules/ListItemModel.swift b/MVMCoreUI/Molecules/Items/ListItemModel.swift similarity index 61% rename from MVMCoreUI/Models/Molecules/ListItemModel.swift rename to MVMCoreUI/Molecules/Items/ListItemModel.swift index 72556dae..5ae9e7fa 100644 --- a/MVMCoreUI/Models/Molecules/ListItemModel.swift +++ b/MVMCoreUI/Molecules/Items/ListItemModel.swift @@ -13,19 +13,10 @@ import Foundation public var molecule: MoleculeProtocol? public var backgroundColor: String? public var action: ActionModel? - public var hideArrow: Bool? - public var separator: SeperatorModel? + public var separator: LineModel? public var style: String? - public init(molecule: MoleculeProtocol?, actionMap: ActionModel?, hideArrow: Bool?, separator: SeperatorModel?, style: String?) { - self.molecule = molecule - self.action = actionMap - self.hideArrow = hideArrow - self.separator = separator - self.style = style - } - enum CodingKeys: String, CodingKey { case moleculeName case molecule @@ -37,19 +28,20 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - self.molecule = try typeContainer.decodeIfPresent(codingKey: .molecule) + molecule = try typeContainer.decodeIfPresent(codingKey: .molecule) action = try typeContainer.decodeIfPresent(ActionModel.self, forKey: .action) - - self.hideArrow = try typeContainer.decodeIfPresent(Bool.self, forKey: .hideArrow) - self.separator = try typeContainer.decodeIfPresent(SeperatorModel.self, forKey: .separator) - self.style = try typeContainer.decodeIfPresent(String.self, forKey: .style) + hideArrow = try typeContainer.decodeIfPresent(Bool.self, forKey: .hideArrow) + separator = try typeContainer.decodeIfPresent(LineModel.self, forKey: .separator) + style = try typeContainer.decodeIfPresent(String.self, forKey: .style) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) - try container.encodeIfPresent(self.molecule, forKey: .molecule) + try container.encodeIfPresent(molecule, forKey: .molecule) try container.encodeIfPresent(action, forKey: .action) try container.encodeIfPresent(hideArrow, forKey: .hideArrow) + try container.encodeIfPresent(separator, forKey: .separator) + try container.encodeIfPresent(style, forKey: .style) } } diff --git a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift index 86395407..a26e2c85 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift @@ -18,7 +18,6 @@ import Foundation ModelRegistry.register(ListItemModel.self) ModelRegistry.register(TextFieldModel.self) ModelRegistry.register(LineModel.self) - ModelRegistry.register(SeperatorModel.self) ModelRegistry.register(ProgressBarModel.self) ModelRegistry.register(MultiProgressBarModel.self) ModelRegistry.register(CaretViewModel.self) From b6ccbecdf5ae53744d87628e785f6d30ac7154f7 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Fri, 13 Dec 2019 17:32:09 -0500 Subject: [PATCH 13/51] clean up --- .../MFViewController+Model.swift | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/MVMCoreUI/BaseControllers/MFViewController+Model.swift b/MVMCoreUI/BaseControllers/MFViewController+Model.swift index fcdde9c3..afc022f8 100644 --- a/MVMCoreUI/BaseControllers/MFViewController+Model.swift +++ b/MVMCoreUI/BaseControllers/MFViewController+Model.swift @@ -9,8 +9,8 @@ import Foundation extension MFViewController: ModuleDelegateProtocol { - public func getModuleWithName(_ moleculeName: String) -> Model? { - guard let moduleJSON = loadObject?.modulesJSON?.optionalDictionaryForKey(moleculeName), + public func getModuleWithName(_ moduleName: String) -> Model? { + guard let moduleJSON = loadObject?.modulesJSON?.optionalDictionaryForKey(moduleName), let moleculeName = moduleJSON.optionalStringForKey("moleculeName"), let modelType = ModelRegistry.getType(for: moleculeName) else { return nil @@ -25,21 +25,7 @@ extension MFViewController: ModuleDelegateProtocol { } public extension MFViewController { - @objc func parsePageJSON() { - (self as? TemplateProtocol)?.parseTemplateJSON() -// guard let pageJSON = loadObject?.pageJSON as? [String: AnyHashable] else { -// return -// } -// do { -// let pageData = try JSONSerialization.data(withJSONObject: pageJSON) -// let decoder = JSONDecoder() -// -// let pageModel = try decoder.decode(PageModel.self, from: pageData) -// self.pageModel = pageModel -// } catch { -// MVMCoreUILoggingHandler.logDebugMessage(withDelegate: "error: \(error)") -// } } } From c6d5775d5704df29cd34aa784a4ee93201637e0c Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Mon, 16 Dec 2019 13:51:37 -0500 Subject: [PATCH 14/51] CaretButtonModel --- MVMCoreUI.xcodeproj/project.pbxproj | 4 +++ .../Atoms/Buttons/CaretButtonModel.swift | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 MVMCoreUI/Atoms/Buttons/CaretButtonModel.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index f50573f6..5d073043 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -59,6 +59,7 @@ 01EB369223609801006832FA /* MoleculeStackModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB368B23609801006832FA /* MoleculeStackModel.swift */; }; 01EB369323609801006832FA /* HeaderModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB368C23609801006832FA /* HeaderModel.swift */; }; 01EB369423609801006832FA /* HeadlineBodyModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB368D23609801006832FA /* HeadlineBodyModel.swift */; }; + 01F2A03223A4498200D954D8 /* CaretButtonModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A03123A4498200D954D8 /* CaretButtonModel.swift */; }; 0A1214A022C11A18007C7030 /* ActionDetailWithImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A12149F22C11A17007C7030 /* ActionDetailWithImage.swift */; }; 0A1B4A96233BB18F005B3FB4 /* CheckboxWithLabelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAFA2232BE63400FB8E22 /* CheckboxWithLabelView.swift */; }; 0A41BA6E2344FCD400D4C0BC /* CATransaction+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A41BA6D2344FCD400D4C0BC /* CATransaction+Extension.swift */; }; @@ -310,6 +311,7 @@ 01EB368B23609801006832FA /* MoleculeStackModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MoleculeStackModel.swift; sourceTree = ""; }; 01EB368C23609801006832FA /* HeaderModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HeaderModel.swift; sourceTree = ""; }; 01EB368D23609801006832FA /* HeadlineBodyModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HeadlineBodyModel.swift; sourceTree = ""; }; + 01F2A03123A4498200D954D8 /* CaretButtonModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CaretButtonModel.swift; sourceTree = ""; }; 0A12149F22C11A17007C7030 /* ActionDetailWithImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionDetailWithImage.swift; sourceTree = ""; }; 0A41BA6D2344FCD400D4C0BC /* CATransaction+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CATransaction+Extension.swift"; sourceTree = ""; }; 0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeadlineBodyButton.swift; sourceTree = ""; }; @@ -937,6 +939,7 @@ isa = PBXGroup; children = ( DBC4391A224421A0001AB423 /* CaretButton.swift */, + 01F2A03123A4498200D954D8 /* CaretButtonModel.swift */, D29DF25821E6A22D003B2FB9 /* MFButtonProtocol.h */, D29DF16B21E69E1F003B2FB9 /* ButtonDelegateProtocol.h */, D29DF16A21E69E1F003B2FB9 /* MFCustomButton.h */, @@ -1364,6 +1367,7 @@ 0105618F224BBE7700E1557D /* FormValidator+FormParams.swift in Sources */, 012CA9E223888AED003F810F /* StackCenteredPageTemplateModel.swift in Sources */, 012A88DA238ED42E00FE3DA1 /* StackPageTemplateModel.swift in Sources */, + 01F2A03223A4498200D954D8 /* CaretButtonModel.swift in Sources */, 0A7BAFA1232BE61800FB8E22 /* Checkbox.swift in Sources */, 011B58F023A2AA980085F53C /* ListItemModelProtocol.swift in Sources */, D22479962316AF6E003FCCF9 /* HeadlineBodyTextButton.swift in Sources */, diff --git a/MVMCoreUI/Atoms/Buttons/CaretButtonModel.swift b/MVMCoreUI/Atoms/Buttons/CaretButtonModel.swift new file mode 100644 index 00000000..a2e42aed --- /dev/null +++ b/MVMCoreUI/Atoms/Buttons/CaretButtonModel.swift @@ -0,0 +1,25 @@ +// +// CaretButtonModel.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 12/13/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + + +public class CaretButtonModel: MoleculeProtocol { + public static var identifier: String = "caretButton" + public var backgroundColor: String? + public var label: String + public var action: ActionModel + public var enabledColor: String? + public var disabledColor: String? + public var enabled: Bool? + + public init(label: String, action: ActionModel) { + self.label = label + self.action = action + } +} From 1db2a5b05875eae13fa5b18cd871301904810754 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 18 Dec 2019 12:06:13 -0500 Subject: [PATCH 15/51] fixes --- .../Atoms/Buttons/CaretButtonModel.swift | 39 ++++++++++++++++--- .../MFTextField+ModelExtension.swift | 4 +- .../ContainerMoleculeProtocol.swift | 7 +--- .../ListItemModelProtocol.swift | 2 +- .../ModelProtocols/MoleculeProtocol.swift | 5 --- .../Models/Molecules/CarouselItemModel.swift | 9 +++-- .../Molecules/DropDownListItemModel.swift | 7 +++- MVMCoreUI/Models/Molecules/FooterModel.swift | 8 ++-- MVMCoreUI/Models/Molecules/HeaderModel.swift | 9 ++--- .../Models/Molecules/TextFieldModel.swift | 4 +- MVMCoreUI/Molecules/Items/ListItemModel.swift | 15 ++++--- .../Items/MoleculeCollectionViewCell.swift | 8 +--- .../Items/MoleculeTableViewCell.swift | 4 +- MVMCoreUI/Molecules/Items/TableViewCell.swift | 3 +- ...MoleculeMappingObject+ModelExtension.swift | 2 +- .../ModelMoleculeDelegateProtocol.swift | 4 +- .../Templates/MoleculeListTemplate.swift | 38 +++++++++--------- 17 files changed, 96 insertions(+), 72 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/CaretButtonModel.swift b/MVMCoreUI/Atoms/Buttons/CaretButtonModel.swift index a2e42aed..c3946788 100644 --- a/MVMCoreUI/Atoms/Buttons/CaretButtonModel.swift +++ b/MVMCoreUI/Atoms/Buttons/CaretButtonModel.swift @@ -7,19 +7,48 @@ // import Foundation - +import MVMCore public class CaretButtonModel: MoleculeProtocol { public static var identifier: String = "caretButton" public var backgroundColor: String? - public var label: String - public var action: ActionModel + public var label: LabelModel + public var action: ActionProtocol public var enabledColor: String? public var disabledColor: String? public var enabled: Bool? - - public init(label: String, action: ActionModel) { + + public init(label: LabelModel, action: ActionProtocol) { self.label = label self.action = action } + + enum CodingKeys: String, CodingKey { + case backgroundColor + case label + case action + case enabledColor + case disabledColor + case enabled + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) + label = try typeContainer.decode(LabelModel.self, forKey: .label) + enabledColor = try typeContainer.decodeIfPresent(String.self, forKey: .enabledColor) + disabledColor = try typeContainer.decodeIfPresent(String.self, forKey: .disabledColor) + enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) + action = try typeContainer.decode(codingKey: .action, typeCodingKey: ActionCodingKey.type) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(label, forKey: .label) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encodeIfPresent(action, forKey: .action) + try container.encodeIfPresent(enabledColor, forKey: .enabledColor) + try container.encodeIfPresent(disabledColor, forKey: .disabledColor) + try container.encodeIfPresent(enabled, forKey: .enabled) + } } diff --git a/MVMCoreUI/Atoms/TextFields/MFTextField+ModelExtension.swift b/MVMCoreUI/Atoms/TextFields/MFTextField+ModelExtension.swift index 81f00282..79ff851e 100644 --- a/MVMCoreUI/Atoms/TextFields/MFTextField+ModelExtension.swift +++ b/MVMCoreUI/Atoms/TextFields/MFTextField+ModelExtension.swift @@ -38,7 +38,9 @@ extension MFTextField: ModelMoleculeViewProtocol { formText = textFieldModel.label as NSString? text = textFieldModel.value as NSString? - enable(textFieldModel.disabled) + if let disabled = textFieldModel.disabled { + enable(disabled) + } errMessage = textFieldModel.errorMsg fieldKey = textFieldModel.fieldKey groupName = textFieldModel.groupName diff --git a/MVMCoreUI/Models/ModelProtocols/ContainerMoleculeProtocol.swift b/MVMCoreUI/Models/ModelProtocols/ContainerMoleculeProtocol.swift index f6ff152e..81ffd123 100644 --- a/MVMCoreUI/Models/ModelProtocols/ContainerMoleculeProtocol.swift +++ b/MVMCoreUI/Models/ModelProtocols/ContainerMoleculeProtocol.swift @@ -9,7 +9,7 @@ import Foundation public protocol ContainerMoleculeProtocol: MoleculeProtocol { - var molecule: MoleculeProtocol? { get } + var molecule: MoleculeProtocol { get } var useHorizontalMargins: Bool? { get } var useVerticalMargins: Bool? { get } var horizontalAlignment: String? { get } @@ -17,11 +17,6 @@ public protocol ContainerMoleculeProtocol: MoleculeProtocol { } extension ContainerMoleculeProtocol { - - public var molecule: MoleculeProtocol? { - get { return nil } - } - public var backgroundColor: String? { get { return nil } } diff --git a/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift b/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift index 59e51708..59bec9ae 100644 --- a/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift +++ b/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift @@ -9,6 +9,6 @@ import Foundation public protocol ListItemModelProtocol: ContainerMoleculeProtocol { - var molecule: MoleculeProtocol? { get } + var molecule: MoleculeProtocol { get } var separator: LineModel? { get set } } diff --git a/MVMCoreUI/Models/ModelProtocols/MoleculeProtocol.swift b/MVMCoreUI/Models/ModelProtocols/MoleculeProtocol.swift index 53f0fee4..581f487c 100644 --- a/MVMCoreUI/Models/ModelProtocols/MoleculeProtocol.swift +++ b/MVMCoreUI/Models/ModelProtocols/MoleculeProtocol.swift @@ -3,15 +3,10 @@ import Foundation public protocol MoleculeProtocol: Model { var moleculeName: String? { get } var backgroundColor: String? { get } - var dictionary: [AnyHashable: Any]? { get } } extension MoleculeProtocol { public var moleculeName: String? { get { return Self.identifier } } - - public var dictionary: [AnyHashable: Any]? { - return toJSON() - } } diff --git a/MVMCoreUI/Models/Molecules/CarouselItemModel.swift b/MVMCoreUI/Models/Molecules/CarouselItemModel.swift index 58aa737f..eb9df665 100644 --- a/MVMCoreUI/Models/Molecules/CarouselItemModel.swift +++ b/MVMCoreUI/Models/Molecules/CarouselItemModel.swift @@ -11,10 +11,10 @@ import Foundation @objcMembers public class CarouselItemModel: ContainerMoleculeProtocol { public static var identifier: String = "carouselItem" - public var backgroundColor: String? + public var molecule: MoleculeProtocol - public init(backgroundColor: String?) { - self.backgroundColor = backgroundColor + public init(molecule: MoleculeProtocol) { + self.molecule = molecule } enum CodingKeys: String, CodingKey { @@ -25,13 +25,14 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - self.backgroundColor = try typeContainer.decode(String.self, forKey: .backgroundColor) + molecule = try typeContainer.decode(codingKey: .molecule) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) try container.encode(backgroundColor, forKey: .backgroundColor) + try container.encode(molecule, forKey: .molecule) try container.encodeIfPresent(self.molecule, forKey: .molecule) } } diff --git a/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift b/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift index 7a7770df..70a9c662 100644 --- a/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift +++ b/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift @@ -10,17 +10,20 @@ import Foundation @objcMembers public class DropDownListItemModel: ListItemModelProtocol { public static var identifier: String = "dropDownListItem" + public var molecule: MoleculeProtocol public var molecules: [[ListItemModel]] public var backgroundColor: String? public var separator: LineModel? public var dropDown: DropDownModel - public init(molecules: [[ListItemModel]], dropDown: DropDownModel) { + public init(molecule: MoleculeProtocol, molecules: [[ListItemModel]], dropDown: DropDownModel) { + self.molecule = molecule self.molecules = molecules self.dropDown = dropDown } enum CodingKeys: String, CodingKey { + case molecule case moleculeName case molecules case separator @@ -30,6 +33,7 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + molecule = try typeContainer.decode(codingKey: .molecule) self.molecules = try typeContainer.decode([[ListItemModel]].self, forKey: .molecules) self.separator = try typeContainer.decode(LineModel.self, forKey: .separator) self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) @@ -38,6 +42,7 @@ import Foundation public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(molecule, forKey: .molecule) try container.encode(moleculeName, forKey: .moleculeName) try container.encode(molecules, forKey: .molecules) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) diff --git a/MVMCoreUI/Models/Molecules/FooterModel.swift b/MVMCoreUI/Models/Molecules/FooterModel.swift index 95a45422..33751aa0 100644 --- a/MVMCoreUI/Models/Molecules/FooterModel.swift +++ b/MVMCoreUI/Models/Molecules/FooterModel.swift @@ -13,11 +13,10 @@ import Foundation public static var identifier: String = "footer" public var moleculeName: String? public var backgroundColor: String? - public var molecule: MoleculeProtocol? + public var molecule: MoleculeProtocol - public init(molecule: MoleculeProtocol?, backgroundColor: String?){ + public init(molecule: MoleculeProtocol){ self.molecule = molecule - self.backgroundColor = backgroundColor } enum CodingKeys: String, CodingKey { @@ -31,7 +30,7 @@ import Foundation let typeContainer = try decoder.container(keyedBy: CodingKeys.self) self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName) self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) - self.molecule = try typeContainer.decodeIfPresent(codingKey: .molecule) + self.molecule = try typeContainer.decode(codingKey: .molecule) } public func encode(to encoder: Encoder) throws { @@ -39,5 +38,6 @@ import Foundation try container.encode(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(self.molecule, forKey: .molecule) try container.encodeIfPresent(self.backgroundColor, forKey: .backgroundColor) + try container.encode(molecule, forKey: .molecule) } } diff --git a/MVMCoreUI/Models/Molecules/HeaderModel.swift b/MVMCoreUI/Models/Molecules/HeaderModel.swift index adbfca47..5212de7c 100644 --- a/MVMCoreUI/Models/Molecules/HeaderModel.swift +++ b/MVMCoreUI/Models/Molecules/HeaderModel.swift @@ -12,13 +12,11 @@ import Foundation public static var identifier: String = "header" public var moleculeName: String? public var backgroundColor: String? - public var molecule: MoleculeProtocol? + public var molecule: MoleculeProtocol public var seperator: LineModel? - public init(molecule: MoleculeProtocol?, backgroundColor: String?, seperator: LineModel?){ + public init(molecule: MoleculeProtocol){ self.molecule = molecule - self.backgroundColor = backgroundColor - self.seperator = seperator } enum CodingKeys: String, CodingKey { @@ -32,7 +30,7 @@ import Foundation let typeContainer = try decoder.container(keyedBy: CodingKeys.self) self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName) self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) - self.molecule = try typeContainer.decodeIfPresent(codingKey: .molecule) + self.molecule = try typeContainer.decode(codingKey: .molecule) self.seperator = try typeContainer.decodeIfPresent(LineModel.self, forKey: .separator) } @@ -42,5 +40,6 @@ import Foundation try container.encodeIfPresent(self.molecule, forKey: .molecule) try container.encodeIfPresent(self.backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(self.seperator, forKey: .separator) + try container.encode(molecule, forKey: .molecule) } } diff --git a/MVMCoreUI/Models/Molecules/TextFieldModel.swift b/MVMCoreUI/Models/Molecules/TextFieldModel.swift index f9b11d5f..ea6f3deb 100644 --- a/MVMCoreUI/Models/Molecules/TextFieldModel.swift +++ b/MVMCoreUI/Models/Molecules/TextFieldModel.swift @@ -13,8 +13,8 @@ import UIKit public static var identifier: String = "textField" public var backgroundColor: String? - public var editable = true - public var disabled = false + public var editable: Bool? + public var disabled: Bool? public var errorMsg: String? public var label: String? public var type: String? diff --git a/MVMCoreUI/Molecules/Items/ListItemModel.swift b/MVMCoreUI/Molecules/Items/ListItemModel.swift index 5ae9e7fa..c1fd5203 100644 --- a/MVMCoreUI/Molecules/Items/ListItemModel.swift +++ b/MVMCoreUI/Molecules/Items/ListItemModel.swift @@ -7,16 +7,21 @@ // import Foundation +import MVMCore @objcMembers public class ListItemModel: ListItemModelProtocol { public static var identifier: String = "listItem" - public var molecule: MoleculeProtocol? + public var molecule: MoleculeProtocol public var backgroundColor: String? - public var action: ActionModel? + public var action: ActionProtocol? public var hideArrow: Bool? public var separator: LineModel? public var style: String? + public init(molecule: MoleculeProtocol) { + self.molecule = molecule + } + enum CodingKeys: String, CodingKey { case moleculeName case molecule @@ -28,8 +33,8 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - molecule = try typeContainer.decodeIfPresent(codingKey: .molecule) - action = try typeContainer.decodeIfPresent(ActionModel.self, forKey: .action) + molecule = try typeContainer.decode(codingKey: .molecule) + action = try typeContainer.decodeIfPresent(codingKey: .action, typeCodingKey: ActionCodingKey.type) hideArrow = try typeContainer.decodeIfPresent(Bool.self, forKey: .hideArrow) separator = try typeContainer.decodeIfPresent(LineModel.self, forKey: .separator) style = try typeContainer.decodeIfPresent(String.self, forKey: .style) @@ -38,7 +43,7 @@ import Foundation public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) - try container.encodeIfPresent(molecule, forKey: .molecule) + try container.encode(molecule, forKey: .molecule) try container.encodeIfPresent(action, forKey: .action) try container.encodeIfPresent(hideArrow, forKey: .hideArrow) try container.encodeIfPresent(separator, forKey: .separator) diff --git a/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift b/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift index bc97be16..00b8c1ee 100644 --- a/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift +++ b/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift @@ -90,18 +90,14 @@ open class MoleculeCollectionViewCell: UICollectionViewCell, MVMCoreUIMoleculeVi backgroundColor = UIColor.mfGet(forHex: backgroundColorString) } - guard let moleculeModel = collectionModel.molecule else { - return - } - if molecule == nil { - if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(moleculeModel, delegateObject, true) { + if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(collectionModel.molecule, delegateObject, true) { contentView.insertSubview(moleculeView, at: 0) NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: moleculeView, useMargins: true).values)) molecule = moleculeView } } else { - (molecule as? ModelMoleculeViewProtocol)?.setWithModel(moleculeModel, delegateObject, additionalData) + (molecule as? ModelMoleculeViewProtocol)?.setWithModel(collectionModel.molecule, delegateObject, additionalData) } // This molecule will handle spacing by default. diff --git a/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift b/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift index 2e45d0f1..f3674562 100644 --- a/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift @@ -14,7 +14,7 @@ import UIKit super.setWithModel(model, delegateObject, additionalData) guard let model = model, - let moleculeModel = (model as? ContainerMoleculeProtocol)?.molecule, + let moleculeModel = (model as? ListItemModelProtocol)?.molecule, let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(moleculeModel, delegateObject, true) else { return } @@ -22,7 +22,7 @@ import UIKit } public override class func name(forReuse molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> String? { - guard let moleculeModel = (molecule as? ContainerMoleculeProtocol)?.molecule else { + guard let moleculeModel = (molecule as? ListItemModelProtocol)?.molecule else { return "\(self)<>" } let className = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moleculeModel) as? ModelMoleculeViewProtocol diff --git a/MVMCoreUI/Molecules/Items/TableViewCell.swift b/MVMCoreUI/Molecules/Items/TableViewCell.swift index 20c48487..216f95aa 100644 --- a/MVMCoreUI/Molecules/Items/TableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/TableViewCell.swift @@ -179,8 +179,7 @@ import UIKit bottomSeparatorView?.setWithModel(separator, nil, nil) } - guard let moleculeModel = model.molecule else { return } - (molecule as? ModelMoleculeViewProtocol)?.setWithModel(moleculeModel, delegateObject, additionalData) + (molecule as? ModelMoleculeViewProtocol)?.setWithModel(model.molecule, delegateObject, additionalData) // This molecule will by default handle margins. if let castView = molecule as? MVMCoreUIViewConstrainingProtocol { diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelExtension.swift b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelExtension.swift index 070c8680..8eda8a52 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelExtension.swift +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelExtension.swift @@ -31,7 +31,7 @@ public extension MVMCoreUIMoleculeMappingObject { if let molecule = molecule as? ModelMoleculeViewProtocol { molecule.setWithModel(model, delegateObject, nil) } else { - molecule.setWithJSON?(model.dictionary, delegateObject: delegateObject, additionalData: nil) + molecule.setWithJSON?(model.toJSON(), delegateObject: delegateObject, additionalData: nil) } } diff --git a/MVMCoreUI/OtherHandlers/ModelMoleculeDelegateProtocol.swift b/MVMCoreUI/OtherHandlers/ModelMoleculeDelegateProtocol.swift index 2120333e..dd79ee3d 100644 --- a/MVMCoreUI/OtherHandlers/ModelMoleculeDelegateProtocol.swift +++ b/MVMCoreUI/OtherHandlers/ModelMoleculeDelegateProtocol.swift @@ -9,6 +9,6 @@ import Foundation public protocol ModelMoleculeDelegateProtocol { - func addMolecules(_ molecules: [MoleculeProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) - func removeMolecules(_ molecules: [MoleculeProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) + func addMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) + func removeMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) } diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index 534d3228..3ba28ecc 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -10,7 +10,7 @@ import UIKit open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol, ModelMoleculeDelegateProtocol { - public var moleculesInfo: [(identifier: String, class: AnyClass, molecule: MoleculeProtocol)]? + public var moleculesInfo: [(identifier: String, class: AnyClass, molecule: ListItemModelProtocol)]? var observer: NSKeyValueObservation? public var templateModel: TemplateModelProtocol? @@ -139,7 +139,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol } } - public func addMolecules(_ molecules: [MoleculeProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) { + public func addMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) { // This dispatch is needed to fix a race condition that can occur if this function is called during the table setup. DispatchQueue.main.async { guard let indexPath = self.tableView?.indexPath(for: sender) else { return } @@ -157,7 +157,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol self.view.layoutIfNeeded() } } - public func removeMolecules(_ molecules: [MoleculeProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) { + public func removeMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) { var indexPaths: [IndexPath] = [] //TODO: cehck for molecule protocola eqality for molecule in molecules { @@ -172,23 +172,21 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol self.updateViewConstraints() self.view.layoutIfNeeded() } - - // MARK: - Convenience /// Returns the (identifier, class) of the molecule for the given map. - func getMoleculeInfo(with molecule: MoleculeProtocol?) -> (identifier: String, class: AnyClass, molecule: MoleculeProtocol)? { - guard let molecule = molecule, - let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(molecule), - let moleculeName = (moleculeClass as? ModelMoleculeViewProtocol.Type)?.name(forReuse: molecule, delegateObject: delegateObject() as? MVMCoreUIDelegateObject) ?? molecule.moleculeName else { + 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.Type)?.name(forReuse: listItem, delegateObject: delegateObject() as? MVMCoreUIDelegateObject) ?? listItem.molecule.moleculeName else { return nil } - return (moleculeName, moleculeClass, molecule) + return (moleculeName, moleculeClass, listItem) } /// Sets up the molecule list and ensures no errors loading all content. - func getMoleculeInfoList() -> [(identifier: String, class: AnyClass, molecule: MoleculeProtocol)]? { - var moleculeList: [(identifier: String, class: AnyClass, molecule: MoleculeProtocol)] = [] + func getMoleculeInfoList() -> [(identifier: String, class: AnyClass, molecule: ListItemModelProtocol)]? { + var moleculeList: [(identifier: String, class: AnyClass, molecule: ListItemModelProtocol)] = [] if let molecules = (templateModel as? ListPageTemplateModel)?.molecules { for molecule in molecules { if let info = getMoleculeInfo(with: molecule) { @@ -201,14 +199,14 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol /// Sets up the header, footer, molecule list and ensures no errors loading all content. func setup() { - var moleculeList: [(identifier: String, class: AnyClass, molecule: MoleculeProtocol)] = [] - if let molecules = loadObject?.pageJSON?.optionalArrayForKey(KeyMolecules) as? [MoleculeProtocol] { - for molecule in molecules { - if let info = getMoleculeInfo(with: molecule) { - moleculeList.append(info) - } - } - } + var moleculeList: [(identifier: String, class: AnyClass, molecule: ListItemModelProtocol)] = [] + if let molecules = (templateModel as? ListPageTemplateModel)?.molecules { + for molecule in molecules { + if let info = getMoleculeInfo(with: molecule) { + moleculeList.append(info) + } + } + } moleculesInfo = moleculeList } From d17ab73d34f6d67bacc29b68ee341fccf89e684f Mon Sep 17 00:00:00 2001 From: panxi Date: Thu, 19 Dec 2019 14:02:52 -0500 Subject: [PATCH 16/51] update encode decode method --- MVMCoreUI/Atoms/Views/CaretViewModel.swift | 5 +-- .../Atoms/Views/LabelModel/LabelModel.swift | 2 +- MVMCoreUI/Atoms/Views/ProgressBar.swift | 2 +- MVMCoreUI/Models/Extensions/ModelHelper.swift | 8 ++-- .../Models/Molecules/CarouselItemModel.swift | 10 ++--- .../Models/Molecules/CarouselModel.swift | 42 ++++++++----------- .../Molecules/DropDownListItemModel.swift | 4 +- MVMCoreUI/Models/Molecules/FooterModel.swift | 16 +++---- MVMCoreUI/Models/Molecules/HeaderModel.swift | 20 ++++----- .../Molecules/MoleculeStackItemModel.swift | 13 +++--- .../Models/Molecules/MoleculeStackModel.swift | 21 ++++------ .../Template/ListPageTemplateModel.swift | 2 +- MVMCoreUI/Molecules/Items/ListItemModel.swift | 5 ++- 13 files changed, 61 insertions(+), 89 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/CaretViewModel.swift b/MVMCoreUI/Atoms/Views/CaretViewModel.swift index 37d095d8..5a8998db 100644 --- a/MVMCoreUI/Atoms/Views/CaretViewModel.swift +++ b/MVMCoreUI/Atoms/Views/CaretViewModel.swift @@ -10,11 +10,8 @@ import Foundation @objcMembers public class CaretViewModel: MoleculeProtocol { - public static var identifier: String { - get{ return "caretView" } - } + public static var identifier: String = "caretView" public var backgroundColor: String? - public var strokeColor: String? public var isHidden: Bool? public var isOpaque: Bool? diff --git a/MVMCoreUI/Atoms/Views/LabelModel/LabelModel.swift b/MVMCoreUI/Atoms/Views/LabelModel/LabelModel.swift index d2c7947f..2b87186f 100644 --- a/MVMCoreUI/Atoms/Views/LabelModel/LabelModel.swift +++ b/MVMCoreUI/Atoms/Views/LabelModel/LabelModel.swift @@ -57,7 +57,7 @@ import Foundation self.fontName = try typeContainer.decodeIfPresent(String.self, forKey: .fontName) self.fontSize = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .fontSize) self.textAlignment = try typeContainer.decodeIfPresent(String.self, forKey: .textAlignment) - self.attributes = try typeContainer.decodeArrayIfPresent(codingKey: .attributes, typeCodingKey: AttributeTypeKey.type) as? [LabelAttributeModel] + self.attributes = try typeContainer.decodeModelsIfPresent(codingKey: .attributes, typeCodingKey: AttributeTypeKey.type) as? [LabelAttributeModel] self.html = try typeContainer.decodeIfPresent(String.self, forKey: .html) self.hero = try typeContainer.decodeIfPresent(Int.self, forKey: .hero) self.makeWholeViewClickable = try typeContainer.decodeIfPresent(Bool.self, forKey: .makeWholeViewClickable) diff --git a/MVMCoreUI/Atoms/Views/ProgressBar.swift b/MVMCoreUI/Atoms/Views/ProgressBar.swift index 0a29d62a..b640e4c7 100644 --- a/MVMCoreUI/Atoms/Views/ProgressBar.swift +++ b/MVMCoreUI/Atoms/Views/ProgressBar.swift @@ -57,7 +57,7 @@ import Foundation } isRounded = progressBarModel.isRounded ?? false thickness = progressBarModel.thickness ?? 8 - progress = (progressBarModel.percentage )/100.0 + progress = (progressBarModel.percentage)/100.0 if let progressColor = progressBarModel.progressColor { progressTintColor = UIColor.mfGet(forHex: progressColor) } diff --git a/MVMCoreUI/Models/Extensions/ModelHelper.swift b/MVMCoreUI/Models/Extensions/ModelHelper.swift index b4d0b1e2..fab9bd5f 100644 --- a/MVMCoreUI/Models/Extensions/ModelHelper.swift +++ b/MVMCoreUI/Models/Extensions/ModelHelper.swift @@ -14,21 +14,21 @@ extension KeyedDecodingContainer where Key : CodingKey { } public func decode(codingKey: KeyedDecodingContainer.Key) throws -> MoleculeProtocol { - return try decode(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName) + return try decodeModel(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName) } public func decodeIfPresent(codingKey: KeyedDecodingContainer.Key) throws -> MoleculeProtocol? { - return try decodeIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName) + return try decodeModelIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName) } public func decodeArray(codingKey: KeyedDecodingContainer.Key) throws -> [MoleculeProtocol] { - guard let models = try decodeArray(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName) as? [MoleculeProtocol] else { + guard let models = try decodeModels(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName) as? [MoleculeProtocol] else { throw ModelRegistry.Error.decoderError } return models } public func decodeArrayIfPresent(codingKey: KeyedDecodingContainer.Key) throws -> [MoleculeProtocol]? { - return try decodeArrayIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName) as? [MoleculeProtocol] + return try decodeModelsIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName) as? [MoleculeProtocol] } } diff --git a/MVMCoreUI/Models/Molecules/CarouselItemModel.swift b/MVMCoreUI/Models/Molecules/CarouselItemModel.swift index 58aa737f..f2392131 100644 --- a/MVMCoreUI/Models/Molecules/CarouselItemModel.swift +++ b/MVMCoreUI/Models/Molecules/CarouselItemModel.swift @@ -13,10 +13,6 @@ import Foundation public static var identifier: String = "carouselItem" public var backgroundColor: String? - public init(backgroundColor: String?) { - self.backgroundColor = backgroundColor - } - enum CodingKeys: String, CodingKey { case moleculeName case molecule @@ -25,13 +21,13 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - self.backgroundColor = try typeContainer.decode(String.self, forKey: .backgroundColor) + backgroundColor = try typeContainer.decode(String.self, forKey: .backgroundColor) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) - try container.encode(backgroundColor, forKey: .backgroundColor) - try container.encodeIfPresent(self.molecule, forKey: .molecule) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encodeModelIfPresent(molecule, forKey: .molecule) } } diff --git a/MVMCoreUI/Models/Molecules/CarouselModel.swift b/MVMCoreUI/Models/Molecules/CarouselModel.swift index 60f2b27c..08bddafd 100644 --- a/MVMCoreUI/Models/Molecules/CarouselModel.swift +++ b/MVMCoreUI/Models/Molecules/CarouselModel.swift @@ -21,16 +21,8 @@ import UIKit public var itemAlignment: String? public var pagingMolecule: PagingMoleculeProtocol? - public init(molecules: [CarouselItemModel], spacing: Float?, border: Bool?, loop: Bool?, height: Float?, itemWidthPercent: Float?, itemAlignment: String?, pagingMolecule: PagingMoleculeProtocol?, backgroundColor: String?){ + public init(molecules: [CarouselItemModel]){ self.molecules = molecules - self.spacing = spacing - self.border = border - self.loop = loop - self.height = height - self.itemWidthPercent = itemWidthPercent - self.itemAlignment = itemAlignment - self.pagingMolecule = pagingMolecule - self.backgroundColor = backgroundColor } enum CodingKeys: String, CodingKey { @@ -47,26 +39,26 @@ import UIKit required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - self.molecules = try typeContainer.decode([CarouselItemModel].self, forKey: .molecules) - self.spacing = try typeContainer.decode(Float.self, forKey: .spacing) - self.border = try typeContainer.decode(Bool.self, forKey: .border) - self.loop = try typeContainer.decode(Bool.self, forKey: .loop) - self.height = try typeContainer.decode(Float.self, forKey: .height) - self.itemWidthPercent = try typeContainer.decode(Float.self, forKey: .itemWidthPercent) - self.itemAlignment = try typeContainer.decode(String.self, forKey: .itemAlignment) - self.pagingMolecule = try typeContainer.decodeIfPresent(codingKey: .pagingMolecule) as? PagingMoleculeProtocol + molecules = try typeContainer.decode([CarouselItemModel].self, forKey: .molecules) + spacing = try typeContainer.decodeIfPresent(Float.self, forKey: .spacing) + border = try typeContainer.decodeIfPresent(Bool.self, forKey: .border) + loop = try typeContainer.decodeIfPresent(Bool.self, forKey: .loop) + height = try typeContainer.decodeIfPresent(Float.self, forKey: .height) + itemWidthPercent = try typeContainer.decodeIfPresent(Float.self, forKey: .itemWidthPercent) + itemAlignment = try typeContainer.decodeIfPresent(String.self, forKey: .itemAlignment) + pagingMolecule = try typeContainer.decodeIfPresent(codingKey: .pagingMolecule) as? PagingMoleculeProtocol } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(moleculeName, forKey: .moleculeName) + try container.encodeIfPresent(moleculeName, forKey: .moleculeName) try container.encode(molecules, forKey: .molecules) - try container.encode(spacing, forKey: .spacing) - try container.encode(border, forKey: .border) - try container.encode(loop, forKey: .loop) - try container.encode(height, forKey: .height) - try container.encode(itemWidthPercent, forKey: .itemWidthPercent) - try container.encode(itemAlignment, forKey: .itemAlignment) - try container.encodeIfPresent(self.pagingMolecule, forKey: .pagingMolecule) + try container.encodeIfPresent(spacing, forKey: .spacing) + try container.encodeIfPresent(border, forKey: .border) + try container.encodeIfPresent(loop, forKey: .loop) + try container.encodeIfPresent(height, forKey: .height) + try container.encodeIfPresent(itemWidthPercent, forKey: .itemWidthPercent) + try container.encodeIfPresent(itemAlignment, forKey: .itemAlignment) + try container.encodeModelIfPresent(pagingMolecule, forKey: .pagingMolecule) } } diff --git a/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift b/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift index 7a7770df..0bac18c6 100644 --- a/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift +++ b/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift @@ -31,14 +31,14 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) self.molecules = try typeContainer.decode([[ListItemModel]].self, forKey: .molecules) - self.separator = try typeContainer.decode(LineModel.self, forKey: .separator) + self.separator = try typeContainer.decodeIfPresent(LineModel.self, forKey: .separator) self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) self.dropDown = try typeContainer.decode(DropDownModel.self, forKey: .dropDown) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(moleculeName, forKey: .moleculeName) + try container.encodeIfPresent(moleculeName, forKey: .moleculeName) try container.encode(molecules, forKey: .molecules) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encode(dropDown, forKey: .dropDown) diff --git a/MVMCoreUI/Models/Molecules/FooterModel.swift b/MVMCoreUI/Models/Molecules/FooterModel.swift index 95a45422..52b21212 100644 --- a/MVMCoreUI/Models/Molecules/FooterModel.swift +++ b/MVMCoreUI/Models/Molecules/FooterModel.swift @@ -15,29 +15,23 @@ import Foundation public var backgroundColor: String? public var molecule: MoleculeProtocol? - public init(molecule: MoleculeProtocol?, backgroundColor: String?){ - self.molecule = molecule - self.backgroundColor = backgroundColor - } - enum CodingKeys: String, CodingKey { case moleculeName case molecule case backgroundColor - case separator } required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName) - self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) - self.molecule = try typeContainer.decodeIfPresent(codingKey: .molecule) + moleculeName = try typeContainer.decodeIfPresent(String.self, forKey: .moleculeName) + backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) + molecule = try typeContainer.decodeIfPresent(codingKey: .molecule) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(moleculeName, forKey: .moleculeName) - try container.encodeIfPresent(self.molecule, forKey: .molecule) + try container.encodeIfPresent(moleculeName, forKey: .moleculeName) + try container.encodeModelIfPresent(self.molecule, forKey: .molecule) try container.encodeIfPresent(self.backgroundColor, forKey: .backgroundColor) } } diff --git a/MVMCoreUI/Models/Molecules/HeaderModel.swift b/MVMCoreUI/Models/Molecules/HeaderModel.swift index adbfca47..45f511e0 100644 --- a/MVMCoreUI/Models/Molecules/HeaderModel.swift +++ b/MVMCoreUI/Models/Molecules/HeaderModel.swift @@ -15,12 +15,6 @@ import Foundation public var molecule: MoleculeProtocol? public var seperator: LineModel? - public init(molecule: MoleculeProtocol?, backgroundColor: String?, seperator: LineModel?){ - self.molecule = molecule - self.backgroundColor = backgroundColor - self.seperator = seperator - } - enum CodingKeys: String, CodingKey { case moleculeName case molecule @@ -30,17 +24,17 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName) - self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) - self.molecule = try typeContainer.decodeIfPresent(codingKey: .molecule) - self.seperator = try typeContainer.decodeIfPresent(LineModel.self, forKey: .separator) + moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName) + backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) + molecule = try typeContainer.decodeIfPresent(codingKey: .molecule) + seperator = try typeContainer.decodeIfPresent(LineModel.self, forKey: .separator) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) - try container.encodeIfPresent(self.molecule, forKey: .molecule) - try container.encodeIfPresent(self.backgroundColor, forKey: .backgroundColor) - try container.encodeIfPresent(self.seperator, forKey: .separator) + try container.encodeModelIfPresent(molecule, forKey: .molecule) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encodeIfPresent(seperator, forKey: .separator) } } diff --git a/MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift b/MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift index 1a7e6f73..0818630f 100644 --- a/MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift +++ b/MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift @@ -52,12 +52,11 @@ import Foundation public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) - try container.encodeIfPresent(self.molecule, forKey: .molecule) - - try container.encode(spacing, forKey: .spacing) - try container.encode(percentage, forKey: .percentage) - try container.encode(verticalAlignment, forKey: .verticalAlignment) - try container.encode(horizontalAlignment, forKey: .horizontalAlignment) - try container.encode(gone, forKey: .gone) + try container.encodeModelIfPresent(self.molecule, forKey: .molecule) + try container.encodeIfPresent(spacing, forKey: .spacing) + try container.encodeIfPresent(percentage, forKey: .percentage) + try container.encodeIfPresent(verticalAlignment, forKey: .verticalAlignment) + try container.encodeIfPresent(horizontalAlignment, forKey: .horizontalAlignment) + try container.encodeIfPresent(gone, forKey: .gone) } } diff --git a/MVMCoreUI/Models/Molecules/MoleculeStackModel.swift b/MVMCoreUI/Models/Molecules/MoleculeStackModel.swift index 9c462339..296c26d6 100644 --- a/MVMCoreUI/Models/Molecules/MoleculeStackModel.swift +++ b/MVMCoreUI/Models/Molecules/MoleculeStackModel.swift @@ -16,31 +16,28 @@ import Foundation public var axis: String? public var spacing: Float? - public init(axis: String?, molecules: [MoleculeStackItemModel]?, spacing: Float?) { - self.axis = axis - self.molecules = molecules - self.spacing = spacing - } - enum CodingKeys: String, CodingKey { case moleculeName case molecules case axis case spacing + case backgroundColor } required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - self.molecules = try typeContainer.decodeIfPresent([MoleculeStackItemModel].self, forKey: .molecules) - self.axis = try typeContainer.decodeIfPresent(String.self, forKey: .axis) - self.spacing = try typeContainer.decodeIfPresent(Float.self, forKey: .spacing) + molecules = try typeContainer.decodeIfPresent([MoleculeStackItemModel].self, forKey: .molecules) + axis = try typeContainer.decodeIfPresent(String.self, forKey: .axis) + spacing = try typeContainer.decodeIfPresent(Float.self, forKey: .spacing) + backgroundColor = try typeContainer.decode(String.self, forKey: .backgroundColor) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(moleculeName, forKey: .moleculeName) + try container.encodeIfPresent(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(molecules, forKey: .molecules) - try container.encode(axis, forKey: .axis) - try container.encode(spacing, forKey: .spacing) + try container.encodeIfPresent(axis, forKey: .axis) + try container.encodeIfPresent(spacing, forKey: .spacing) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) } } diff --git a/MVMCoreUI/Models/Template/ListPageTemplateModel.swift b/MVMCoreUI/Models/Template/ListPageTemplateModel.swift index fa8b96a2..ffeff803 100644 --- a/MVMCoreUI/Models/Template/ListPageTemplateModel.swift +++ b/MVMCoreUI/Models/Template/ListPageTemplateModel.swift @@ -54,7 +54,7 @@ import Foundation try container.encode(pageType, forKey: .pageType) try container.encode(screenHeading, forKey: .screenHeading) - try container.encodeArray(molecules, forKey: .molecules) + try container.encodeModels(molecules, forKey: .molecules) try container.encodeIfPresent(isAtomicTabs, forKey: .isAtomicTabs) try container.encodeIfPresent(header, forKey: .header) try container.encodeIfPresent(footer, forKey: .footer) diff --git a/MVMCoreUI/Molecules/Items/ListItemModel.swift b/MVMCoreUI/Molecules/Items/ListItemModel.swift index 5ae9e7fa..cfb1165b 100644 --- a/MVMCoreUI/Molecules/Items/ListItemModel.swift +++ b/MVMCoreUI/Molecules/Items/ListItemModel.swift @@ -20,6 +20,7 @@ import Foundation enum CodingKeys: String, CodingKey { case moleculeName case molecule + case backgroundColor case action case hideArrow case separator @@ -29,6 +30,7 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) molecule = try typeContainer.decodeIfPresent(codingKey: .molecule) + backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) action = try typeContainer.decodeIfPresent(ActionModel.self, forKey: .action) hideArrow = try typeContainer.decodeIfPresent(Bool.self, forKey: .hideArrow) separator = try typeContainer.decodeIfPresent(LineModel.self, forKey: .separator) @@ -38,7 +40,8 @@ import Foundation public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) - try container.encodeIfPresent(molecule, forKey: .molecule) + try container.encodeModelIfPresent(molecule, forKey: .molecule) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(action, forKey: .action) try container.encodeIfPresent(hideArrow, forKey: .hideArrow) try container.encodeIfPresent(separator, forKey: .separator) From bf27d19ae15032208ae4b8c76916211c195eb213 Mon Sep 17 00:00:00 2001 From: panxi Date: Thu, 19 Dec 2019 14:25:26 -0500 Subject: [PATCH 17/51] change float to cgfloat for nslayoutconstraint --- MVMCoreUI/Models/Molecules/CarouselModel.swift | 12 ++++++------ MVMCoreUI/Organisms/Carousel.swift | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/MVMCoreUI/Models/Molecules/CarouselModel.swift b/MVMCoreUI/Models/Molecules/CarouselModel.swift index 08bddafd..47e36518 100644 --- a/MVMCoreUI/Models/Molecules/CarouselModel.swift +++ b/MVMCoreUI/Models/Molecules/CarouselModel.swift @@ -13,11 +13,11 @@ import UIKit public var backgroundColor: String? public var molecules: [CarouselItemModel] - public var spacing: Float? + public var spacing: CGFloat? public var border: Bool? public var loop: Bool? - public var height: Float? - public var itemWidthPercent: Float? + public var height: CGFloat? + public var itemWidthPercent: CGFloat? public var itemAlignment: String? public var pagingMolecule: PagingMoleculeProtocol? @@ -40,11 +40,11 @@ import UIKit required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) molecules = try typeContainer.decode([CarouselItemModel].self, forKey: .molecules) - spacing = try typeContainer.decodeIfPresent(Float.self, forKey: .spacing) + spacing = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .spacing) border = try typeContainer.decodeIfPresent(Bool.self, forKey: .border) loop = try typeContainer.decodeIfPresent(Bool.self, forKey: .loop) - height = try typeContainer.decodeIfPresent(Float.self, forKey: .height) - itemWidthPercent = try typeContainer.decodeIfPresent(Float.self, forKey: .itemWidthPercent) + height = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .height) + itemWidthPercent = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .itemWidthPercent) itemAlignment = try typeContainer.decodeIfPresent(String.self, forKey: .itemAlignment) pagingMolecule = try typeContainer.decodeIfPresent(codingKey: .pagingMolecule) as? PagingMoleculeProtocol } diff --git a/MVMCoreUI/Organisms/Carousel.swift b/MVMCoreUI/Organisms/Carousel.swift index 116f1135..6af1224b 100644 --- a/MVMCoreUI/Organisms/Carousel.swift +++ b/MVMCoreUI/Organisms/Carousel.swift @@ -98,11 +98,11 @@ open class Carousel: ViewConstrainingView, ModelMoleculeViewProtocol { registerCells(with: caroselModel, delegateObject: delegateObject) setupLayout(with: caroselModel) prepareMolecules(with: caroselModel) - itemWidthPercent = CGFloat((caroselModel.itemWidthPercent ?? 100) / 100) + itemWidthPercent = (caroselModel.itemWidthPercent ?? 100) / 100 setAlignment(with: caroselModel.itemAlignment) if let height = caroselModel.height { - collectionViewHeight?.constant = CGFloat(height) + collectionViewHeight?.constant = height collectionViewHeight?.isActive = true } @@ -122,7 +122,7 @@ open class Carousel: ViewConstrainingView, ModelMoleculeViewProtocol { func setupLayout(with carouselModel: CarouselModel?) { let layout = UICollectionViewFlowLayout() layout.scrollDirection = .horizontal - layout.minimumLineSpacing = CGFloat(carouselModel?.spacing ?? 1) + layout.minimumLineSpacing = carouselModel?.spacing ?? 1 layout.minimumInteritemSpacing = 0 collectionView.collectionViewLayout = layout } From b620a533d52b4d69a1a3a6ea56de398914193b81 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 8 Jan 2020 11:22:34 -0500 Subject: [PATCH 18/51] Color CaretLink model change name --- MVMCoreUI.xcodeproj/project.pbxproj | 8 ++--- ...ButtonModel.swift => CaretLinkModel.swift} | 30 ++++++++++------- MVMCoreUI/Atoms/Views/CaretViewModel.swift | 2 +- MVMCoreUI/Atoms/Views/ProgressBarModel.swift | 33 +++++++++++-------- .../ModelProtocols/MoleculeProtocol.swift | 2 +- 5 files changed, 43 insertions(+), 32 deletions(-) rename MVMCoreUI/Atoms/Buttons/{CaretButtonModel.swift => CaretLinkModel.swift} (59%) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 18eaaf7b..8363aad1 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -66,7 +66,7 @@ 01EB369223609801006832FA /* MoleculeStackModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB368B23609801006832FA /* MoleculeStackModel.swift */; }; 01EB369323609801006832FA /* HeaderModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB368C23609801006832FA /* HeaderModel.swift */; }; 01EB369423609801006832FA /* HeadlineBodyModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB368D23609801006832FA /* HeadlineBodyModel.swift */; }; - 01F2A03223A4498200D954D8 /* CaretButtonModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A03123A4498200D954D8 /* CaretButtonModel.swift */; }; + 01F2A03223A4498200D954D8 /* CaretLinkModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A03123A4498200D954D8 /* CaretLinkModel.swift */; }; 0A1214A022C11A18007C7030 /* ActionDetailWithImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A12149F22C11A17007C7030 /* ActionDetailWithImage.swift */; }; 0A1B4A96233BB18F005B3FB4 /* CheckboxWithLabelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAFA2232BE63400FB8E22 /* CheckboxWithLabelView.swift */; }; 0A209CD323A7E2810068F8B0 /* UIStackViewAlignment+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A209CD223A7E2810068F8B0 /* UIStackViewAlignment+Extension.swift */; }; @@ -326,7 +326,7 @@ 01EB368B23609801006832FA /* MoleculeStackModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MoleculeStackModel.swift; sourceTree = ""; }; 01EB368C23609801006832FA /* HeaderModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HeaderModel.swift; sourceTree = ""; }; 01EB368D23609801006832FA /* HeadlineBodyModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HeadlineBodyModel.swift; sourceTree = ""; }; - 01F2A03123A4498200D954D8 /* CaretButtonModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CaretButtonModel.swift; sourceTree = ""; }; + 01F2A03123A4498200D954D8 /* CaretLinkModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CaretLinkModel.swift; sourceTree = ""; }; 0A12149F22C11A17007C7030 /* ActionDetailWithImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionDetailWithImage.swift; sourceTree = ""; }; 0A209CD223A7E2810068F8B0 /* UIStackViewAlignment+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIStackViewAlignment+Extension.swift"; sourceTree = ""; }; 0A41BA6D2344FCD400D4C0BC /* CATransaction+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CATransaction+Extension.swift"; sourceTree = ""; }; @@ -983,7 +983,7 @@ isa = PBXGroup; children = ( DBC4391A224421A0001AB423 /* CaretButton.swift */, - 01F2A03123A4498200D954D8 /* CaretButtonModel.swift */, + 01F2A03123A4498200D954D8 /* CaretLinkModel.swift */, D29DF25821E6A22D003B2FB9 /* MFButtonProtocol.h */, D29DF16B21E69E1F003B2FB9 /* ButtonDelegateProtocol.h */, D29DF16A21E69E1F003B2FB9 /* MFCustomButton.h */, @@ -1418,7 +1418,7 @@ 0105618F224BBE7700E1557D /* FormValidator+FormParams.swift in Sources */, 012CA9E223888AED003F810F /* (null) in Sources */, 012A88DA238ED42E00FE3DA1 /* (null) in Sources */, - 01F2A03223A4498200D954D8 /* CaretButtonModel.swift in Sources */, + 01F2A03223A4498200D954D8 /* CaretLinkModel.swift in Sources */, 0A7BAFA1232BE61800FB8E22 /* Checkbox.swift in Sources */, 011B58F023A2AA980085F53C /* ListItemModelProtocol.swift in Sources */, D22479962316AF6E003FCCF9 /* HeadlineBodyTextButton.swift in Sources */, diff --git a/MVMCoreUI/Atoms/Buttons/CaretButtonModel.swift b/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift similarity index 59% rename from MVMCoreUI/Atoms/Buttons/CaretButtonModel.swift rename to MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift index cf21a19b..0cd9c252 100644 --- a/MVMCoreUI/Atoms/Buttons/CaretButtonModel.swift +++ b/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift @@ -1,5 +1,5 @@ // -// CaretButtonModel.swift +// CaretLinkModel.swift // MVMCoreUI // // Created by Suresh, Kamlesh on 12/13/19. @@ -9,14 +9,14 @@ import Foundation import MVMCore -public class CaretButtonModel: MoleculeProtocol { - public static var identifier: String = "caretButton" +public class CaretLinkModel: MoleculeProtocol { + public static var identifier: String = "caretLink" public var backgroundColor: String? public var label: LabelModel public var action: ActionProtocol - public var enabledColor: String? - public var disabledColor: String? - public var enabled: Bool? + public var enabledColor: UIColor = .black + public var disabledColor: UIColor = .mfSilver() + public var enabled: Bool = true public init(label: LabelModel, action: ActionProtocol) { self.label = label @@ -36,9 +36,15 @@ public class CaretButtonModel: MoleculeProtocol { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) label = try typeContainer.decode(LabelModel.self, forKey: .label) - enabledColor = try typeContainer.decodeIfPresent(String.self, forKey: .enabledColor) - disabledColor = try typeContainer.decodeIfPresent(String.self, forKey: .disabledColor) - enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) + if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor)?.uiColor { + enabledColor = color + } + if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor)?.uiColor { + disabledColor = color + } + if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) { + self.enabled = enabled + } action = try typeContainer.decodeModel(codingKey: .action, typeCodingKey: ActionCodingKey.type) } @@ -47,8 +53,8 @@ public class CaretButtonModel: MoleculeProtocol { try container.encode(label, forKey: .label) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeModel(action, forKey: .action) - try container.encodeIfPresent(enabledColor, forKey: .enabledColor) - try container.encodeIfPresent(disabledColor, forKey: .disabledColor) - try container.encodeIfPresent(enabled, forKey: .enabled) + try container.encode(Color(uiColor: enabledColor), forKey: .enabledColor) + try container.encode(Color(uiColor: disabledColor), forKey: .disabledColor) + try container.encode(enabled, forKey: .enabled) } } diff --git a/MVMCoreUI/Atoms/Views/CaretViewModel.swift b/MVMCoreUI/Atoms/Views/CaretViewModel.swift index 5a8998db..8d2bc16c 100644 --- a/MVMCoreUI/Atoms/Views/CaretViewModel.swift +++ b/MVMCoreUI/Atoms/Views/CaretViewModel.swift @@ -11,7 +11,7 @@ import Foundation @objcMembers public class CaretViewModel: MoleculeProtocol { public static var identifier: String = "caretView" - public var backgroundColor: String? + public var backgroundColor: Color? public var strokeColor: String? public var isHidden: Bool? public var isOpaque: Bool? diff --git a/MVMCoreUI/Atoms/Views/ProgressBarModel.swift b/MVMCoreUI/Atoms/Views/ProgressBarModel.swift index 3450fc87..784b938c 100644 --- a/MVMCoreUI/Atoms/Views/ProgressBarModel.swift +++ b/MVMCoreUI/Atoms/Views/ProgressBarModel.swift @@ -10,33 +10,38 @@ import Foundation @objcMembers public class ProgressBarModel: MoleculeProtocol { public static var identifier: String = "progressbar" - public var moleculeName: String public var isRounded: Bool? public var thickness: CGFloat? ///from 0 to 100 - public var percentage: Float - public var progressColor: String? - public var backgroundColor: String? + public var percent: CGFloat + public var progressColor: Color = Color(uiColor: .mfCerulean()) + public var backgroundColor: Color? = Color(uiColor: .mfLightSilver()) enum CodingKeys: String, CodingKey { case moleculeName case isRounded = "roundRect" case thickness - case percentage = "percent" + case percent case progressColor case backgroundColor } + init(_ percent: CGFloat) { + self.percent = percent + } + required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName) - self.isRounded = try typeContainer.decodeIfPresent(Bool.self, forKey: .isRounded) - self.thickness = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .thickness) - self.percentage = try typeContainer.decode(Float.self, forKey: .percentage) - self.progressColor = try typeContainer.decodeIfPresent(String.self, forKey: .progressColor) - self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) - + isRounded = try typeContainer.decodeIfPresent(Bool.self, forKey: .isRounded) + thickness = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .thickness) + percent = try typeContainer.decode(CGFloat.self, forKey: .percent) + if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .progressColor) { + progressColor = color + } + if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) { + backgroundColor = color + } } public func encode(to encoder: Encoder) throws { @@ -44,8 +49,8 @@ import Foundation try container.encode(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(isRounded, forKey: .isRounded) try container.encodeIfPresent(thickness, forKey: .thickness) - try container.encodeIfPresent(percentage, forKey: .percentage) - try container.encodeIfPresent(progressColor, forKey: .progressColor) + try container.encode(percent, forKey: .percent) + try container.encode(progressColor, forKey: .progressColor) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) } } diff --git a/MVMCoreUI/Models/ModelProtocols/MoleculeProtocol.swift b/MVMCoreUI/Models/ModelProtocols/MoleculeProtocol.swift index e05f16b6..b8117e60 100644 --- a/MVMCoreUI/Models/ModelProtocols/MoleculeProtocol.swift +++ b/MVMCoreUI/Models/ModelProtocols/MoleculeProtocol.swift @@ -2,7 +2,7 @@ import Foundation public protocol MoleculeProtocol: Model { var moleculeName: String? { get } - var backgroundColor: String? { get set} + var backgroundColor: Color? { get set} } extension MoleculeProtocol { From 2e514a7de589d0aeb2aab424f4e4b1f6eef19a0b Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 8 Jan 2020 13:22:45 -0500 Subject: [PATCH 19/51] Colors --- MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift | 4 ++-- MVMCoreUI/Atoms/Views/DashLine.swift | 4 ++-- MVMCoreUI/Atoms/Views/DashLineModel.swift | 6 +++--- MVMCoreUI/Atoms/Views/ImageViewModel.swift | 2 +- MVMCoreUI/Atoms/Views/Label.swift | 4 ++-- MVMCoreUI/Atoms/Views/LabelModel/LabelModel.swift | 4 ++-- MVMCoreUI/Atoms/Views/LeftRightLabelModel.swift | 2 +- MVMCoreUI/Atoms/Views/MFView+ModelExtension.swift | 4 ++-- MVMCoreUI/Atoms/Views/MultiProgressModel.swift | 2 +- MVMCoreUI/Atoms/Views/ProgressBar.swift | 8 +++----- MVMCoreUI/Atoms/Views/ProgressBarModel.swift | 2 +- MVMCoreUI/BaseClasses/View.swift | 4 ++-- .../Models/ModelProtocols/ContainerMoleculeProtocol.swift | 2 +- MVMCoreUI/Models/Molecules/CarouselItemModel.swift | 4 ++-- MVMCoreUI/Models/Molecules/CarouselModel.swift | 4 ++-- MVMCoreUI/Models/Molecules/DropDownListItemModel.swift | 4 ++-- MVMCoreUI/Models/Molecules/DropDownModel.swift | 2 +- MVMCoreUI/Models/Molecules/FooterModel.swift | 4 ++-- MVMCoreUI/Models/Molecules/HeaderModel.swift | 2 +- MVMCoreUI/Models/Molecules/LineModel.swift | 2 +- MVMCoreUI/Models/Molecules/ModuleMoleculeModel.swift | 2 +- MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift | 2 +- MVMCoreUI/Models/Molecules/MoleculeStackModel.swift | 2 +- MVMCoreUI/Models/Molecules/TextFieldModel.swift | 2 +- MVMCoreUI/Molecules/Items/ListItemModel.swift | 2 +- .../Molecules/Items/MoleculeCollectionViewCell.swift | 4 ++-- MVMCoreUI/Molecules/Items/TableViewCell.swift | 4 ++-- .../EyebrowHeadlineBodyLink.swift | 2 +- .../VerticalCombinationViews/HeadlineBodyModel.swift | 2 +- 29 files changed, 45 insertions(+), 47 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift b/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift index 0cd9c252..4d3c6223 100644 --- a/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift +++ b/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift @@ -11,7 +11,7 @@ import MVMCore public class CaretLinkModel: MoleculeProtocol { public static var identifier: String = "caretLink" - public var backgroundColor: String? + public var backgroundColor: Color? public var label: LabelModel public var action: ActionProtocol public var enabledColor: UIColor = .black @@ -34,7 +34,7 @@ public class CaretLinkModel: MoleculeProtocol { required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) label = try typeContainer.decode(LabelModel.self, forKey: .label) if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor)?.uiColor { enabledColor = color diff --git a/MVMCoreUI/Atoms/Views/DashLine.swift b/MVMCoreUI/Atoms/Views/DashLine.swift index 52ed9a65..48decdf9 100644 --- a/MVMCoreUI/Atoms/Views/DashLine.swift +++ b/MVMCoreUI/Atoms/Views/DashLine.swift @@ -90,12 +90,12 @@ open class DashLine: View { guard let dashLineModel = model as? DashLineModel else { return } - dashColor = UIColor.mfGet(forHex: dashLineModel.dashColor) + dashColor = dashLineModel.dashColor.uiColor if let isHiddenValue = dashLineModel.isHidden { isHidden = isHiddenValue } if let backgroundColor = dashLineModel.backgroundColor { - dashLayer?.backgroundColor = UIColor.mfGet(forHex: backgroundColor).cgColor + dashLayer?.backgroundColor = backgroundColor.uiColor.cgColor } } } diff --git a/MVMCoreUI/Atoms/Views/DashLineModel.swift b/MVMCoreUI/Atoms/Views/DashLineModel.swift index 172e5dd6..06d85f08 100644 --- a/MVMCoreUI/Atoms/Views/DashLineModel.swift +++ b/MVMCoreUI/Atoms/Views/DashLineModel.swift @@ -10,12 +10,12 @@ import Foundation @objcMembers public class DashLineModel: MoleculeProtocol { public static var identifier: String = "dashLine" - public var backgroundColor: String? + public var backgroundColor: Color? - public var dashColor: String + public var dashColor: Color public var isHidden: Bool? - public init(dashColor: String) { + public init(dashColor: Color) { self.dashColor = dashColor } } diff --git a/MVMCoreUI/Atoms/Views/ImageViewModel.swift b/MVMCoreUI/Atoms/Views/ImageViewModel.swift index 16c32d8f..a65c946a 100644 --- a/MVMCoreUI/Atoms/Views/ImageViewModel.swift +++ b/MVMCoreUI/Atoms/Views/ImageViewModel.swift @@ -11,7 +11,7 @@ import Foundation @objcMembers public class ImageViewModel: MoleculeProtocol { public static var identifier: String = "image" public var moleculeName: String - public var backgroundColor: String? + public var backgroundColor: Color? public var image: String public var accessibilityText: String? diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index b37e74fb..b4b4e36a 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -235,8 +235,8 @@ public typealias ActionBlock = () -> () } makeWholeViewClickable = labelModel.makeWholeViewClickable ?? false - if let backgroundColorHex = labelModel.backgroundColor, !backgroundColorHex.isEmpty { - backgroundColor = UIColor.mfGet(forHex: backgroundColorHex) + if let backgroundColor = labelModel.backgroundColor { + self.backgroundColor = backgroundColor.uiColor } if let accessibilityText = labelModel.accessibilityText { accessibilityLabel = accessibilityText diff --git a/MVMCoreUI/Atoms/Views/LabelModel/LabelModel.swift b/MVMCoreUI/Atoms/Views/LabelModel/LabelModel.swift index 2b87186f..90c694a0 100644 --- a/MVMCoreUI/Atoms/Views/LabelModel/LabelModel.swift +++ b/MVMCoreUI/Atoms/Views/LabelModel/LabelModel.swift @@ -12,7 +12,7 @@ import Foundation @objcMembers public class LabelModel: MoleculeProtocol { public static var identifier: String = "label" public var moleculeName: String? - public var backgroundColor: String? + public var backgroundColor: Color? public var text: String public var accessibilityText: String? @@ -52,7 +52,7 @@ import Foundation self.text = try typeContainer.decode(String.self, forKey: .text) self.accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText) self.textColor = try typeContainer.decodeIfPresent(String.self, forKey: .textColor) - self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) + self.backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) self.fontStyle = try typeContainer.decodeIfPresent(String.self, forKey: .fontStyle) self.fontName = try typeContainer.decodeIfPresent(String.self, forKey: .fontName) self.fontSize = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .fontSize) diff --git a/MVMCoreUI/Atoms/Views/LeftRightLabelModel.swift b/MVMCoreUI/Atoms/Views/LeftRightLabelModel.swift index 30015d70..e006afc9 100644 --- a/MVMCoreUI/Atoms/Views/LeftRightLabelModel.swift +++ b/MVMCoreUI/Atoms/Views/LeftRightLabelModel.swift @@ -10,7 +10,7 @@ import UIKit @objcMembers public class LeftRightLabelModel: MoleculeProtocol { public static var identifier: String = "leftRightLabel" - public var backgroundColor: String? + public var backgroundColor: Color? public var leftText: LabelModel public var rightText: LabelModel diff --git a/MVMCoreUI/Atoms/Views/MFView+ModelExtension.swift b/MVMCoreUI/Atoms/Views/MFView+ModelExtension.swift index bfeb7312..df6b09a5 100644 --- a/MVMCoreUI/Atoms/Views/MFView+ModelExtension.swift +++ b/MVMCoreUI/Atoms/Views/MFView+ModelExtension.swift @@ -11,8 +11,8 @@ 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) + if let backgroundColor = model?.backgroundColor { + self.backgroundColor = backgroundColor.uiColor } } } diff --git a/MVMCoreUI/Atoms/Views/MultiProgressModel.swift b/MVMCoreUI/Atoms/Views/MultiProgressModel.swift index 25522070..9d1f11fd 100644 --- a/MVMCoreUI/Atoms/Views/MultiProgressModel.swift +++ b/MVMCoreUI/Atoms/Views/MultiProgressModel.swift @@ -17,7 +17,7 @@ import Foundation @objcMembers public class MultiProgressBarModel: MoleculeProtocol { public static var identifier: String = "multiProgressBar" public var moleculeName: String - public var backgroundColor: String? + public var backgroundColor: Color? public var progressList: [SingleProgressBarModel] public var thickness: CGFloat? public var roundedRect: Bool? diff --git a/MVMCoreUI/Atoms/Views/ProgressBar.swift b/MVMCoreUI/Atoms/Views/ProgressBar.swift index 90d63dfb..8a3b0bb0 100644 --- a/MVMCoreUI/Atoms/Views/ProgressBar.swift +++ b/MVMCoreUI/Atoms/Views/ProgressBar.swift @@ -57,12 +57,10 @@ import Foundation } isRounded = progressBarModel.isRounded ?? false thickness = progressBarModel.thickness ?? 8 - progress = (progressBarModel.percentage)/100.0 - if let progressColor = progressBarModel.progressColor { - progressTintColor = UIColor.mfGet(forHex: progressColor) - } + progress = Float((progressBarModel.percent)/100.0) + progressTintColor = progressBarModel.progressColor.uiColor if let backgroundColor = progressBarModel.backgroundColor { - trackTintColor = UIColor.mfGet(forHex: backgroundColor) + trackTintColor = backgroundColor.uiColor } } diff --git a/MVMCoreUI/Atoms/Views/ProgressBarModel.swift b/MVMCoreUI/Atoms/Views/ProgressBarModel.swift index 784b938c..47fabb6a 100644 --- a/MVMCoreUI/Atoms/Views/ProgressBarModel.swift +++ b/MVMCoreUI/Atoms/Views/ProgressBarModel.swift @@ -14,7 +14,7 @@ import Foundation public var isRounded: Bool? public var thickness: CGFloat? ///from 0 to 100 - public var percent: CGFloat + @Clamping(range: 0...100) public var percent: CGFloat public var progressColor: Color = Color(uiColor: .mfCerulean()) public var backgroundColor: Color? = Color(uiColor: .mfLightSilver()) diff --git a/MVMCoreUI/BaseClasses/View.swift b/MVMCoreUI/BaseClasses/View.swift index 8ae6dfa7..0cb1088d 100644 --- a/MVMCoreUI/BaseClasses/View.swift +++ b/MVMCoreUI/BaseClasses/View.swift @@ -42,8 +42,8 @@ import UIKit open func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { self.model = model - if let backgroundColorString = model?.backgroundColor { - backgroundColor = UIColor.mfGet(for: backgroundColorString) + if let backgroundColor = model?.backgroundColor { + self.backgroundColor = backgroundColor.uiColor } } } diff --git a/MVMCoreUI/Models/ModelProtocols/ContainerMoleculeProtocol.swift b/MVMCoreUI/Models/ModelProtocols/ContainerMoleculeProtocol.swift index 81ffd123..9a303bdf 100644 --- a/MVMCoreUI/Models/ModelProtocols/ContainerMoleculeProtocol.swift +++ b/MVMCoreUI/Models/ModelProtocols/ContainerMoleculeProtocol.swift @@ -17,7 +17,7 @@ public protocol ContainerMoleculeProtocol: MoleculeProtocol { } extension ContainerMoleculeProtocol { - public var backgroundColor: String? { + public var backgroundColor: Color? { get { return nil } } diff --git a/MVMCoreUI/Models/Molecules/CarouselItemModel.swift b/MVMCoreUI/Models/Molecules/CarouselItemModel.swift index 3339ed09..1ccf898f 100644 --- a/MVMCoreUI/Models/Molecules/CarouselItemModel.swift +++ b/MVMCoreUI/Models/Molecules/CarouselItemModel.swift @@ -12,7 +12,7 @@ import Foundation @objcMembers public class CarouselItemModel: ContainerMoleculeProtocol { public static var identifier: String = "carouselItem" public var molecule: MoleculeProtocol - public var backgroundColor: String? + public var backgroundColor: Color? public init(molecule: MoleculeProtocol) { self.molecule = molecule @@ -27,7 +27,7 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) molecule = try typeContainer.decodeMolecule(codingKey: .molecule) - backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) } public func encode(to encoder: Encoder) throws { diff --git a/MVMCoreUI/Models/Molecules/CarouselModel.swift b/MVMCoreUI/Models/Molecules/CarouselModel.swift index 56bec824..9b55f97a 100644 --- a/MVMCoreUI/Models/Molecules/CarouselModel.swift +++ b/MVMCoreUI/Models/Molecules/CarouselModel.swift @@ -10,7 +10,7 @@ import UIKit @objcMembers public class CarouselModel: MoleculeProtocol { public static var identifier: String = "carousel" - public var backgroundColor: String? + public var backgroundColor: Color? public var molecules: [CarouselItemModel] public var spacing: Float? @@ -41,7 +41,7 @@ import UIKit required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) self.molecules = try typeContainer.decode([CarouselItemModel].self, forKey: .molecules) - self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) + self.backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) self.spacing = try typeContainer.decode(Float.self, forKey: .spacing) self.border = try typeContainer.decode(Bool.self, forKey: .border) self.loop = try typeContainer.decode(Bool.self, forKey: .loop) diff --git a/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift b/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift index 9e447713..260e7063 100644 --- a/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift +++ b/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift @@ -12,7 +12,7 @@ import Foundation public static var identifier: String = "dropDownListItem" public var molecule: MoleculeProtocol public var molecules: [[ListItemModel]] - public var backgroundColor: String? + public var backgroundColor: Color? public var separator: LineModel? public var dropDown: DropDownModel @@ -36,7 +36,7 @@ import Foundation molecule = try typeContainer.decodeMolecule(codingKey: .molecule) self.molecules = try typeContainer.decode([[ListItemModel]].self, forKey: .molecules) self.separator = try typeContainer.decodeIfPresent(LineModel.self, forKey: .separator) - self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) + self.backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) self.dropDown = try typeContainer.decode(DropDownModel.self, forKey: .dropDown) } diff --git a/MVMCoreUI/Models/Molecules/DropDownModel.swift b/MVMCoreUI/Models/Molecules/DropDownModel.swift index b28eda5d..c0320737 100644 --- a/MVMCoreUI/Models/Molecules/DropDownModel.swift +++ b/MVMCoreUI/Models/Molecules/DropDownModel.swift @@ -11,7 +11,7 @@ import Foundation @objcMembers public class DropDownModel: MoleculeProtocol { public static var identifier: String = "dropDownModel" - public var backgroundColor: String? + public var backgroundColor: Color? public var label: String public var options: [String] } diff --git a/MVMCoreUI/Models/Molecules/FooterModel.swift b/MVMCoreUI/Models/Molecules/FooterModel.swift index 83043f81..93f0a4e3 100644 --- a/MVMCoreUI/Models/Molecules/FooterModel.swift +++ b/MVMCoreUI/Models/Molecules/FooterModel.swift @@ -12,7 +12,7 @@ import Foundation @objcMembers public class FooterModel: ContainerMoleculeProtocol { public static var identifier: String = "footer" public var moleculeName: String? - public var backgroundColor: String? + public var backgroundColor: Color? public var molecule: MoleculeProtocol public init(molecule: MoleculeProtocol){ @@ -28,7 +28,7 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName) - self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) + self.backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) self.molecule = try typeContainer.decodeMolecule(codingKey: .molecule) } diff --git a/MVMCoreUI/Models/Molecules/HeaderModel.swift b/MVMCoreUI/Models/Molecules/HeaderModel.swift index c28d7080..2f824773 100644 --- a/MVMCoreUI/Models/Molecules/HeaderModel.swift +++ b/MVMCoreUI/Models/Molecules/HeaderModel.swift @@ -11,7 +11,7 @@ import Foundation @objcMembers public class HeaderModel: MoleculeContainerModel, MoleculeProtocol { public static var identifier: String = "header" public var moleculeName: String? - public var backgroundColor: String? + public var backgroundColor: Color? public var line: LineModel? enum HeaderCodingKeys: String, CodingKey { diff --git a/MVMCoreUI/Models/Molecules/LineModel.swift b/MVMCoreUI/Models/Molecules/LineModel.swift index c6a22c62..66010536 100644 --- a/MVMCoreUI/Models/Molecules/LineModel.swift +++ b/MVMCoreUI/Models/Molecules/LineModel.swift @@ -10,6 +10,6 @@ import UIKit @objcMembers public class LineModel: MoleculeProtocol { public static var identifier: String = "line" - public var backgroundColor: String? + public var backgroundColor: Color? public var type: String? } diff --git a/MVMCoreUI/Models/Molecules/ModuleMoleculeModel.swift b/MVMCoreUI/Models/Molecules/ModuleMoleculeModel.swift index 6e170b03..35702824 100644 --- a/MVMCoreUI/Models/Molecules/ModuleMoleculeModel.swift +++ b/MVMCoreUI/Models/Molecules/ModuleMoleculeModel.swift @@ -9,7 +9,7 @@ import Foundation open class ModuleMoleculeModel: MoleculeProtocol { - public var backgroundColor: String? + public var backgroundColor: Color? public static var identifier: String = "moduleMolecule" public var moduleName: String diff --git a/MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift b/MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift index a0e7825c..106ea6e5 100644 --- a/MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift +++ b/MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift @@ -10,7 +10,7 @@ import Foundation @objcMembers public class MoleculeStackItemModel: MoleculeContainerModel, MoleculeProtocol { public static var identifier: String = "stackItem" - public var backgroundColor: String? + public var backgroundColor: Color? public var spacing: CGFloat? public var percentage: Int? = 0 public var gone: Bool = false diff --git a/MVMCoreUI/Models/Molecules/MoleculeStackModel.swift b/MVMCoreUI/Models/Molecules/MoleculeStackModel.swift index 530c7393..f8012a30 100644 --- a/MVMCoreUI/Models/Molecules/MoleculeStackModel.swift +++ b/MVMCoreUI/Models/Molecules/MoleculeStackModel.swift @@ -10,7 +10,7 @@ import Foundation @objcMembers public class MoleculeStackModel: ContainerModel, MoleculeProtocol { public static var identifier: String = "moleculeStack" - public var backgroundColor: String? + public var backgroundColor: Color? public var molecules: [MoleculeStackItemModel] public var axis: NSLayoutConstraint.Axis = .vertical public var spacing: CGFloat = 16.0 diff --git a/MVMCoreUI/Models/Molecules/TextFieldModel.swift b/MVMCoreUI/Models/Molecules/TextFieldModel.swift index ea6f3deb..3a76bbb3 100644 --- a/MVMCoreUI/Models/Molecules/TextFieldModel.swift +++ b/MVMCoreUI/Models/Molecules/TextFieldModel.swift @@ -11,7 +11,7 @@ import UIKit @objcMembers public class TextFieldModel: MoleculeProtocol, FormModelProtocol { public static var identifier: String = "textField" - public var backgroundColor: String? + public var backgroundColor: Color? public var editable: Bool? public var disabled: Bool? diff --git a/MVMCoreUI/Molecules/Items/ListItemModel.swift b/MVMCoreUI/Molecules/Items/ListItemModel.swift index 1311e69f..bdff2842 100644 --- a/MVMCoreUI/Molecules/Items/ListItemModel.swift +++ b/MVMCoreUI/Molecules/Items/ListItemModel.swift @@ -12,7 +12,7 @@ import MVMCore @objcMembers public class ListItemModel: ListItemModelProtocol { public static var identifier: String = "listItem" public var molecule: MoleculeProtocol - public var backgroundColor: String? + public var backgroundColor: Color? public var action: ActionProtocol? public var hideArrow: Bool? public var separator: LineModel? diff --git a/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift b/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift index d532147c..b976ca64 100644 --- a/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift +++ b/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift @@ -87,8 +87,8 @@ open class MoleculeCollectionViewCell: UICollectionViewCell, MVMCoreUIMoleculeVi peakingRightArrow.tintColor = color } - if let backgroundColorString = collectionModel.backgroundColor { - backgroundColor = UIColor.mfGet(forHex: backgroundColorString) + if let backgroundColor = collectionModel.backgroundColor { + self.backgroundColor = backgroundColor.uiColor } if molecule == nil { diff --git a/MVMCoreUI/Molecules/Items/TableViewCell.swift b/MVMCoreUI/Molecules/Items/TableViewCell.swift index 60af3f68..d74f0ee5 100644 --- a/MVMCoreUI/Molecules/Items/TableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/TableViewCell.swift @@ -163,8 +163,8 @@ import UIKit bottomMarginPadding = 0 } - if let backgroundColorString = model.backgroundColor { - backgroundColor = UIColor.mfGet(forHex: backgroundColorString) + if let backgroundColor = model.backgroundColor { + self.backgroundColor = backgroundColor.uiColor } // Add the caret if there is an action and it's not declared hidden. diff --git a/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift b/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift index 975c4851..706e4712 100644 --- a/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift +++ b/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift @@ -10,7 +10,7 @@ import UIKit struct EyebrowHeadlineBodyLinkModel: MoleculeProtocol { static var identifier: String = "eyebrowHeadlineBodyLink" - var backgroundColor: String? + var backgroundColor: Color? public var eyeBrow: LabelModel? public var headline: LabelModel? diff --git a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyModel.swift b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyModel.swift index c6dbd059..6ce51d3e 100644 --- a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyModel.swift +++ b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyModel.swift @@ -13,7 +13,7 @@ import Foundation public var headline: LabelModel public var body: LabelModel public var style: String? - public var backgroundColor: String? + public var backgroundColor: Color? public init(headline: LabelModel, body: LabelModel) { self.headline = headline From d4c9753041d85f732c15a08289017153105a3bb3 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 8 Jan 2020 14:27:10 -0500 Subject: [PATCH 20/51] Percent --- MVMCoreUI/Atoms/Views/MultiProgress.swift | 2 +- MVMCoreUI/Atoms/Views/MultiProgressModel.swift | 10 +++++++--- MVMCoreUI/Atoms/Views/ProgressBarModel.swift | 16 +++++++--------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/MultiProgress.swift b/MVMCoreUI/Atoms/Views/MultiProgress.swift index bbe8ed76..aceaf775 100644 --- a/MVMCoreUI/Atoms/Views/MultiProgress.swift +++ b/MVMCoreUI/Atoms/Views/MultiProgress.swift @@ -27,7 +27,7 @@ import UIKit let view = UIView(frame: .zero) view.translatesAutoresizingMaskIntoConstraints = false addSubview(view) - view.backgroundColor = UIColor.mfGet(forHex: progressObject.color) + view.backgroundColor = progressObject.color.uiColor view.widthAnchor.constraint(equalTo: widthAnchor, multiplier: progressObject.progress).isActive = true view.leadingAnchor.constraint(equalTo: previous?.trailingAnchor ?? leadingAnchor).isActive = true previous = view diff --git a/MVMCoreUI/Atoms/Views/MultiProgressModel.swift b/MVMCoreUI/Atoms/Views/MultiProgressModel.swift index 9d1f11fd..98bb09cf 100644 --- a/MVMCoreUI/Atoms/Views/MultiProgressModel.swift +++ b/MVMCoreUI/Atoms/Views/MultiProgressModel.swift @@ -8,10 +8,14 @@ import Foundation - @objcMembers public class SingleProgressBarModel: Codable { - var progress: CGFloat - var color: String + @Percent var progress: CGFloat + var color: Color + + init(_ progress: CGFloat, color: Color) { + self.progress = progress + self.color = color + } } @objcMembers public class MultiProgressBarModel: MoleculeProtocol { diff --git a/MVMCoreUI/Atoms/Views/ProgressBarModel.swift b/MVMCoreUI/Atoms/Views/ProgressBarModel.swift index 47fabb6a..1e0bfeb1 100644 --- a/MVMCoreUI/Atoms/Views/ProgressBarModel.swift +++ b/MVMCoreUI/Atoms/Views/ProgressBarModel.swift @@ -10,13 +10,11 @@ import Foundation @objcMembers public class ProgressBarModel: MoleculeProtocol { public static var identifier: String = "progressbar" - - public var isRounded: Bool? - public var thickness: CGFloat? - ///from 0 to 100 - @Clamping(range: 0...100) public var percent: CGFloat + @Percent public var percent: CGFloat public var progressColor: Color = Color(uiColor: .mfCerulean()) public var backgroundColor: Color? = Color(uiColor: .mfLightSilver()) + public var isRounded: Bool? + public var thickness: CGFloat? enum CodingKeys: String, CodingKey { case moleculeName @@ -33,8 +31,6 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - isRounded = try typeContainer.decodeIfPresent(Bool.self, forKey: .isRounded) - thickness = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .thickness) percent = try typeContainer.decode(CGFloat.self, forKey: .percent) if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .progressColor) { progressColor = color @@ -42,15 +38,17 @@ import Foundation if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) { backgroundColor = color } + isRounded = try typeContainer.decodeIfPresent(Bool.self, forKey: .isRounded) + thickness = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .thickness) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) - try container.encodeIfPresent(isRounded, forKey: .isRounded) - try container.encodeIfPresent(thickness, forKey: .thickness) try container.encode(percent, forKey: .percent) try container.encode(progressColor, forKey: .progressColor) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encodeIfPresent(isRounded, forKey: .isRounded) + try container.encodeIfPresent(thickness, forKey: .thickness) } } From b3f10ec1c62851b4190baf9817f211b90b222dbd Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 8 Jan 2020 16:25:35 -0500 Subject: [PATCH 21/51] Fix stack --- MVMCoreUI/Organisms/MoleculeStackView.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/MVMCoreUI/Organisms/MoleculeStackView.swift b/MVMCoreUI/Organisms/MoleculeStackView.swift index eb0317cd..05e10c0d 100644 --- a/MVMCoreUI/Organisms/MoleculeStackView.swift +++ b/MVMCoreUI/Organisms/MoleculeStackView.swift @@ -81,8 +81,6 @@ open class MoleculeStackView: Container { public override func updateView(_ size: CGFloat) { super.updateView(size) - directionalLayoutMargins.leading = 0 - directionalLayoutMargins.trailing = 0 for item in stackItems { item.updateView(size) } From b97416e7d6d2b11e7569a8e3eff8a015bf2fce3b Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 8 Jan 2020 16:45:42 -0500 Subject: [PATCH 22/51] Multip progress --- MVMCoreUI/Atoms/Views/MultiProgressModel.swift | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/MultiProgressModel.swift b/MVMCoreUI/Atoms/Views/MultiProgressModel.swift index 98bb09cf..da2b8f69 100644 --- a/MVMCoreUI/Atoms/Views/MultiProgressModel.swift +++ b/MVMCoreUI/Atoms/Views/MultiProgressModel.swift @@ -20,33 +20,31 @@ import Foundation @objcMembers public class MultiProgressBarModel: MoleculeProtocol { public static var identifier: String = "multiProgressBar" - public var moleculeName: String - public var backgroundColor: Color? public var progressList: [SingleProgressBarModel] + public var backgroundColor: Color? public var thickness: CGFloat? public var roundedRect: Bool? enum CodingKeys: String, CodingKey { - case moleculeName case progressList case thickness case roundedRect + case backgroundColor } required public init(from decoder: Decoder) throws { - let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName) - self.progressList = try typeContainer.decode([SingleProgressBarModel].self, forKey: .progressList) - self.thickness = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .thickness) - self.roundedRect = try typeContainer.decodeIfPresent(Bool.self, forKey: .roundedRect) + progressList = try typeContainer.decode([SingleProgressBarModel].self, forKey: .progressList) + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) + thickness = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .thickness) + roundedRect = try typeContainer.decodeIfPresent(Bool.self, forKey: .roundedRect) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(moleculeName, forKey: .moleculeName) - try container.encodeIfPresent(progressList, forKey: .progressList) + try container.encode(progressList, forKey: .progressList) try container.encodeIfPresent(thickness, forKey: .thickness) try container.encodeIfPresent(roundedRect, forKey: .roundedRect) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) } } From 54d0ea3e5c46b661a135425562853173e2ff591f Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 8 Jan 2020 16:50:47 -0500 Subject: [PATCH 23/51] ModuleMolecule fixes --- .../Molecules/ModelMoleculeViewProtocol.swift | 4 ++ MVMCoreUI/Molecules/ModuleMolecule.swift | 66 ++++++++++--------- 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift b/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift index 0d9f2906..a1828fa7 100644 --- a/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift +++ b/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift @@ -12,6 +12,7 @@ public protocol ModelMoleculeViewProtocol { func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String: AnyHashable]?) 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 { @@ -21,4 +22,7 @@ extension ModelMoleculeViewProtocol { public static func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { return nil } + public static func requiredModules(_ molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { + return nil + } } diff --git a/MVMCoreUI/Molecules/ModuleMolecule.swift b/MVMCoreUI/Molecules/ModuleMolecule.swift index fa82cb89..f5d580de 100644 --- a/MVMCoreUI/Molecules/ModuleMolecule.swift +++ b/MVMCoreUI/Molecules/ModuleMolecule.swift @@ -47,36 +47,40 @@ open class ModuleMolecule: Container { } } - #warning("Kamlesh: uncomment below code") - //TODO: Kamlesh: uncomment below code + public static func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { -// public override class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { -// guard let moduleName = json?.optionalStringForKey("moduleName"), let module = delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) else { -// // Critical error -// return 0 -// } -// return MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: module)?.estimatedHeight?(forRow: module, delegateObject: delegateObject) ?? 0 -// } -// -// public override class func name(forReuse molecule: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? { -// guard let moduleName = molecule?.optionalStringForKey("moduleName"), let module = delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) else { -// // Critical error -// return "moduleMolecule<>" -// } -// return "moduleMolecule<" + (MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: module)?.name?(forReuse: module, delegateObject: delegateObject) ?? module.stringForkey(KeyMoleculeName)) + ">" -// } -// -// public override class func requiredModules(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { -// let moduleName = json?.optionalStringForKey("moduleName") -// if moduleName == nil || delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) == nil { -// if let errorObject = MVMCoreErrorObject(title: nil, message: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess), code: CoreUIErrorCode.ErrorCodeModuleMolecule.rawValue, domain: ErrorDomainNative, location: String(describing: self)) { -// error?.pointee = errorObject -// MVMCoreUILoggingHandler.shared()?.addError(toLog: errorObject) -// } -// } -// if let moduleName = moduleName { -// return [moduleName] -// } -// return nil -// } + guard let moduleMolecule = molecule as? ModuleMoleculeModel, + let moduleModel = delegateObject?.moduleProtocol?.getModuleWithName(moduleMolecule.moduleName) as? MoleculeProtocol, + let classType = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moduleModel) as? ModelMoleculeViewProtocol.Type, + let height = classType.estimatedHeight(forRow: moduleModel, delegateObject: delegateObject)else { + // Critical error + return 0 + } + return height + } + + public override func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { + guard let moduleMolecule = model as? ModuleMoleculeModel, + let moduleModel = delegateObject?.moduleProtocol?.getModuleWithName(moduleMolecule.moduleName) as? MoleculeProtocol, + let classType = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moduleModel) as? ModelMoleculeViewProtocol, + let name = classType.nameForReuse(moduleModel, delegateObject) else { + // Critical error + return "moduleMolecule<>" + } + return name + } + + //TODO: Scottt please check this. + public static func requiredModules(_ molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { + + guard let moduleName = (molecule as? ModuleMoleculeModel)?.moduleName, + let _ = delegateObject?.moduleProtocol?.getModuleWithName(moduleName) else { + if let errorObject = MVMCoreErrorObject(title: nil, message: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess), code: CoreUIErrorCode.ErrorCodeModuleMolecule.rawValue, domain: ErrorDomainNative, location: String(describing: self)) { + error?.pointee = errorObject + MVMCoreUILoggingHandler.shared()?.addError(toLog: errorObject) + } + return nil + } + return [moduleName] + } } From f40335ce193f09f4b9fddeecc1b5c39a484b0f99 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 9 Jan 2020 10:46:00 -0500 Subject: [PATCH 24/51] progress, multi progress, caret --- MVMCoreUI/Atoms/Views/CaretView.swift | 39 ++++--------------- MVMCoreUI/Atoms/Views/CaretViewModel.swift | 30 +++++++++++++- MVMCoreUI/Atoms/Views/MultiProgress.swift | 14 ++++--- .../Atoms/Views/MultiProgressModel.swift | 4 ++ MVMCoreUI/Atoms/Views/ProgressBar.swift | 26 +++---------- MVMCoreUI/Atoms/Views/ProgressBarModel.swift | 2 +- .../Molecules/ModelMoleculeViewProtocol.swift | 7 ++++ MVMCoreUI/Organisms/MoleculeStackView.swift | 1 - .../OtherHandlers/MoleculeObjectMapping.swift | 1 + 9 files changed, 62 insertions(+), 62 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/CaretView.swift b/MVMCoreUI/Atoms/Views/CaretView.swift index fb9689e5..4a0b9c36 100644 --- a/MVMCoreUI/Atoms/Views/CaretView.swift +++ b/MVMCoreUI/Atoms/Views/CaretView.swift @@ -102,27 +102,10 @@ open class CaretView: View { @objc open override func setAsMolecule() { defaultState() } - - open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - // Configure class properties with JSON values - guard let dictionary = json else { return } - - if let strokeColorHex = dictionary["strokeColor"] as? String { - strokeColor = UIColor.mfGet(forHex: strokeColorHex) - } - - if let isHiddenValue = dictionary[KeyIsHidden] as? Bool { - isHidden = isHiddenValue - } - - if let isOpaqueValue = dictionary[KeyIsOpaque] as? Bool { - isOpaque = isOpaqueValue - } - - if let lineWidthValue = dictionary["lineWidth"] as? CGFloat { - lineWidth = lineWidthValue - } + + public override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { + guard let json = json, let model = try? Self.decodeJSONToModel(json: json, type: CaretViewModel.self) else { return } + setWithModel(model, delegateObject, additionalData as? [String : AnyHashable]) } //MARK: - MVMCoreMoleculeViewProtocol @@ -131,17 +114,9 @@ open class CaretView: View { guard let caretModel = model as? CaretViewModel else { return } - if let strokeColorHex = caretModel.strokeColor { - strokeColor = UIColor.mfGet(forHex: strokeColorHex) - } - - if let isHiddenValue = caretModel.isHidden { - isHidden = isHiddenValue - } - - if let isOpaqueValue = caretModel.isOpaque { - isOpaque = isOpaqueValue - } + strokeColor = caretModel.strokeColor.uiColor + isHidden = caretModel.isHidden ?? false + isOpaque = caretModel.isOpaque ?? false if let lineWidthValue = caretModel.lineWidth { lineWidth = lineWidthValue diff --git a/MVMCoreUI/Atoms/Views/CaretViewModel.swift b/MVMCoreUI/Atoms/Views/CaretViewModel.swift index 8d2bc16c..f26a150f 100644 --- a/MVMCoreUI/Atoms/Views/CaretViewModel.swift +++ b/MVMCoreUI/Atoms/Views/CaretViewModel.swift @@ -12,8 +12,36 @@ import Foundation public static var identifier: String = "caretView" public var backgroundColor: Color? - public var strokeColor: String? + public var strokeColor: Color = Color(uiColor: .black) public var isHidden: Bool? public var isOpaque: Bool? public var lineWidth: CGFloat? + + enum CodingKeys: String, CodingKey { + case backgroundColor + case strokeColor + case isHidden + case isOpaque + case lineWidth + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + if let strokeColor = try typeContainer.decodeIfPresent(Color.self, forKey: .strokeColor) { + self.strokeColor = strokeColor + } + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) + isHidden = try typeContainer.decodeIfPresent(Bool.self, forKey: .isHidden) + isOpaque = try typeContainer.decodeIfPresent(Bool.self, forKey: .isOpaque) + lineWidth = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .lineWidth) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(strokeColor, forKey: .strokeColor) + try container.encodeIfPresent(isHidden, forKey: .isHidden) + try container.encodeIfPresent(isOpaque, forKey: .isOpaque) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encodeIfPresent(lineWidth, forKey: .lineWidth) + } } diff --git a/MVMCoreUI/Atoms/Views/MultiProgress.swift b/MVMCoreUI/Atoms/Views/MultiProgress.swift index aceaf775..29fbf465 100644 --- a/MVMCoreUI/Atoms/Views/MultiProgress.swift +++ b/MVMCoreUI/Atoms/Views/MultiProgress.swift @@ -9,7 +9,10 @@ import UIKit @objcMembers open class MultiProgress: View { - + var multiProgressModel: MultiProgressBarModel? { + get { return model as? MultiProgressBarModel } + } + ///passing value to progressList creates corresponding progress bars var progressList: Array? { didSet { @@ -63,7 +66,7 @@ import UIKit //MARK: - MVMCoreMoleculeViewProtocol public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { super.setWithModel(model, delegateObject, additionalData) - guard let multiProgressModel = model as? MultiProgressBarModel else { + guard let multiProgressModel = multiProgressModel else { return } roundedRect = multiProgressModel.roundedRect ?? false @@ -78,9 +81,8 @@ import UIKit progressList = nil } - override open func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - thicknessConstraint?.constant = json?.optionalCGFloatForKey("thickness") ?? defaultHeight - roundedRect = json?.optionalBoolForKey("roundedRect") ?? false + public override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { + guard let json = json, let model = try? Self.decodeJSONToModel(json: json, type: MultiProgressBarModel.self) else { return } + setWithModel(model, delegateObject, additionalData as? [String : AnyHashable]) } } diff --git a/MVMCoreUI/Atoms/Views/MultiProgressModel.swift b/MVMCoreUI/Atoms/Views/MultiProgressModel.swift index da2b8f69..b0251ff6 100644 --- a/MVMCoreUI/Atoms/Views/MultiProgressModel.swift +++ b/MVMCoreUI/Atoms/Views/MultiProgressModel.swift @@ -32,6 +32,10 @@ import Foundation case backgroundColor } + public init(_ progressList: [SingleProgressBarModel]) { + self.progressList = progressList + } + required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) progressList = try typeContainer.decode([SingleProgressBarModel].self, forKey: .progressList) diff --git a/MVMCoreUI/Atoms/Views/ProgressBar.swift b/MVMCoreUI/Atoms/Views/ProgressBar.swift index 8a3b0bb0..dff5bfc4 100644 --- a/MVMCoreUI/Atoms/Views/ProgressBar.swift +++ b/MVMCoreUI/Atoms/Views/ProgressBar.swift @@ -9,11 +9,12 @@ import Foundation @objcMembers open class ProgressBar: UIProgressView, MVMCoreViewProtocol, ModelMoleculeViewProtocol, MVMCoreUIMoleculeViewProtocol { - var isRounded = false + var progressBarModel: ProgressBarModel? + var thickness: CGFloat = 8.0 { willSet(newValue) { heightAnchor.constraint(equalToConstant: newValue).isActive = true - if isRounded { + if progressBarModel?.isRounded ?? false { layer.cornerRadius = newValue/2.0 } else { progressViewStyle = .bar @@ -40,7 +41,6 @@ import Foundation public func setupView() { clipsToBounds = true translatesAutoresizingMaskIntoConstraints = false - isRounded = false thickness = 8 progress = 0 progressTintColor = UIColor.mfCerulean() @@ -55,7 +55,6 @@ import Foundation guard let progressBarModel = model as? ProgressBarModel else { return } - isRounded = progressBarModel.isRounded ?? false thickness = progressBarModel.thickness ?? 8 progress = Float((progressBarModel.percent)/100.0) progressTintColor = progressBarModel.progressColor.uiColor @@ -66,26 +65,11 @@ import Foundation // MARK: - MVMCoreUIMoleculeViewProtocol public func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { - if let isRounded = json?.optionalBoolForKey("roundedRect") { - self.isRounded = isRounded - } - if let thickness = json?.optionalCGFloatForKey("thickness") { - self.thickness = thickness - } - // as? Float returns nil, apple defect. - if let percentage = json?["percent"] as? CGFloat { - progress = Float(percentage/100.0) - } - if let progressColor = json?.optionalStringForKey("progressColor") { - progressTintColor = UIColor.mfGet(forHex: progressColor) - } - if let backgroundColor = json?.optionalStringForKey("backgroundColor") { - trackTintColor = UIColor.mfGet(forHex: backgroundColor) - } + guard let json = json, let model = try? Self.decodeJSONToModel(json: json, type: ProgressBarModel.self) else { return } + setWithModel(model, delegateObject, additionalData as? [String : AnyHashable]) } public func reset() { - isRounded = false thickness = 8 progress = 0 progressTintColor = UIColor.mfCerulean() diff --git a/MVMCoreUI/Atoms/Views/ProgressBarModel.swift b/MVMCoreUI/Atoms/Views/ProgressBarModel.swift index 1e0bfeb1..1850c411 100644 --- a/MVMCoreUI/Atoms/Views/ProgressBarModel.swift +++ b/MVMCoreUI/Atoms/Views/ProgressBarModel.swift @@ -25,7 +25,7 @@ import Foundation case backgroundColor } - init(_ percent: CGFloat) { + public init(_ percent: CGFloat) { self.percent = percent } diff --git a/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift b/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift index a1828fa7..8b06ab0e 100644 --- a/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift +++ b/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift @@ -25,4 +25,11 @@ 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) + let decoder = JSONDecoder() + return try decoder.decode(type, from: data) + } } diff --git a/MVMCoreUI/Organisms/MoleculeStackView.swift b/MVMCoreUI/Organisms/MoleculeStackView.swift index 05e10c0d..8dd43193 100644 --- a/MVMCoreUI/Organisms/MoleculeStackView.swift +++ b/MVMCoreUI/Organisms/MoleculeStackView.swift @@ -143,7 +143,6 @@ open class MoleculeStackView: Container { } else { setWithModel(model, delegateObject, additionalData as? [String : AnyHashable]) } - } public class func name(forReuse molecule: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? { diff --git a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift index d66c1558..2b9b78a5 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift @@ -33,5 +33,6 @@ import Foundation // //ModelRegistry.register(ModuleMoleculeModel.self) ModelRegistry.register(LeftRightLabelModel.self) + ModelRegistry.register(CaretViewModel.self) } } From d651fb5783519e7160ecd3dae332cea44c55828f Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 9 Jan 2020 11:00:00 -0500 Subject: [PATCH 25/51] Dash line color require for model, optional for server --- MVMCoreUI/Atoms/Views/DashLine.swift | 26 ++++++++--------------- MVMCoreUI/Atoms/Views/DashLineModel.swift | 24 ++++++++++++++++++++- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/DashLine.swift b/MVMCoreUI/Atoms/Views/DashLine.swift index 48decdf9..89541b0c 100644 --- a/MVMCoreUI/Atoms/Views/DashLine.swift +++ b/MVMCoreUI/Atoms/Views/DashLine.swift @@ -15,8 +15,11 @@ open class DashLine: View { // MARK: - Properties //------------------------------------------------------ - @objc public var dashColor: UIColor? - @objc public var dashLayer: CAShapeLayer? + var dashModel: DashLineModel? { + get { return model as? DashLineModel } + } + + @objc private var dashLayer: CAShapeLayer? //------------------------------------------------------ // MARK: - Lifecycle @@ -53,7 +56,7 @@ open class DashLine: View { dashLayer.lineCap = .round dashLayer.lineDashPattern = [NSNumber(value: 2), NSNumber(value: 2)] dashLayer.path = path.cgPath - dashLayer.strokeColor = dashColor?.cgColor ?? UIColor.mfLighterGray().cgColor + dashLayer.strokeColor = dashModel?.dashColor.uiColor.cgColor ?? UIColor.mfLighterGray().cgColor dashLayer.fillColor = UIColor.clear.cgColor dashLayer.backgroundColor = backgroundColor?.cgColor ?? UIColor.white.cgColor self.dashLayer = dashLayer @@ -70,27 +73,16 @@ open class DashLine: View { } open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - - // Configure class properties with JSON values - guard let jsonDictionary = json else { return } - - if let isHiddenValue = jsonDictionary[KeyIsHidden] as? Bool { - isHidden = isHiddenValue - } - - if let dashColorHex = jsonDictionary["dashColor"] as? String { - dashColor = UIColor.mfGet(forHex: dashColorHex) - } + guard let json = json, let model = try? Self.decodeJSONToModel(json: json, type: DashLineModel.self) else { return } + setWithModel(model, delegateObject, additionalData as? [String : AnyHashable]) } //MARK: - MVMCoreMoleculeViewProtocol public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { super.setWithModel(model, delegateObject, additionalData) - guard let dashLineModel = model as? DashLineModel else { + guard let dashLineModel = dashModel else { return } - dashColor = dashLineModel.dashColor.uiColor if let isHiddenValue = dashLineModel.isHidden { isHidden = isHiddenValue } diff --git a/MVMCoreUI/Atoms/Views/DashLineModel.swift b/MVMCoreUI/Atoms/Views/DashLineModel.swift index 06d85f08..ec6b8a15 100644 --- a/MVMCoreUI/Atoms/Views/DashLineModel.swift +++ b/MVMCoreUI/Atoms/Views/DashLineModel.swift @@ -12,10 +12,32 @@ import Foundation public static var identifier: String = "dashLine" public var backgroundColor: Color? - public var dashColor: Color + public var dashColor: Color = Color(uiColor: .mfLighterGray()) public var isHidden: Bool? public init(dashColor: Color) { self.dashColor = dashColor } + + enum CodingKeys: String, CodingKey { + case backgroundColor + case dashColor + case isHidden + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + if let dashColor = try typeContainer.decodeIfPresent(Color.self, forKey: .dashColor) { + self.dashColor = dashColor + } + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) + isHidden = try typeContainer.decodeIfPresent(Bool.self, forKey: .isHidden) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(dashColor, forKey: .dashColor) + try container.encodeIfPresent(isHidden, forKey: .isHidden) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + } } From 3e8b69a0bc76c53a4fad50e5badd1770bf89c6c6 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 9 Jan 2020 11:38:32 -0500 Subject: [PATCH 26/51] Line and image update --- MVMCoreUI/Atoms/Views/ImageViewModel.swift | 1 - .../Atoms/Views/LeftRightLabelModel.swift | 1 - MVMCoreUI/Atoms/Views/Line.swift | 68 +++++++++---------- .../Containers/NavigationController.swift | 2 +- MVMCoreUI/Models/Molecules/LineModel.swift | 38 ++++++++++- .../Items/DropDownFilterTableViewCell.swift | 4 +- MVMCoreUI/Molecules/Items/TableViewCell.swift | 24 +++---- MVMCoreUI/Molecules/StandardHeaderView.swift | 4 +- 8 files changed, 88 insertions(+), 54 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/ImageViewModel.swift b/MVMCoreUI/Atoms/Views/ImageViewModel.swift index a65c946a..0944c36e 100644 --- a/MVMCoreUI/Atoms/Views/ImageViewModel.swift +++ b/MVMCoreUI/Atoms/Views/ImageViewModel.swift @@ -10,7 +10,6 @@ import Foundation @objcMembers public class ImageViewModel: MoleculeProtocol { public static var identifier: String = "image" - public var moleculeName: String public var backgroundColor: Color? public var image: String diff --git a/MVMCoreUI/Atoms/Views/LeftRightLabelModel.swift b/MVMCoreUI/Atoms/Views/LeftRightLabelModel.swift index e006afc9..5e091446 100644 --- a/MVMCoreUI/Atoms/Views/LeftRightLabelModel.swift +++ b/MVMCoreUI/Atoms/Views/LeftRightLabelModel.swift @@ -13,5 +13,4 @@ import UIKit public var backgroundColor: Color? public var leftText: LabelModel public var rightText: LabelModel - } diff --git a/MVMCoreUI/Atoms/Views/Line.swift b/MVMCoreUI/Atoms/Views/Line.swift index d5f4f4b6..7b80d59a 100644 --- a/MVMCoreUI/Atoms/Views/Line.swift +++ b/MVMCoreUI/Atoms/Views/Line.swift @@ -9,42 +9,35 @@ import UIKit @objcMembers open class Line: View { + var lineModel: LineModel? { + get { return model as? LineModel } + } public var heightConstraint: NSLayoutConstraint? - public enum Style: String, Codable { - case standard - case thin - case medium - case heavy - case none - } - - public var style = Style.standard { - didSet { - switch style { - case .standard: - heightConstraint?.constant = 1 - backgroundColor = .mfSilver() - case .thin: - heightConstraint?.constant = 1 - backgroundColor = .black - case .medium: - heightConstraint?.constant = 2 - backgroundColor = .black - case .heavy: - heightConstraint?.constant = 4 - backgroundColor = .black - case .none: - heightConstraint?.constant = 0 - } + open func setStyle(_ style: LineModel.Style) { + switch style { + case .standard: + heightConstraint?.constant = 1 + backgroundColor = .mfSilver() + case .thin: + heightConstraint?.constant = 1 + backgroundColor = .black + case .medium: + heightConstraint?.constant = 2 + backgroundColor = .black + case .heavy: + heightConstraint?.constant = 4 + backgroundColor = .black + case .none: + heightConstraint?.constant = 0 } } // MARK: - Helpers open func shouldBeVisible() -> Bool { - guard let type = json?.optionalStringForKey(KeyType) else { return false } - return type != "none" + guard let type = lineModel?.type else { return false } + return type != .none } public convenience init(pinTo view: UIView, edge: UIRectEdge, useMargin: Bool) { @@ -56,26 +49,33 @@ import UIKit // MARK: - MVMCoreViewProtocol open override func setupView() { super.setupView() - backgroundColor = .black heightConstraint = heightAnchor.constraint(equalToConstant: 1) heightConstraint?.isActive = true + setStyle(.standard) } // MARK: - MVMCoreUIMoleculeViewProtocol open override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { // If no type, default to standard. - if let typeString = json?.optionalStringForKey(KeyType), let type = Style.init(rawValue: typeString) { - style = type + if let typeString = json?.optionalStringForKey(KeyType), let type = LineModel.Style.init(rawValue: typeString) { + setStyle(type) } else { - style = .standard + setStyle(.standard) } super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) } + open override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + if let lineModel = model as? LineModel { + setStyle(lineModel.type ?? .standard) + } + super.setWithModel(model, delegateObject, additionalData) + } + open override func reset() { - style = .standard + setStyle(.standard) } open func copyBackgroundColor() -> Bool { @@ -83,7 +83,7 @@ import UIKit } public static func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { - guard let type = json?.optionalStringForKey(KeyType), let style = Style(rawValue: type) else { return 1 } + guard let type = json?.optionalStringForKey(KeyType), let style = LineModel.Style(rawValue: type) else { return 1 } switch style { case .none: return 0 diff --git a/MVMCoreUI/Containers/NavigationController.swift b/MVMCoreUI/Containers/NavigationController.swift index 353ea861..623b2f47 100644 --- a/MVMCoreUI/Containers/NavigationController.swift +++ b/MVMCoreUI/Containers/NavigationController.swift @@ -29,7 +29,7 @@ import UIKit let navigationController = self.init() style(navigationController.navigationBar) navigationController.separatorView = Line(pinTo: navigationController.navigationBar, edge: .bottom, useMargin: false) - navigationController.separatorView?.style = .standard + navigationController.separatorView?.setStyle(.standard) MVMCoreUISession.sharedGlobal()?.navigationController = navigationController MVMCoreNavigationHandler.shared()?.viewControllerToPresentOn = navigationController MVMCoreNavigationHandler.shared()?.navigationController = navigationController diff --git a/MVMCoreUI/Models/Molecules/LineModel.swift b/MVMCoreUI/Models/Molecules/LineModel.swift index 66010536..88e09be0 100644 --- a/MVMCoreUI/Models/Molecules/LineModel.swift +++ b/MVMCoreUI/Models/Molecules/LineModel.swift @@ -9,7 +9,43 @@ import UIKit @objcMembers public class LineModel: MoleculeProtocol { + + /* + The frequency of the line in a moleculeList. + all (between all cells, above top, below bottom) + allExceptTop (between all cells, below bottom) + allExceptBottom (between all cells, above top) + between (between all cells) + */ + public enum Frequency: String, Codable { + case all + case allExceptTop + case allExceptBottom + case between + } + + /* + The style of the line. + standard (1 height, silver) + thin (1 height, black) + medium (2 height, black) + heavy (4 height, black) + none (hidden) + */ + public enum Style: String, Codable { + case standard + case thin + case medium + case heavy + case none + } + public static var identifier: String = "line" + public var type: Style? = .standard + public var frequency: Frequency? = .allExceptTop public var backgroundColor: Color? - public var type: String? + + public init(type: Style) { + self.type = type + } } diff --git a/MVMCoreUI/Molecules/Items/DropDownFilterTableViewCell.swift b/MVMCoreUI/Molecules/Items/DropDownFilterTableViewCell.swift index 2f856074..a9d9c360 100644 --- a/MVMCoreUI/Molecules/Items/DropDownFilterTableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/DropDownFilterTableViewCell.swift @@ -53,7 +53,7 @@ import UIKit } public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { - bottomSeparatorView?.style = .none + bottomSeparatorView?.setStyle(.none) self.delegateObject = delegateObject super.setWithModel(model, delegateObject, additionalData) @@ -65,6 +65,6 @@ import UIKit public override func reset() { super.reset() bottomMarginPadding = 0 - bottomSeparatorView?.style = .none + bottomSeparatorView?.setStyle(.none) } } diff --git a/MVMCoreUI/Molecules/Items/TableViewCell.swift b/MVMCoreUI/Molecules/Items/TableViewCell.swift index d74f0ee5..ba017c4e 100644 --- a/MVMCoreUI/Molecules/Items/TableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/TableViewCell.swift @@ -62,29 +62,29 @@ import UIKit open func styleStandard() { topMarginPadding = 24 bottomMarginPadding = 24 - topSeparatorView?.style = .none - bottomSeparatorView?.style = .standard + topSeparatorView?.setStyle(.none) + bottomSeparatorView?.setStyle(.standard) } open func styleHeader() { topMarginPadding = 48 bottomMarginPadding = 16 - topSeparatorView?.style = .none - bottomSeparatorView?.style = .thin + topSeparatorView?.setStyle(.none) + bottomSeparatorView?.setStyle(.thin) } open func styleFooter() { topMarginPadding = 24 bottomMarginPadding = 0 - topSeparatorView?.style = .none - bottomSeparatorView?.style = .none + topSeparatorView?.setStyle(.none) + bottomSeparatorView?.setStyle(.none) } open func styleNone() { topMarginPadding = 0 bottomMarginPadding = 0 - topSeparatorView?.style = .none - bottomSeparatorView?.style = .none + topSeparatorView?.setStyle(.none) + bottomSeparatorView?.setStyle(.none) } /// Adds the molecule to the view. @@ -264,8 +264,8 @@ import UIKit setSeparatorFrequency(separatorFrequency, indexPath: indexPath) } } else { - topSeparatorView?.style = .standard - bottomSeparatorView?.style = .standard + topSeparatorView?.setStyle(.standard) + bottomSeparatorView?.setStyle(.standard) setSeparatorFrequency(TableViewCell.SeparatorFrequency.allExceptTop, indexPath: indexPath) } } @@ -285,7 +285,7 @@ import UIKit open func addSeparatorsIfNeeded() { if topSeparatorView == nil { let line = Line() - line.style = .none + line.setStyle(.none) addSubview(line) NSLayoutConstraint.pinViewTop(toSuperview: line, useMargins: false, constant: 0).isActive = true NSLayoutConstraint.pinViewLeft(toSuperview: line, useMargins: true, constant: 0).isActive = true @@ -294,7 +294,7 @@ import UIKit } if bottomSeparatorView == nil { let line = Line() - line.style = .none + line.setStyle(.none) addSubview(line) NSLayoutConstraint.pinViewBottom(toSuperview: line, useMargins: false, constant: 0).isActive = true NSLayoutConstraint.pinViewLeft(toSuperview: line, useMargins: true, constant: 0).isActive = true diff --git a/MVMCoreUI/Molecules/StandardHeaderView.swift b/MVMCoreUI/Molecules/StandardHeaderView.swift index 686aac3b..eeb46a6a 100644 --- a/MVMCoreUI/Molecules/StandardHeaderView.swift +++ b/MVMCoreUI/Molecules/StandardHeaderView.swift @@ -26,7 +26,7 @@ public class StandardHeaderView: MoleculeContainer { guard line == nil else { return } let line = Line() - line.style = .heavy + line.setStyle(.heavy) addSubview(line) NSLayoutConstraint.pinViewBottom(toSuperview: line, useMargins: false, constant: 0).isActive = true NSLayoutConstraint.pinViewLeft(toSuperview: line, useMargins: true, constant: 0).isActive = true @@ -56,7 +56,7 @@ public class StandardHeaderView: MoleculeContainer { open override func reset() { super.reset() - line?.style = .heavy + line?.setStyle(.heavy) } public class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { From 2365a2fab4022e8895f4c19d43db1ebd91849f81 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 9 Jan 2020 13:45:17 -0500 Subject: [PATCH 27/51] fixes --- MVMCoreUI/Molecules/ModuleMolecule.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/MVMCoreUI/Molecules/ModuleMolecule.swift b/MVMCoreUI/Molecules/ModuleMolecule.swift index f5d580de..107dc3f9 100644 --- a/MVMCoreUI/Molecules/ModuleMolecule.swift +++ b/MVMCoreUI/Molecules/ModuleMolecule.swift @@ -20,8 +20,7 @@ open class ModuleMolecule: Container { } public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String: AnyHashable]?) { - #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. + super.setWithModel(model, delegateObject, additionalData) guard let moduleMoleculeModel = model as? ModuleMoleculeModel, let moduleModel = delegateObject?.moduleProtocol?.getModuleWithName(moduleMoleculeModel.moduleName) as? MoleculeProtocol else { From 78461d0557c0d7cdf25ab3d952bc74e3bb3a8f37 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 9 Jan 2020 13:48:35 -0500 Subject: [PATCH 28/51] CaretLink --- MVMCoreUI.xcodeproj/project.pbxproj | 4 ++++ MVMCoreUI/Atoms/Buttons/CaretButton.swift | 16 ++++++++++++- MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift | 12 +++++----- .../Buttons/MFCustomButton+ActionModel.swift | 23 +++++++++++++++++++ .../MVMCoreUIMoleculeMappingObject.m | 2 +- .../OtherHandlers/MoleculeObjectMapping.swift | 1 + 6 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 MVMCoreUI/Atoms/Buttons/MFCustomButton+ActionModel.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 8363aad1..80ff4c39 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -122,6 +122,7 @@ D282AAB4223FDDAE00C46919 /* MFLoadImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AAB3223FDDAE00C46919 /* MFLoadImageView.swift */; }; D282AABA224131D100C46919 /* MFTransparentGIFView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AAB9224131D100C46919 /* MFTransparentGIFView.swift */; }; D282AACB2243C61700C46919 /* ButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AACA2243C61700C46919 /* ButtonView.swift */; }; + D28A837723C79FC600DFE4FC /* MFCustomButton+ActionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A837623C79FC600DFE4FC /* MFCustomButton+ActionModel.swift */; }; D296E13C229598BF0051EBE7 /* MoleculeListCellProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D296E13B2295969C0051EBE7 /* MoleculeListCellProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; D296E1412295EBBA0051EBE7 /* MoleculeDelegateProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D296E1402295EBBA0051EBE7 /* MoleculeDelegateProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; D296E14722A5984C0051EBE7 /* MVMCoreUIViewConstrainingProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D296E14622A597490051EBE7 /* MVMCoreUIViewConstrainingProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -381,6 +382,7 @@ D282AAB3223FDDAE00C46919 /* MFLoadImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MFLoadImageView.swift; sourceTree = ""; }; D282AAB9224131D100C46919 /* MFTransparentGIFView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MFTransparentGIFView.swift; sourceTree = ""; }; D282AACA2243C61700C46919 /* ButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonView.swift; sourceTree = ""; }; + D28A837623C79FC600DFE4FC /* MFCustomButton+ActionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MFCustomButton+ActionModel.swift"; sourceTree = ""; }; D296E13B2295969C0051EBE7 /* MoleculeListCellProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MoleculeListCellProtocol.h; sourceTree = ""; }; D296E1402295EBBA0051EBE7 /* MoleculeDelegateProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MoleculeDelegateProtocol.h; sourceTree = ""; }; D296E14622A597490051EBE7 /* MVMCoreUIViewConstrainingProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIViewConstrainingProtocol.h; sourceTree = ""; }; @@ -988,6 +990,7 @@ D29DF16B21E69E1F003B2FB9 /* ButtonDelegateProtocol.h */, D29DF16A21E69E1F003B2FB9 /* MFCustomButton.h */, D29DF17021E69E1F003B2FB9 /* MFCustomButton.m */, + D28A837623C79FC600DFE4FC /* MFCustomButton+ActionModel.swift */, D29DF16C21E69E1F003B2FB9 /* PrimaryButton.h */, D29DF17121E69E1F003B2FB9 /* PrimaryButton.m */, D282AACA2243C61700C46919 /* ButtonView.swift */, @@ -1395,6 +1398,7 @@ D282AABA224131D100C46919 /* MFTransparentGIFView.swift in Sources */, 944589232385DA9600DE9FD4 /* ImageViewModel.swift in Sources */, D213347723843825008E41B3 /* Line.swift in Sources */, + D28A837723C79FC600DFE4FC /* MFCustomButton+ActionModel.swift in Sources */, 012A88EC238F084D00FE3DA1 /* FooterModel.swift in Sources */, D2A514672213885800345BFB /* StandardHeaderView.swift in Sources */, 01EB369023609801006832FA /* ListItemModel.swift in Sources */, diff --git a/MVMCoreUI/Atoms/Buttons/CaretButton.swift b/MVMCoreUI/Atoms/Buttons/CaretButton.swift index 6c9de088..b3ff5409 100644 --- a/MVMCoreUI/Atoms/Buttons/CaretButton.swift +++ b/MVMCoreUI/Atoms/Buttons/CaretButton.swift @@ -8,7 +8,7 @@ // -open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol, MVMCoreUIViewConstrainingProtocol { +open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol, MVMCoreUIViewConstrainingProtocol, ModelMoleculeViewProtocol { //------------------------------------------------------ // MARK: - Constants @@ -132,6 +132,20 @@ open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol, MVMCoreUI } } + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + guard let caretLinkModel = model as? CaretLinkModel else { return } + if let color = caretLinkModel.backgroundColor { + backgroundColor = color.uiColor + } + enabledColor = caretLinkModel.enabledColor.uiColor + if let color = caretLinkModel.disabledColor { + disabledColor = color.uiColor + } + isEnabled = caretLinkModel.enabled + set(with: caretLinkModel.action, delegateObject: delegateObject, additionalData: additionalData) + setTitle(caretLinkModel.label.text, for: .normal) + } + public func needsToBeConstrained() -> Bool { return true } diff --git a/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift b/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift index 4d3c6223..3cc77a54 100644 --- a/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift +++ b/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift @@ -14,8 +14,8 @@ public class CaretLinkModel: MoleculeProtocol { public var backgroundColor: Color? public var label: LabelModel public var action: ActionProtocol - public var enabledColor: UIColor = .black - public var disabledColor: UIColor = .mfSilver() + public var enabledColor: Color = Color(uiColor: .black) + public var disabledColor: Color? = Color(uiColor: .mfSilver()) public var enabled: Bool = true public init(label: LabelModel, action: ActionProtocol) { @@ -36,10 +36,10 @@ public class CaretLinkModel: MoleculeProtocol { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) label = try typeContainer.decode(LabelModel.self, forKey: .label) - if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor)?.uiColor { + if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor) { enabledColor = color } - if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor)?.uiColor { + if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor) { disabledColor = color } if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) { @@ -53,8 +53,8 @@ public class CaretLinkModel: MoleculeProtocol { try container.encode(label, forKey: .label) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeModel(action, forKey: .action) - try container.encode(Color(uiColor: enabledColor), forKey: .enabledColor) - try container.encode(Color(uiColor: disabledColor), forKey: .disabledColor) + try container.encode(enabled, forKey: .enabledColor) + try container.encodeIfPresent(disabledColor, forKey: .disabledColor) try container.encode(enabled, forKey: .enabled) } } diff --git a/MVMCoreUI/Atoms/Buttons/MFCustomButton+ActionModel.swift b/MVMCoreUI/Atoms/Buttons/MFCustomButton+ActionModel.swift new file mode 100644 index 00000000..b967db48 --- /dev/null +++ b/MVMCoreUI/Atoms/Buttons/MFCustomButton+ActionModel.swift @@ -0,0 +1,23 @@ +// +// MFCustomButton+ActionModel.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 1/9/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation + +public extension MFCustomButton { + func set(with action: ActionProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + buttonDelegate = delegateObject?.buttonDelegate + add({ [weak self] sender in + guard let self = self else { return } + if let data = try? action.encode(using: JSONEncoder()), + let actionMap = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any], + delegateObject?.buttonDelegate?.button?(self, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? true { + MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) + } + }, for: .touchUpInside) + } +} diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index c656ab2f..3a8b7622 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -35,7 +35,7 @@ @"twoButtonView": TwoButtonView.class, @"footer": StandardFooterView.class, @"caretView": CaretView.class, - @"caretButton": CaretButton.class, + @"caretLink": CaretButton.class, @"textField": MFTextField.class, @"dropDown": DropDown.class, @"digitTextField": MFDigitTextField.class, diff --git a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift index 2b9b78a5..4eb9e4a8 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift @@ -34,5 +34,6 @@ import Foundation //ModelRegistry.register(ModuleMoleculeModel.self) ModelRegistry.register(LeftRightLabelModel.self) ModelRegistry.register(CaretViewModel.self) + ModelRegistry.register(CaretLinkModel.self) } } From f6c3a02f0e1a730de2e0e3bfc9154e0a45ff4966 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 9 Jan 2020 14:20:58 -0500 Subject: [PATCH 29/51] remove old extension --- MVMCoreUI.xcodeproj/project.pbxproj | 4 - .../MFTextField+ModelExtension.swift | 2 +- .../ViewConstrainingView+ModelExtension.swift | 89 ------------------- MVMCoreUI/Molecules/Scroller.swift | 3 +- MVMCoreUI/Organisms/Carousel.swift | 2 +- 5 files changed, 3 insertions(+), 97 deletions(-) delete mode 100644 MVMCoreUI/Atoms/Views/ViewConstrainingView+ModelExtension.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 80ff4c39..25fd66ea 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -28,7 +28,6 @@ 012A88EE239858E300FE3DA1 /* ContainerMoleculeProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88ED239858E300FE3DA1 /* ContainerMoleculeProtocol.swift */; }; 012A88F123985E0100FE3DA1 /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88F023985E0100FE3DA1 /* Color.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 */; }; 012CA9DE2388723E003F810F /* (null) in Sources */ = {isa = PBXBuildFile; }; 012CA9E223888AED003F810F /* (null) in Sources */ = {isa = PBXBuildFile; }; @@ -292,7 +291,6 @@ 012A88ED239858E300FE3DA1 /* ContainerMoleculeProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerMoleculeProtocol.swift; sourceTree = ""; }; 012A88F023985E0100FE3DA1 /* Color.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Color.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 = ""; }; 014AA72123C501E2006F3E93 /* MoleculeContainerModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MoleculeContainerModel.swift; sourceTree = ""; }; 014AA72223C501E2006F3E93 /* ContainerModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContainerModel.swift; sourceTree = ""; }; @@ -1019,7 +1017,6 @@ 012CA99D2385A2D3003F810F /* MFView+ModelExtension.swift */, D29DF28721E7AC2B003B2FB9 /* ViewConstrainingView.h */, D29DF28821E7AC2B003B2FB9 /* ViewConstrainingView.m */, - 012CA99B23859FDC003F810F /* ViewConstrainingView+ModelExtension.swift */, D282AAB9224131D100C46919 /* MFTransparentGIFView.swift */, D282AAB3223FDDAE00C46919 /* MFLoadImageView.swift */, 944589222385DA9500DE9FD4 /* ImageViewModel.swift */, @@ -1497,7 +1494,6 @@ 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 */, D2B18B922361E65A00A9AEDC /* CoreUIObject.swift in Sources */, D29DF2BE21E7BEA4003B2FB9 /* TopTabbar.m in Sources */, diff --git a/MVMCoreUI/Atoms/TextFields/MFTextField+ModelExtension.swift b/MVMCoreUI/Atoms/TextFields/MFTextField+ModelExtension.swift index 79ff851e..9944e22d 100644 --- a/MVMCoreUI/Atoms/TextFields/MFTextField+ModelExtension.swift +++ b/MVMCoreUI/Atoms/TextFields/MFTextField+ModelExtension.swift @@ -20,7 +20,7 @@ extension MFTextField: ModelMoleculeViewProtocol { //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) + setUpDefaultWithModel(model, delegateObject, additionalData) guard let textFieldModel = model as? TextFieldModel, let delegateObject = delegateObject else { diff --git a/MVMCoreUI/Atoms/Views/ViewConstrainingView+ModelExtension.swift b/MVMCoreUI/Atoms/Views/ViewConstrainingView+ModelExtension.swift deleted file mode 100644 index bd6312f2..00000000 --- a/MVMCoreUI/Atoms/Views/ViewConstrainingView+ModelExtension.swift +++ /dev/null @@ -1,89 +0,0 @@ -// -// 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? ContainerMoleculeProtocol)?.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 containerMoleculeModel = model as? ContainerModelProtocol { - if let useHorizontalMargins = containerMoleculeModel.useHorizontalMargins { - updateViewHorizontalDefaults = useHorizontalMargins - } - if let useVerticalMargins = containerMoleculeModel.useVerticalMargins { - updateViewVerticalDefaults = useVerticalMargins - } - - if let horizontalAlignment = containerMoleculeModel.horizontalAlignment { - alignHorizontal(horizontalAlignment) - } - if let verticalAlignment = containerMoleculeModel.verticalAlignment { - alignVertical(verticalAlignment) - } - } - - #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/Molecules/Scroller.swift b/MVMCoreUI/Molecules/Scroller.swift index 1ce3ceb2..01477158 100644 --- a/MVMCoreUI/Molecules/Scroller.swift +++ b/MVMCoreUI/Molecules/Scroller.swift @@ -29,10 +29,9 @@ import UIKit } public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { - //super.setWithModel(model, delegateObject, 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) + setUpDefaultWithModel(model, delegateObject, additionalData) guard let model = model, let moleculeModel = (model as? ContainerMoleculeProtocol)?.molecule else { diff --git a/MVMCoreUI/Organisms/Carousel.swift b/MVMCoreUI/Organisms/Carousel.swift index 50ca800a..ef19f1a3 100644 --- a/MVMCoreUI/Organisms/Carousel.swift +++ b/MVMCoreUI/Organisms/Carousel.swift @@ -88,7 +88,7 @@ open class Carousel: ViewConstrainingView, ModelMoleculeViewProtocol { #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(caroselModel, delegateObject, additionalData) + setUpDefaultWithModel(model, delegateObject, additionalData) collectionView.backgroundColor = backgroundColor collectionView.layer.borderColor = backgroundColor?.cgColor From b3b37db8489ed06076a6860f9cbdfc5f3db8cf0a Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 9 Jan 2020 14:26:26 -0500 Subject: [PATCH 30/51] remove deprecated --- MVMCoreUI/Atoms/Views/ViewConstrainingView.m | 4 ++-- .../MVMCoreUIMoleculeMappingObject+ModelExtension.swift | 2 +- MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m | 2 +- MVMCoreUI/OtherHandlers/MVMCoreUIViewConstrainingProtocol.h | 3 --- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/ViewConstrainingView.m b/MVMCoreUI/Atoms/Views/ViewConstrainingView.m index 29f2c9be..54a12612 100644 --- a/MVMCoreUI/Atoms/Views/ViewConstrainingView.m +++ b/MVMCoreUI/Atoms/Views/ViewConstrainingView.m @@ -342,8 +342,8 @@ self.updateViewVerticalDefaults = NO; self.topMarginPadding = PaddingDefaultVerticalSpacing3; self.bottomMarginPadding = PaddingDefaultVerticalSpacing3; - if ([self.molecule respondsToSelector:@selector(alignment)]) { - [self alignHorizontal:[(UIView *)self.molecule alignment]]; + if ([self.molecule respondsToSelector:@selector(horizontalAlignment)]) { + [self alignHorizontal:[(UIView *)self.molecule horizontalAlignment]]; } [self alignVertical:UIStackViewAlignmentFill]; if ([self.molecule respondsToSelector:@selector(reset)]) { diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelExtension.swift b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelExtension.swift index 8eda8a52..45ce1bab 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelExtension.swift +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelExtension.swift @@ -37,7 +37,7 @@ public extension MVMCoreUIMoleculeMappingObject { if constrainIfNeeded, let castMolecule = molecule as? MVMCoreUIViewConstrainingProtocol, castMolecule.needsToBeConstrained?() ?? false { - let view = ViewConstrainingView(molecule: molecule, alignment: castMolecule.alignment?() ?? .fill) + let view = ViewConstrainingView(molecule: molecule, alignment: castMolecule.horizontalAlignment?() ?? .fill) setData() return view } else { diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index 3a8b7622..e32f8962 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -121,7 +121,7 @@ // Check if we need to constrain this view. UIView *castMolecule = [molecule conformsToProtocol:@protocol(MVMCoreUIViewConstrainingProtocol)] ? (UIView *)molecule : nil; if (constrainIfNeeded && [castMolecule respondsToSelector:@selector(needsToBeConstrained)] && [castMolecule needsToBeConstrained]) { - molecule = [[ViewConstrainingView alloc] initWithMolecule:molecule alignment:[castMolecule respondsToSelector:@selector(alignment)] ? [castMolecule alignment] : UIStackViewAlignmentFill]; + molecule = [[ViewConstrainingView alloc] initWithMolecule:molecule alignment:[castMolecule respondsToSelector:@selector(horizontalAlignment)] ? [castMolecule horizontalAlignment] : UIStackViewAlignmentFill]; } [molecule setWithJSON:json delegateObject:delegateObject additionalData:nil]; return molecule; diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIViewConstrainingProtocol.h b/MVMCoreUI/OtherHandlers/MVMCoreUIViewConstrainingProtocol.h index a2ac2340..12aaacdb 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIViewConstrainingProtocol.h +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIViewConstrainingProtocol.h @@ -15,9 +15,6 @@ /// Notifies the creator that the view may not be suitable to be shown on its own and it needs to be added to a view to help with layout. - (BOOL)needsToBeConstrained; -/// The alignment if constrained. -- (UIStackViewAlignment)alignment __deprecated; - /// The alignment if constrained. - (UIStackViewAlignment)horizontalAlignment; From 40def6e19b22706962f0e52b80290d483f9766c0 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 9 Jan 2020 14:30:25 -0500 Subject: [PATCH 31/51] control default --- MVMCoreUI/BaseClasses/Control.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MVMCoreUI/BaseClasses/Control.swift b/MVMCoreUI/BaseClasses/Control.swift index e425a29b..a633f4e1 100644 --- a/MVMCoreUI/BaseClasses/Control.swift +++ b/MVMCoreUI/BaseClasses/Control.swift @@ -51,6 +51,9 @@ import UIKit public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { self.model = model + if let backgroundColor = model?.backgroundColor { + self.backgroundColor = backgroundColor.uiColor + } } //-------------------------------------------------- From c8f8f8136db192845610902396e834d138f12113 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 9 Jan 2020 15:11:03 -0500 Subject: [PATCH 32/51] model changes --- MVMCoreUI/Models/Molecules/DropDownModel.swift | 5 +++++ MVMCoreUI/Models/Molecules/FooterModel.swift | 2 -- MVMCoreUI/Models/Molecules/HeaderModel.swift | 4 ++-- MVMCoreUI/Models/Molecules/ModuleMoleculeModel.swift | 4 ++++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Models/Molecules/DropDownModel.swift b/MVMCoreUI/Models/Molecules/DropDownModel.swift index c0320737..95caa2b6 100644 --- a/MVMCoreUI/Models/Molecules/DropDownModel.swift +++ b/MVMCoreUI/Models/Molecules/DropDownModel.swift @@ -14,4 +14,9 @@ import Foundation public var backgroundColor: Color? public var label: String public var options: [String] + + public init(label: String, options: [String]) { + self.label = label + self.options = options + } } diff --git a/MVMCoreUI/Models/Molecules/FooterModel.swift b/MVMCoreUI/Models/Molecules/FooterModel.swift index 93f0a4e3..025538e6 100644 --- a/MVMCoreUI/Models/Molecules/FooterModel.swift +++ b/MVMCoreUI/Models/Molecules/FooterModel.swift @@ -11,7 +11,6 @@ import Foundation @objcMembers public class FooterModel: ContainerMoleculeProtocol { public static var identifier: String = "footer" - public var moleculeName: String? public var backgroundColor: Color? public var molecule: MoleculeProtocol @@ -27,7 +26,6 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName) self.backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) self.molecule = try typeContainer.decodeMolecule(codingKey: .molecule) } diff --git a/MVMCoreUI/Models/Molecules/HeaderModel.swift b/MVMCoreUI/Models/Molecules/HeaderModel.swift index 2f824773..1e4ab9f2 100644 --- a/MVMCoreUI/Models/Molecules/HeaderModel.swift +++ b/MVMCoreUI/Models/Molecules/HeaderModel.swift @@ -10,19 +10,18 @@ import Foundation @objcMembers public class HeaderModel: MoleculeContainerModel, MoleculeProtocol { public static var identifier: String = "header" - public var moleculeName: String? public var backgroundColor: Color? public var line: LineModel? enum HeaderCodingKeys: String, CodingKey { case moleculeName case line + case backgroundColor } required public init(from decoder: Decoder) throws { try super.init(from: decoder) let typeContainer = try decoder.container(keyedBy: HeaderCodingKeys.self) - moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName) line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line) // Default Values @@ -39,5 +38,6 @@ import Foundation var container = encoder.container(keyedBy: HeaderCodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) try container.encode(line, forKey: .line) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) } } diff --git a/MVMCoreUI/Models/Molecules/ModuleMoleculeModel.swift b/MVMCoreUI/Models/Molecules/ModuleMoleculeModel.swift index 35702824..56259942 100644 --- a/MVMCoreUI/Models/Molecules/ModuleMoleculeModel.swift +++ b/MVMCoreUI/Models/Molecules/ModuleMoleculeModel.swift @@ -17,6 +17,10 @@ open class ModuleMoleculeModel: MoleculeProtocol { case moduleName } + public init(_ moduleName: String) { + self.moduleName = moduleName + } + required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) moduleName = try typeContainer.decode(String.self, forKey:.moduleName) From 0e6a2202ea0afe79300d8a5d68acbafb762bc4b7 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 9 Jan 2020 15:51:42 -0500 Subject: [PATCH 33/51] Remove old file --- .../ContainerMoleculeProtocol.swift | 40 ------------------- 1 file changed, 40 deletions(-) delete mode 100644 MVMCoreUI/Models/ModelProtocols/ContainerMoleculeProtocol.swift diff --git a/MVMCoreUI/Models/ModelProtocols/ContainerMoleculeProtocol.swift b/MVMCoreUI/Models/ModelProtocols/ContainerMoleculeProtocol.swift deleted file mode 100644 index 9a303bdf..00000000 --- a/MVMCoreUI/Models/ModelProtocols/ContainerMoleculeProtocol.swift +++ /dev/null @@ -1,40 +0,0 @@ -// -// ContainerMoleculeProtocol.swift -// MVMCoreUI -// -// Created by Suresh, Kamlesh on 12/4/19. -// Copyright © 2019 Verizon Wireless. All rights reserved. -// - -import Foundation - -public protocol ContainerMoleculeProtocol: MoleculeProtocol { - var molecule: MoleculeProtocol { get } - var useHorizontalMargins: Bool? { get } - var useVerticalMargins: Bool? { get } - var horizontalAlignment: String? { get } - var verticalAlignment: String? { get } -} - -extension ContainerMoleculeProtocol { - public var backgroundColor: Color? { - get { return nil } - } - - public var useHorizontalMargins: Bool? { - get { return nil } - } - - public var useVerticalMargins: Bool? { - get { return nil } - } - - public var horizontalAlignment: String? { - get { return nil } - } - - public var verticalAlignment: String? { - get { return nil } - } -} - From 391e3a635de0b1a7f49f657875ee286de1044955 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 9 Jan 2020 15:53:42 -0500 Subject: [PATCH 34/51] remove file --- MVMCoreUI.xcodeproj/project.pbxproj | 4 ---- 1 file changed, 4 deletions(-) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 25fd66ea..9643a16f 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -25,7 +25,6 @@ 012A88DA238ED42E00FE3DA1 /* (null) in Sources */ = {isa = PBXBuildFile; }; 012A88DB238ED45900FE3DA1 /* CarouselModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88AE238C626E00FE3DA1 /* CarouselModel.swift */; }; 012A88EC238F084D00FE3DA1 /* FooterModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88EB238F084D00FE3DA1 /* FooterModel.swift */; }; - 012A88EE239858E300FE3DA1 /* ContainerMoleculeProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88ED239858E300FE3DA1 /* ContainerMoleculeProtocol.swift */; }; 012A88F123985E0100FE3DA1 /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88F023985E0100FE3DA1 /* Color.swift */; }; 012CA99A2384A687003F810F /* MFTextField+ModelExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012CA9992384A687003F810F /* MFTextField+ModelExtension.swift */; }; 012CA99E2385A2D3003F810F /* MFView+ModelExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012CA99D2385A2D3003F810F /* MFView+ModelExtension.swift */; }; @@ -288,7 +287,6 @@ 012A88C5238DA34000FE3DA1 /* ModuleMoleculeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModuleMoleculeModel.swift; sourceTree = ""; }; 012A88C7238DB02000FE3DA1 /* ModelMoleculeDelegateProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelMoleculeDelegateProtocol.swift; sourceTree = ""; }; 012A88EB238F084D00FE3DA1 /* FooterModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FooterModel.swift; sourceTree = ""; }; - 012A88ED239858E300FE3DA1 /* ContainerMoleculeProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerMoleculeProtocol.swift; sourceTree = ""; }; 012A88F023985E0100FE3DA1 /* Color.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = ""; }; 012CA9992384A687003F810F /* MFTextField+ModelExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MFTextField+ModelExtension.swift"; sourceTree = ""; }; 012CA99D2385A2D3003F810F /* MFView+ModelExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MFView+ModelExtension.swift"; sourceTree = ""; }; @@ -556,7 +554,6 @@ 01EB3683236097C0006832FA /* MoleculeProtocol.swift */, 012A88AC238C418100FE3DA1 /* TemplateProtocol.swift */, 012A889B23889E8400FE3DA1 /* TemplateModelProtocol.swift */, - 012A88ED239858E300FE3DA1 /* ContainerMoleculeProtocol.swift */, 011B58EF23A2AA980085F53C /* ListItemModelProtocol.swift */, ); path = ModelProtocols; @@ -1411,7 +1408,6 @@ 014AA72523C501E2006F3E93 /* ContainerModel.swift in Sources */, D29DF2EF21ECEAE1003B2FB9 /* MFFonts.m in Sources */, D22479942316AE5E003FCCF9 /* NSLayoutConstraintExtension.swift in Sources */, - 012A88EE239858E300FE3DA1 /* ContainerMoleculeProtocol.swift in Sources */, D2B18B94236214AD00A9AEDC /* NavigationController.swift in Sources */, D282AACB2243C61700C46919 /* ButtonView.swift in Sources */, D2D6CD4222E78FAB00D701B8 /* ThreeLayerTemplate.swift in Sources */, From 8d2348fe633f8557096f6c20ad5e809ad9797ff6 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 9 Jan 2020 15:59:56 -0500 Subject: [PATCH 35/51] swiftify MoleculeDelegateProtocol --- MVMCoreUI.xcodeproj/project.pbxproj | 8 ----- MVMCoreUI/Atoms/Views/MFLoadImageView.swift | 2 +- .../MFViewController+Model.swift | 11 +++++- MVMCoreUI/BaseControllers/MFViewController.h | 3 +- MVMCoreUI/BaseControllers/MFViewController.m | 9 ----- MVMCoreUI/MVMCoreUI.h | 1 - .../AccordionMoleculeTableViewCell.swift | 4 +-- .../Items/DropDownFilterTableViewCell.swift | 4 +-- .../Molecules/Items/TabsTableViewCell.swift | 4 +-- MVMCoreUI/Molecules/ModuleMolecule.swift | 8 ++--- .../MVMCoreUIDelegateObject.swift | 6 ++-- .../ModelMoleculeDelegateProtocol.swift | 34 ++++++++++++++++++- .../Templates/MoleculeListTemplate.swift | 4 +-- 13 files changed, 59 insertions(+), 39 deletions(-) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 25fd66ea..15675325 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -52,7 +52,6 @@ 017BEB4A236235BA0024EF95 /* ModelMoleculeViewProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB49236235BA0024EF95 /* ModelMoleculeViewProtocol.swift */; }; 017BEB7B236763000024EF95 /* LineModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB7A236763000024EF95 /* LineModel.swift */; }; 017BEB7F23676E870024EF95 /* MoleculeObjectMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB7E23676E870024EF95 /* MoleculeObjectMapping.swift */; }; - 0189255C239AA7EB004E8AFF /* ModuleDelegateProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0189255B239AA7EB004E8AFF /* ModuleDelegateProtocol.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 */; }; @@ -123,7 +122,6 @@ D282AACB2243C61700C46919 /* ButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AACA2243C61700C46919 /* ButtonView.swift */; }; D28A837723C79FC600DFE4FC /* MFCustomButton+ActionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A837623C79FC600DFE4FC /* MFCustomButton+ActionModel.swift */; }; D296E13C229598BF0051EBE7 /* MoleculeListCellProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D296E13B2295969C0051EBE7 /* MoleculeListCellProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; - D296E1412295EBBA0051EBE7 /* MoleculeDelegateProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D296E1402295EBBA0051EBE7 /* MoleculeDelegateProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; 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, ); }; }; @@ -312,7 +310,6 @@ 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 /* MoleculeObjectMapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeObjectMapping.swift; sourceTree = ""; }; - 0189255B239AA7EB004E8AFF /* ModuleDelegateProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModuleDelegateProtocol.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 = ""; }; @@ -382,7 +379,6 @@ D282AACA2243C61700C46919 /* ButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonView.swift; sourceTree = ""; }; D28A837623C79FC600DFE4FC /* MFCustomButton+ActionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MFCustomButton+ActionModel.swift"; sourceTree = ""; }; D296E13B2295969C0051EBE7 /* MoleculeListCellProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MoleculeListCellProtocol.h; sourceTree = ""; }; - D296E1402295EBBA0051EBE7 /* MoleculeDelegateProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MoleculeDelegateProtocol.h; 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 = ""; }; @@ -1095,13 +1091,11 @@ D2C5001621F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.h */, D2C5001721F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m */, D296E14622A597490051EBE7 /* MVMCoreUIViewConstrainingProtocol.h */, - D296E1402295EBBA0051EBE7 /* MoleculeDelegateProtocol.h */, 012A88C7238DB02000FE3DA1 /* ModelMoleculeDelegateProtocol.swift */, D2A514562211C53C00345BFB /* MVMCoreUIMoleculeMappingObject.h */, D2A514572211C53C00345BFB /* MVMCoreUIMoleculeMappingObject.m */, 017BEB432362192F0024EF95 /* MVMCoreUIMoleculeMappingObject+ModelExtension.swift */, 017BEB7E23676E870024EF95 /* MoleculeObjectMapping.swift */, - 0189255B239AA7EB004E8AFF /* ModuleDelegateProtocol.swift */, ); path = OtherHandlers; sourceTree = ""; @@ -1231,7 +1225,6 @@ D29DF12D21E6851E003B2FB9 /* MVMCoreUITopAlertBaseView.h in Headers */, D29DF24E21E6A177003B2FB9 /* MFDigitTextField.h in Headers */, D29770F321F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.h in Headers */, - D296E1412295EBBA0051EBE7 /* MoleculeDelegateProtocol.h in Headers */, D2C5001821F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.h in Headers */, D29770FD21F7C77400B2F0D0 /* MVMCoreUITextFieldView.h in Headers */, D29DF17421E69E1F003B2FB9 /* MFCustomButton.h in Headers */, @@ -1380,7 +1373,6 @@ D29DF24D21E6A177003B2FB9 /* MFTextField.m in Sources */, 014AA72D23C5059B006F3E93 /* StackPageTemplateModel.swift in Sources */, 012A88C4238D86E600FE3DA1 /* CollectionCellMoleculeProtocol.swift in Sources */, - 0189255C239AA7EB004E8AFF /* ModuleDelegateProtocol.swift in Sources */, 94C2D9AB23872EB50006CF46 /* LabelAttributeActionModel.swift in Sources */, 014AA73123C5059B006F3E93 /* ListPageTemplateModel.swift in Sources */, 017BEB4023620A230024EF95 /* TextFieldModel.swift in Sources */, diff --git a/MVMCoreUI/Atoms/Views/MFLoadImageView.swift b/MVMCoreUI/Atoms/Views/MFLoadImageView.swift index 95b00cd7..17515e71 100644 --- a/MVMCoreUI/Atoms/Views/MFLoadImageView.swift +++ b/MVMCoreUI/Atoms/Views/MFLoadImageView.swift @@ -289,7 +289,7 @@ import UIKit self?.addConstraints(width: width, height: height, size: image?.size) self?.loadingSpinnerHeightConstraint?.constant = 0 if layoutWillChange { - self?.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated?(self!) + self?.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self!) } completionHandler(image,data,isFallbackImage) })} diff --git a/MVMCoreUI/BaseControllers/MFViewController+Model.swift b/MVMCoreUI/BaseControllers/MFViewController+Model.swift index afc022f8..264592c0 100644 --- a/MVMCoreUI/BaseControllers/MFViewController+Model.swift +++ b/MVMCoreUI/BaseControllers/MFViewController+Model.swift @@ -8,7 +8,14 @@ import Foundation -extension MFViewController: ModuleDelegateProtocol { +extension MFViewController: MoleculeDelegateProtocol { + public func getModuleWithName(_ name: String?) -> [AnyHashable : Any]? { + guard let name = name else { + return nil + } + return loadObject?.modulesJSON?.optionalDictionaryForKey(name) + } + public func getModuleWithName(_ moduleName: String) -> Model? { guard let moduleJSON = loadObject?.modulesJSON?.optionalDictionaryForKey(moduleName), let moleculeName = moduleJSON.optionalStringForKey("moleculeName"), @@ -29,3 +36,5 @@ public extension MFViewController { (self as? TemplateProtocol)?.parseTemplateJSON() } } + +//MoleculeDelegateProtocol diff --git a/MVMCoreUI/BaseControllers/MFViewController.h b/MVMCoreUI/BaseControllers/MFViewController.h index c1415df4..cd96a07f 100644 --- a/MVMCoreUI/BaseControllers/MFViewController.h +++ b/MVMCoreUI/BaseControllers/MFViewController.h @@ -27,14 +27,13 @@ #import #import #import -#import @class MainMenuViewController; @class MVMCoreUITabBarPageControlViewController; @class MVMAnimationManager; @class DelegateObject; -@interface MFViewController : UIViewController +@interface MFViewController : UIViewController // Stores the load object that this screen was loaded with. @property (nullable, strong, nonatomic) MVMCoreLoadObject *loadObject; diff --git a/MVMCoreUI/BaseControllers/MFViewController.m b/MVMCoreUI/BaseControllers/MFViewController.m index 153af17f..1d97efd9 100644 --- a/MVMCoreUI/BaseControllers/MFViewController.m +++ b/MVMCoreUI/BaseControllers/MFViewController.m @@ -834,15 +834,6 @@ } } -#pragma mark - MoleculeDelegateProtocol - -- (NSDictionary *)getModuleWithName:(NSString *)name { - if (!name) { - return nil; - } - return [self.loadObject.modulesJSON dict:name]; -} - #pragma mark - adobe analytics - (nullable NSArray *)additionalActionsToTrackWithMainActionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData { diff --git a/MVMCoreUI/MVMCoreUI.h b/MVMCoreUI/MVMCoreUI.h index 795298b3..ff9b4087 100644 --- a/MVMCoreUI/MVMCoreUI.h +++ b/MVMCoreUI/MVMCoreUI.h @@ -20,7 +20,6 @@ FOUNDATION_EXPORT const unsigned char MVMCoreUIVersionString[]; #import #import #import -#import #import #import diff --git a/MVMCoreUI/Molecules/Items/AccordionMoleculeTableViewCell.swift b/MVMCoreUI/Molecules/Items/AccordionMoleculeTableViewCell.swift index 075d33f1..d6a5e05d 100644 --- a/MVMCoreUI/Molecules/Items/AccordionMoleculeTableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/AccordionMoleculeTableViewCell.swift @@ -34,9 +34,9 @@ import UIKit } if accordionButton.isSelected { - delegateObject?.moleculeDelegate?.addMolecules?(molecules, sender: self, animation: .automatic) + delegateObject?.moleculeDelegate?.addMolecules(molecules, sender: self, animation: .automatic) } else { - delegateObject?.moleculeDelegate?.removeMolecules?(molecules, sender: self, animation: .automatic) + delegateObject?.moleculeDelegate?.removeMolecules(molecules, sender: self, animation: .automatic) } if (json?.boolForKey("hideSeparatorWhenExpanded") ?? false) && (self.bottomSeparatorView?.shouldBeVisible() ?? false) { diff --git a/MVMCoreUI/Molecules/Items/DropDownFilterTableViewCell.swift b/MVMCoreUI/Molecules/Items/DropDownFilterTableViewCell.swift index a9d9c360..a2ca4383 100644 --- a/MVMCoreUI/Molecules/Items/DropDownFilterTableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/DropDownFilterTableViewCell.swift @@ -39,10 +39,10 @@ import UIKit if self.previousIndex != NSNotFound { let previousMolecules = moleculesArrays[self.previousIndex] - self.delegateObject?.moleculeDelegate?.removeMolecules?(previousMolecules, sender: self, animation: .fade) + self.delegateObject?.moleculeDelegate?.removeMolecules(previousMolecules, sender: self, animation: .fade) } let molecules = moleculesArrays[index] - self.delegateObject?.moleculeDelegate?.addMolecules?(molecules, sender: self, animation: .fade) + self.delegateObject?.moleculeDelegate?.addMolecules(molecules, sender: self, animation: .fade) self.previousIndex = index } } diff --git a/MVMCoreUI/Molecules/Items/TabsTableViewCell.swift b/MVMCoreUI/Molecules/Items/TabsTableViewCell.swift index b75f4600..d9626ae0 100644 --- a/MVMCoreUI/Molecules/Items/TabsTableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/TabsTableViewCell.swift @@ -58,7 +58,7 @@ extension TabsTableViewCell: TopTabbarDelegate { public func shouldSelectItem(at index: Int, topTabbar: TopTabbar) -> Bool { if let moleculesArrays = json?.arrayForKey(KeyMolecules), let molecules = moleculesArrays[topTabbar.selectedIndex] as? [[AnyHashable: Any]] { - delegateObject?.moleculeDelegate?.removeMolecules?(molecules, sender: self, animation: index < tabs.selectedIndex ? .right : .left) + delegateObject?.moleculeDelegate?.removeMolecules(molecules, sender: self, animation: index < tabs.selectedIndex ? .right : .left) } previousTabIndex = tabs.selectedIndex return true @@ -67,7 +67,7 @@ extension TabsTableViewCell: TopTabbarDelegate { public func topTabbar(_ topTabbar: TopTabbar, didSelectItemAt index: Int) { if let moleculesArrays = json?.arrayForKey(KeyMolecules), let molecules = moleculesArrays[index] as? [[AnyHashable: Any]] { - delegateObject?.moleculeDelegate?.addMolecules?(molecules, sender: self, animation: index < previousTabIndex ? .left : .right) + delegateObject?.moleculeDelegate?.addMolecules(molecules, sender: self, animation: index < previousTabIndex ? .left : .right) } } } diff --git a/MVMCoreUI/Molecules/ModuleMolecule.swift b/MVMCoreUI/Molecules/ModuleMolecule.swift index 107dc3f9..863df271 100644 --- a/MVMCoreUI/Molecules/ModuleMolecule.swift +++ b/MVMCoreUI/Molecules/ModuleMolecule.swift @@ -23,7 +23,7 @@ open class ModuleMolecule: Container { super.setWithModel(model, delegateObject, additionalData) guard let moduleMoleculeModel = model as? ModuleMoleculeModel, - let moduleModel = delegateObject?.moduleProtocol?.getModuleWithName(moduleMoleculeModel.moduleName) as? MoleculeProtocol else { + let moduleModel = delegateObject?.moleculeDelegate?.getModuleWithName(moduleMoleculeModel.moduleName) as? MoleculeProtocol else { // Critical error return } @@ -49,7 +49,7 @@ open class ModuleMolecule: Container { public static func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { guard let moduleMolecule = molecule as? ModuleMoleculeModel, - let moduleModel = delegateObject?.moduleProtocol?.getModuleWithName(moduleMolecule.moduleName) as? MoleculeProtocol, + let moduleModel = delegateObject?.moleculeDelegate?.getModuleWithName(moduleMolecule.moduleName) as? MoleculeProtocol, let classType = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moduleModel) as? ModelMoleculeViewProtocol.Type, let height = classType.estimatedHeight(forRow: moduleModel, delegateObject: delegateObject)else { // Critical error @@ -60,7 +60,7 @@ open class ModuleMolecule: Container { public override func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { guard let moduleMolecule = model as? ModuleMoleculeModel, - let moduleModel = delegateObject?.moduleProtocol?.getModuleWithName(moduleMolecule.moduleName) as? MoleculeProtocol, + let moduleModel = delegateObject?.moleculeDelegate?.getModuleWithName(moduleMolecule.moduleName) as? MoleculeProtocol, let classType = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moduleModel) as? ModelMoleculeViewProtocol, let name = classType.nameForReuse(moduleModel, delegateObject) else { // Critical error @@ -73,7 +73,7 @@ open class ModuleMolecule: Container { public static func requiredModules(_ molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { guard let moduleName = (molecule as? ModuleMoleculeModel)?.moduleName, - let _ = delegateObject?.moduleProtocol?.getModuleWithName(moduleName) else { + let _ = delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) else { if let errorObject = MVMCoreErrorObject(title: nil, message: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess), code: CoreUIErrorCode.ErrorCodeModuleMolecule.rawValue, domain: ErrorDomainNative, location: String(describing: self)) { error?.pointee = errorObject MVMCoreUILoggingHandler.shared()?.addError(toLog: errorObject) diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIDelegateObject.swift b/MVMCoreUI/OtherHandlers/MVMCoreUIDelegateObject.swift index 6a7fbc05..f64162db 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIDelegateObject.swift +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIDelegateObject.swift @@ -12,16 +12,14 @@ open class MVMCoreUIDelegateObject: DelegateObject { public weak var formValidationProtocol: FormValidationProtocol? public weak var buttonDelegate: ButtonDelegateProtocol? public weak var uiTextFieldDelegate: UITextFieldDelegate? - public weak var moleculeDelegate: MoleculeDelegateProtocol? - public var moduleProtocol: ModuleDelegateProtocol? - + public var moleculeDelegate: MoleculeDelegateProtocol? + open override func setAll(withDelegate delegate: Any) { super.setAll(withDelegate: delegate) formValidationProtocol = delegate as? FormValidationProtocol buttonDelegate = delegate as? ButtonDelegateProtocol uiTextFieldDelegate = delegate as? UITextFieldDelegate moleculeDelegate = delegate as? MoleculeDelegateProtocol - moduleProtocol = delegate as? ModuleDelegateProtocol } class func delegateObject(from controller: MVMCoreViewControllerProtocol?) -> MVMCoreUIDelegateObject? { diff --git a/MVMCoreUI/OtherHandlers/ModelMoleculeDelegateProtocol.swift b/MVMCoreUI/OtherHandlers/ModelMoleculeDelegateProtocol.swift index dd79ee3d..1ea4df38 100644 --- a/MVMCoreUI/OtherHandlers/ModelMoleculeDelegateProtocol.swift +++ b/MVMCoreUI/OtherHandlers/ModelMoleculeDelegateProtocol.swift @@ -8,7 +8,39 @@ import Foundation -public protocol ModelMoleculeDelegateProtocol { +public protocol MoleculeDelegateProtocol { + + /// returns a module for the corresponding module name. + func getModuleWithName(_ name: String?) -> [AnyHashable : Any]? + func getModuleWithName(_ moleculeName: String) -> Model? + + /// Notifies the delegate that the molecule layout update. Should be called when the layout may change due to an async method. + func moleculeLayoutUpdated(_ molecule: UIView & MVMCoreUIMoleculeViewProtocol) //optional + + /// Asks the delegate to add or remove molecules. + //optional + func addMolecules(_ molecules: [[AnyHashable : Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) + func removeMolecules(_ molecules: [[AnyHashable : Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) + + //optional func addMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) func removeMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) } + +extension MoleculeDelegateProtocol { + public func moleculeLayoutUpdated(_ molecule: UIView & MVMCoreUIMoleculeViewProtocol) { + // Do Nothing + } + public func addMolecules(_ molecules: [[AnyHashable : Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) { + // Do nothpublic ing + } + public func removeMolecules(_ molecules: [[AnyHashable : Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) { + // Do nothing + } + public func addMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) { + // Do nothpublic ing + } + public func removeMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) { + // Do nothing + } +} diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index 94c0d009..ecd55350 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -8,7 +8,7 @@ import UIKit -open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol, ModelMoleculeDelegateProtocol { +open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol { public var moleculesInfo: [(identifier: String, class: AnyClass, molecule: ListItemModelProtocol)]? var observer: NSKeyValueObservation? @@ -129,7 +129,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol } // MARK: - MoleculeDelegateProtocol - open override func moleculeLayoutUpdated(_ molecule: UIView & MVMCoreUIMoleculeViewProtocol) { + open func moleculeLayoutUpdated(_ molecule: UIView & MVMCoreUIMoleculeViewProtocol) { if let tableView = tableView { let point = molecule.convert(molecule.bounds.origin, to: tableView) if let indexPath = tableView.indexPathForRow(at: point), tableView.indexPathsForVisibleRows?.contains(indexPath) ?? false { From a7072fe1a0260c033ad2eff9197faf13d2bceba3 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 9 Jan 2020 16:01:27 -0500 Subject: [PATCH 36/51] remove template --- MVMCoreUI.xcodeproj/project.pbxproj | 8 -------- 1 file changed, 8 deletions(-) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 15675325..ace76ad4 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -558,13 +558,6 @@ path = ModelProtocols; sourceTree = ""; }; - 012A889A238898C600FE3DA1 /* Template */ = { - isa = PBXGroup; - children = ( - ); - path = Template; - sourceTree = ""; - }; 012A88EF23985E0100FE3DA1 /* Primitive Models */ = { isa = PBXGroup; children = ( @@ -601,7 +594,6 @@ 014AA72023C501E2006F3E93 /* Container */, 011B58EE23A2AA850085F53C /* ModelProtocols */, 012A88EF23985E0100FE3DA1 /* Primitive Models */, - 012A889A238898C600FE3DA1 /* Template */, 946EE1B5237B663A0036751F /* Extensions */, 01EB368723609801006832FA /* Molecules */, ); From 7fb22648c08d732fa3547ae4843490c65de995f1 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 9 Jan 2020 16:27:02 -0500 Subject: [PATCH 37/51] Container updates --- .../CollectionCellMoleculeProtocol.swift | 4 +-- .../ListItemModelProtocol.swift | 4 +-- .../Models/Molecules/CarouselItemModel.swift | 32 +++++++++---------- .../Molecules/DropDownListItemModel.swift | 26 +++++++-------- MVMCoreUI/Molecules/Items/ListItemModel.swift | 31 +++++++----------- .../Items/MoleculeCollectionViewCell.swift | 4 +-- .../Items/MoleculeTableViewCell.swift | 9 ++++++ MVMCoreUI/Molecules/Items/TableViewCell.swift | 13 ++------ MVMCoreUI/Molecules/Scroller.swift | 2 +- 9 files changed, 57 insertions(+), 68 deletions(-) diff --git a/MVMCoreUI/Models/ModelProtocols/CollectionCellMoleculeProtocol.swift b/MVMCoreUI/Models/ModelProtocols/CollectionCellMoleculeProtocol.swift index e18c8907..3dbdc694 100644 --- a/MVMCoreUI/Models/ModelProtocols/CollectionCellMoleculeProtocol.swift +++ b/MVMCoreUI/Models/ModelProtocols/CollectionCellMoleculeProtocol.swift @@ -8,7 +8,7 @@ import Foundation -public protocol CollectionCellMoleculeProtocol: ContainerMoleculeProtocol { +public protocol CollectionCellMoleculeProtocol: ContainerModelProtocol, MoleculeProtocol { var peakingUI: Bool? {get} - var peakingArrowColor: String? {get} + var peakingArrowColor: Color? {get} } diff --git a/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift b/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift index 59bec9ae..53bf51ea 100644 --- a/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift +++ b/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift @@ -8,7 +8,7 @@ import Foundation -public protocol ListItemModelProtocol: ContainerMoleculeProtocol { +public protocol ListItemModelProtocol: ContainerModelProtocol, Model { var molecule: MoleculeProtocol { get } - var separator: LineModel? { get set } + var line: LineModel? { get set } } diff --git a/MVMCoreUI/Models/Molecules/CarouselItemModel.swift b/MVMCoreUI/Models/Molecules/CarouselItemModel.swift index 1ccf898f..e86b89c3 100644 --- a/MVMCoreUI/Models/Molecules/CarouselItemModel.swift +++ b/MVMCoreUI/Models/Molecules/CarouselItemModel.swift @@ -9,31 +9,31 @@ import Foundation -@objcMembers public class CarouselItemModel: ContainerMoleculeProtocol { +@objcMembers public class CarouselItemModel: MoleculeContainerModel, CollectionCellMoleculeProtocol { public static var identifier: String = "carouselItem" - public var molecule: MoleculeProtocol public var backgroundColor: Color? - - public init(molecule: MoleculeProtocol) { - self.molecule = molecule - } - - enum CodingKeys: String, CodingKey { - case moleculeName - case molecule + public var peakingUI: Bool? + public var peakingArrowColor: Color? + + enum CarouselItemCodingKeys: String, CodingKey { case backgroundColor + case peakingUI + case peakingArrowColor } required public init(from decoder: Decoder) throws { - let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - molecule = try typeContainer.decodeMolecule(codingKey: .molecule) + let typeContainer = try decoder.container(keyedBy: CarouselItemCodingKeys.self) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) + peakingUI = try typeContainer.decodeIfPresent(Bool.self, forKey: .peakingUI) + peakingArrowColor = try typeContainer.decodeIfPresent(Color.self, forKey: .peakingArrowColor) + try super.init(from: decoder) } - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(moleculeName, forKey: .moleculeName) + public override func encode(to encoder: Encoder) throws { + try super.encode(to: encoder) + var container = encoder.container(keyedBy: CarouselItemCodingKeys.self) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) - try container.encodeModelIfPresent(molecule, forKey: .molecule) + try container.encodeIfPresent(peakingUI, forKey: .peakingUI) + try container.encodeIfPresent(peakingArrowColor, forKey: .peakingArrowColor) } } diff --git a/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift b/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift index 260e7063..1ef1ca1f 100644 --- a/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift +++ b/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift @@ -8,42 +8,38 @@ import Foundation -@objcMembers public class DropDownListItemModel: ListItemModelProtocol { +@objcMembers public class DropDownListItemModel: MoleculeContainerModel, ListItemModelProtocol { public static var identifier: String = "dropDownListItem" - public var molecule: MoleculeProtocol public var molecules: [[ListItemModel]] public var backgroundColor: Color? - public var separator: LineModel? + public var line: LineModel? public var dropDown: DropDownModel public init(molecule: MoleculeProtocol, molecules: [[ListItemModel]], dropDown: DropDownModel) { - self.molecule = molecule self.molecules = molecules self.dropDown = dropDown + super.init(with: molecule) } - enum CodingKeys: String, CodingKey { - case molecule - case moleculeName + enum DropDownCodingKeys: String, CodingKey { case molecules - case separator + case line case backgroundColor case dropDown } required public init(from decoder: Decoder) throws { - let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - molecule = try typeContainer.decodeMolecule(codingKey: .molecule) + let typeContainer = try decoder.container(keyedBy: DropDownCodingKeys.self) self.molecules = try typeContainer.decode([[ListItemModel]].self, forKey: .molecules) - self.separator = try typeContainer.decodeIfPresent(LineModel.self, forKey: .separator) + self.line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line) self.backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) self.dropDown = try typeContainer.decode(DropDownModel.self, forKey: .dropDown) + try super.init(from: decoder) } - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeModel(molecule, forKey: .molecule) - try container.encode(moleculeName, forKey: .moleculeName) + public override func encode(to encoder: Encoder) throws { + try super.encode(to: encoder) + var container = encoder.container(keyedBy: DropDownCodingKeys.self) try container.encode(molecules, forKey: .molecules) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encode(dropDown, forKey: .dropDown) diff --git a/MVMCoreUI/Molecules/Items/ListItemModel.swift b/MVMCoreUI/Molecules/Items/ListItemModel.swift index bdff2842..bef2cb84 100644 --- a/MVMCoreUI/Molecules/Items/ListItemModel.swift +++ b/MVMCoreUI/Molecules/Items/ListItemModel.swift @@ -9,46 +9,39 @@ import Foundation import MVMCore -@objcMembers public class ListItemModel: ListItemModelProtocol { +@objcMembers public class ListItemModel: MoleculeContainerModel, ListItemModelProtocol { public static var identifier: String = "listItem" - public var molecule: MoleculeProtocol public var backgroundColor: Color? public var action: ActionProtocol? public var hideArrow: Bool? - public var separator: LineModel? + public var line: LineModel? public var style: String? - public init(molecule: MoleculeProtocol) { - self.molecule = molecule - } - - enum CodingKeys: String, CodingKey { - case moleculeName - case molecule + enum ListItemCodingKeys: String, CodingKey { case backgroundColor case action case hideArrow - case separator + case line case style } required public init(from decoder: Decoder) throws { - let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - molecule = try typeContainer.decodeMolecule(codingKey: .molecule) + let typeContainer = try decoder.container(keyedBy: ListItemCodingKeys.self) + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) action = try typeContainer.decodeModelIfPresent(codingKey: .action, typeCodingKey: ActionCodingKey.type) hideArrow = try typeContainer.decodeIfPresent(Bool.self, forKey: .hideArrow) - separator = try typeContainer.decodeIfPresent(LineModel.self, forKey: .separator) + line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line) style = try typeContainer.decodeIfPresent(String.self, forKey: .style) + try super.init(from: decoder) } - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(moleculeName, forKey: .moleculeName) - try container.encodeModelIfPresent(molecule, forKey: .molecule) + public override func encode(to encoder: Encoder) throws { + try super.encode(to: encoder) + var container = encoder.container(keyedBy: ListItemCodingKeys.self) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeModelIfPresent(action, forKey: .action) try container.encodeIfPresent(hideArrow, forKey: .hideArrow) - try container.encodeIfPresent(separator, forKey: .separator) + try container.encodeIfPresent(line, forKey: .line) try container.encodeIfPresent(style, forKey: .style) } } diff --git a/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift b/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift index b976ca64..1603c876 100644 --- a/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift +++ b/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift @@ -69,7 +69,7 @@ open class MoleculeCollectionViewCell: UICollectionViewCell, MVMCoreUIMoleculeVi public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { - guard let collectionModel = model as? CollectionCellMoleculeProtocol else { + guard let collectionModel = model as? CarouselItemModel else { return } @@ -82,7 +82,7 @@ open class MoleculeCollectionViewCell: UICollectionViewCell, MVMCoreUIMoleculeVi // Handles peaking. allowsPeaking = collectionModel.peakingUI ?? false if let peakingArrowColor = collectionModel.peakingArrowColor { - let color = UIColor.mfGet(forHex: peakingArrowColor) + let color = peakingArrowColor.uiColor peakingLeftArrow.tintColor = color peakingRightArrow.tintColor = color } diff --git a/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift b/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift index 9bfab3f3..40222f03 100644 --- a/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift @@ -38,4 +38,13 @@ import UIKit } return theClass.requiredModules?(moleculeJSON, delegateObject: delegateObject, error: error) } + + public static 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 { + return 80 + } + return max(2 * PaddingDefaultVerticalSpacing3, height) + } } diff --git a/MVMCoreUI/Molecules/Items/TableViewCell.swift b/MVMCoreUI/Molecules/Items/TableViewCell.swift index ba017c4e..9fbad78b 100644 --- a/MVMCoreUI/Molecules/Items/TableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/TableViewCell.swift @@ -177,7 +177,7 @@ import UIKit } // override the separator - if let separator = model.separator { + if let separator = model.line { addSeparatorsIfNeeded() bottomSeparatorView?.setWithModel(separator, nil, nil) } @@ -193,19 +193,10 @@ import UIKit backgroundColor = .white } - public static func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { - guard let moleculeModel = (molecule as? ContainerMoleculeProtocol)?.molecule, - let classType = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moleculeModel) as? ModelMoleculeViewProtocol.Type, - let height = classType.estimatedHeight(forRow: moleculeModel, delegateObject: delegateObject) else { - return 80 - } - return max(2 * PaddingDefaultVerticalSpacing3, height) - } - - 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 @objc public func addCaretViewAccessory() { diff --git a/MVMCoreUI/Molecules/Scroller.swift b/MVMCoreUI/Molecules/Scroller.swift index 01477158..4be1025a 100644 --- a/MVMCoreUI/Molecules/Scroller.swift +++ b/MVMCoreUI/Molecules/Scroller.swift @@ -34,7 +34,7 @@ import UIKit setUpDefaultWithModel(model, delegateObject, additionalData) guard let model = model, - let moleculeModel = (model as? ContainerMoleculeProtocol)?.molecule else { + let moleculeModel = (model as? MoleculeContainerModel)?.molecule else { return } From 826cb7f28469af1d336c342472c864d6666b8dae Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 9 Jan 2020 16:28:00 -0500 Subject: [PATCH 38/51] container change footer --- MVMCoreUI/Models/Molecules/FooterModel.swift | 28 +++++++------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/MVMCoreUI/Models/Molecules/FooterModel.swift b/MVMCoreUI/Models/Molecules/FooterModel.swift index 93f0a4e3..757e2fd5 100644 --- a/MVMCoreUI/Models/Molecules/FooterModel.swift +++ b/MVMCoreUI/Models/Molecules/FooterModel.swift @@ -9,33 +9,23 @@ import Foundation -@objcMembers public class FooterModel: ContainerMoleculeProtocol { +@objcMembers public class FooterModel: MoleculeContainerModel, MoleculeProtocol { public static var identifier: String = "footer" - public var moleculeName: String? public var backgroundColor: Color? - public var molecule: MoleculeProtocol - public init(molecule: MoleculeProtocol){ - self.molecule = molecule - } - - enum CodingKeys: String, CodingKey { - case moleculeName - case molecule + enum FooterCodingKeys: String, CodingKey { case backgroundColor } required public init(from decoder: Decoder) throws { - let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName) - self.backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) - self.molecule = try typeContainer.decodeMolecule(codingKey: .molecule) + let typeContainer = try decoder.container(keyedBy: FooterCodingKeys.self) + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) + try super.init(from: decoder) } - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(moleculeName, forKey: .moleculeName) - try container.encodeIfPresent(self.backgroundColor, forKey: .backgroundColor) - try container.encodeModel(self.molecule, forKey: .moleculeName) + public override func encode(to encoder: Encoder) throws { + try super.encode(to: encoder) + var container = encoder.container(keyedBy: FooterCodingKeys.self) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) } } From 629f30e07344d600481be1f4b107ba66fe88edb8 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 9 Jan 2020 16:38:14 -0500 Subject: [PATCH 39/51] container updates --- MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift | 2 +- MVMCoreUI/Molecules/Items/TableViewCell.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift b/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift index 53bf51ea..a77f9374 100644 --- a/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift +++ b/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift @@ -8,7 +8,7 @@ import Foundation -public protocol ListItemModelProtocol: ContainerModelProtocol, Model { +public protocol ListItemModelProtocol: ContainerModelProtocol, MoleculeProtocol { var molecule: MoleculeProtocol { get } var line: LineModel? { get set } } diff --git a/MVMCoreUI/Molecules/Items/TableViewCell.swift b/MVMCoreUI/Molecules/Items/TableViewCell.swift index bf616419..ee6e79dd 100644 --- a/MVMCoreUI/Molecules/Items/TableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/TableViewCell.swift @@ -78,8 +78,8 @@ import UIKit open func styleShortDivider() { topMarginPadding = 32 bottomMarginPadding = 16 - topSeparatorView?.style = .none - bottomSeparatorView?.style = .thin + topSeparatorView?.setStyle(.none) + bottomSeparatorView?.setStyle(.thin) } open func styleFooter() { From 99a258c0f8d5c3a74ecac715d2a0b0ae80acb70b Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Fri, 10 Jan 2020 08:57:56 -0500 Subject: [PATCH 40/51] Template associated type testing --- MVMCoreUI.xcodeproj/project.pbxproj | 20 +++++++----- .../ModelProtocols/PageModelProtocol.swift | 15 +++++++++ .../TemplateModelProtocol.swift | 5 +-- .../ModelProtocols/TemplateProtocol.swift | 32 +++++++++++++------ .../Template/ListPageTemplateModel.swift | 2 +- .../StackCenteredPageTemplateModel.swift | 2 +- .../Template/StackPageTemplateModel.swift | 2 +- .../ThreeLayerPageTemplateModel.swift | 3 +- .../Templates/MoleculeListTemplate.swift | 26 +++++---------- .../Templates/MoleculeStackTemplate.swift | 22 +++---------- MVMCoreUI/Templates/ThreeLayerTemplate.swift | 22 +++---------- 11 files changed, 70 insertions(+), 81 deletions(-) create mode 100644 MVMCoreUI/Models/ModelProtocols/PageModelProtocol.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index ba0db1dd..7769203b 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -119,6 +119,7 @@ D282AABA224131D100C46919 /* MFTransparentGIFView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AAB9224131D100C46919 /* MFTransparentGIFView.swift */; }; D282AACB2243C61700C46919 /* ButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AACA2243C61700C46919 /* ButtonView.swift */; }; D28A837723C79FC600DFE4FC /* MFCustomButton+ActionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A837623C79FC600DFE4FC /* MFCustomButton+ActionModel.swift */; }; + D28A837923C7D5BC00DFE4FC /* PageModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A837823C7D5BC00DFE4FC /* PageModelProtocol.swift */; }; D296E13C229598BF0051EBE7 /* MoleculeListCellProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D296E13B2295969C0051EBE7 /* MoleculeListCellProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; 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 */; }; @@ -374,6 +375,7 @@ D282AAB9224131D100C46919 /* MFTransparentGIFView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MFTransparentGIFView.swift; sourceTree = ""; }; D282AACA2243C61700C46919 /* ButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonView.swift; sourceTree = ""; }; D28A837623C79FC600DFE4FC /* MFCustomButton+ActionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MFCustomButton+ActionModel.swift"; sourceTree = ""; }; + D28A837823C7D5BC00DFE4FC /* PageModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageModelProtocol.swift; sourceTree = ""; }; D296E13B2295969C0051EBE7 /* MoleculeListCellProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MoleculeListCellProtocol.h; 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 = ""; }; @@ -548,6 +550,7 @@ 01EB3683236097C0006832FA /* MoleculeProtocol.swift */, 012A88AC238C418100FE3DA1 /* TemplateProtocol.swift */, 012A889B23889E8400FE3DA1 /* TemplateModelProtocol.swift */, + D28A837823C7D5BC00DFE4FC /* PageModelProtocol.swift */, 011B58EF23A2AA980085F53C /* ListItemModelProtocol.swift */, ); path = ModelProtocols; @@ -624,6 +627,14 @@ path = Molecules; sourceTree = ""; }; + 0A5D59C323AD488600EFD9E9 /* Protocols */ = { + isa = PBXGroup; + children = ( + 0A5D59C123AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift */, + ); + path = Protocols; + sourceTree = ""; + }; 946EE1B5237B663A0036751F /* Extensions */ = { isa = PBXGroup; children = ( @@ -654,14 +665,6 @@ name = "Recovered References"; sourceTree = ""; }; - 0A5D59C323AD488600EFD9E9 /* Protocols */ = { - isa = PBXGroup; - children = ( - 0A5D59C123AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift */, - ); - path = Protocols; - sourceTree = ""; - }; D213347423842FE3008E41B3 /* Controllers */ = { isa = PBXGroup; children = ( @@ -1411,6 +1414,7 @@ D29DF2AE21E7B3A4003B2FB9 /* MFTextView.m in Sources */, 017BEB382360C6AC0024EF95 /* RadioButtonLabel.swift in Sources */, D29DF18121E69E50003B2FB9 /* MFView.m in Sources */, + D28A837923C7D5BC00DFE4FC /* PageModelProtocol.swift in Sources */, D29DF18321E69E54003B2FB9 /* SeparatorView.m in Sources */, D29DF17A21E69E1F003B2FB9 /* MFCustomButton.m in Sources */, 017BEB7B236763000024EF95 /* LineModel.swift in Sources */, diff --git a/MVMCoreUI/Models/ModelProtocols/PageModelProtocol.swift b/MVMCoreUI/Models/ModelProtocols/PageModelProtocol.swift new file mode 100644 index 00000000..8c6d1557 --- /dev/null +++ b/MVMCoreUI/Models/ModelProtocols/PageModelProtocol.swift @@ -0,0 +1,15 @@ +// +// PageModelProtocol.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 1/9/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation + +public protocol PageModelProtocol: Model { + var pageType: String { get set } + var screenHeading: String? { get set } + var isAtomicTabs: Bool? { get set } +} diff --git a/MVMCoreUI/Models/ModelProtocols/TemplateModelProtocol.swift b/MVMCoreUI/Models/ModelProtocols/TemplateModelProtocol.swift index 3eeb9673..66472da6 100644 --- a/MVMCoreUI/Models/ModelProtocols/TemplateModelProtocol.swift +++ b/MVMCoreUI/Models/ModelProtocols/TemplateModelProtocol.swift @@ -8,11 +8,8 @@ import Foundation -public protocol TemplateModelProtocol: Model { +public protocol TemplateModelProtocol: PageModelProtocol { var template: String { get } - var pageType: String { get set } - var screenHeading: String { get set } - var isAtomicTabs: Bool? { get set } } extension TemplateModelProtocol { diff --git a/MVMCoreUI/Models/ModelProtocols/TemplateProtocol.swift b/MVMCoreUI/Models/ModelProtocols/TemplateProtocol.swift index 90e3e635..c6fd38cd 100644 --- a/MVMCoreUI/Models/ModelProtocols/TemplateProtocol.swift +++ b/MVMCoreUI/Models/ModelProtocols/TemplateProtocol.swift @@ -9,21 +9,33 @@ import Foundation public protocol TemplateProtocol { - var templateModel: TemplateModelProtocol? {get} - func parseTemplateJSON() - func templateData() -> Data? + associatedtype TemplateModel: TemplateModelProtocol + var templateModel: TemplateModel? { get set } } -extension TemplateProtocol where Self: MFViewController { - public func templateData() -> Data? { - guard let pageJSON = loadObject?.pageJSON as? [String: AnyHashable] else { - return nil - } +public extension TemplateProtocol { + +} + +public extension TemplateProtocol where Self: MFViewController { + mutating func parseTemplateJSON() { + guard let pageJSON = loadObject?.pageJSON as? [String: AnyHashable] else { return } do { - return try JSONSerialization.data(withJSONObject: pageJSON) + let data = try JSONSerialization.data(withJSONObject: pageJSON) + let decoder = JSONDecoder() + let templateModel = try decoder.decode(TemplateModel.self, from: data) + self.templateModel = templateModel } catch { MVMCoreUILoggingHandler.logDebugMessage(withDelegate: "error: \(error)") - return nil } } } + +class Testing: MFViewController, TemplateProtocol { + typealias TemplateModel = StackPageTemplateModel + var templateModel: StackPageTemplateModel? + + public func parsePageJSON() { + parseTemplateJSON() + } +} diff --git a/MVMCoreUI/Models/Template/ListPageTemplateModel.swift b/MVMCoreUI/Models/Template/ListPageTemplateModel.swift index 587cf6a5..c457969a 100644 --- a/MVMCoreUI/Models/Template/ListPageTemplateModel.swift +++ b/MVMCoreUI/Models/Template/ListPageTemplateModel.swift @@ -13,7 +13,7 @@ import Foundation public static var identifier: String = "listTemplate" public var pageType: String - public var screenHeading: String + public var screenHeading: String? public var isAtomicTabs: Bool? public var header: HeaderModel? diff --git a/MVMCoreUI/Models/Template/StackCenteredPageTemplateModel.swift b/MVMCoreUI/Models/Template/StackCenteredPageTemplateModel.swift index 27eaa362..804103c4 100644 --- a/MVMCoreUI/Models/Template/StackCenteredPageTemplateModel.swift +++ b/MVMCoreUI/Models/Template/StackCenteredPageTemplateModel.swift @@ -14,7 +14,7 @@ import Foundation public var pageType: String - public var screenHeading: String + public var screenHeading: String? public var isAtomicTabs: Bool? diff --git a/MVMCoreUI/Models/Template/StackPageTemplateModel.swift b/MVMCoreUI/Models/Template/StackPageTemplateModel.swift index d05d91f3..0d8bef77 100644 --- a/MVMCoreUI/Models/Template/StackPageTemplateModel.swift +++ b/MVMCoreUI/Models/Template/StackPageTemplateModel.swift @@ -14,7 +14,7 @@ import Foundation public var pageType: String - public var screenHeading: String + public var screenHeading: String? public var isAtomicTabs: Bool? diff --git a/MVMCoreUI/Models/Template/ThreeLayerPageTemplateModel.swift b/MVMCoreUI/Models/Template/ThreeLayerPageTemplateModel.swift index 658a021f..b4604fbc 100644 --- a/MVMCoreUI/Models/Template/ThreeLayerPageTemplateModel.swift +++ b/MVMCoreUI/Models/Template/ThreeLayerPageTemplateModel.swift @@ -9,12 +9,11 @@ import Foundation @objcMembers public class ThreeLayerPageTemplateModel: TemplateModelProtocol { - public static var identifier: String = "threeLayer" public var pageType: String - public var screenHeading: String + public var screenHeading: String? public var isAtomicTabs: Bool? diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index ecd55350..c78fe19c 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -13,20 +13,10 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol public var moleculesInfo: [(identifier: String, class: AnyClass, molecule: ListItemModelProtocol)]? var observer: NSKeyValueObservation? - public var templateModel: TemplateModelProtocol? - - public func parseTemplateJSON() { - guard let templateData = templateData() else { - return - } - - do { - let decoder = JSONDecoder() - let templateModel = try decoder.decode(ListPageTemplateModel.self, from: templateData) - self.templateModel = templateModel - } catch { - MVMCoreUILoggingHandler.logDebugMessage(withDelegate: "error: \(error)") - } + public var templateModel: ListPageTemplateModel? + + public func parsePageJSON() { + parseTemplateJSON() } open override var loadObject: MVMCoreLoadObject? { @@ -44,7 +34,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol } open override func viewForTop() -> UIView { - guard let headerModel = (templateModel as? ListPageTemplateModel)?.header, + guard let headerModel = templateModel?.header, let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(headerModel, delegateObject() as? MVMCoreUIDelegateObject, true) else { return super.viewForTop() } @@ -52,7 +42,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol } override open func viewForBottom() -> UIView { - guard let footerModel = (templateModel as? ListPageTemplateModel)?.footer, + guard let footerModel = templateModel?.footer, let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(footerModel, delegateObject() as? MVMCoreUIDelegateObject, true) else { return super.viewForBottom() } @@ -187,7 +177,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol /// Sets up the molecule list and ensures no errors loading all content. func getMoleculeInfoList() -> [(identifier: String, class: AnyClass, molecule: ListItemModelProtocol)]? { var moleculeList: [(identifier: String, class: AnyClass, molecule: ListItemModelProtocol)] = [] - if let molecules = (templateModel as? ListPageTemplateModel)?.molecules { + if let molecules = templateModel?.molecules { for molecule in molecules { if let info = getMoleculeInfo(with: molecule) { moleculeList.append(info) @@ -200,7 +190,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol /// Sets up the header, footer, molecule list and ensures no errors loading all content. func setup() { var moleculeList: [(identifier: String, class: AnyClass, molecule: ListItemModelProtocol)] = [] - if let molecules = (templateModel as? ListPageTemplateModel)?.molecules { + if let molecules = templateModel?.molecules { for molecule in molecules { if let info = getMoleculeInfo(with: molecule) { moleculeList.append(info) diff --git a/MVMCoreUI/Templates/MoleculeStackTemplate.swift b/MVMCoreUI/Templates/MoleculeStackTemplate.swift index 9ee96d04..7c75a555 100644 --- a/MVMCoreUI/Templates/MoleculeStackTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeStackTemplate.swift @@ -11,21 +11,7 @@ import UIKit open class MoleculeStackTemplate: ThreeLayerViewController, TemplateProtocol { var observer: NSKeyValueObservation? - public var templateModel: TemplateModelProtocol? - - public func parseTemplateJSON() { - guard let templateData = templateData() else { - return - } - - do { - let decoder = JSONDecoder() - let templateModel = try decoder.decode(StackPageTemplateModel.self, from: templateData) - self.templateModel = templateModel - } catch { - MVMCoreUILoggingHandler.logDebugMessage(withDelegate: "error: \(error)") - } - } + public var templateModel: StackPageTemplateModel? open override var loadObject: MVMCoreLoadObject? { didSet { @@ -46,7 +32,7 @@ open class MoleculeStackTemplate: ThreeLayerViewController, TemplateProtocol { } open override func viewForTop() -> UIView? { - guard let headerModel = (templateModel as? StackPageTemplateModel)?.header, + guard let headerModel = templateModel?.header, let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(headerModel, delegateObject() as? MVMCoreUIDelegateObject, true) else { return nil } @@ -55,7 +41,7 @@ open class MoleculeStackTemplate: ThreeLayerViewController, TemplateProtocol { open override func viewForMiddle() -> UIView? { - guard let moleculeStackModel = (templateModel as? StackPageTemplateModel)?.moleculeStack else { + guard let moleculeStackModel = templateModel?.moleculeStack else { return nil } @@ -67,7 +53,7 @@ open class MoleculeStackTemplate: ThreeLayerViewController, TemplateProtocol { } override open func viewForBottom() -> UIView? { - guard let footerModel = (templateModel as? StackPageTemplateModel)?.footer, + guard let footerModel = templateModel?.footer, let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(footerModel, delegateObject() as? MVMCoreUIDelegateObject, true) else { return nil } diff --git a/MVMCoreUI/Templates/ThreeLayerTemplate.swift b/MVMCoreUI/Templates/ThreeLayerTemplate.swift index f87a1e29..c6ceb97c 100644 --- a/MVMCoreUI/Templates/ThreeLayerTemplate.swift +++ b/MVMCoreUI/Templates/ThreeLayerTemplate.swift @@ -10,21 +10,7 @@ import UIKit @objcMembers open class ThreeLayerTemplate: ThreeLayerViewController, TemplateProtocol { - public var templateModel: TemplateModelProtocol? - - public func parseTemplateJSON() { - guard let templateData = templateData() else { - return - } - - do { - let decoder = JSONDecoder() - let templateModel = try decoder.decode(StackPageTemplateModel.self, from: templateData) - self.templateModel = templateModel - } catch { - MVMCoreUILoggingHandler.logDebugMessage(withDelegate: "error: \(error)") - } - } + public var templateModel: ThreeLayerPageTemplateModel? override open func viewDidLoad() { super.viewDidLoad() @@ -39,7 +25,7 @@ import UIKit open override func viewForTop() -> UIView? { - guard let headerModel = (templateModel as? ThreeLayerPageTemplateModel)?.header, + guard let headerModel = templateModel?.header, let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(headerModel, delegateObject() as? MVMCoreUIDelegateObject, true) else { return nil } @@ -47,7 +33,7 @@ import UIKit } open override func viewForMiddle() -> UIView? { - guard let middleModel = (templateModel as? ThreeLayerPageTemplateModel)?.middle, + guard let middleModel = templateModel?.middle, let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(middleModel, delegateObject() as? MVMCoreUIDelegateObject, true) else { return nil } @@ -55,7 +41,7 @@ import UIKit } override open func viewForBottom() -> UIView? { - guard let footerModel = (templateModel as? ThreeLayerPageTemplateModel)?.footer, + guard let footerModel = templateModel?.footer, let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(footerModel, delegateObject() as? MVMCoreUIDelegateObject, true) else { return nil } From 90d7b188d19ca86ec13aa7c2ac7e5397cb15d0a4 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Fri, 10 Jan 2020 09:55:42 -0500 Subject: [PATCH 41/51] each template must parse themselves... --- .../MFViewController+Model.swift | 3 --- .../ModelProtocols/TemplateProtocol.swift | 19 +++---------------- .../Templates/MoleculeListTemplate.swift | 3 +-- .../Templates/MoleculeStackTemplate.swift | 3 +++ MVMCoreUI/Templates/ThreeLayerTemplate.swift | 5 ++++- 5 files changed, 11 insertions(+), 22 deletions(-) diff --git a/MVMCoreUI/BaseControllers/MFViewController+Model.swift b/MVMCoreUI/BaseControllers/MFViewController+Model.swift index 264592c0..b3ff4ec6 100644 --- a/MVMCoreUI/BaseControllers/MFViewController+Model.swift +++ b/MVMCoreUI/BaseControllers/MFViewController+Model.swift @@ -33,8 +33,5 @@ extension MFViewController: MoleculeDelegateProtocol { public extension MFViewController { @objc func parsePageJSON() { - (self as? TemplateProtocol)?.parseTemplateJSON() } } - -//MoleculeDelegateProtocol diff --git a/MVMCoreUI/Models/ModelProtocols/TemplateProtocol.swift b/MVMCoreUI/Models/ModelProtocols/TemplateProtocol.swift index c6fd38cd..8293f18b 100644 --- a/MVMCoreUI/Models/ModelProtocols/TemplateProtocol.swift +++ b/MVMCoreUI/Models/ModelProtocols/TemplateProtocol.swift @@ -8,18 +8,14 @@ import Foundation -public protocol TemplateProtocol { +public protocol TemplateProtocol: class { associatedtype TemplateModel: TemplateModelProtocol var templateModel: TemplateModel? { get set } } -public extension TemplateProtocol { - -} - public extension TemplateProtocol where Self: MFViewController { - mutating func parseTemplateJSON() { - guard let pageJSON = loadObject?.pageJSON as? [String: AnyHashable] else { return } + func parseTemplateJSON() { + guard let pageJSON = self.loadObject?.pageJSON as? [String: AnyHashable] else { return } do { let data = try JSONSerialization.data(withJSONObject: pageJSON) let decoder = JSONDecoder() @@ -30,12 +26,3 @@ public extension TemplateProtocol where Self: MFViewController { } } } - -class Testing: MFViewController, TemplateProtocol { - typealias TemplateModel = StackPageTemplateModel - var templateModel: StackPageTemplateModel? - - public func parsePageJSON() { - parseTemplateJSON() - } -} diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index c78fe19c..7b572c44 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -14,8 +14,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol var observer: NSKeyValueObservation? public var templateModel: ListPageTemplateModel? - - public func parsePageJSON() { + public override func parsePageJSON() { parseTemplateJSON() } diff --git a/MVMCoreUI/Templates/MoleculeStackTemplate.swift b/MVMCoreUI/Templates/MoleculeStackTemplate.swift index 7c75a555..3dc9a58c 100644 --- a/MVMCoreUI/Templates/MoleculeStackTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeStackTemplate.swift @@ -12,6 +12,9 @@ open class MoleculeStackTemplate: ThreeLayerViewController, TemplateProtocol { var observer: NSKeyValueObservation? public var templateModel: StackPageTemplateModel? + public override func parsePageJSON() { + parseTemplateJSON() + } open override var loadObject: MVMCoreLoadObject? { didSet { diff --git a/MVMCoreUI/Templates/ThreeLayerTemplate.swift b/MVMCoreUI/Templates/ThreeLayerTemplate.swift index c6ceb97c..67326d09 100644 --- a/MVMCoreUI/Templates/ThreeLayerTemplate.swift +++ b/MVMCoreUI/Templates/ThreeLayerTemplate.swift @@ -11,7 +11,10 @@ import UIKit @objcMembers open class ThreeLayerTemplate: ThreeLayerViewController, TemplateProtocol { public var templateModel: ThreeLayerPageTemplateModel? - + public override func parsePageJSON() { + parseTemplateJSON() + } + override open func viewDidLoad() { super.viewDidLoad() bottomViewOutsideOfScroll = true From 5bb6b9bc7591ce8263e317f7ae6b811150688592 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 13 Jan 2020 09:38:39 -0500 Subject: [PATCH 42/51] Line items update --- MVMCoreUI.xcodeproj/project.pbxproj | 34 ++++++--- MVMCoreUI/Atoms/Buttons/CaretButton.swift | 2 +- .../MFTextField+ModelExtension.swift | 2 +- MVMCoreUI/Atoms/Views/CaretView.swift | 6 +- MVMCoreUI/Atoms/Views/DashLine.swift | 4 +- MVMCoreUI/Atoms/Views/GraphView.swift | 4 +- MVMCoreUI/Atoms/Views/Label.swift | 2 +- .../Atoms/Views/LeftRightLabelView.swift | 2 +- MVMCoreUI/Atoms/Views/Line.swift | 2 +- MVMCoreUI/Atoms/Views/MFLoadImageView.swift | 2 +- .../Atoms/Views/MFView+ModelExtension.swift | 4 +- MVMCoreUI/Atoms/Views/MultiProgress.swift | 4 +- MVMCoreUI/Atoms/Views/ProgressBar.swift | 6 +- MVMCoreUI/BaseClasses/Control.swift | 2 +- MVMCoreUI/BaseClasses/View.swift | 2 +- .../MFViewController+Model.swift | 4 +- MVMCoreUI/Containers/Container.swift | 10 +-- MVMCoreUI/MVMCoreUI.h | 1 - MVMCoreUI/Models/Extensions/ModelHelper.swift | 13 ++++ .../ListItemModelProtocol.swift | 23 +++++- .../ModelProtocols/TemplateProtocol.swift | 2 +- .../Template/ListPageTemplateModel.swift | 67 ++++++++--------- .../TabsModel.swift | 50 +++++++++++++ .../Items/AccordionListItemModel.swift | 46 ++++++++++++ .../AccordionMoleculeTableViewCell.swift | 7 +- .../Items/DropDownFilterTableViewCell.swift | 17 ++--- .../Items}/DropDownListItemModel.swift | 26 ++++--- .../Items/MoleculeCollectionViewCell.swift | 4 +- .../Items/MoleculeTableViewCell.swift | 6 +- MVMCoreUI/Molecules/Items/StackItem.swift | 4 +- .../Items/StackItemModel.swift} | 2 +- MVMCoreUI/Molecules/Items/TableViewCell.swift | 71 ++++++------------- .../Molecules/Items/TabsListItemModel.swift | 54 ++++++++++++++ .../Molecules/Items/TabsTableViewCell.swift | 20 ++---- .../SwitchMolecules/HeadlineBodySwitch.swift | 2 +- .../Molecules/ModelMoleculeViewProtocol.swift | 2 +- MVMCoreUI/Molecules/ModuleMolecule.swift | 2 +- MVMCoreUI/Molecules/MoleculeContainer.swift | 2 +- MVMCoreUI/Molecules/Scroller.swift | 2 +- MVMCoreUI/Molecules/StandardHeaderView.swift | 2 +- .../EyebrowHeadlineBodyLink.swift | 8 +-- .../HeadlineBody.swift | 2 +- MVMCoreUI/Organisms/Carousel.swift | 2 +- .../MoleculeStackModel.swift | 6 +- MVMCoreUI/Organisms/MoleculeStackView.swift | 8 +-- .../ModelMoleculeDelegateProtocol.swift | 2 +- .../OtherHandlers/MoleculeObjectMapping.swift | 2 +- .../Templates/MoleculeListCellProtocol.h | 22 ------ .../Templates/MoleculeListCellProtocol.swift | 32 +++++++++ .../Templates/MoleculeListTemplate.swift | 8 +-- 50 files changed, 393 insertions(+), 216 deletions(-) create mode 100644 MVMCoreUI/Molecules/HorizontalCombinationViews/TabsModel.swift create mode 100644 MVMCoreUI/Molecules/Items/AccordionListItemModel.swift rename MVMCoreUI/{Models/Molecules => Molecules/Items}/DropDownListItemModel.swift (62%) rename MVMCoreUI/{Models/Molecules/MoleculeStackItemModel.swift => Molecules/Items/StackItemModel.swift} (94%) create mode 100644 MVMCoreUI/Molecules/Items/TabsListItemModel.swift rename MVMCoreUI/{Models/Molecules => Organisms}/MoleculeStackModel.swift (91%) delete mode 100644 MVMCoreUI/Templates/MoleculeListCellProtocol.h create mode 100644 MVMCoreUI/Templates/MoleculeListCellProtocol.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 7769203b..b34f888b 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -108,7 +108,7 @@ D260D7B122D65BDD007E7233 /* MVMCoreUIPageControl.h in Headers */ = {isa = PBXBuildFile; fileRef = D260D7AF22D65BDD007E7233 /* MVMCoreUIPageControl.h */; settings = {ATTRIBUTES = (Public, ); }; }; D260D7B222D65BDD007E7233 /* MVMCoreUIPageControl.m in Sources */ = {isa = PBXBuildFile; fileRef = D260D7B022D65BDD007E7233 /* MVMCoreUIPageControl.m */; }; D260D7B622D68514007E7233 /* MVMCoreUIPagingProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D260D7B522D68509007E7233 /* MVMCoreUIPagingProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; - D268C70C2386DFFD007F2C1C /* MoleculeStackItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB368A23609801006832FA /* MoleculeStackItemModel.swift */; }; + D268C70C2386DFFD007F2C1C /* StackItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB368A23609801006832FA /* StackItemModel.swift */; }; D268C70E238C22D7007F2C1C /* DropDownFilterTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D268C70D238C22D7007F2C1C /* DropDownFilterTableViewCell.swift */; }; D268C712238D6699007F2C1C /* DropDown.swift in Sources */ = {isa = PBXBuildFile; fileRef = D268C711238D6699007F2C1C /* DropDown.swift */; }; D274CA332236A78900B01B62 /* StandardFooterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D274CA322236A78900B01B62 /* StandardFooterView.swift */; }; @@ -120,7 +120,10 @@ D282AACB2243C61700C46919 /* ButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AACA2243C61700C46919 /* ButtonView.swift */; }; D28A837723C79FC600DFE4FC /* MFCustomButton+ActionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A837623C79FC600DFE4FC /* MFCustomButton+ActionModel.swift */; }; D28A837923C7D5BC00DFE4FC /* PageModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A837823C7D5BC00DFE4FC /* PageModelProtocol.swift */; }; - D296E13C229598BF0051EBE7 /* MoleculeListCellProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D296E13B2295969C0051EBE7 /* MoleculeListCellProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; + D28A837B23C928DA00DFE4FC /* MoleculeListCellProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A837A23C928DA00DFE4FC /* MoleculeListCellProtocol.swift */; }; + D28A837D23CCA86A00DFE4FC /* TabsListItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A837C23CCA86A00DFE4FC /* TabsListItemModel.swift */; }; + D28A837F23CCA96400DFE4FC /* TabsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A837E23CCA96400DFE4FC /* TabsModel.swift */; }; + D28A838123CCB0D800DFE4FC /* AccordionListItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A838023CCB0D800DFE4FC /* AccordionListItemModel.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, ); }; }; @@ -314,7 +317,7 @@ 01EB3683236097C0006832FA /* MoleculeProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MoleculeProtocol.swift; sourceTree = ""; }; 01EB368823609801006832FA /* LabelModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LabelModel.swift; sourceTree = ""; }; 01EB368923609801006832FA /* ListItemModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListItemModel.swift; sourceTree = ""; }; - 01EB368A23609801006832FA /* MoleculeStackItemModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MoleculeStackItemModel.swift; sourceTree = ""; }; + 01EB368A23609801006832FA /* StackItemModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StackItemModel.swift; sourceTree = ""; }; 01EB368B23609801006832FA /* MoleculeStackModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MoleculeStackModel.swift; sourceTree = ""; }; 01EB368C23609801006832FA /* HeaderModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HeaderModel.swift; sourceTree = ""; }; 01EB368D23609801006832FA /* HeadlineBodyModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HeadlineBodyModel.swift; sourceTree = ""; }; @@ -376,7 +379,10 @@ D282AACA2243C61700C46919 /* ButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonView.swift; sourceTree = ""; }; D28A837623C79FC600DFE4FC /* MFCustomButton+ActionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MFCustomButton+ActionModel.swift"; sourceTree = ""; }; D28A837823C7D5BC00DFE4FC /* PageModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageModelProtocol.swift; sourceTree = ""; }; - D296E13B2295969C0051EBE7 /* MoleculeListCellProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MoleculeListCellProtocol.h; sourceTree = ""; }; + D28A837A23C928DA00DFE4FC /* MoleculeListCellProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeListCellProtocol.swift; sourceTree = ""; }; + D28A837C23CCA86A00DFE4FC /* TabsListItemModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabsListItemModel.swift; sourceTree = ""; }; + D28A837E23CCA96400DFE4FC /* TabsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabsModel.swift; sourceTree = ""; }; + D28A838023CCB0D800DFE4FC /* AccordionListItemModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccordionListItemModel.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 = ""; }; @@ -613,9 +619,6 @@ isa = PBXGroup; children = ( 011B58F323A2CCC80085F53C /* DropDownModel.swift */, - 011B58F123A2AE2C0085F53C /* DropDownListItemModel.swift */, - 01EB368A23609801006832FA /* MoleculeStackItemModel.swift */, - 01EB368B23609801006832FA /* MoleculeStackModel.swift */, 01EB368C23609801006832FA /* HeaderModel.swift */, 012A88EB238F084D00FE3DA1 /* FooterModel.swift */, 017BEB3F23620A230024EF95 /* TextFieldModel.swift */, @@ -723,6 +726,7 @@ children = ( D2B1E3E422F37D6A0065F95C /* ImageHeadlineBody.swift */, D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */, + D28A837E23CCA96400DFE4FC /* TabsModel.swift */, ); path = HorizontalCombinationViews; sourceTree = ""; @@ -739,6 +743,7 @@ D22479902316A9CB003FCCF9 /* Organisms */ = { isa = PBXGroup; children = ( + 01EB368B23609801006832FA /* MoleculeStackModel.swift */, D2A5145E2211DDC100345BFB /* MoleculeStackView.swift */, D2A6390022CBB1820052ED1F /* Carousel.swift */, ); @@ -752,9 +757,13 @@ 01509D8E2327EC6F00EF99AA /* MoleculeTableViewCell.swift */, 01EB368923609801006832FA /* ListItemModel.swift */, D2A6390422CBCE160052ED1F /* MoleculeCollectionViewCell.swift */, + D28A838023CCB0D800DFE4FC /* AccordionListItemModel.swift */, D224799A231965AD003FCCF9 /* AccordionMoleculeTableViewCell.swift */, + D28A837C23CCA86A00DFE4FC /* TabsListItemModel.swift */, D27CD40D2322EEAF00C1DC07 /* TabsTableViewCell.swift */, + 011B58F123A2AE2C0085F53C /* DropDownListItemModel.swift */, D268C70D238C22D7007F2C1C /* DropDownFilterTableViewCell.swift */, + 01EB368A23609801006832FA /* StackItemModel.swift */, D2FB151C23A40F1500C20E10 /* StackItem.swift */, ); path = Items; @@ -790,7 +799,6 @@ D29DF0CE21E404D4003B2FB9 /* MVMCoreUI */ = { isa = PBXGroup; children = ( - D29DF10D21E67A70003B2FB9 /* Atoms */, 01509D96232803B200EF99AA /* Models */, D2B18B7D236090D500A9AEDC /* BaseClasses */, 01C74D87224298E2009C25A3 /* FormUIHelpers */, @@ -803,6 +811,7 @@ D22D1F582204D2590077CEC0 /* Legacy */, D29DF10F21E67A7D003B2FB9 /* BaseControllers */, D29DF11E21E6851E003B2FB9 /* TopAlert */, + D29DF10D21E67A70003B2FB9 /* Atoms */, D29DF10E21E67A77003B2FB9 /* Molecules */, D22479902316A9CB003FCCF9 /* Organisms */, D29DF0DF21E418B2003B2FB9 /* Templates */, @@ -817,7 +826,7 @@ children = ( D2A5146022121FBF00345BFB /* MoleculeStackTemplate.swift */, D2A514622213643100345BFB /* MoleculeStackCenteredTemplate.swift */, - D296E13B2295969C0051EBE7 /* MoleculeListCellProtocol.h */, + D28A837A23C928DA00DFE4FC /* MoleculeListCellProtocol.swift */, D2E1FAE02268E81D00AEFD8C /* MoleculeListTemplate.swift */, D2D6CD4122E78FAB00D701B8 /* ThreeLayerTemplate.swift */, ); @@ -1231,7 +1240,6 @@ D29DF2A121E7AF4E003B2FB9 /* MVMCoreUIUtility.h in Headers */, D29DF17621E69E1F003B2FB9 /* PrimaryButton.h in Headers */, D29DF2C821E7BFC1003B2FB9 /* MFSizeObject.h in Headers */, - D296E13C229598BF0051EBE7 /* MoleculeListCellProtocol.h in Headers */, D29DF32021ED0CBA003B2FB9 /* LabelView.h in Headers */, D29770C921F7C4AE00B2F0D0 /* TopLabelsView.h in Headers */, D29DF2E121E9240B003B2FB9 /* MVMCoreUIPanelProtocol.h in Headers */, @@ -1325,6 +1333,7 @@ 012CA9E423888B1B003F810F /* (null) in Sources */, 9402C35023A2CEA3004B974C /* LeftRightLabelModel.swift in Sources */, D29DF32121ED0CBA003B2FB9 /* LabelView.m in Sources */, + D28A838123CCB0D800DFE4FC /* AccordionListItemModel.swift in Sources */, DBC4391822442197001AB423 /* CaretView.swift in Sources */, D29770F221F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.m in Sources */, D29B771022C281F400D6ACE0 /* ModuleMolecule.swift in Sources */, @@ -1363,6 +1372,7 @@ D2C5001921F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m in Sources */, D29DF12E21E6851E003B2FB9 /* MVMCoreUITopAlertView.m in Sources */, D29DF2CF21E7C104003B2FB9 /* MFLoadingViewController.m in Sources */, + D28A837B23C928DA00DFE4FC /* MoleculeListCellProtocol.swift in Sources */, 014AA72F23C5059B006F3E93 /* ThreeLayerPageTemplateModel.swift in Sources */, D22D1F572204CE5D0077CEC0 /* MVMCoreUIStackableViewController.m in Sources */, D2A5145F2211DDC100345BFB /* MoleculeStackView.swift in Sources */, @@ -1385,10 +1395,11 @@ 944589232385DA9600DE9FD4 /* ImageViewModel.swift in Sources */, D213347723843825008E41B3 /* Line.swift in Sources */, D28A837723C79FC600DFE4FC /* MFCustomButton+ActionModel.swift in Sources */, + D28A837F23CCA96400DFE4FC /* TabsModel.swift in Sources */, 012A88EC238F084D00FE3DA1 /* FooterModel.swift in Sources */, D2A514672213885800345BFB /* StandardHeaderView.swift in Sources */, 01EB369023609801006832FA /* ListItemModel.swift in Sources */, - D268C70C2386DFFD007F2C1C /* MoleculeStackItemModel.swift in Sources */, + D268C70C2386DFFD007F2C1C /* StackItemModel.swift in Sources */, DBEFFA04225A829700230692 /* Label.swift in Sources */, D2D6CD4022E78C1A00D701B8 /* Scroller.swift in Sources */, 01509D952327ED1900EF99AA /* HeadlineBodyTextButtonSwitch.swift in Sources */, @@ -1459,6 +1470,7 @@ D29770C821F7C4AE00B2F0D0 /* TopLabelsView.m in Sources */, 01EB369323609801006832FA /* HeaderModel.swift in Sources */, D2E1FADF2268B8E700AEFD8C /* ThreeLayerTableViewController.swift in Sources */, + D28A837D23CCA86A00DFE4FC /* TabsListItemModel.swift in Sources */, 012A88C6238DA34000FE3DA1 /* ModuleMoleculeModel.swift in Sources */, 94C2D9A123872BCC0006CF46 /* LabelAttributeUnderlineModel.swift in Sources */, D20A9A5E2243D3E300ADE781 /* TwoButtonView.swift in Sources */, diff --git a/MVMCoreUI/Atoms/Buttons/CaretButton.swift b/MVMCoreUI/Atoms/Buttons/CaretButton.swift index b3ff5409..16b571d1 100644 --- a/MVMCoreUI/Atoms/Buttons/CaretButton.swift +++ b/MVMCoreUI/Atoms/Buttons/CaretButton.swift @@ -132,7 +132,7 @@ open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol, MVMCoreUI } } - public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { guard let caretLinkModel = model as? CaretLinkModel else { return } if let color = caretLinkModel.backgroundColor { backgroundColor = color.uiColor diff --git a/MVMCoreUI/Atoms/TextFields/MFTextField+ModelExtension.swift b/MVMCoreUI/Atoms/TextFields/MFTextField+ModelExtension.swift index 9944e22d..e0c5ce0f 100644 --- a/MVMCoreUI/Atoms/TextFields/MFTextField+ModelExtension.swift +++ b/MVMCoreUI/Atoms/TextFields/MFTextField+ModelExtension.swift @@ -16,7 +16,7 @@ enum TextType: String { } extension MFTextField: ModelMoleculeViewProtocol { // - public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { //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. diff --git a/MVMCoreUI/Atoms/Views/CaretView.swift b/MVMCoreUI/Atoms/Views/CaretView.swift index 4a0b9c36..653bfef0 100644 --- a/MVMCoreUI/Atoms/Views/CaretView.swift +++ b/MVMCoreUI/Atoms/Views/CaretView.swift @@ -103,13 +103,13 @@ open class CaretView: View { defaultState() } - public override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { + public override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { guard let json = json, let model = try? Self.decodeJSONToModel(json: json, type: CaretViewModel.self) else { return } - setWithModel(model, delegateObject, additionalData as? [String : AnyHashable]) + setWithModel(model, delegateObject, additionalData) } //MARK: - MVMCoreMoleculeViewProtocol - override public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + override public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.setWithModel(model, delegateObject, additionalData) guard let caretModel = model as? CaretViewModel else { return diff --git a/MVMCoreUI/Atoms/Views/DashLine.swift b/MVMCoreUI/Atoms/Views/DashLine.swift index 89541b0c..94bd987c 100644 --- a/MVMCoreUI/Atoms/Views/DashLine.swift +++ b/MVMCoreUI/Atoms/Views/DashLine.swift @@ -74,11 +74,11 @@ open class DashLine: View { open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { guard let json = json, let model = try? Self.decodeJSONToModel(json: json, type: DashLineModel.self) else { return } - setWithModel(model, delegateObject, additionalData as? [String : AnyHashable]) + setWithModel(model, delegateObject, additionalData) } //MARK: - MVMCoreMoleculeViewProtocol - public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.setWithModel(model, delegateObject, additionalData) guard let dashLineModel = dashModel else { return diff --git a/MVMCoreUI/Atoms/Views/GraphView.swift b/MVMCoreUI/Atoms/Views/GraphView.swift index ca63c67f..40c353b2 100644 --- a/MVMCoreUI/Atoms/Views/GraphView.swift +++ b/MVMCoreUI/Atoms/Views/GraphView.swift @@ -126,11 +126,11 @@ public struct GraphObject { widthAnchor.constraint(equalTo: heightAnchor).isActive = true } - override open func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + override open func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.setWithModel(model, delegateObject, additionalData) } - override open func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { + override open func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) let object = GraphObject(json) graphObject = object diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index b4b4e36a..28f0078f 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -218,7 +218,7 @@ public typealias ActionBlock = () -> () case left } - public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { clauses = [] guard let labelModel = model as? LabelModel else { return } attributedText = nil diff --git a/MVMCoreUI/Atoms/Views/LeftRightLabelView.swift b/MVMCoreUI/Atoms/Views/LeftRightLabelView.swift index 979d2abb..5e128e26 100644 --- a/MVMCoreUI/Atoms/Views/LeftRightLabelView.swift +++ b/MVMCoreUI/Atoms/Views/LeftRightLabelView.swift @@ -179,7 +179,7 @@ import Foundation //MARK: - MVMCoreMoleculeViewProtocol - open override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + open override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.setWithModel(model, delegateObject, additionalData) guard let leftRightLabelModel = model as? LeftRightLabelModel else { return diff --git a/MVMCoreUI/Atoms/Views/Line.swift b/MVMCoreUI/Atoms/Views/Line.swift index 7b80d59a..d7cbc5e8 100644 --- a/MVMCoreUI/Atoms/Views/Line.swift +++ b/MVMCoreUI/Atoms/Views/Line.swift @@ -67,7 +67,7 @@ import UIKit super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) } - open override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + open override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { if let lineModel = model as? LineModel { setStyle(lineModel.type ?? .standard) } diff --git a/MVMCoreUI/Atoms/Views/MFLoadImageView.swift b/MVMCoreUI/Atoms/Views/MFLoadImageView.swift index 17515e71..7be1187a 100644 --- a/MVMCoreUI/Atoms/Views/MFLoadImageView.swift +++ b/MVMCoreUI/Atoms/Views/MFLoadImageView.swift @@ -209,7 +209,7 @@ import UIKit } } - public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { guard let imageModel = model as? ImageViewModel else { return } diff --git a/MVMCoreUI/Atoms/Views/MFView+ModelExtension.swift b/MVMCoreUI/Atoms/Views/MFView+ModelExtension.swift index df6b09a5..2ba216d7 100644 --- a/MVMCoreUI/Atoms/Views/MFView+ModelExtension.swift +++ b/MVMCoreUI/Atoms/Views/MFView+ModelExtension.swift @@ -9,7 +9,7 @@ import Foundation extension MFView { - public func setUpDefaultWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String: AnyHashable]?) { + public func setUpDefaultWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { self.model = model if let backgroundColor = model?.backgroundColor { self.backgroundColor = backgroundColor.uiColor @@ -18,7 +18,7 @@ extension MFView { } extension ModelMoleculeViewProtocol where Self: MFView { - func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String: AnyHashable]?) { + func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { setUpDefaultWithModel(model, delegateObject, additionalData) } } diff --git a/MVMCoreUI/Atoms/Views/MultiProgress.swift b/MVMCoreUI/Atoms/Views/MultiProgress.swift index 29fbf465..e5978c9c 100644 --- a/MVMCoreUI/Atoms/Views/MultiProgress.swift +++ b/MVMCoreUI/Atoms/Views/MultiProgress.swift @@ -64,7 +64,7 @@ import UIKit } //MARK: - MVMCoreMoleculeViewProtocol - public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.setWithModel(model, delegateObject, additionalData) guard let multiProgressModel = multiProgressModel else { return @@ -83,6 +83,6 @@ import UIKit public override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { guard let json = json, let model = try? Self.decodeJSONToModel(json: json, type: MultiProgressBarModel.self) else { return } - setWithModel(model, delegateObject, additionalData as? [String : AnyHashable]) + setWithModel(model, delegateObject, additionalData) } } diff --git a/MVMCoreUI/Atoms/Views/ProgressBar.swift b/MVMCoreUI/Atoms/Views/ProgressBar.swift index dff5bfc4..bbf5a5de 100644 --- a/MVMCoreUI/Atoms/Views/ProgressBar.swift +++ b/MVMCoreUI/Atoms/Views/ProgressBar.swift @@ -51,7 +51,7 @@ import Foundation } //MARK: - MVMCoreMoleculeViewProtocol - public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String: AnyHashable]?) { + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { guard let progressBarModel = model as? ProgressBarModel else { return } @@ -64,9 +64,9 @@ import Foundation } // MARK: - MVMCoreUIMoleculeViewProtocol - public func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { + public func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { guard let json = json, let model = try? Self.decodeJSONToModel(json: json, type: ProgressBarModel.self) else { return } - setWithModel(model, delegateObject, additionalData as? [String : AnyHashable]) + setWithModel(model, delegateObject, additionalData) } public func reset() { diff --git a/MVMCoreUI/BaseClasses/Control.swift b/MVMCoreUI/BaseClasses/Control.swift index 769e7acb..915e0891 100644 --- a/MVMCoreUI/BaseClasses/Control.swift +++ b/MVMCoreUI/BaseClasses/Control.swift @@ -49,7 +49,7 @@ import UIKit } } - public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { self.model = model if let backgroundColor = model?.backgroundColor { self.backgroundColor = backgroundColor.uiColor diff --git a/MVMCoreUI/BaseClasses/View.swift b/MVMCoreUI/BaseClasses/View.swift index 0cb1088d..45631d93 100644 --- a/MVMCoreUI/BaseClasses/View.swift +++ b/MVMCoreUI/BaseClasses/View.swift @@ -40,7 +40,7 @@ import UIKit return model?.moleculeName } - open func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + open func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { self.model = model if let backgroundColor = model?.backgroundColor { self.backgroundColor = backgroundColor.uiColor diff --git a/MVMCoreUI/BaseControllers/MFViewController+Model.swift b/MVMCoreUI/BaseControllers/MFViewController+Model.swift index b3ff4ec6..88f05360 100644 --- a/MVMCoreUI/BaseControllers/MFViewController+Model.swift +++ b/MVMCoreUI/BaseControllers/MFViewController+Model.swift @@ -16,10 +16,10 @@ extension MFViewController: MoleculeDelegateProtocol { return loadObject?.modulesJSON?.optionalDictionaryForKey(name) } - public func getModuleWithName(_ moduleName: String) -> Model? { + public func getModuleWithName(_ moduleName: String) -> MoleculeProtocol? { guard let moduleJSON = loadObject?.modulesJSON?.optionalDictionaryForKey(moduleName), let moleculeName = moduleJSON.optionalStringForKey("moleculeName"), - let modelType = ModelRegistry.getType(for: moleculeName) else { + let modelType = ModelRegistry.getType(for: moleculeName) as? MoleculeProtocol.Type else { return nil } do { diff --git a/MVMCoreUI/Containers/Container.swift b/MVMCoreUI/Containers/Container.swift index f1998aac..ab495b81 100644 --- a/MVMCoreUI/Containers/Container.swift +++ b/MVMCoreUI/Containers/Container.swift @@ -172,11 +172,11 @@ public class ContainerHelper: NSObject { MFStyler.setMarginsFor(view, size: size, defaultHorizontal: model?.useHorizontalMargins ?? false, top: (model?.useVerticalMargins ?? false) ? (model?.topMarginPadding ?? 0) : 0, bottom: (model?.useVerticalMargins ?? false) ? (model?.bottomMarginPadding ?? 0) : 0) } - func set(with model: ContainerModelProtocol) { - if let horizontalAlignment = model.horizontalAlignment { + func set(with model: ContainerModelProtocol, for contained: MVMCoreUIViewConstrainingProtocol?) { + if let horizontalAlignment = model.horizontalAlignment ?? contained?.horizontalAlignment?() { alignHorizontal(horizontalAlignment) } - if let verticalAlignment = model.verticalAlignment { + if let verticalAlignment = model.verticalAlignment ?? contained?.verticalAlignment?() { alignVertical(verticalAlignment) } } @@ -203,10 +203,10 @@ open class Container: View { get { return model as? ContainerModelProtocol } } - override open func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + override open func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.setWithModel(model, delegateObject, additionalData) guard let containerModel = model as? ContainerModelProtocol else { return } - containerHelper.set(with: containerModel) + containerHelper.set(with: containerModel, for: view as? MVMCoreUIViewConstrainingProtocol) } } diff --git a/MVMCoreUI/MVMCoreUI.h b/MVMCoreUI/MVMCoreUI.h index ff9b4087..a71be907 100644 --- a/MVMCoreUI/MVMCoreUI.h +++ b/MVMCoreUI/MVMCoreUI.h @@ -20,7 +20,6 @@ FOUNDATION_EXPORT const unsigned char MVMCoreUIVersionString[]; #import #import #import -#import #import #pragma mark - TopAlert diff --git a/MVMCoreUI/Models/Extensions/ModelHelper.swift b/MVMCoreUI/Models/Extensions/ModelHelper.swift index 7c73f264..72bb5f8f 100644 --- a/MVMCoreUI/Models/Extensions/ModelHelper.swift +++ b/MVMCoreUI/Models/Extensions/ModelHelper.swift @@ -35,4 +35,17 @@ extension KeyedDecodingContainer where Key : CodingKey { public func decodeMoleculesIfPresent(codingKey: KeyedDecodingContainer.Key) throws -> [MoleculeProtocol]? { return try decodeModelsIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName) as? [MoleculeProtocol] } + + /// Decodes an array with arrays of molecules based on the identifiers, optional. + public func decodeMolecules2DIfPresent(codingKey: KeyedDecodingContainer.Key) throws -> [[MoleculeProtocol]]? { + return try decodeModels2DIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName) as? [[MoleculeProtocol]] + } + + /// Decodes an array with arrays of models based on the identifiers. + public func decodeMolecules2D(codingKey: KeyedDecodingContainer.Key) throws -> [[MoleculeProtocol]] { + guard let models = try decodeModels2D(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName) as? [[MoleculeProtocol]] else { + throw ModelRegistry.Error.decoderError + } + return models + } } diff --git a/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift b/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift index a77f9374..7a990d61 100644 --- a/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift +++ b/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift @@ -9,6 +9,27 @@ import Foundation public protocol ListItemModelProtocol: ContainerModelProtocol, MoleculeProtocol { - var molecule: MoleculeProtocol { get } var line: LineModel? { get set } + var action: ActionProtocol? { get set } + var hideArrow: Bool? { get set } + var style: String? { get set } +} + +// Not a strict requirement. +extension ListItemModelProtocol { + public var action: ActionProtocol? { + get { + return nil + } + set { + } + } + + public var style: String? { + get { + return nil + } + set { + } + } } diff --git a/MVMCoreUI/Models/ModelProtocols/TemplateProtocol.swift b/MVMCoreUI/Models/ModelProtocols/TemplateProtocol.swift index 8293f18b..eb4463d5 100644 --- a/MVMCoreUI/Models/ModelProtocols/TemplateProtocol.swift +++ b/MVMCoreUI/Models/ModelProtocols/TemplateProtocol.swift @@ -15,7 +15,7 @@ public protocol TemplateProtocol: class { public extension TemplateProtocol where Self: MFViewController { func parseTemplateJSON() { - guard let pageJSON = self.loadObject?.pageJSON as? [String: AnyHashable] else { return } + guard let pageJSON = self.loadObject?.pageJSON else { return } do { let data = try JSONSerialization.data(withJSONObject: pageJSON) let decoder = JSONDecoder() diff --git a/MVMCoreUI/Models/Template/ListPageTemplateModel.swift b/MVMCoreUI/Models/Template/ListPageTemplateModel.swift index c457969a..dd8d3979 100644 --- a/MVMCoreUI/Models/Template/ListPageTemplateModel.swift +++ b/MVMCoreUI/Models/Template/ListPageTemplateModel.swift @@ -19,6 +19,7 @@ import Foundation public var header: HeaderModel? public var molecules: [ListItemModelProtocol] public var footer: MoleculeStackModel? + public var line: LineModel? public init(pageType: String, screenHeading: String, molecules: [ListItemModelProtocol]) { self.pageType = pageType @@ -26,39 +27,41 @@ import Foundation self.molecules = molecules } - enum CodingKeys: String, CodingKey { - case moleculeName - case pageType - case screenHeading - case molecules - case header - case footer - case isAtomicTabs - } + enum CodingKeys: String, CodingKey { + case moleculeName + case pageType + case screenHeading + case molecules + case header + case footer + case line + case isAtomicTabs + } - required public init(from decoder: Decoder) throws { - let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - self.pageType = try typeContainer.decode(String.self, forKey: .pageType) - self.screenHeading = try typeContainer.decode(String.self, forKey: .screenHeading) + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + pageType = try typeContainer.decode(String.self, forKey: .pageType) + screenHeading = try typeContainer.decodeIfPresent(String.self, forKey: .screenHeading) + + guard let molecules = try typeContainer.decodeMolecules(codingKey: .molecules) as? [ListItemModelProtocol] else { + throw JSONError.pathNotFound + } + self.molecules = molecules + isAtomicTabs = try typeContainer.decodeIfPresent(Bool.self, forKey: .isAtomicTabs) + header = try typeContainer.decodeIfPresent(HeaderModel.self, forKey: .header) + footer = try typeContainer.decodeIfPresent(MoleculeStackModel.self, forKey: .footer) + line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line) + } - guard let molecules = try typeContainer.decodeMolecules(codingKey: .molecules) as? [ListItemModelProtocol] else { - throw JSONError.pathNotFound - } - self.molecules = molecules - self.isAtomicTabs = try typeContainer.decodeIfPresent(Bool.self, forKey: .isAtomicTabs) - self.header = try typeContainer.decodeIfPresent(HeaderModel.self, forKey: .header) - self.footer = try typeContainer.decodeIfPresent(MoleculeStackModel.self, forKey: .footer) - } - - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(pageType, forKey: .pageType) - try container.encode(screenHeading, forKey: .screenHeading) - - try container.encodeModels(molecules, forKey: .molecules) - try container.encodeIfPresent(isAtomicTabs, forKey: .isAtomicTabs) - try container.encodeIfPresent(header, forKey: .header) - try container.encodeIfPresent(footer, forKey: .footer) - } + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(pageType, forKey: .pageType) + try container.encodeIfPresent(screenHeading, forKey: .screenHeading) + try container.encodeModels(molecules, forKey: .molecules) + try container.encodeIfPresent(isAtomicTabs, forKey: .isAtomicTabs) + try container.encodeIfPresent(header, forKey: .header) + try container.encodeIfPresent(footer, forKey: .footer) + try container.encode(line, forKey: .line) + } } diff --git a/MVMCoreUI/Molecules/HorizontalCombinationViews/TabsModel.swift b/MVMCoreUI/Molecules/HorizontalCombinationViews/TabsModel.swift new file mode 100644 index 00000000..0e358871 --- /dev/null +++ b/MVMCoreUI/Molecules/HorizontalCombinationViews/TabsModel.swift @@ -0,0 +1,50 @@ +// +// TabsModel.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 1/13/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import UIKit + +public class TabsModel: MoleculeProtocol { + public static var identifier: String = "tabs" + public var backgroundColor: Color? + public var tabs: [LabelModel] + public var selectedColor = Color(uiColor: .mfTomatoRed()) + + // Must be capped to 0...(tabs.count - 1) + public var selectedIndex: Int = 0 + + enum TabsCodingKeys: String, CodingKey { + case tabs + case backgroundColor + case selectedColor + case selectedIndex + } + + public init(with tabs: [LabelModel]) { + self.tabs = tabs + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: TabsCodingKeys.self) + tabs = try typeContainer.decode([LabelModel].self, forKey: .tabs) + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) + if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .selectedColor) { + selectedColor = color + } + if let index = try typeContainer.decodeIfPresent(Int.self, forKey: .selectedIndex) { + selectedIndex = index + } + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: TabsCodingKeys.self) + try container.encode(tabs, forKey: .tabs) + try container.encode(backgroundColor, forKey: .backgroundColor) + try container.encode(selectedColor, forKey: .selectedColor) + try container.encode(selectedIndex, forKey: .selectedIndex) + } +} diff --git a/MVMCoreUI/Molecules/Items/AccordionListItemModel.swift b/MVMCoreUI/Molecules/Items/AccordionListItemModel.swift new file mode 100644 index 00000000..d5519288 --- /dev/null +++ b/MVMCoreUI/Molecules/Items/AccordionListItemModel.swift @@ -0,0 +1,46 @@ +// +// AccordionListItemModel.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 1/13/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import UIKit + +class AccordionListItemModel: MoleculeContainerModel, ListItemModelProtocol { + public static var identifier: String = "accordionListItem" + public var molecules: [ListItemModelProtocol] + public var backgroundColor: Color? + public var hideLineWhenExpanded: Bool = false + public var hideArrow: Bool? = true + public var line: LineModel? + + enum AccordionListItemCodingKeys: String, CodingKey { + case molecules + case backgroundColor + case hideLineWhenExpanded + case hideArrow + case line + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: AccordionListItemCodingKeys.self) + molecules = try typeContainer.decodeMolecules(codingKey: .molecules) as! [ListItemModelProtocol] + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) + line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line) + if let hideLine = try typeContainer.decodeIfPresent(Bool.self, forKey: .hideLineWhenExpanded) { + hideLineWhenExpanded = hideLine + } + try super.init(from: decoder) + } + + public override func encode(to encoder: Encoder) throws { + try super.encode(to: encoder) + var container = encoder.container(keyedBy: AccordionListItemCodingKeys.self) + try container.encodeModels(molecules, forKey: .molecules) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encodeIfPresent(hideLineWhenExpanded, forKey: .hideLineWhenExpanded) + try container.encodeIfPresent(line, forKey: .line) + } +} diff --git a/MVMCoreUI/Molecules/Items/AccordionMoleculeTableViewCell.swift b/MVMCoreUI/Molecules/Items/AccordionMoleculeTableViewCell.swift index d6a5e05d..db4e322e 100644 --- a/MVMCoreUI/Molecules/Items/AccordionMoleculeTableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/AccordionMoleculeTableViewCell.swift @@ -9,6 +9,7 @@ import UIKit @objcMembers public class AccordionMoleculeTableViewCell: MoleculeTableViewCell { + var accordionListItemModel: AccordionListItemModel? let accordionButton = createAccordionButton() static func createAccordionButton() -> MFCustomButton { @@ -26,10 +27,10 @@ import UIKit accessoryView = accordionButton } - public override func didSelectCell(atIndex indexPath: IndexPath, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { + override public func didSelectCell(at index: IndexPath, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { accordionButton.isSelected = !accordionButton.isSelected accordionButton.setTitle(accordionButton.isSelected ? "-" : "+", for: .normal) - guard let molecules = json?.optionalArrayForKey(KeyMolecules) as? [[AnyHashable: Any]] else { + guard let molecules = accordionListItemModel?.molecules else { return } @@ -39,7 +40,7 @@ import UIKit delegateObject?.moleculeDelegate?.removeMolecules(molecules, sender: self, animation: .automatic) } - if (json?.boolForKey("hideSeparatorWhenExpanded") ?? false) && (self.bottomSeparatorView?.shouldBeVisible() ?? false) { + if (accordionListItemModel?.hideLineWhenExpanded ?? false) && (self.bottomSeparatorView?.shouldBeVisible() ?? false) { bottomSeparatorView?.isHidden = accordionButton.isSelected } } diff --git a/MVMCoreUI/Molecules/Items/DropDownFilterTableViewCell.swift b/MVMCoreUI/Molecules/Items/DropDownFilterTableViewCell.swift index a2ca4383..4df2e7e2 100644 --- a/MVMCoreUI/Molecules/Items/DropDownFilterTableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/DropDownFilterTableViewCell.swift @@ -9,6 +9,7 @@ import UIKit @objcMembers public class DropDownFilterTableViewCell: TableViewCell { + var dropDownListItemModel: DropDownListItemModel? let dropDown = DropDown(forDropDownWithBothDelegates: nil) var delegateObject: MVMCoreUIDelegateObject? var previousIndex = NSNotFound @@ -20,7 +21,6 @@ import UIKit guard let dropDown = dropDown, dropDown.superview == nil else { return } - bottomMarginPadding = 0 dropDown.translatesAutoresizingMaskIntoConstraints = false contentView.addSubview(dropDown) @@ -35,14 +35,12 @@ import UIKit guard change.newValue != change.oldValue, let self = self, let options = self.dropDown?.json?.optionalArrayForKey("options") as? [NSString], let index = options.firstIndex(of: change.newValue!! as NSString), - let moleculesArrays = self.json?.arrayForKey(KeyMolecules) as? [[[AnyHashable: Any]]] else { return } + let molecules = self.dropDownListItemModel?.molecules else { return } if self.previousIndex != NSNotFound { - let previousMolecules = moleculesArrays[self.previousIndex] - self.delegateObject?.moleculeDelegate?.removeMolecules(previousMolecules, sender: self, animation: .fade) + self.delegateObject?.moleculeDelegate?.removeMolecules(molecules[self.previousIndex], sender: self, animation: .fade) } - let molecules = moleculesArrays[index] - self.delegateObject?.moleculeDelegate?.addMolecules(molecules, sender: self, animation: .fade) + self.delegateObject?.moleculeDelegate?.addMolecules(molecules[index], sender: self, animation: .fade) self.previousIndex = index } } @@ -52,19 +50,18 @@ import UIKit dropDown?.updateView(size) } - public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { - bottomSeparatorView?.setStyle(.none) + public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + dropDownListItemModel = model as? DropDownListItemModel self.delegateObject = delegateObject super.setWithModel(model, delegateObject, additionalData) dropDown?.mfTextFieldDelegate = delegateObject?.uiTextFieldDelegate as? MFTextFieldDelegate dropDown?.uiTextFieldDelegate = delegateObject?.uiTextFieldDelegate - dropDown?.setWithJSON(json?.optionalDictionaryForKey("dropDown"), delegateObject: delegateObject, additionalData: additionalData) + dropDown?.setWithModel(dropDownListItemModel, delegateObject, additionalData) } public override func reset() { super.reset() - bottomMarginPadding = 0 bottomSeparatorView?.setStyle(.none) } } diff --git a/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift b/MVMCoreUI/Molecules/Items/DropDownListItemModel.swift similarity index 62% rename from MVMCoreUI/Models/Molecules/DropDownListItemModel.swift rename to MVMCoreUI/Molecules/Items/DropDownListItemModel.swift index 1ef1ca1f..64e8c69b 100644 --- a/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift +++ b/MVMCoreUI/Molecules/Items/DropDownListItemModel.swift @@ -10,12 +10,13 @@ import Foundation @objcMembers public class DropDownListItemModel: MoleculeContainerModel, ListItemModelProtocol { public static var identifier: String = "dropDownListItem" - public var molecules: [[ListItemModel]] - public var backgroundColor: Color? - public var line: LineModel? + public var molecules: [[ListItemModelProtocol]] public var dropDown: DropDownModel + public var backgroundColor: Color? + public var line: LineModel? = LineModel(type: .none) + public var hideArrow: Bool? = true - public init(molecule: MoleculeProtocol, molecules: [[ListItemModel]], dropDown: DropDownModel) { + public init(molecule: MoleculeProtocol, molecules: [[ListItemModelProtocol]], dropDown: DropDownModel) { self.molecules = molecules self.dropDown = dropDown super.init(with: molecule) @@ -23,25 +24,28 @@ import Foundation enum DropDownCodingKeys: String, CodingKey { case molecules + case dropDown case line case backgroundColor - case dropDown } required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: DropDownCodingKeys.self) - self.molecules = try typeContainer.decode([[ListItemModel]].self, forKey: .molecules) - self.line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line) - self.backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) - self.dropDown = try typeContainer.decode(DropDownModel.self, forKey: .dropDown) + molecules = try typeContainer.decodeMolecules2D(codingKey: .molecules) as! [[ListItemModelProtocol]] + dropDown = try typeContainer.decode(DropDownModel.self, forKey: .dropDown) + if let lineModel = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line) { + line = lineModel + } + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) try super.init(from: decoder) } public override func encode(to encoder: Encoder) throws { try super.encode(to: encoder) var container = encoder.container(keyedBy: DropDownCodingKeys.self) - try container.encode(molecules, forKey: .molecules) - try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encodeModels2D(molecules, forKey: .molecules) try container.encode(dropDown, forKey: .dropDown) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encodeIfPresent(line, forKey: .line) } } diff --git a/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift b/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift index 1603c876..b396dde6 100644 --- a/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift +++ b/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift @@ -8,7 +8,7 @@ import UIKit -open class MoleculeCollectionViewCell: UICollectionViewCell, MVMCoreUIMoleculeViewProtocol, MoleculeListCellProtocol, ModelMoleculeViewProtocol { +open class MoleculeCollectionViewCell: UICollectionViewCell, MVMCoreUIMoleculeViewProtocol, ModelMoleculeViewProtocol { open var molecule: (UIView & MVMCoreUIMoleculeViewProtocol)? open var json: [AnyHashable: Any]? @@ -68,7 +68,7 @@ open class MoleculeCollectionViewCell: UICollectionViewCell, MVMCoreUIMoleculeVi } - public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { guard let collectionModel = model as? CarouselItemModel else { return } diff --git a/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift b/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift index 40222f03..1fee9e20 100644 --- a/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift @@ -11,11 +11,11 @@ import UIKit @objcMembers open class MoleculeTableViewCell: TableViewCell { // MARK: - MVMCoreUIMoleculeViewProtocol - public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.setWithModel(model, delegateObject, additionalData) guard let model = model, - let moleculeModel = (model as? ListItemModelProtocol)?.molecule, + let moleculeModel = (model as? ListItemModel)?.molecule, let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(moleculeModel, delegateObject, true) else { return } @@ -23,7 +23,7 @@ import UIKit } public override class func name(forReuse molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> String? { - guard let moleculeModel = (molecule as? ListItemModelProtocol)?.molecule else { + guard let moleculeModel = (molecule as? ListItemModel)?.molecule else { return "\(self)<>" } let className = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moleculeModel) as? ModelMoleculeViewProtocol diff --git a/MVMCoreUI/Molecules/Items/StackItem.swift b/MVMCoreUI/Molecules/Items/StackItem.swift index e121a1ee..59c30962 100644 --- a/MVMCoreUI/Molecules/Items/StackItem.swift +++ b/MVMCoreUI/Molecules/Items/StackItem.swift @@ -9,7 +9,7 @@ import UIKit open class StackItem: MoleculeContainer { - var stackItemModel: MoleculeStackItemModel? { - get { return model as? MoleculeStackItemModel } + var stackItemModel: StackItemModel? { + get { return model as? StackItemModel } } } diff --git a/MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift b/MVMCoreUI/Molecules/Items/StackItemModel.swift similarity index 94% rename from MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift rename to MVMCoreUI/Molecules/Items/StackItemModel.swift index 106ea6e5..a5128f1b 100644 --- a/MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift +++ b/MVMCoreUI/Molecules/Items/StackItemModel.swift @@ -8,7 +8,7 @@ import Foundation -@objcMembers public class MoleculeStackItemModel: MoleculeContainerModel, MoleculeProtocol { +@objcMembers public class StackItemModel: MoleculeContainerModel, MoleculeProtocol { public static var identifier: String = "stackItem" public var backgroundColor: Color? public var spacing: CGFloat? diff --git a/MVMCoreUI/Molecules/Items/TableViewCell.swift b/MVMCoreUI/Molecules/Items/TableViewCell.swift index ee6e79dd..3cf51ab6 100644 --- a/MVMCoreUI/Molecules/Items/TableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/TableViewCell.swift @@ -11,12 +11,8 @@ import UIKit @objcMembers open class TableViewCell: UITableViewCell, MVMCoreUIMoleculeViewProtocol, MoleculeListCellProtocol, ModelMoleculeViewProtocol { open var molecule: (UIView & MVMCoreUIMoleculeViewProtocol)? - open var json: [AnyHashable: Any]? - open var listItemModel: ListItemModel? + open var listItemModel: ListItemModelProtocol? public let containerHelper = ContainerHelper() - - // In updateView, will set padding to default. - open var updateViewHorizontalDefaults = true // For the accessory view convenience. private var caretView: CaretView? @@ -26,19 +22,10 @@ import UIKit // For separation between cells. public var topSeparatorView: Line? public var bottomSeparatorView: Line? - public enum SeparatorFrequency: String { - case all - case allExceptTop - case allExceptBottom - case between - } /// For subclasses that want to use a custom accessory view. open var customAccessoryView = false - open var topMarginPadding: CGFloat = 24 - open var bottomMarginPadding: CGFloat = 24 - private var heroAccessoryCenter: CGPoint? // MARK: - Styling @@ -62,36 +49,36 @@ import UIKit } open func styleStandard() { - topMarginPadding = 24 - bottomMarginPadding = 24 + listItemModel?.topMarginPadding = 24 + listItemModel?.bottomMarginPadding = 24 topSeparatorView?.setStyle(.none) bottomSeparatorView?.setStyle(.standard) } open func styleTallDivider() { - topMarginPadding = 48 - bottomMarginPadding = 16 + listItemModel?.topMarginPadding = 48 + listItemModel?.bottomMarginPadding = 16 topSeparatorView?.setStyle(.none) bottomSeparatorView?.setStyle(.thin) } open func styleShortDivider() { - topMarginPadding = 32 - bottomMarginPadding = 16 + listItemModel?.topMarginPadding = 32 + listItemModel?.bottomMarginPadding = 16 topSeparatorView?.setStyle(.none) bottomSeparatorView?.setStyle(.thin) } open func styleFooter() { - topMarginPadding = 24 - bottomMarginPadding = 0 + listItemModel?.topMarginPadding = 24 + listItemModel?.bottomMarginPadding = 0 topSeparatorView?.setStyle(.none) bottomSeparatorView?.setStyle(.none) } open func styleNone() { - topMarginPadding = 0 - bottomMarginPadding = 0 + listItemModel?.topMarginPadding = 0 + listItemModel?.bottomMarginPadding = 0 topSeparatorView?.setStyle(.none) bottomSeparatorView?.setStyle(.none) } @@ -125,7 +112,7 @@ import UIKit // MARK: - MFViewProtocol public func updateView(_ size: CGFloat) { - MFStyler.setMarginsFor(self, size: size, defaultHorizontal: updateViewHorizontalDefaults, top: topMarginPadding, bottom: bottomMarginPadding) + containerHelper.updateViewMargins(self, model: listItemModel, size: size) if accessoryView != nil { // Smaller left margin if accessory view. @@ -155,23 +142,14 @@ import UIKit } //TODO: Model, Change to model - public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { - guard let model = model as? ListItemModel else { + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + guard let model = model as? ListItemModelProtocol else { return } self.listItemModel = model style(with: model.style) - if let useHorizontalMargins = model.useHorizontalMargins { - updateViewHorizontalDefaults = useHorizontalMargins - } - - if (model.useVerticalMargins ?? true) == false { - topMarginPadding = 0 - bottomMarginPadding = 0 - } - if let backgroundColor = model.backgroundColor { self.backgroundColor = backgroundColor.uiColor } @@ -192,12 +170,11 @@ import UIKit } guard let molecule = molecule else { return } - containerHelper.set(with: json, for: molecule) + containerHelper.set(with: model, for: molecule as? MVMCoreUIViewConstrainingProtocol) } public func reset() { molecule?.reset?() - updateViewHorizontalDefaults = true styleStandard() backgroundColor = .white } @@ -254,23 +231,19 @@ import UIKit // MARK: - MoleculeListCellProtocol /// For when the separator between cells shows using json and frequency. Default is type: standard, frequency: allExceptTop. - //TODO: Change to model - public func setSeparatorWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?, indexPath: IndexPath) { + public func setLines(with model: LineModel?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?, indexPath: IndexPath) { addSeparatorsIfNeeded() - if let json = json { - topSeparatorView?.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - bottomSeparatorView?.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - if let separatorFrequencyString = json.optionalStringForKey("frequency"), let separatorFrequency = SeparatorFrequency(rawValue: separatorFrequencyString) { - setSeparatorFrequency(separatorFrequency, indexPath: indexPath) - } + if let model = model { + topSeparatorView?.setWithModel(model, delegateObject, additionalData) + bottomSeparatorView?.setWithModel(model, delegateObject, additionalData) } else { topSeparatorView?.setStyle(.standard) bottomSeparatorView?.setStyle(.standard) - setSeparatorFrequency(TableViewCell.SeparatorFrequency.allExceptTop, indexPath: indexPath) } + setSeparatorFrequency(model?.frequency ?? .allExceptTop, indexPath: indexPath) } - public func didSelectCell(atIndex indexPath: IndexPath, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + public func didSelectCell(at index: IndexPath, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { //TODO: Use object when handleAction is rewrote to handle action model if let actionMap = self.listItemModel?.action?.toJSON() { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) @@ -304,7 +277,7 @@ import UIKit } /// For when the separator between cells shows. - public func setSeparatorFrequency(_ separatorFrequency: SeparatorFrequency, indexPath: IndexPath) { + public func setSeparatorFrequency(_ separatorFrequency: LineModel.Frequency, indexPath: IndexPath) { switch separatorFrequency { case .all: if indexPath.row == 0 { diff --git a/MVMCoreUI/Molecules/Items/TabsListItemModel.swift b/MVMCoreUI/Molecules/Items/TabsListItemModel.swift new file mode 100644 index 00000000..d27b9097 --- /dev/null +++ b/MVMCoreUI/Molecules/Items/TabsListItemModel.swift @@ -0,0 +1,54 @@ +// +// TabsListItemModel.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 1/13/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import UIKit + +public class TabsListItemModel: ContainerModel, ListItemModelProtocol { + public static var identifier: String = "tabsListItem" + var tabs: TabsModel + var molecules: [[ListItemModelProtocol]] + + public var backgroundColor: Color? + public var hideArrow: Bool? = true + public var line: LineModel? = LineModel(type: .standard) + + enum TabsListItemCodingKeys: String, CodingKey { + case tabs + case molecules + case backgroundColor + case line + } + + public init(with tabs: TabsModel, molecules: [[ListItemModelProtocol]]) { + self.tabs = tabs + self.molecules = molecules + super.init() + self.topMarginPadding = 8 + self.bottomMarginPadding = 0 + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: TabsListItemCodingKeys.self) + tabs = try typeContainer.decode(TabsModel.self, forKey: .tabs) + molecules = try typeContainer.decodeMolecules2D(codingKey: .molecules) as! [[ListItemModelProtocol]] + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) + if let lineModel = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line) { + line = lineModel + } + try super.init(from: decoder) + } + + public override func encode(to encoder: Encoder) throws { + try super.encode(to: encoder) + var container = encoder.container(keyedBy: TabsListItemCodingKeys.self) + try container.encode(tabs, forKey: .tabs) + try container.encodeModels2D(molecules, forKey: .molecules) + try container.encode(backgroundColor, forKey: .backgroundColor) + try container.encodeIfPresent(line, forKey: .line) + } +} diff --git a/MVMCoreUI/Molecules/Items/TabsTableViewCell.swift b/MVMCoreUI/Molecules/Items/TabsTableViewCell.swift index d9626ae0..99d2d9ab 100644 --- a/MVMCoreUI/Molecules/Items/TabsTableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/TabsTableViewCell.swift @@ -9,6 +9,7 @@ import UIKit @objcMembers public class TabsTableViewCell: TableViewCell { + var tabsListItemModel: TabsListItemModel? let tabs = TopTabbar(frame: .zero) var delegateObject: MVMCoreUIDelegateObject? var previousTabIndex = 0 @@ -20,8 +21,6 @@ import UIKit return } tabs.paddingBeforeFirstTab = false - topMarginPadding = 8 - bottomMarginPadding = 0 tabs.translatesAutoresizingMaskIntoConstraints = false tabs.delegate = self @@ -39,7 +38,7 @@ import UIKit // MARK: - MoleculeDelegateProtocol - public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.setWithModel(model, delegateObject, additionalData) self.delegateObject = delegateObject tabs.reloadData() @@ -47,17 +46,13 @@ import UIKit public override func reset() { super.reset() - topMarginPadding = 8 - bottomMarginPadding = 0 + tabs.reset() } } -//TODO: Models changes - extension TabsTableViewCell: TopTabbarDelegate { public func shouldSelectItem(at index: Int, topTabbar: TopTabbar) -> Bool { - if let moleculesArrays = json?.arrayForKey(KeyMolecules), - let molecules = moleculesArrays[topTabbar.selectedIndex] as? [[AnyHashable: Any]] { + if let molecules = tabsListItemModel?.molecules[topTabbar.selectedIndex] { delegateObject?.moleculeDelegate?.removeMolecules(molecules, sender: self, animation: index < tabs.selectedIndex ? .right : .left) } previousTabIndex = tabs.selectedIndex @@ -65,8 +60,7 @@ extension TabsTableViewCell: TopTabbarDelegate { } public func topTabbar(_ topTabbar: TopTabbar, didSelectItemAt index: Int) { - if let moleculesArrays = json?.arrayForKey(KeyMolecules), - let molecules = moleculesArrays[index] as? [[AnyHashable: Any]] { + if let molecules = tabsListItemModel?.molecules[index] { delegateObject?.moleculeDelegate?.addMolecules(molecules, sender: self, animation: index < previousTabIndex ? .left : .right) } } @@ -74,11 +68,11 @@ extension TabsTableViewCell: TopTabbarDelegate { extension TabsTableViewCell: TopTabbarDataSource { public func number(ofTopTabbarItems topTabbar: TopTabbar) -> Int { - return json?.optionalDictionaryForKey("tabs")?.optionalArrayForKey("tabs")?.count ?? 0 + return tabsListItemModel?.tabs.tabs.count ?? 0 } public func topTabbar(_ topTabbar: TopTabbar, titleForItemAt index: Int) -> String? { - guard let tabs = json?.optionalDictionaryForKey("tabs")?.arrayForKey("tabs"), let label = tabs[index] as? [AnyHashable: Any], let title = label.optionalStringForKey(KeyText) else { + guard let title = tabsListItemModel?.tabs.tabs[index].text else { return "Select" } return title diff --git a/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift b/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift index 7e5fcda8..eca878ab 100644 --- a/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift +++ b/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift @@ -37,7 +37,7 @@ import UIKit //MARK: - MVMCoreMoleculeViewProtocol - open override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + open override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.setWithModel(model, delegateObject, additionalData) // guard let headlineModel = model as? headlinebodyswitch // headlineBody.setWithModel(mode, <#T##delegateObject: MVMCoreUIDelegateObject?##MVMCoreUIDelegateObject?#>, <#T##additionalData: [String : AnyHashable]?##[String : AnyHashable]?#>) diff --git a/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift b/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift index 8b06ab0e..de8e4d4f 100644 --- a/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift +++ b/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift @@ -9,7 +9,7 @@ import Foundation public protocol ModelMoleculeViewProtocol { - func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String: AnyHashable]?) + func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) 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]? diff --git a/MVMCoreUI/Molecules/ModuleMolecule.swift b/MVMCoreUI/Molecules/ModuleMolecule.swift index 863df271..3b49544c 100644 --- a/MVMCoreUI/Molecules/ModuleMolecule.swift +++ b/MVMCoreUI/Molecules/ModuleMolecule.swift @@ -19,7 +19,7 @@ open class ModuleMolecule: Container { super.setupView() } - public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String: AnyHashable]?) { + public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.setWithModel(model, delegateObject, additionalData) guard let moduleMoleculeModel = model as? ModuleMoleculeModel, diff --git a/MVMCoreUI/Molecules/MoleculeContainer.swift b/MVMCoreUI/Molecules/MoleculeContainer.swift index ed8555fb..f45ca482 100644 --- a/MVMCoreUI/Molecules/MoleculeContainer.swift +++ b/MVMCoreUI/Molecules/MoleculeContainer.swift @@ -25,7 +25,7 @@ open class MoleculeContainer: Container { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) } - public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { if let casteModel = model as? MoleculeContainerModel { if view != nil { (view as? ModelMoleculeViewProtocol)?.setWithModel(casteModel.molecule, delegateObject, additionalData) diff --git a/MVMCoreUI/Molecules/Scroller.swift b/MVMCoreUI/Molecules/Scroller.swift index 4be1025a..ee83077d 100644 --- a/MVMCoreUI/Molecules/Scroller.swift +++ b/MVMCoreUI/Molecules/Scroller.swift @@ -28,7 +28,7 @@ import UIKit constraint.isActive = true } - public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { #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. setUpDefaultWithModel(model, delegateObject, additionalData) diff --git a/MVMCoreUI/Molecules/StandardHeaderView.swift b/MVMCoreUI/Molecules/StandardHeaderView.swift index eeb46a6a..c13638d8 100644 --- a/MVMCoreUI/Molecules/StandardHeaderView.swift +++ b/MVMCoreUI/Molecules/StandardHeaderView.swift @@ -42,7 +42,7 @@ public class StandardHeaderView: MoleculeContainer { } } - open override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + open override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.setWithModel(model, delegateObject, additionalData) guard let headerModel = model as? HeaderModel else { diff --git a/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift b/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift index 706e4712..419df541 100644 --- a/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift +++ b/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift @@ -34,10 +34,10 @@ struct EyebrowHeadlineBodyLinkModel: MoleculeProtocol { guard stack.superview == nil else { return } - let eyebrowStackItem = MoleculeStackItemModel(with: casteModel!.eyeBrow!) - let headlineStackItem = MoleculeStackItemModel(with: casteModel!.headline!) - let bodyStackItem = MoleculeStackItemModel(with: casteModel!.body!) - let linkStackItem = MoleculeStackItemModel(with: casteModel!.link!) + let eyebrowStackItem = StackItemModel(with: casteModel!.eyeBrow!) + let headlineStackItem = StackItemModel(with: casteModel!.headline!) + let bodyStackItem = StackItemModel(with: casteModel!.body!) + let linkStackItem = StackItemModel(with: casteModel!.link!) // To visually take into account the extra padding in the intrinsic content of a button. linkStackItem.spacing = -6 diff --git a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBody.swift b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBody.swift index a70b106d..1d1f154a 100644 --- a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBody.swift +++ b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBody.swift @@ -119,7 +119,7 @@ open class HeadlineBody: View { } } - public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.setWithModel(model, delegateObject, additionalData) guard let headlineBodyModel = model as? HeadlineBodyModel else { diff --git a/MVMCoreUI/Organisms/Carousel.swift b/MVMCoreUI/Organisms/Carousel.swift index ef19f1a3..181ae372 100644 --- a/MVMCoreUI/Organisms/Carousel.swift +++ b/MVMCoreUI/Organisms/Carousel.swift @@ -81,7 +81,7 @@ open class Carousel: ViewConstrainingView, ModelMoleculeViewProtocol { // MARK: - MVMCoreUIMoleculeViewProtocol //TODO: Model, Change to model - public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { guard let caroselModel = model as? CarouselModel else { return } diff --git a/MVMCoreUI/Models/Molecules/MoleculeStackModel.swift b/MVMCoreUI/Organisms/MoleculeStackModel.swift similarity index 91% rename from MVMCoreUI/Models/Molecules/MoleculeStackModel.swift rename to MVMCoreUI/Organisms/MoleculeStackModel.swift index f8012a30..73c7c0a5 100644 --- a/MVMCoreUI/Models/Molecules/MoleculeStackModel.swift +++ b/MVMCoreUI/Organisms/MoleculeStackModel.swift @@ -11,11 +11,11 @@ import Foundation @objcMembers public class MoleculeStackModel: ContainerModel, MoleculeProtocol { public static var identifier: String = "moleculeStack" public var backgroundColor: Color? - public var molecules: [MoleculeStackItemModel] + public var molecules: [StackItemModel] public var axis: NSLayoutConstraint.Axis = .vertical public var spacing: CGFloat = 16.0 - public init(molecules: [MoleculeStackItemModel]) { + public init(molecules: [StackItemModel]) { self.molecules = molecules super.init() } @@ -29,7 +29,7 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: StackCodingKeys.self) - molecules = try typeContainer.decodeMolecules(codingKey: .molecules) as! [MoleculeStackItemModel] + molecules = try typeContainer.decodeMolecules(codingKey: .molecules) as! [StackItemModel] if let axisString = try typeContainer.decodeIfPresent(String.self, forKey: .axis), let optionalAxis = NSLayoutConstraint.Axis(rawValue: axisString) { axis = optionalAxis } diff --git a/MVMCoreUI/Organisms/MoleculeStackView.swift b/MVMCoreUI/Organisms/MoleculeStackView.swift index 8dd43193..738333d9 100644 --- a/MVMCoreUI/Organisms/MoleculeStackView.swift +++ b/MVMCoreUI/Organisms/MoleculeStackView.swift @@ -95,7 +95,7 @@ open class MoleculeStackView: Container { } } - public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { let previousModel = stackModel super.setWithModel(model, delegateObject, additionalData) removeAllItemViews() @@ -139,9 +139,9 @@ open class MoleculeStackView: Container { let data = try! JSONSerialization.data(withJSONObject: json!) let decoder = JSONDecoder() let model = try! decoder.decode(MoleculeStackModel.self, from: data) - setWithModel(model, delegateObject, additionalData as? [String : AnyHashable]) + setWithModel(model, delegateObject, additionalData) } else { - setWithModel(model, delegateObject, additionalData as? [String : AnyHashable]) + setWithModel(model, delegateObject, additionalData) } } @@ -210,7 +210,7 @@ open class MoleculeStackView: Container { func addView(_ view: View, lastItem: Bool) { guard let model = view.model else { return } let stackItem = StackItem(andContain: view) - stackItem.model = MoleculeStackItemModel(with: model) + stackItem.model = StackItemModel(with: model) addStackItem(stackItem, lastItem: lastItem) } diff --git a/MVMCoreUI/OtherHandlers/ModelMoleculeDelegateProtocol.swift b/MVMCoreUI/OtherHandlers/ModelMoleculeDelegateProtocol.swift index 1ea4df38..1611930a 100644 --- a/MVMCoreUI/OtherHandlers/ModelMoleculeDelegateProtocol.swift +++ b/MVMCoreUI/OtherHandlers/ModelMoleculeDelegateProtocol.swift @@ -12,7 +12,7 @@ public protocol MoleculeDelegateProtocol { /// returns a module for the corresponding module name. func getModuleWithName(_ name: String?) -> [AnyHashable : Any]? - func getModuleWithName(_ moleculeName: String) -> Model? + func getModuleWithName(_ moleculeName: String) -> MoleculeProtocol? /// Notifies the delegate that the molecule layout update. Should be called when the layout may change due to an async method. func moleculeLayoutUpdated(_ molecule: UIView & MVMCoreUIMoleculeViewProtocol) //optional diff --git a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift index 4eb9e4a8..a8401d3f 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift @@ -14,7 +14,7 @@ import Foundation ModelRegistry.register(HeaderModel.self) ModelRegistry.register(HeadlineBodyModel.self) ModelRegistry.register(MoleculeStackModel.self) - ModelRegistry.register(MoleculeStackItemModel.self) + ModelRegistry.register(StackItemModel.self) ModelRegistry.register(ListItemModel.self) ModelRegistry.register(TextFieldModel.self) ModelRegistry.register(LineModel.self) diff --git a/MVMCoreUI/Templates/MoleculeListCellProtocol.h b/MVMCoreUI/Templates/MoleculeListCellProtocol.h deleted file mode 100644 index 3fa19a02..00000000 --- a/MVMCoreUI/Templates/MoleculeListCellProtocol.h +++ /dev/null @@ -1,22 +0,0 @@ -// -// MoleculeListCellProtocol.h -// MVMCoreUI -// -// Created by Scott Pfeil on 5/22/19. -// Copyright © 2019 Verizon Wireless. All rights reserved. -// -#import -@class MVMCoreUIDelegateObject; - -@protocol MoleculeListCellProtocol -@optional - -/// Can set the separator according to what the moleculeList commands. -- (void)setSeparatorWithJSON:(nullable NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject additionalData:(nullable NSDictionary *)additionalData indexPath:(nonnull NSIndexPath *)indexPath; - -/// Handle action -- (void)didSelectCellAtIndex:(nonnull NSIndexPath *)indexPath delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject additionalData:(nullable NSDictionary *)additionalData; - -- (void)willDisplay; - -@end diff --git a/MVMCoreUI/Templates/MoleculeListCellProtocol.swift b/MVMCoreUI/Templates/MoleculeListCellProtocol.swift new file mode 100644 index 00000000..5d9b9525 --- /dev/null +++ b/MVMCoreUI/Templates/MoleculeListCellProtocol.swift @@ -0,0 +1,32 @@ +// +// MoleculeListCellProtocol.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 1/10/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation + +public protocol MoleculeListCellProtocol { + /// Can set the separator according to what the moleculeList commands. + func setLines(with model: LineModel?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?, indexPath: IndexPath) + + /// Handle action when cell is pressed + func didSelectCell(at index: IndexPath, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) + + /// Called by the list when the cell will display. + func willDisplay() +} + +// Default implementation does nothing +extension MoleculeListCellProtocol { + public func setLines(with model: LineModel?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?, indexPath: IndexPath) { + } + + public func didSelectCell(at index: IndexPath, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + } + + func willDisplay() { + } +} diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index 7b572c44..13d814e9 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -85,7 +85,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol let moleculeCell = cell as? MVMCoreUIMoleculeViewProtocol moleculeCell?.reset?() if let protocolCell = cell as? MoleculeListCellProtocol { - protocolCell.setSeparatorWithJSON?(loadObject?.pageJSON?.optionalDictionaryForKey("separator"), delegateObject: delegate, additionalData: nil, indexPath: indexPath) + protocolCell.setLines(with: templateModel?.line, delegateObject: delegate, additionalData: nil, indexPath: indexPath) } (moleculeCell as? ModelMoleculeViewProtocol)?.setWithModel(moleculeInfo.molecule, delegate, nil) moleculeCell?.updateView(tableView.bounds.width) @@ -95,13 +95,13 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol open override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { if let protocolCell = cell as? MoleculeListCellProtocol { - protocolCell.willDisplay?() + protocolCell.willDisplay() } } open override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { if let cell = tableView.cellForRow(at: indexPath) as? MoleculeListCellProtocol { - cell.didSelectCell?(atIndex: indexPath, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, additionalData: nil) + cell.didSelectCell(at: indexPath, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, additionalData: nil) } } @@ -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.molecule.moleculeName else { + let moleculeName = (moleculeClass as? ModelMoleculeViewProtocol)?.nameForReuse(listItem, delegateObject() as? MVMCoreUIDelegateObject) else { return nil } return (moleculeName, moleculeClass, listItem) From 1b06d7007b4149600794f852a3577693babd7cef Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 13 Jan 2020 10:20:11 -0500 Subject: [PATCH 43/51] circle progress --- MVMCoreUI.xcodeproj/project.pbxproj | 4 + .../Atoms/Views/CircleProgressModel.swift | 128 +++++++++++++++++ MVMCoreUI/Atoms/Views/GraphView.swift | 132 +++--------------- 3 files changed, 149 insertions(+), 115 deletions(-) create mode 100644 MVMCoreUI/Atoms/Views/CircleProgressModel.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index b34f888b..b7c3e2fc 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -124,6 +124,7 @@ D28A837D23CCA86A00DFE4FC /* TabsListItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A837C23CCA86A00DFE4FC /* TabsListItemModel.swift */; }; D28A837F23CCA96400DFE4FC /* TabsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A837E23CCA96400DFE4FC /* TabsModel.swift */; }; D28A838123CCB0D800DFE4FC /* AccordionListItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A838023CCB0D800DFE4FC /* AccordionListItemModel.swift */; }; + D28A838323CCBD3F00DFE4FC /* CircleProgressModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A838223CCBD3F00DFE4FC /* CircleProgressModel.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, ); }; }; @@ -383,6 +384,7 @@ D28A837C23CCA86A00DFE4FC /* TabsListItemModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabsListItemModel.swift; sourceTree = ""; }; D28A837E23CCA96400DFE4FC /* TabsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabsModel.swift; sourceTree = ""; }; D28A838023CCB0D800DFE4FC /* AccordionListItemModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccordionListItemModel.swift; sourceTree = ""; }; + D28A838223CCBD3F00DFE4FC /* CircleProgressModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircleProgressModel.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 = ""; }; @@ -1040,6 +1042,7 @@ 0A7BAFA0232BE61800FB8E22 /* Checkbox.swift */, 0A7BAFA2232BE63400FB8E22 /* CheckboxWithLabelView.swift */, 01004F2F22721C3800991ECC /* RadioButton.swift */, + D28A838223CCBD3F00DFE4FC /* CircleProgressModel.swift */, 943784F3236B77BB006A1E82 /* GraphView.swift */, 943784F4236B77BB006A1E82 /* GraphViewAnimationHandler.swift */, ); @@ -1399,6 +1402,7 @@ 012A88EC238F084D00FE3DA1 /* FooterModel.swift in Sources */, D2A514672213885800345BFB /* StandardHeaderView.swift in Sources */, 01EB369023609801006832FA /* ListItemModel.swift in Sources */, + D28A838323CCBD3F00DFE4FC /* CircleProgressModel.swift in Sources */, D268C70C2386DFFD007F2C1C /* StackItemModel.swift in Sources */, DBEFFA04225A829700230692 /* Label.swift in Sources */, D2D6CD4022E78C1A00D701B8 /* Scroller.swift in Sources */, diff --git a/MVMCoreUI/Atoms/Views/CircleProgressModel.swift b/MVMCoreUI/Atoms/Views/CircleProgressModel.swift new file mode 100644 index 00000000..20f49dc0 --- /dev/null +++ b/MVMCoreUI/Atoms/Views/CircleProgressModel.swift @@ -0,0 +1,128 @@ +// +// CircleProgressModel.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 1/13/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import UIKit + +public enum GraphSize: String, Codable { + case small, medium, large +} + +public enum GraphStyle: String, Codable { + case unlimited, safetyMode +} + +public class CircleProgressModel: MoleculeProtocol { + public static var identifier: String = "circleProgress" + public var style: GraphStyle = .unlimited { + didSet { + updateStyle() + } + } + + public var size: GraphSize = .small { + didSet { + updateSize() + } + } + public var diameter: CGFloat = 24 + public var lineWidth: CGFloat = 5 + public var clockwise: Bool = true + public var duration : Double = 1.0 + public var colors = [Color]() + public var backgroundColor: Color? + + public init() {} + + enum CircleProgressCodingKeys: String, CodingKey { + case style + case size + case diameter + case lineWidth + case clockwise + case duration + case colors + case backgroundColor + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CircleProgressCodingKeys.self) + if let style = try typeContainer.decodeIfPresent(GraphStyle.self, forKey: .style) { + self.style = style + } + if let size = try typeContainer.decodeIfPresent(GraphSize.self, forKey: .size) { + self.size = size + } + if let diameter = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .diameter) { + self.diameter = diameter + } + if let lineWidth = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .lineWidth) { + self.lineWidth = lineWidth + } + if let clockwise = try typeContainer.decodeIfPresent(Bool.self, forKey: .clockwise) { + self.clockwise = clockwise + } + if let duration = try typeContainer.decodeIfPresent(Double.self, forKey: .duration) { + self.duration = duration + } + if let colors = try typeContainer.decodeIfPresent([Color].self, forKey: .colors) { + self.colors = colors + } + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CircleProgressCodingKeys.self) + try container.encode(style, forKey: .style) + try container.encode(size, forKey: .size) + try container.encode(diameter, forKey: .diameter) + try container.encode(lineWidth, forKey: .lineWidth) + try container.encode(clockwise, forKey: .clockwise) + try container.encode(duration, forKey: .duration) + try container.encode(colors, forKey: .colors) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + } + + func getCGColorsFromArray(_ colorArray: [String]) -> [Color] { + return colorArray.map { (colorString) -> Color in + return Color(uiColor: UIColor.mfGet(forHex: colorString)) + } + } + + func updateStyle() { + switch style { + case .unlimited: + duration = 1.0 + clockwise = true + //current style, only the end part shows darker look + colors = getCGColorsFromArray(["#007AB8","#007AB8","#033554"]) + break + case .safetyMode: + duration = 1.5 + clockwise = true + colors = getCGColorsFromArray(["#CC4D0F","#CC4D0F","AB0309"]) + break + } + } + + func updateSize() { + switch size { + case .small: + diameter = MFSizeObject(standardSize: 20)?.getValueBasedOnApplicationWidth() ?? 20 + lineWidth = MFSizeObject(standardSize: 4)?.getValueBasedOnApplicationWidth() ?? 4 + break + case .medium: + diameter = MFSizeObject(standardSize: 100)?.getValueBasedOnApplicationWidth() ?? 100 + lineWidth = MFSizeObject(standardSize: 8)?.getValueBasedOnApplicationWidth() ?? 8 + break + case .large: + diameter = MFSizeObject(standardSize: 180)?.getValueBasedOnApplicationWidth() ?? 180 + lineWidth = MFSizeObject(standardSize: 12)?.getValueBasedOnApplicationWidth() ?? 12 + break + } + } +} diff --git a/MVMCoreUI/Atoms/Views/GraphView.swift b/MVMCoreUI/Atoms/Views/GraphView.swift index 40c353b2..146daecf 100644 --- a/MVMCoreUI/Atoms/Views/GraphView.swift +++ b/MVMCoreUI/Atoms/Views/GraphView.swift @@ -8,113 +8,13 @@ import UIKit - -enum GraphSize: String { - case small, medium, large -} - -enum GraphStyle: String { - case unlimited, safetyMode -} - -///Graph Object contains properties -public struct GraphObject { - - var style: GraphStyle { - didSet { - updateStyle() - } - } - var size: GraphSize { - didSet { - updateSize() - } - } - var diameter: CGFloat = 24 - var lineWidth: CGFloat = 5 - var clockwise: Bool = true - var duration : Double = 1.0 - var colors = [CGColor]() - - public init(_ json: [AnyHashable : Any]?) { - style = .unlimited - size = .small - guard let json = json else { - return - } - if let styleString = json.optionalStringForKey("style") { - style = GraphStyle(rawValue: styleString) ?? .unlimited - } - if let sizeString = json.optionalStringForKey("size") { - size = GraphSize(rawValue: sizeString) ?? .small - } - updateStyle() - updateSize() - if let diameter = json.optionalCGFloatForKey("diameter") { - self.diameter = diameter - } - if let lineWidth = json.optionalCGFloatForKey("lineWidth") { - self.lineWidth = lineWidth - } - if let clockwise = json.optionalBoolForKey("clockwise") { - self.clockwise = clockwise - } - if let duration = json["duration"] as? Double { - self.duration = duration - } - if let colorArray = json.optionalArrayForKey("colors") as? [String] { - colors = getCGColorsFromArray(colorArray) - } - } - - func getCGColorsFromArray(_ colorArray: [String]) -> [CGColor] { - return colorArray.map { (colorString) -> CGColor in - return UIColor.mfGet(forHex: colorString).cgColor - } - } - - mutating func updateStyle() { - switch style { - case .unlimited: - duration = 1.0 - clockwise = true - //current style, only the end part shows darker look - colors = getCGColorsFromArray(["#007AB8","#007AB8","#033554"]) - break - case .safetyMode: - duration = 1.5 - clockwise = true - colors = getCGColorsFromArray(["#CC4D0F","#CC4D0F","AB0309"]) - break - } - } - - //those are - mutating func updateSize() { - switch size { - case .small: - diameter = MFSizeObject(standardSize: 20)?.getValueBasedOnApplicationWidth() ?? 20 - lineWidth = MFSizeObject(standardSize: 4)?.getValueBasedOnApplicationWidth() ?? 4 - break - case .medium: - diameter = MFSizeObject(standardSize: 100)?.getValueBasedOnApplicationWidth() ?? 100 - lineWidth = MFSizeObject(standardSize: 8)?.getValueBasedOnApplicationWidth() ?? 8 - break - case .large: - diameter = MFSizeObject(standardSize: 180)?.getValueBasedOnApplicationWidth() ?? 180 - lineWidth = MFSizeObject(standardSize: 12)?.getValueBasedOnApplicationWidth() ?? 12 - break - } - } -} - - @objcMembers open class GraphView: View, MVMCoreUIViewConstrainingProtocol { var heightConstraint: NSLayoutConstraint? var gradientLayer: CALayer? - var graphObject: GraphObject? - + var graphModel: CircleProgressModel? { + return model as? CircleProgressModel + } // MARK: setup open override func setupView() { @@ -128,14 +28,16 @@ public struct GraphObject { override open func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.setWithModel(model, delegateObject, additionalData) + guard let model = model as? CircleProgressModel else { return } + createGraphCircle(model) + rotationAnimation(model) } override open func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - let object = GraphObject(json) - graphObject = object - createGraphCircle(object) - rotationAnimation(object) + guard let graphModel = graphModel else { return } + createGraphCircle(graphModel) + rotationAnimation(graphModel) } class func getAngle(_ piValue: Double) -> Double { @@ -147,7 +49,7 @@ public struct GraphObject { } // MARK: circle - open func createGraphCircle(_ graphObject: GraphObject) { + open func createGraphCircle(_ graphObject: CircleProgressModel) { if let sublayers = layer.sublayers { for sublayer in sublayers { sublayer.removeAllAnimations() @@ -188,14 +90,14 @@ public struct GraphObject { | | | ------------- */ - func createGradientLayer(_ graphObject: GraphObject) -> CALayer { + func createGradientLayer(_ graphObject: CircleProgressModel) -> CALayer { let containLayer = CALayer() containLayer.frame = CGRect(x: 0, y: 0, width: graphObject.diameter, height: graphObject.diameter) let radius = graphObject.diameter / 2.0 //create graident layers guard graphObject.colors.count > 1 else { - containLayer.backgroundColor = graphObject.colors.first + containLayer.backgroundColor = graphObject.colors.first?.uiColor.cgColor return containLayer } var topGradientHeight : CGFloat = 0.0 @@ -214,7 +116,7 @@ public struct GraphObject { leftColors.removeLast() topLayer.colors = [leftColors.last!, rightColors.first!] } else { - topLayer.backgroundColor = leftColors.last + topLayer.backgroundColor = leftColors.last?.uiColor.cgColor } containLayer.addSublayer(topLayer) @@ -227,7 +129,7 @@ public struct GraphObject { if leftColors.count > 1 { leftLayer.colors = Array(leftColors) } else { - leftLayer.backgroundColor = leftColors.first + leftLayer.backgroundColor = leftColors.first?.uiColor.cgColor } containLayer.addSublayer(leftLayer) @@ -238,7 +140,7 @@ public struct GraphObject { if rightColors.count > 1 { rightLayer.colors = Array(rightColors) } else { - rightLayer.backgroundColor = rightColors.first + rightLayer.backgroundColor = rightColors.first?.uiColor.cgColor } containLayer.addSublayer(rightLayer) @@ -250,7 +152,7 @@ public struct GraphObject { } //MARK: Animation - func rotationAnimation(_ object: GraphObject) { + func rotationAnimation(_ object: CircleProgressModel) { MVMCoreDispatchUtility.performBlock(onMainThread:{ let rotation = CABasicAnimation(keyPath: "transform.rotation") let animationHandler = GraphViewAnimationHandler.shared @@ -281,7 +183,7 @@ public struct GraphObject { extension GraphView: CAAnimationDelegate { public func animationDidStop(_ anim: CAAnimation, finished flag: Bool) { - if let object = graphObject { + if let object = graphModel { rotationAnimation(object) } } From fe9131f3c67157d2c0de2b863903557dea835b21 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 13 Jan 2020 10:22:04 -0500 Subject: [PATCH 44/51] update json func --- MVMCoreUI/Atoms/Views/GraphView.swift | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/GraphView.swift b/MVMCoreUI/Atoms/Views/GraphView.swift index 146daecf..cda77660 100644 --- a/MVMCoreUI/Atoms/Views/GraphView.swift +++ b/MVMCoreUI/Atoms/Views/GraphView.swift @@ -34,10 +34,8 @@ import UIKit } override open func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - guard let graphModel = graphModel else { return } - createGraphCircle(graphModel) - rotationAnimation(graphModel) + guard let json = json, let model = try? Self.decodeJSONToModel(json: json, type: CircleProgressModel.self) else { return } + setWithModel(model, delegateObject, additionalData) } class func getAngle(_ piValue: Double) -> Double { From f9620e4bc718ad4b8cc28ef4a7868a343c2dfcbb Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 13 Jan 2020 10:40:53 -0500 Subject: [PATCH 45/51] List template fix --- .../Models/Template/ListPageTemplateModel.swift | 14 +++++++------- MVMCoreUI/Templates/MoleculeListTemplate.swift | 12 ++---------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/MVMCoreUI/Models/Template/ListPageTemplateModel.swift b/MVMCoreUI/Models/Template/ListPageTemplateModel.swift index dd8d3979..61729c99 100644 --- a/MVMCoreUI/Models/Template/ListPageTemplateModel.swift +++ b/MVMCoreUI/Models/Template/ListPageTemplateModel.swift @@ -16,12 +16,12 @@ import Foundation public var screenHeading: String? public var isAtomicTabs: Bool? - public var header: HeaderModel? + public var header: MoleculeProtocol? public var molecules: [ListItemModelProtocol] - public var footer: MoleculeStackModel? + public var footer: MoleculeProtocol? public var line: LineModel? - public init(pageType: String, screenHeading: String, molecules: [ListItemModelProtocol]) { + public init(pageType: String, screenHeading: String?, molecules: [ListItemModelProtocol]) { self.pageType = pageType self.screenHeading = screenHeading self.molecules = molecules @@ -48,8 +48,8 @@ import Foundation } self.molecules = molecules isAtomicTabs = try typeContainer.decodeIfPresent(Bool.self, forKey: .isAtomicTabs) - header = try typeContainer.decodeIfPresent(HeaderModel.self, forKey: .header) - footer = try typeContainer.decodeIfPresent(MoleculeStackModel.self, forKey: .footer) + header = try typeContainer.decodeMoleculeIfPresent(codingKey: .header) + footer = try typeContainer.decodeMoleculeIfPresent(codingKey: .footer) line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line) } @@ -59,8 +59,8 @@ import Foundation try container.encodeIfPresent(screenHeading, forKey: .screenHeading) try container.encodeModels(molecules, forKey: .molecules) try container.encodeIfPresent(isAtomicTabs, forKey: .isAtomicTabs) - try container.encodeIfPresent(header, forKey: .header) - try container.encodeIfPresent(footer, forKey: .footer) + try container.encodeModelIfPresent(header, forKey: .header) + try container.encodeModelIfPresent(footer, forKey: .footer) try container.encode(line, forKey: .line) } } diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index 13d814e9..03f4e0fc 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) else { + let moleculeName = (moleculeClass as? ModelMoleculeViewProtocol)?.nameForReuse(listItem, delegateObject() as? MVMCoreUIDelegateObject) ?? listItem.moleculeName else { return nil } return (moleculeName, moleculeClass, listItem) @@ -188,15 +188,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol /// Sets up the header, footer, molecule list and ensures no errors loading all content. func setup() { - var moleculeList: [(identifier: String, class: AnyClass, molecule: ListItemModelProtocol)] = [] - if let molecules = templateModel?.molecules { - for molecule in molecules { - if let info = getMoleculeInfo(with: molecule) { - moleculeList.append(info) - } - } - } - moleculesInfo = moleculeList + moleculesInfo = getMoleculeInfoList() } /// Adds modules from requiredModules() to the MVMCoreViewControllerMapping.requiredModules map. From 824e077097ad5444bdee0843ce94eb244cce151a Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 13 Jan 2020 10:46:18 -0500 Subject: [PATCH 46/51] stack model fixes --- .../Template/StackPageTemplateModel.swift | 40 +++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Models/Template/StackPageTemplateModel.swift b/MVMCoreUI/Models/Template/StackPageTemplateModel.swift index 0d8bef77..9cce36ab 100644 --- a/MVMCoreUI/Models/Template/StackPageTemplateModel.swift +++ b/MVMCoreUI/Models/Template/StackPageTemplateModel.swift @@ -18,7 +18,41 @@ import Foundation public var isAtomicTabs: Bool? - public var header: HeaderModel? - public var moleculeStack: MoleculeStackModel? - public var footer: FooterModel? + public var header: MoleculeProtocol? + public var moleculeStack: MoleculeStackModel + public var footer: MoleculeProtocol? + + public init(pageType: String, moleculeStack: MoleculeStackModel) { + self.pageType = pageType + self.moleculeStack = moleculeStack + } + + enum CodingKeys: String, CodingKey { + case pageType + case screenHeading + case header + case footer + case moleculeStack + case isAtomicTabs + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + pageType = try typeContainer.decode(String.self, forKey: .pageType) + moleculeStack = try typeContainer.decode(MoleculeStackModel.self, forKey: .moleculeStack) + screenHeading = try typeContainer.decodeIfPresent(String.self, forKey: .screenHeading) + isAtomicTabs = try typeContainer.decodeIfPresent(Bool.self, forKey: .isAtomicTabs) + header = try typeContainer.decodeMoleculeIfPresent(codingKey: .header) + footer = try typeContainer.decodeMoleculeIfPresent(codingKey: .footer) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(pageType, forKey: .pageType) + try container.encode(moleculeStack, forKey: .moleculeStack) + try container.encodeIfPresent(screenHeading, forKey: .screenHeading) + try container.encodeIfPresent(isAtomicTabs, forKey: .isAtomicTabs) + try container.encodeModelIfPresent(header, forKey: .header) + try container.encodeModelIfPresent(footer, forKey: .footer) + } } From 1feee6aa9a6ef15875a3d32dfd9443123e627a61 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 13 Jan 2020 10:48:35 -0500 Subject: [PATCH 47/51] three layer model fix --- .../ThreeLayerPageTemplateModel.swift | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Models/Template/ThreeLayerPageTemplateModel.swift b/MVMCoreUI/Models/Template/ThreeLayerPageTemplateModel.swift index b4604fbc..5d4d1b25 100644 --- a/MVMCoreUI/Models/Template/ThreeLayerPageTemplateModel.swift +++ b/MVMCoreUI/Models/Template/ThreeLayerPageTemplateModel.swift @@ -17,7 +17,43 @@ import Foundation public var isAtomicTabs: Bool? - public var header: MoleculeStackModel? - public var middle: MoleculeStackModel? - public var footer: MoleculeStackModel? + public var header: MoleculeProtocol? + public var middle: MoleculeProtocol? + public var footer: MoleculeProtocol? + + public init(pageType: String, header: MoleculeProtocol?, middle: MoleculeProtocol?, footer: MoleculeProtocol?) { + self.pageType = pageType + self.header = header + self.middle = middle + self.footer = footer + } + + enum CodingKeys: String, CodingKey { + case pageType + case screenHeading + case header + case footer + case middle + case isAtomicTabs + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + pageType = try typeContainer.decode(String.self, forKey: .pageType) + screenHeading = try typeContainer.decodeIfPresent(String.self, forKey: .screenHeading) + isAtomicTabs = try typeContainer.decodeIfPresent(Bool.self, forKey: .isAtomicTabs) + header = try typeContainer.decodeMoleculeIfPresent(codingKey: .header) + header = try typeContainer.decodeMoleculeIfPresent(codingKey: .middle) + footer = try typeContainer.decodeMoleculeIfPresent(codingKey: .footer) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(pageType, forKey: .pageType) + try container.encodeIfPresent(screenHeading, forKey: .screenHeading) + try container.encodeIfPresent(isAtomicTabs, forKey: .isAtomicTabs) + try container.encodeModelIfPresent(header, forKey: .header) + try container.encodeModelIfPresent(header, forKey: .middle) + try container.encodeModelIfPresent(footer, forKey: .footer) + } } From 3edb1a583fddcc5e9d63a5b0897ed1addd34dbc6 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 13 Jan 2020 10:53:52 -0500 Subject: [PATCH 48/51] module molecule update --- MVMCoreUI/Molecules/ModuleMolecule.swift | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Molecules/ModuleMolecule.swift b/MVMCoreUI/Molecules/ModuleMolecule.swift index 3b49544c..e2411ec0 100644 --- a/MVMCoreUI/Molecules/ModuleMolecule.swift +++ b/MVMCoreUI/Molecules/ModuleMolecule.swift @@ -23,7 +23,7 @@ open class ModuleMolecule: Container { super.setWithModel(model, delegateObject, additionalData) guard let moduleMoleculeModel = model as? ModuleMoleculeModel, - let moduleModel = delegateObject?.moleculeDelegate?.getModuleWithName(moduleMoleculeModel.moduleName) as? MoleculeProtocol else { + let moduleModel = delegateObject?.moleculeDelegate?.getModuleWithName(moduleMoleculeModel.moduleName) else { // Critical error return } @@ -49,7 +49,7 @@ open class ModuleMolecule: Container { public static func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { guard let moduleMolecule = molecule as? ModuleMoleculeModel, - let moduleModel = delegateObject?.moleculeDelegate?.getModuleWithName(moduleMolecule.moduleName) as? MoleculeProtocol, + let moduleModel = delegateObject?.moleculeDelegate?.getModuleWithName(moduleMolecule.moduleName), let classType = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moduleModel) as? ModelMoleculeViewProtocol.Type, let height = classType.estimatedHeight(forRow: moduleModel, delegateObject: delegateObject)else { // Critical error @@ -60,7 +60,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) as? MoleculeProtocol, + let moduleModel = delegateObject?.moleculeDelegate?.getModuleWithName(moduleMolecule.moduleName), let classType = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moduleModel) as? ModelMoleculeViewProtocol, let name = classType.nameForReuse(moduleModel, delegateObject) else { // Critical error @@ -69,7 +69,6 @@ open class ModuleMolecule: Container { return name } - //TODO: Scottt please check this. public static func requiredModules(_ molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { guard let moduleName = (molecule as? ModuleMoleculeModel)?.moduleName, From 73c19383b6dc73b4130918e42a210341a658d5b8 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 13 Jan 2020 11:08:58 -0500 Subject: [PATCH 49/51] Scroller update --- MVMCoreUI.xcodeproj/project.pbxproj | 4 ++ MVMCoreUI/Molecules/Scroller.swift | 48 ++++++------------- MVMCoreUI/Molecules/ScrollerModel.swift | 14 ++++++ .../OtherHandlers/MoleculeObjectMapping.swift | 9 +++- 4 files changed, 40 insertions(+), 35 deletions(-) create mode 100644 MVMCoreUI/Molecules/ScrollerModel.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index b7c3e2fc..eaed8902 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -125,6 +125,7 @@ D28A837F23CCA96400DFE4FC /* TabsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A837E23CCA96400DFE4FC /* TabsModel.swift */; }; D28A838123CCB0D800DFE4FC /* AccordionListItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A838023CCB0D800DFE4FC /* AccordionListItemModel.swift */; }; D28A838323CCBD3F00DFE4FC /* CircleProgressModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A838223CCBD3F00DFE4FC /* CircleProgressModel.swift */; }; + D28A838523CCCA8900DFE4FC /* ScrollerModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A838423CCCA8900DFE4FC /* ScrollerModel.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, ); }; }; @@ -385,6 +386,7 @@ D28A837E23CCA96400DFE4FC /* TabsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabsModel.swift; sourceTree = ""; }; D28A838023CCB0D800DFE4FC /* AccordionListItemModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccordionListItemModel.swift; sourceTree = ""; }; D28A838223CCBD3F00DFE4FC /* CircleProgressModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircleProgressModel.swift; sourceTree = ""; }; + D28A838423CCCA8900DFE4FC /* ScrollerModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollerModel.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 = ""; }; @@ -869,6 +871,7 @@ D274CA322236A78900B01B62 /* StandardFooterView.swift */, 0116A4E4228B19640094F3ED /* RadioButtonModel.swift */, D29B770F22C281F400D6ACE0 /* ModuleMolecule.swift */, + D28A838423CCCA8900DFE4FC /* ScrollerModel.swift */, D2D6CD3F22E78C1A00D701B8 /* Scroller.swift */, 0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */, 017BEB372360C6AC0024EF95 /* RadioButtonLabel.swift */, @@ -1486,6 +1489,7 @@ D29DF11821E6805F003B2FB9 /* NSLayoutConstraint+MFConvenience.m in Sources */, 94C2D9A323872C110006CF46 /* LabelAttributeStrikeThroughModel.swift in Sources */, 011B58F423A2CCC80085F53C /* DropDownModel.swift in Sources */, + D28A838523CCCA8900DFE4FC /* ScrollerModel.swift in Sources */, D29DF26C21E6AA0B003B2FB9 /* FLAnimatedImage.m in Sources */, 012A88F123985E0100FE3DA1 /* Color.swift in Sources */, 012A889C23889E8400FE3DA1 /* TemplateModelProtocol.swift in Sources */, diff --git a/MVMCoreUI/Molecules/Scroller.swift b/MVMCoreUI/Molecules/Scroller.swift index ee83077d..451eba75 100644 --- a/MVMCoreUI/Molecules/Scroller.swift +++ b/MVMCoreUI/Molecules/Scroller.swift @@ -8,7 +8,7 @@ import UIKit -@objcMembers open class Scroller: ViewConstrainingView { +@objcMembers open class Scroller: Container { public let scrollView = UIScrollView(frame: .zero) public let contentView = MVMCoreUICommonViewsUtility.commonView() @@ -20,7 +20,8 @@ import UIKit translatesAutoresizingMaskIntoConstraints = false scrollView.translatesAutoresizingMaskIntoConstraints = false addSubview(scrollView) - pinView(toSuperView: scrollView) + NSLayoutConstraint.constraintPinSubview(toSuperview: scrollView) + contentView.translatesAutoresizingMaskIntoConstraints = false scrollView.addSubview(contentView) NSLayoutConstraint.constraintPinSubview(toSuperview: contentView) let constraint = contentView.widthAnchor.constraint(equalTo: scrollView.widthAnchor, multiplier: 1.0) @@ -28,39 +29,18 @@ import UIKit constraint.isActive = true } - public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { - #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. - setUpDefaultWithModel(model, delegateObject, additionalData) - - guard let model = model, - let moleculeModel = (model as? MoleculeContainerModel)?.molecule else { - return - } - - if molecule == nil { - if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(moleculeModel, delegateObject, true) { - contentView.addSubview(moleculeView) - pinView(toSuperView: moleculeView) - molecule = moleculeView + public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + if let casteModel = model as? ScrollerModel { + if view != nil { + (view as? ModelMoleculeViewProtocol)?.setWithModel(casteModel.molecule, delegateObject, additionalData) + } else { + if let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(casteModel.molecule, delegateObject) { + contentView.addSubview(molecule) + molecule.translatesAutoresizingMaskIntoConstraints = false + containerHelper.constrainView(molecule) + } } - } else { - (molecule as? ModelMoleculeViewProtocol)?.setWithModel(moleculeModel, delegateObject, additionalData) } + super.setWithModel(model, delegateObject, additionalData) } - -// open override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { -// guard let json = json, let moleculeJSON = json.optionalDictionaryForKey(KeyMolecule) else { -// return -// } -// if molecule == nil { -// if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject, constrainIfNeeded: true) { -// contentView.addSubview(moleculeView) -// pinView(toSuperView: moleculeView) -// molecule = moleculeView -// } -// } else { -// molecule?.setWithJSON(moleculeJSON, delegateObject: delegateObject, additionalData: additionalData) -// } -// } } diff --git a/MVMCoreUI/Molecules/ScrollerModel.swift b/MVMCoreUI/Molecules/ScrollerModel.swift new file mode 100644 index 00000000..3fa225fb --- /dev/null +++ b/MVMCoreUI/Molecules/ScrollerModel.swift @@ -0,0 +1,14 @@ +// +// ScrollerModel.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 1/13/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import UIKit + +public class ScrollerModel: MoleculeContainerModel, MoleculeProtocol { + public static var identifier: String = "scroller" + public var backgroundColor: Color? +} diff --git a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift index a8401d3f..01677585 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift @@ -15,7 +15,6 @@ import Foundation ModelRegistry.register(HeadlineBodyModel.self) ModelRegistry.register(MoleculeStackModel.self) ModelRegistry.register(StackItemModel.self) - ModelRegistry.register(ListItemModel.self) ModelRegistry.register(TextFieldModel.self) ModelRegistry.register(LineModel.self) ModelRegistry.register(ProgressBarModel.self) @@ -23,6 +22,14 @@ import Foundation ModelRegistry.register(CaretViewModel.self) ModelRegistry.register(DashLineModel.self) ModelRegistry.register(ImageViewModel.self) + ModelRegistry.register(TabsModel.self) + ModelRegistry.register(ScrollerModel.self) + // list items + ModelRegistry.register(ListItemModel.self) + ModelRegistry.register(DropDownListItemModel.self) + ModelRegistry.register(AccordionListItemModel.self) + ModelRegistry.register(TabsListItemModel.self) + //need to move labelattributemodel to different method ModelRegistry.register(LabelAttributeFontModel.self) ModelRegistry.register(LabelAttributeColorModel.self) From 13183f7b76ffcbbcee6f90a33248137abf3902da Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Mon, 13 Jan 2020 11:10:51 -0500 Subject: [PATCH 50/51] remove null in project file --- MVMCoreUI.xcodeproj/project.pbxproj | 8 -------- 1 file changed, 8 deletions(-) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index b34f888b..0c0ccde7 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -22,15 +22,11 @@ 012A88C4238D86E600FE3DA1 /* CollectionCellMoleculeProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88C3238D86E600FE3DA1 /* CollectionCellMoleculeProtocol.swift */; }; 012A88C6238DA34000FE3DA1 /* ModuleMoleculeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88C5238DA34000FE3DA1 /* ModuleMoleculeModel.swift */; }; 012A88C8238DB02000FE3DA1 /* ModelMoleculeDelegateProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88C7238DB02000FE3DA1 /* ModelMoleculeDelegateProtocol.swift */; }; - 012A88DA238ED42E00FE3DA1 /* (null) in Sources */ = {isa = PBXBuildFile; }; 012A88DB238ED45900FE3DA1 /* CarouselModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88AE238C626E00FE3DA1 /* CarouselModel.swift */; }; 012A88EC238F084D00FE3DA1 /* FooterModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88EB238F084D00FE3DA1 /* FooterModel.swift */; }; 012A88F123985E0100FE3DA1 /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88F023985E0100FE3DA1 /* Color.swift */; }; 012CA99A2384A687003F810F /* MFTextField+ModelExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012CA9992384A687003F810F /* MFTextField+ModelExtension.swift */; }; 012CA99E2385A2D3003F810F /* MFView+ModelExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012CA99D2385A2D3003F810F /* MFView+ModelExtension.swift */; }; - 012CA9DE2388723E003F810F /* (null) in Sources */ = {isa = PBXBuildFile; }; - 012CA9E223888AED003F810F /* (null) in Sources */ = {isa = PBXBuildFile; }; - 012CA9E423888B1B003F810F /* (null) in Sources */ = {isa = PBXBuildFile; }; 014AA72423C501E2006F3E93 /* MoleculeContainerModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 014AA72123C501E2006F3E93 /* MoleculeContainerModel.swift */; }; 014AA72523C501E2006F3E93 /* ContainerModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 014AA72223C501E2006F3E93 /* ContainerModel.swift */; }; 014AA72623C501E2006F3E93 /* ContainerModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 014AA72323C501E2006F3E93 /* ContainerModelProtocol.swift */; }; @@ -1330,7 +1326,6 @@ files = ( 0A5D59C223AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift in Sources */, 943784F5236B77BB006A1E82 /* GraphView.swift in Sources */, - 012CA9E423888B1B003F810F /* (null) in Sources */, 9402C35023A2CEA3004B974C /* LeftRightLabelModel.swift in Sources */, D29DF32121ED0CBA003B2FB9 /* LabelView.m in Sources */, D28A838123CCB0D800DFE4FC /* AccordionListItemModel.swift in Sources */, @@ -1416,8 +1411,6 @@ D2D6CD4222E78FAB00D701B8 /* ThreeLayerTemplate.swift in Sources */, 01EB368F23609801006832FA /* LabelModel.swift in Sources */, 0105618F224BBE7700E1557D /* FormValidator+FormParams.swift in Sources */, - 012CA9E223888AED003F810F /* (null) in Sources */, - 012A88DA238ED42E00FE3DA1 /* (null) in Sources */, 01F2A03223A4498200D954D8 /* CaretLinkModel.swift in Sources */, 0A7BAFA1232BE61800FB8E22 /* Checkbox.swift in Sources */, 011B58F023A2AA980085F53C /* ListItemModelProtocol.swift in Sources */, @@ -1449,7 +1442,6 @@ D29DF29521E7ADB8003B2FB9 /* ProgrammaticScrollViewController.m in Sources */, D2FB151B23A2B65B00C20E10 /* MoleculeContainer.swift in Sources */, D2A638FD22CA98280052ED1F /* HeadlineBody.swift in Sources */, - 012CA9DE2388723E003F810F /* (null) in Sources */, D29DF16121E69996003B2FB9 /* MFViewController.m in Sources */, D2E1FAE12268E81D00AEFD8C /* MoleculeListTemplate.swift in Sources */, DB06250B2293456500B72DD3 /* LeftRightLabelView.swift in Sources */, From bb0be7251949c26256d92644c8712208a9e0352f Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 13 Jan 2020 11:33:44 -0500 Subject: [PATCH 51/51] Link update --- MVMCoreUI.xcodeproj/project.pbxproj | 8 +++ MVMCoreUI/Atoms/Buttons/LinkModel.swift | 53 +++++++++++++++++++ .../Buttons/MFTextButton+ModelExtension.swift | 24 +++++++++ .../EyebrowHeadlineBodyLink.swift | 32 ++++++----- 4 files changed, 104 insertions(+), 13 deletions(-) create mode 100644 MVMCoreUI/Atoms/Buttons/LinkModel.swift create mode 100644 MVMCoreUI/Atoms/Buttons/MFTextButton+ModelExtension.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index eaed8902..3b55716b 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -126,6 +126,8 @@ D28A838123CCB0D800DFE4FC /* AccordionListItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A838023CCB0D800DFE4FC /* AccordionListItemModel.swift */; }; D28A838323CCBD3F00DFE4FC /* CircleProgressModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A838223CCBD3F00DFE4FC /* CircleProgressModel.swift */; }; D28A838523CCCA8900DFE4FC /* ScrollerModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A838423CCCA8900DFE4FC /* ScrollerModel.swift */; }; + D28A838723CCCF6500DFE4FC /* MFTextButton+ModelExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A838623CCCF6500DFE4FC /* MFTextButton+ModelExtension.swift */; }; + D28A838923CCCFCB00DFE4FC /* LinkModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A838823CCCFCB00DFE4FC /* LinkModel.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, ); }; }; @@ -387,6 +389,8 @@ D28A838023CCB0D800DFE4FC /* AccordionListItemModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccordionListItemModel.swift; sourceTree = ""; }; D28A838223CCBD3F00DFE4FC /* CircleProgressModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircleProgressModel.swift; sourceTree = ""; }; D28A838423CCCA8900DFE4FC /* ScrollerModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollerModel.swift; sourceTree = ""; }; + D28A838623CCCF6500DFE4FC /* MFTextButton+ModelExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MFTextButton+ModelExtension.swift"; sourceTree = ""; }; + D28A838823CCCFCB00DFE4FC /* LinkModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkModel.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 = ""; }; @@ -998,6 +1002,8 @@ D29DF16C21E69E1F003B2FB9 /* PrimaryButton.h */, D29DF17121E69E1F003B2FB9 /* PrimaryButton.m */, D282AACA2243C61700C46919 /* ButtonView.swift */, + D28A838823CCCFCB00DFE4FC /* LinkModel.swift */, + D28A838623CCCF6500DFE4FC /* MFTextButton+ModelExtension.swift */, D29DF16D21E69E1F003B2FB9 /* MFTextButton.h */, D29DF17221E69E1F003B2FB9 /* MFTextButton.m */, ); @@ -1343,6 +1349,7 @@ DBC4391822442197001AB423 /* CaretView.swift in Sources */, D29770F221F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.m in Sources */, D29B771022C281F400D6ACE0 /* ModuleMolecule.swift in Sources */, + D28A838923CCCFCB00DFE4FC /* LinkModel.swift in Sources */, 94C2D9A923872E5E0006CF46 /* LabelAttributeImageModel.swift in Sources */, DBC4391922442197001AB423 /* DashLine.swift in Sources */, 0AA33B34239813C50067DD0F /* UIColor+Extension.swift in Sources */, @@ -1383,6 +1390,7 @@ D22D1F572204CE5D0077CEC0 /* MVMCoreUIStackableViewController.m in Sources */, D2A5145F2211DDC100345BFB /* MoleculeStackView.swift in Sources */, D29DF27621E79E81003B2FB9 /* MVMCoreUILoggingHandler.m in Sources */, + D28A838723CCCF6500DFE4FC /* MFTextButton+ModelExtension.swift in Sources */, D29DF24D21E6A177003B2FB9 /* MFTextField.m in Sources */, 014AA72D23C5059B006F3E93 /* StackPageTemplateModel.swift in Sources */, 012A88C4238D86E600FE3DA1 /* CollectionCellMoleculeProtocol.swift in Sources */, diff --git a/MVMCoreUI/Atoms/Buttons/LinkModel.swift b/MVMCoreUI/Atoms/Buttons/LinkModel.swift new file mode 100644 index 00000000..6b3ff39e --- /dev/null +++ b/MVMCoreUI/Atoms/Buttons/LinkModel.swift @@ -0,0 +1,53 @@ +// +// LinkModel.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 1/13/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import UIKit + +public class LinkModel: MoleculeProtocol { + public static var identifier: String = "link" + public var backgroundColor: Color? + public var title: String + public var action: ActionProtocol + public var enabled = true + public var textColor = Color(uiColor: .mfTextButton()) + + public init(title: String, action: ActionProtocol) { + self.title = title + self.action = action + } + + enum CodingKeys: String, CodingKey { + case backgroundColor + case title + case action + case enabled + case textColor + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) + title = try typeContainer.decode(String.self, forKey: .title) + action = try typeContainer.decodeModel(codingKey: .action, typeCodingKey: ActionCodingKey.type) + if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) { + self.enabled = enabled + } + if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .textColor) { + textColor = color + } + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(title, forKey: .title) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encodeModel(action, forKey: .action) + try container.encode(enabled, forKey: .enabled) + try container.encode(textColor, forKey: .textColor) + } +} diff --git a/MVMCoreUI/Atoms/Buttons/MFTextButton+ModelExtension.swift b/MVMCoreUI/Atoms/Buttons/MFTextButton+ModelExtension.swift new file mode 100644 index 00000000..a6df6745 --- /dev/null +++ b/MVMCoreUI/Atoms/Buttons/MFTextButton+ModelExtension.swift @@ -0,0 +1,24 @@ +// +// MFTextButton_ModelExtension.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 1/13/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import UIKit + +// temporary until link is finished +extension MFTextButton: ModelMoleculeViewProtocol { + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { + guard let model = model as? LinkModel else { return } + setTitle(model.title, for: .normal) + 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) + } + } +} diff --git a/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift b/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift index 419df541..1262994f 100644 --- a/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift +++ b/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift @@ -18,7 +18,7 @@ struct EyebrowHeadlineBodyLinkModel: MoleculeProtocol { public var link: LineModel? } -@objcMembers open class EyebrowHeadlineBodyLink: ViewConstrainingView { +@objcMembers open class EyebrowHeadlineBodyLink: Container { let stack = MoleculeStackView(frame: .zero) let eyebrow = Label.commonLabelB3(true) let headline = Label.commonLabelB1(true) @@ -48,7 +48,7 @@ struct EyebrowHeadlineBodyLinkModel: MoleculeProtocol { stack.stackItems = [StackItem(andContain: eyebrow),StackItem(andContain: headline),StackItem(andContain: body),StackItem(andContain: link)] addSubview(stack) - pinView(toSuperView: stack) + NSLayoutConstraint.constraintPinSubview(toSuperview: stack) } open override func updateView(_ size: CGFloat) { @@ -57,17 +57,23 @@ struct EyebrowHeadlineBodyLinkModel: MoleculeProtocol { } // MARK: - MVMCoreUIMoleculeViewProtocol + + open override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { + super.setWithModel(model, delegateObject, additionalData) + eyebrow.setWithModel(casteModel?.eyeBrow, delegateObject, additionalData) + headline.setWithModel(casteModel?.headline, delegateObject, additionalData) + body.setWithModel(casteModel?.body, delegateObject, additionalData) + link.setWithModel(casteModel?.link, delegateObject, additionalData) + + (stack.stackItems[0].model as? StackItemModel)?.gone = !eyebrow.hasText + (stack.stackItems[1].model as? StackItemModel)?.gone = !headline.hasText + (stack.stackItems[2].model as? StackItemModel)?.gone = !body.hasText + (stack.stackItems[3].model as? StackItemModel)?.gone = ((link.titleLabel?.text?.count) ?? 0) == 0 + stack.restack() + } open override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { - super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - /* eyebrow.setWithJSON(json?.optionalDictionaryForKey("eyebrow"), delegateObject: delegateObject, additionalData: additionalData) - stack.stackItems[0].gone = !eyebrow.hasText - headline.setWithJSON(json?.optionalDictionaryForKey("headline"), delegateObject: delegateObject, additionalData: additionalData) - stack.stackItems[1].gone = !headline.hasText - body.setWithJSON(json?.optionalDictionaryForKey("body"), delegateObject: delegateObject, additionalData: additionalData) - stack.stackItems[2].gone = !body.hasText - link.setWithJSON(json?.optionalDictionaryForKey("link"), delegateObject: delegateObject, additionalData: additionalData) - stack.stackItems[3].gone = link.titleLabel?.text?.count ?? 0 == 0 - stack.restack()*/ + guard let json = json, let model = try? Self.decodeJSONToModel(json: json, type: EyebrowHeadlineBodyLinkModel.self) else { return } + setWithModel(model, delegateObject, additionalData) } open override func reset() { @@ -79,7 +85,7 @@ struct EyebrowHeadlineBodyLinkModel: MoleculeProtocol { body.styleB2(true) } - public override class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { + public static func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { return 65 } }