From ecf34bb34d5ce35d7cbc437171915785b27a7637 Mon Sep 17 00:00:00 2001 From: vasavk Date: Thu, 18 Jul 2019 15:45:52 +0530 Subject: [PATCH 1/4] Added multiLabelListItem - iOS as per MOBFIRST-17824 Signed-off-by: vasavk --- MVMCoreUI.xcodeproj/project.pbxproj | 4 ++ MVMCoreUI/Molecules/MultiLabelListItem.swift | 48 +++++++++++++++++++ .../MVMCoreUIMoleculeMappingObject.m | 1 + 3 files changed, 53 insertions(+) create mode 100644 MVMCoreUI/Molecules/MultiLabelListItem.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 04c2b811..9c0e69fa 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -18,6 +18,7 @@ 01DF55E021F8FAA800CC099B /* MFTextFieldListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */; }; 01DF567021FA5AB300CC099B /* TextFieldListFormViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF566F21FA5AB300CC099B /* TextFieldListFormViewController.swift */; }; 01E569D3223FFFA500327251 /* ThreeLayerViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = D2A5146A2214905000345BFB /* ThreeLayerViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; }; + 18423C7E22E07B260069C7B7 /* MultiLabelListItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18423C7D22E07B260069C7B7 /* MultiLabelListItem.swift */; }; B8200E152280C4CF007245F4 /* ProgressBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8200E142280C4CF007245F4 /* ProgressBar.swift */; }; B8200E192281DC1A007245F4 /* ProgressBarWithLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8200E182281DC1A007245F4 /* ProgressBarWithLabel.swift */; }; D206997721FB8A0B00CAE0DE /* MVMCoreUINavigationController.h in Headers */ = {isa = PBXBuildFile; fileRef = D206997521FB8A0B00CAE0DE /* MVMCoreUINavigationController.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -187,6 +188,7 @@ 01CA51B4229716F60071A6EE /* Switch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Switch.swift; sourceTree = ""; }; 01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MFTextFieldListView.swift; sourceTree = ""; }; 01DF566F21FA5AB300CC099B /* TextFieldListFormViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextFieldListFormViewController.swift; sourceTree = ""; }; + 18423C7D22E07B260069C7B7 /* MultiLabelListItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MultiLabelListItem.swift; sourceTree = ""; }; B8200E142280C4CF007245F4 /* ProgressBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressBar.swift; sourceTree = ""; }; B8200E182281DC1A007245F4 /* ProgressBarWithLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressBarWithLabel.swift; sourceTree = ""; }; D206997521FB8A0B00CAE0DE /* MVMCoreUINavigationController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUINavigationController.h; sourceTree = ""; }; @@ -459,6 +461,7 @@ D29DF10E21E67A77003B2FB9 /* Molecules */ = { isa = PBXGroup; children = ( + 18423C7D22E07B260069C7B7 /* MultiLabelListItem.swift */, 01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */, D29770C721F7C4AE00B2F0D0 /* TopLabelsView.h */, D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */, @@ -901,6 +904,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 18423C7E22E07B260069C7B7 /* MultiLabelListItem.swift in Sources */, D29DF32121ED0CBA003B2FB9 /* LabelView.m in Sources */, DBC4391822442197001AB423 /* CaretView.swift in Sources */, D29770F221F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.m in Sources */, diff --git a/MVMCoreUI/Molecules/MultiLabelListItem.swift b/MVMCoreUI/Molecules/MultiLabelListItem.swift new file mode 100644 index 00000000..adbd7cf3 --- /dev/null +++ b/MVMCoreUI/Molecules/MultiLabelListItem.swift @@ -0,0 +1,48 @@ +// +// multiLabelListItem.swift +// MVMCoreUI +// +// Created by Kanamarlapudi, Vasavi on 15/7/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +@objcMembers public class MultiLabelListItem: ViewConstrainingView { + + var moleculestackview = MoleculeStackView(frame: .zero) + + open override func needsToBeConstrained() -> Bool { + return true + } + + open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) + + let moleculestackjson = json?.optionalDictionaryForKey("moleculeStack") + moleculestackview.setWithJSON(moleculestackjson, delegateObject: delegateObject, additionalData: additionalData) + moleculestackview.useStackSpacingBeforeFirstItem = true + } + + override open func setupView() { + super.setupView() + addSubview(moleculestackview) + + moleculestackview.leftAnchor.constraint(equalTo: self.leftAnchor).isActive = true + moleculestackview.topAnchor.constraint(equalTo: self.topAnchor).isActive = true + let topleftwidthconstraint = NSLayoutConstraint(item: moleculestackview, attribute: .width, relatedBy: .equal, toItem: self, attribute: .width, multiplier: 0.5, constant: 0.0) + topleftwidthconstraint.priority = UILayoutPriority(100) + topleftwidthconstraint.isActive = true + moleculestackview.setContentHuggingPriority(UILayoutPriority(911), for: .horizontal) + moleculestackview.setContentHuggingPriority(UILayoutPriority(911), for: .vertical) + + var bottomconstraint = bottomAnchor.constraint(equalTo: moleculestackview.bottomAnchor, constant: PaddingTwo) + bottomconstraint.priority = UILayoutPriority(249) + bottomconstraint.isActive = true + bottomAnchor.constraint(greaterThanOrEqualTo: moleculestackview.bottomAnchor, constant: PaddingTwo).isActive = true + bottomconstraint = bottomAnchor.constraint(equalTo: moleculestackview.bottomAnchor, constant: PaddingTwo) + bottomconstraint.priority = UILayoutPriority(249) + bottomconstraint.isActive = true + bottomAnchor.constraint(greaterThanOrEqualTo: moleculestackview.bottomAnchor, constant: PaddingTwo).isActive = true + } +} diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index 67279c6e..b45255e4 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -48,6 +48,7 @@ @"image": MFLoadImageView.class, @"leftRightLabelView": LeftRightLabelView.class, @"moduleMolecule": ModuleMolecule.class, + @"multiLabelListItem": MultiLabelListItem.class, @"headlineBody": HeadlineBody.class } mutableCopy]; }); From f2db8528a7baa3999c7fe8f5bdbe7d096458d9d5 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 24 Jul 2019 12:44:45 -0400 Subject: [PATCH 2/4] threeLayer template scroller molecule border color. remove default height fix missing update view --- MVMCoreUI.xcodeproj/project.pbxproj | 8 +++ MVMCoreUI/Atoms/Views/ViewConstrainingView.m | 3 ++ .../ThreeLayerViewController.swift | 2 +- MVMCoreUI/Molecules/Carousel.swift | 11 +++- MVMCoreUI/Molecules/Scroller.swift | 42 +++++++++++++++ MVMCoreUI/Molecules/StandardHeaderView.swift | 5 -- .../MVMCoreUIMoleculeMappingObject.m | 1 + .../MVMCoreUIViewControllerMappingObject.m | 4 +- MVMCoreUI/Templates/ThreeLayerTemplate.swift | 52 +++++++++++++++++++ 9 files changed, 119 insertions(+), 9 deletions(-) create mode 100644 MVMCoreUI/Molecules/Scroller.swift create mode 100644 MVMCoreUI/Templates/ThreeLayerTemplate.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 9323507e..920b1d72 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -169,6 +169,8 @@ D2A6390522CBCE160052ED1F /* MoleculeCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2A6390422CBCE160052ED1F /* MoleculeCollectionViewCell.swift */; }; D2C5001821F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.h in Headers */ = {isa = PBXBuildFile; fileRef = D2C5001621F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.h */; settings = {ATTRIBUTES = (Public, ); }; }; D2C5001921F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m in Sources */ = {isa = PBXBuildFile; fileRef = D2C5001721F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m */; }; + D2D6CD4022E78C1A00D701B8 /* Scroller.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2D6CD3F22E78C1A00D701B8 /* Scroller.swift */; }; + D2D6CD4222E78FAB00D701B8 /* ThreeLayerTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2D6CD4122E78FAB00D701B8 /* ThreeLayerTemplate.swift */; }; D2E1FADB2260D3D200AEFD8C /* MVMCoreUIDelegateObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E1FADA2260D3D200AEFD8C /* MVMCoreUIDelegateObject.swift */; }; D2E1FADD2268B25E00AEFD8C /* MoleculeTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E1FADC2268B25E00AEFD8C /* MoleculeTableViewCell.swift */; }; D2E1FADF2268B8E700AEFD8C /* ThreeLayerTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E1FADE2268B8E700AEFD8C /* ThreeLayerTableViewController.swift */; }; @@ -347,6 +349,8 @@ D2A6390422CBCE160052ED1F /* MoleculeCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeCollectionViewCell.swift; sourceTree = ""; }; D2C5001621F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIViewControllerMappingObject.h; sourceTree = ""; }; D2C5001721F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUIViewControllerMappingObject.m; sourceTree = ""; }; + D2D6CD3F22E78C1A00D701B8 /* Scroller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Scroller.swift; sourceTree = ""; }; + D2D6CD4122E78FAB00D701B8 /* ThreeLayerTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreeLayerTemplate.swift; sourceTree = ""; }; D2E1FADA2260D3D200AEFD8C /* MVMCoreUIDelegateObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MVMCoreUIDelegateObject.swift; sourceTree = ""; }; D2E1FADC2268B25E00AEFD8C /* MoleculeTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeTableViewCell.swift; sourceTree = ""; }; D2E1FADE2268B8E700AEFD8C /* ThreeLayerTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreeLayerTableViewController.swift; sourceTree = ""; }; @@ -443,6 +447,7 @@ D2A514622213643100345BFB /* MoleculeStackCenteredTemplate.swift */, D296E13B2295969C0051EBE7 /* MoleculeListCellProtocol.h */, D2E1FAE02268E81D00AEFD8C /* MoleculeListTemplate.swift */, + D2D6CD4122E78FAB00D701B8 /* ThreeLayerTemplate.swift */, ); path = Templates; sourceTree = ""; @@ -490,6 +495,7 @@ D260D7AF22D65BDD007E7233 /* MVMCoreUIPageControl.h */, D260D7B022D65BDD007E7233 /* MVMCoreUIPageControl.m */, D260D7B522D68509007E7233 /* MVMCoreUIPagingProtocol.h */, + D2D6CD3F22E78C1A00D701B8 /* Scroller.swift */, ); path = Molecules; sourceTree = ""; @@ -949,12 +955,14 @@ D282AABA224131D100C46919 /* MFTransparentGIFView.swift in Sources */, D2A514672213885800345BFB /* StandardHeaderView.swift in Sources */, DBEFFA04225A829700230692 /* Label.swift in Sources */, + D2D6CD4022E78C1A00D701B8 /* Scroller.swift in Sources */, D29DF13021E6851E003B2FB9 /* MVMCoreUITopAlertShortView.m in Sources */, D28B4F8B21FF967C00712C7A /* MVMCoreUIObject.m in Sources */, D260D7B222D65BDD007E7233 /* MVMCoreUIPageControl.m in Sources */, D29DF26D21E6AA0B003B2FB9 /* FLAnimatedImageView.m in Sources */, D29DF2EF21ECEAE1003B2FB9 /* MFFonts.m in Sources */, D282AACB2243C61700C46919 /* ButtonView.swift in Sources */, + D2D6CD4222E78FAB00D701B8 /* ThreeLayerTemplate.swift in Sources */, 0105618F224BBE7700E1557D /* FormValidator+FormParams.swift in Sources */, D2E1FADD2268B25E00AEFD8C /* MoleculeTableViewCell.swift in Sources */, D29DF2AE21E7B3A4003B2FB9 /* MFTextView.m in Sources */, diff --git a/MVMCoreUI/Atoms/Views/ViewConstrainingView.m b/MVMCoreUI/Atoms/Views/ViewConstrainingView.m index 6295a218..4b4ad4eb 100644 --- a/MVMCoreUI/Atoms/Views/ViewConstrainingView.m +++ b/MVMCoreUI/Atoms/Views/ViewConstrainingView.m @@ -307,6 +307,9 @@ if ([self.constrainedView respondsToSelector:@selector(updateView:)]) { [((id)self.constrainedView) updateView:size]; } + if (self.molecule != self.constrainedView) { + [self.molecule updateView:size]; + } [MFStyler setDefaultMarginsForView:self size:size horizontal:self.updateViewHorizontalDefaults vertical:self.updateViewVerticalDefaults]; UIEdgeInsets margins = [MVMCoreUIUtility getMarginsForView:self]; if (self.updateViewHorizontalDefaults) { diff --git a/MVMCoreUI/BaseControllers/ThreeLayerViewController.swift b/MVMCoreUI/BaseControllers/ThreeLayerViewController.swift index 299cdf9b..dae861dd 100644 --- a/MVMCoreUI/BaseControllers/ThreeLayerViewController.swift +++ b/MVMCoreUI/BaseControllers/ThreeLayerViewController.swift @@ -22,7 +22,7 @@ open class ThreeLayerViewController: ProgrammaticScrollViewController { var bottomViewOutsideOfScroll = false private var safeAreaView: UIView? - private var heightConstraint: NSLayoutConstraint? + var heightConstraint: NSLayoutConstraint? open override func updateViews() { super.updateViews() diff --git a/MVMCoreUI/Molecules/Carousel.swift b/MVMCoreUI/Molecules/Carousel.swift index 082fcd6d..db796782 100644 --- a/MVMCoreUI/Molecules/Carousel.swift +++ b/MVMCoreUI/Molecules/Carousel.swift @@ -62,7 +62,7 @@ open class Carousel: ViewConstrainingView { pinView(toSuperView: collectionView) collectionViewHeight = collectionView.heightAnchor.constraint(equalToConstant: 300) - collectionViewHeight?.isActive = true + collectionViewHeight?.isActive = false } open override func updateView(_ size: CGFloat) { @@ -81,12 +81,19 @@ 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) + collectionView.backgroundColor = backgroundColor + collectionView.layer.borderColor = backgroundColor?.cgColor + collectionView.layer.borderWidth = (json?.boolForKey("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")) - collectionViewHeight?.constant = json?.optionalCGFloatForKey("height") ?? 300 + if let height = json?.optionalCGFloatForKey("height") { + collectionViewHeight?.constant = height + collectionViewHeight?.isActive = true + } setupPagingMolecule(json: json?.optionalDictionaryForKey("pagingMolecule"), delegateObject: delegateObject) collectionView.reloadData() } diff --git a/MVMCoreUI/Molecules/Scroller.swift b/MVMCoreUI/Molecules/Scroller.swift new file mode 100644 index 00000000..b76bbb10 --- /dev/null +++ b/MVMCoreUI/Molecules/Scroller.swift @@ -0,0 +1,42 @@ +// +// Scroller.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 7/23/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +@objcMembers open class Scroller: ViewConstrainingView { + public let scrollView = UIScrollView(frame: .zero) + public let contentView = MVMCoreUICommonViewsUtility.commonView() + + override open func setupView() { + super.setupView() + guard scrollView.superview == nil else { + return + } + addConstrainedView(scrollView) + scrollView.addSubview(contentView) + if let constraints = (NSLayoutConstraint.pinView(toSuperview: contentView, useMargins: false) as NSDictionary).allValues as? [NSLayoutConstraint] { + NSLayoutConstraint.activate(constraints) + } + contentView.widthAnchor.constraint(equalTo: scrollView.widthAnchor, multiplier: 1.0, constant: -0.1).isActive = true + } + + 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 0e6c6776..093a2e31 100644 --- a/MVMCoreUI/Molecules/StandardHeaderView.swift +++ b/MVMCoreUI/Molecules/StandardHeaderView.swift @@ -15,11 +15,6 @@ public class StandardHeaderView: ViewConstrainingView { open override func updateView(_ size: CGFloat) { super.updateView(size) separatorView?.updateView(size) - if separatorView?.isHidden ?? true { - let margins = MVMCoreUIUtility.getMarginsFor(self) - MVMCoreUIUtility.setMarginsFor(self, leading: margins.left, top: margins.top, trailing: margins.right, bottom: 0) - bottomPin?.constant = 0 - } } public override func setupView() { diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index 325a8fed..c8a0b040 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -53,6 +53,7 @@ @"carousel": Carousel.class, @"carouselItem": MoleculeCollectionViewCell.class, @"barsPager": MVMCoreUIPageControl.class, + @"scroller": Scroller.class } mutableCopy]; }); return mapping; diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIViewControllerMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIViewControllerMappingObject.m index 4e33da75..e770ede5 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIViewControllerMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIViewControllerMappingObject.m @@ -22,7 +22,9 @@ @"textFieldListForm" : [[MVMCoreViewControllerProgrammaticMappingObject alloc] initWithClass:[TextFieldListFormViewController class]], @"moleculeStack" : [[MVMCoreViewControllerProgrammaticMappingObject alloc] initWithClass:[MoleculeStackTemplate class]], @"centerMoleculeStack" : [[MVMCoreViewControllerProgrammaticMappingObject alloc] initWithClass:[MoleculeStackCenteredTemplate class]], - @"moleculeList" : [[MVMCoreViewControllerProgrammaticMappingObject alloc] initWithClass:[MoleculeListTemplate class]] + @"moleculeList" : [[MVMCoreViewControllerProgrammaticMappingObject alloc] initWithClass:[MoleculeListTemplate class]], + @"threeLayer" : + [[MVMCoreViewControllerProgrammaticMappingObject alloc] initWithClass:[ThreeLayerTemplate class]] } mutableCopy]; }); return viewControllerMapping; diff --git a/MVMCoreUI/Templates/ThreeLayerTemplate.swift b/MVMCoreUI/Templates/ThreeLayerTemplate.swift new file mode 100644 index 00000000..20475a6b --- /dev/null +++ b/MVMCoreUI/Templates/ThreeLayerTemplate.swift @@ -0,0 +1,52 @@ +// +// ThreeLayerTemplate.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 7/23/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +@objcMembers open class ThreeLayerTemplate: ThreeLayerViewController { + + override open func viewDidLoad() { + super.viewDidLoad() + bottomViewOutsideOfScroll = true + // Do any additional setup after loading the view. + } + + open override func newDataBuildScreen() { + 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 + } + 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 + } + 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 + } + return molecule + } + + open override func spaceBetweenMiddleAndBottom() -> CGFloat? { + return 0 + } + + open override func spaceBetweenTopAndMiddle() -> CGFloat? { + return 0 + } +} From 5ebc4b0e31119b3e11b75405f97d2bd5754108df Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 24 Jul 2019 15:38:13 -0400 Subject: [PATCH 3/4] strikethrough fix warning fix. --- MVMCoreUI/Atoms/Views/Label.swift | 2 +- MVMCoreUI/Molecules/Scroller.swift | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index 10b9220e..57a16ad8 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -217,7 +217,7 @@ public typealias ActionBlock = () -> Void case "strikethrough": attributedString.addAttribute(.strikethroughStyle, value: NSUnderlineStyle.thick.rawValue, range: range) - + attributedString.addAttribute(.baselineOffset, value: 0, range: range) case "color": if let colorHex = attribute.optionalStringForKey(KeyTextColor), !colorHex.isEmpty { attributedString.removeAttribute(.foregroundColor, range: range) diff --git a/MVMCoreUI/Molecules/Scroller.swift b/MVMCoreUI/Molecules/Scroller.swift index b76bbb10..cd2949d8 100644 --- a/MVMCoreUI/Molecules/Scroller.swift +++ b/MVMCoreUI/Molecules/Scroller.swift @@ -17,12 +17,14 @@ import UIKit guard scrollView.superview == nil else { return } + translatesAutoresizingMaskIntoConstraints = false + scrollView.translatesAutoresizingMaskIntoConstraints = false addConstrainedView(scrollView) scrollView.addSubview(contentView) - if let constraints = (NSLayoutConstraint.pinView(toSuperview: contentView, useMargins: false) as NSDictionary).allValues as? [NSLayoutConstraint] { - NSLayoutConstraint.activate(constraints) - } - contentView.widthAnchor.constraint(equalTo: scrollView.widthAnchor, multiplier: 1.0, constant: -0.1).isActive = true + NSLayoutConstraint.constraintPinSubview(toSuperview: contentView) + let constraint = contentView.widthAnchor.constraint(equalTo: scrollView.widthAnchor, multiplier: 1.0) + constraint.priority = UILayoutPriority(rawValue: 999) + constraint.isActive = true } open override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { From 245d7d93d6578868e5736b9085287b3a209c822b Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 25 Jul 2019 10:44:14 -0400 Subject: [PATCH 4/4] efficiency commit --- MVMCoreUI/Atoms/Views/MFLoadImageView.swift | 63 +++++++++++++++++---- 1 file changed, 52 insertions(+), 11 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/MFLoadImageView.swift b/MVMCoreUI/Atoms/Views/MFLoadImageView.swift index 996dea95..1debda74 100644 --- a/MVMCoreUI/Atoms/Views/MFLoadImageView.swift +++ b/MVMCoreUI/Atoms/Views/MFLoadImageView.swift @@ -155,6 +155,39 @@ import UIKit return false } + // MARK: - Constraints + + func setHeight(_ height: CGFloat) { + if let heightConstraint = heightConstraint, MVMCoreGetterUtility.cgfequal(heightConstraint.multiplier, 1) { + heightConstraint.constant = height + } else { + heightConstraint?.isActive = false + heightConstraint = imageView.heightAnchor.constraint(equalToConstant: height) + heightConstraint?.priority = UILayoutPriority(rawValue: 900) + } + heightConstraint?.isActive = true + } + + func setWidth(_ width: CGFloat) { + if let widthConstraint = widthConstraint, MVMCoreGetterUtility.cgfequal(widthConstraint.multiplier, 1) { + widthConstraint.constant = width + } else { + widthConstraint = imageView.widthAnchor.constraint(equalToConstant: width) + widthConstraint?.priority = UILayoutPriority(rawValue: 900) + } + widthConstraint?.isActive = true + } + + func layoutWillChange(width: CGFloat?, height: CGFloat?, size: CGSize?) -> Bool { + guard addSizeConstraintsForAspectRatio else { + return false + } + let widthWillChange = !MVMCoreGetterUtility.cgfequal(widthConstraint?.constant ?? 0, width ?? 0) + let heightWillChange = !MVMCoreGetterUtility.cgfequal(heightConstraint?.constant ?? 0, height ?? 0) + let sizeWillChange = (width == nil || height == nil) && !(size?.equalTo(imageView.image?.size ?? CGSize.zero) ?? false) + return widthWillChange || heightWillChange || sizeWillChange + } + // Constrains the image view to be the size provided. Used to size it to the image to fix aspect fit defect. func addConstraints(width: NSNumber?, height: NSNumber?, size: CGSize?) { widthConstraint?.isActive = false @@ -164,21 +197,19 @@ import UIKit } if let width = width, let height = height { - heightConstraint = imageView.heightAnchor.constraint(equalToConstant: height.cgfloat()) - widthConstraint = imageView.widthAnchor.constraint(equalToConstant: width.cgfloat()) + setHeight(height.cgfloat()) + setWidth(width.cgfloat()) } else if let width = width, let size = size { - widthConstraint = imageView.widthAnchor.constraint(equalToConstant: width.cgfloat()) + setWidth(width.cgfloat()) heightConstraint = imageView.heightAnchor.constraint(equalTo: imageView.widthAnchor, multiplier: size.height/size.width) + heightConstraint?.priority = UILayoutPriority(rawValue: 900) + heightConstraint?.isActive = true } else if let height = height, let size = size { - heightConstraint = imageView.heightAnchor.constraint(equalToConstant: height.cgfloat()) + setHeight(height.cgfloat()) widthConstraint = imageView.widthAnchor.constraint(equalTo: imageView.heightAnchor, multiplier: size.width/size.height) + widthConstraint?.priority = UILayoutPriority(rawValue: 900) + widthConstraint?.isActive = true } - widthConstraint?.priority = UILayoutPriority(rawValue: 900) - heightConstraint?.priority = UILayoutPriority(rawValue: 900) - heightConstraint?.isActive = true - widthConstraint?.isActive = true - imageView.setContentHuggingPriority(UILayoutPriority.defaultLow, for: NSLayoutConstraint.Axis.horizontal) - imageView.setContentHuggingPriority(UILayoutPriority.defaultLow, for: NSLayoutConstraint.Axis.vertical) } // MARK: - MVMCoreUIMoleculeViewProtocol functions @@ -200,6 +231,13 @@ import UIKit } let width = json?.optionalCGFloatForKey("width") ?? imageWidth let height = json?.optionalCGFloatForKey("height") ?? imageHeight + // For smoother transitions, set constraints that we know immediately. + if let width = width, addSizeConstraintsForAspectRatio { + setWidth(width) + } + if let height = height, addSizeConstraintsForAspectRatio { + setHeight(height) + } if let imageName = json?.optionalStringForKey("image"), shouldLoadImage(withName: imageName, width: width, height: height) { imageView.image = nil imageView.animatedImage = nil @@ -225,8 +263,11 @@ import UIKit self?.isFallbackImage = isFallbackImage self?.loadingSpinnerHeightConstraint?.constant = 0 self?.loadingSpinner.pause() + let layoutWillChange = self?.layoutWillChange(width: self?.currentImageWidth, height: self?.currentImageHeight, size: image?.size) ?? false self?.addConstraints(width: width, height: height, size: image?.size) - self?.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated?(self!) + if layoutWillChange { + self?.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated?(self!) + } completionHandler(image,data,isFallbackImage) })}