From 00c114bb465b07e2b9ee5c05e361cb03bcfcf2b2 Mon Sep 17 00:00:00 2001 From: Damodaram <> Date: Thu, 28 May 2020 08:46:19 +0530 Subject: [PATCH 01/11] Intial commit --- MVMCoreUI.xcodeproj/project.pbxproj | 16 +++ .../CollectionViewCenterLayout.swift | 61 +++++++++ .../Selectors/TagCollectionViewCell.swift | 32 +++++ .../Atomic/Atoms/Selectors/TagsList.swift | 120 ++++++++++++++++++ .../Atoms/Selectors/TagsListModel.swift | 44 +++++++ MVMCoreUI/Atomic/MoleculeObjectMapping.swift | 2 + 6 files changed, 275 insertions(+) create mode 100644 MVMCoreUI/Atomic/Atoms/Selectors/CollectionViewCenterLayout.swift create mode 100644 MVMCoreUI/Atomic/Atoms/Selectors/TagCollectionViewCell.swift create mode 100644 MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift create mode 100644 MVMCoreUI/Atomic/Atoms/Selectors/TagsListModel.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 9079fc39..76bd5c1f 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -215,6 +215,10 @@ BB2BF0EC2452A9D5001D0FC2 /* ListDeviceComplexButtonSmallModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2BF0EB2452A9D5001D0FC2 /* ListDeviceComplexButtonSmallModel.swift */; }; BB2C968F24330EA7006FF80C /* ListRightVariableTextLinkAllTextAndLinksModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2C968D24330EA7006FF80C /* ListRightVariableTextLinkAllTextAndLinksModel.swift */; }; BB2C969224330F73006FF80C /* ListRightVariableTextLinkAllTextAndLinks.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2C969124330F73006FF80C /* ListRightVariableTextLinkAllTextAndLinks.swift */; }; + BB2FB3BB247E7EBC00DF73CD /* TagCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2FB3BA247E7EBC00DF73CD /* TagCollectionViewCell.swift */; }; + BB2FB3BD247E7EF200DF73CD /* TagsList.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2FB3BC247E7EF200DF73CD /* TagsList.swift */; }; + BB2FB3BF247E7F0900DF73CD /* TagsListModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2FB3BE247E7F0900DF73CD /* TagsListModel.swift */; }; + BB2FB3C1247EC1EB00DF73CD /* CollectionViewCenterLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2FB3C0247EC1EB00DF73CD /* CollectionViewCenterLayout.swift */; }; BB47A586241615EF002BB23C /* ListOneColumnFullWidthTextDividerSubsectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB47A585241615EF002BB23C /* ListOneColumnFullWidthTextDividerSubsectionModel.swift */; }; BB47A588241615FA002BB23C /* ListOneColumnFullWidthTextDividerSubsection.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB47A587241615FA002BB23C /* ListOneColumnFullWidthTextDividerSubsection.swift */; }; BB54C5202434D92F0038326C /* ListRightVariableButtonAllTextAndLinks.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB54C51E2434D92F0038326C /* ListRightVariableButtonAllTextAndLinks.swift */; }; @@ -641,6 +645,10 @@ BB2BF0EB2452A9D5001D0FC2 /* ListDeviceComplexButtonSmallModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListDeviceComplexButtonSmallModel.swift; sourceTree = ""; }; BB2C968D24330EA7006FF80C /* ListRightVariableTextLinkAllTextAndLinksModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListRightVariableTextLinkAllTextAndLinksModel.swift; sourceTree = ""; }; BB2C969124330F73006FF80C /* ListRightVariableTextLinkAllTextAndLinks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListRightVariableTextLinkAllTextAndLinks.swift; sourceTree = ""; }; + BB2FB3BA247E7EBC00DF73CD /* TagCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagCollectionViewCell.swift; sourceTree = ""; }; + BB2FB3BC247E7EF200DF73CD /* TagsList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagsList.swift; sourceTree = ""; }; + BB2FB3BE247E7F0900DF73CD /* TagsListModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagsListModel.swift; sourceTree = ""; }; + BB2FB3C0247EC1EB00DF73CD /* CollectionViewCenterLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionViewCenterLayout.swift; sourceTree = ""; }; BB47A585241615EF002BB23C /* ListOneColumnFullWidthTextDividerSubsectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListOneColumnFullWidthTextDividerSubsectionModel.swift; sourceTree = ""; }; BB47A587241615FA002BB23C /* ListOneColumnFullWidthTextDividerSubsection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListOneColumnFullWidthTextDividerSubsection.swift; sourceTree = ""; }; BB54C51E2434D92F0038326C /* ListRightVariableButtonAllTextAndLinks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListRightVariableButtonAllTextAndLinks.swift; sourceTree = ""; }; @@ -1404,6 +1412,10 @@ D264FAA8243FE17A00D98315 /* Selectors */ = { isa = PBXGroup; children = ( + BB2FB3BA247E7EBC00DF73CD /* TagCollectionViewCell.swift */, + BB2FB3C0247EC1EB00DF73CD /* CollectionViewCenterLayout.swift */, + BB2FB3BC247E7EF200DF73CD /* TagsList.swift */, + BB2FB3BE247E7F0900DF73CD /* TagsListModel.swift */, D264FAAB2441009400D98315 /* RadioBoxCollectionViewCell.swift */, BBAA4F01243D8E3B005AAD5F /* RadioBoxesModel.swift */, BBAA4EFF243D8E3B005AAD5F /* RadioBoxes.swift */, @@ -2090,6 +2102,7 @@ D2755D7B23689C7500485468 /* TableViewCell.swift in Sources */, 0A25209624645AFD000FA9F6 /* TextViewEntryField.swift in Sources */, 014AA72623C501E2006F3E93 /* ContainerModelProtocol.swift in Sources */, + BB2FB3BF247E7F0900DF73CD /* TagsListModel.swift in Sources */, AA11A42123F15D7000D7962F /* ListRightVariablePaymentsModel.swift in Sources */, 011D9626240EBB16000E3791 /* RadioButtonLabelModel.swift in Sources */, 8DDD6C1D244D90B8006A2232 /* ListThreeColumnDataUsage.swift in Sources */, @@ -2155,6 +2168,7 @@ D260105D23D0BCD400764D80 /* Stack.swift in Sources */, 0A7EF85D23D8A95600B2AAD1 /* TextEntryFieldModel.swift in Sources */, BB54C5212434D92F0038326C /* ListRightVariableButtonAllTextAndLinksModel.swift in Sources */, + BB2FB3C1247EC1EB00DF73CD /* CollectionViewCenterLayout.swift in Sources */, D2092349244A51D40044AD09 /* RadioSwatchModel.swift in Sources */, 8DD1E370243B3D0500D8F2DF /* ListThreeColumnInternationalData.swift in Sources */, D2D6CD4222E78FAB00D701B8 /* ThreeLayerTemplate.swift in Sources */, @@ -2224,6 +2238,7 @@ D253BB9E2458751F002DE544 /* BGImageMoleculeModel.swift in Sources */, 0ABD1371237DB0450081388D /* ItemDropdownEntryField.swift in Sources */, 8D24041123E7FB9E009E23BE /* ListLeftVariableIconWithRightCaret.swift in Sources */, + BB2FB3BD247E7EF200DF73CD /* TagsList.swift in Sources */, BBAA4F03243D8E3B005AAD5F /* RadioBoxes.swift in Sources */, D2E1FAE12268E81D00AEFD8C /* MoleculeListTemplate.swift in Sources */, 525019E72406853600EED91C /* ListFourColumnDataUsageDivider.swift in Sources */, @@ -2267,6 +2282,7 @@ 0A21DB83235DFBC500C160A2 /* MdnEntryField.swift in Sources */, 0AE98BB723FF18E9004C5109 /* ArrowModel.swift in Sources */, D28A837D23CCA86A00DFE4FC /* TabsListItemModel.swift in Sources */, + BB2FB3BB247E7EBC00DF73CD /* TagCollectionViewCell.swift in Sources */, 012A88C6238DA34000FE3DA1 /* ModuleMoleculeModel.swift in Sources */, 94C2D9A123872BCC0006CF46 /* LabelAttributeUnderlineModel.swift in Sources */, D20A9A5E2243D3E300ADE781 /* TwoButtonView.swift in Sources */, diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/CollectionViewCenterLayout.swift b/MVMCoreUI/Atomic/Atoms/Selectors/CollectionViewCenterLayout.swift new file mode 100644 index 00000000..671629b9 --- /dev/null +++ b/MVMCoreUI/Atomic/Atoms/Selectors/CollectionViewCenterLayout.swift @@ -0,0 +1,61 @@ +// +// CollectionViewCenterLayout.swift +// MVMCoreUI +// +// Created by Dhamodaram Nandi on 27/05/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import UIKit + +class CollectionViewRow { + var attributes = [UICollectionViewLayoutAttributes]() + var spacing: CGFloat = 0 + + + + init(spacing: CGFloat) { + self.spacing = spacing + } + + func add(attribute: UICollectionViewLayoutAttributes) { + attributes.append(attribute) + } + + var rowWidth: CGFloat { + return attributes.reduce(0, { result, attribute -> CGFloat in + return result + attribute.frame.width + }) + CGFloat(attributes.count - 1) * spacing + } + + func centerLayout(collectionViewWidth: CGFloat) { + let padding = (collectionViewWidth - rowWidth) / 2 + var offset = padding + for attribute in attributes { + attribute.frame.origin.x = offset + offset += attribute.frame.width + spacing + } + } +} + +class UICollectionViewCenterLayout: UICollectionViewFlowLayout { + override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { + guard let attributes = super.layoutAttributesForElements(in: rect) else { + return nil + } + + var rows = [CollectionViewRow]() + var currentRowY: CGFloat = -1 + + for attribute in attributes { + if currentRowY != attribute.frame.origin.y { + currentRowY = attribute.frame.origin.y + rows.append(CollectionViewRow(spacing: 10)) + } + rows.last?.add(attribute: attribute) + } + + rows.forEach { $0.centerLayout(collectionViewWidth: collectionView?.frame.width ?? 0) } + return rows.flatMap { $0.attributes } + } +} diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/TagCollectionViewCell.swift b/MVMCoreUI/Atomic/Atoms/Selectors/TagCollectionViewCell.swift new file mode 100644 index 00000000..086530f0 --- /dev/null +++ b/MVMCoreUI/Atomic/Atoms/Selectors/TagCollectionViewCell.swift @@ -0,0 +1,32 @@ +// +// TagCollectionViewCell.swift +// MVMCoreUI +// +// Created by Dhamodaram Nandi on 27/05/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation +open class TagCollectionViewCell: CollectionViewCell { + public let tagLabel = Label() + + open override func reset() { + super.reset() + backgroundColor = .clear + } + + open override func setupView() { + super.setupView() + layer.borderColor = UIColor.mvmCoolGray6.cgColor + layer.borderWidth = 1 + + tagLabel.numberOfLines = 0 + addMolecule(tagLabel) + MVMCoreUIUtility.setMarginsFor(contentView, leading: 15, top: 13, trailing: 15, bottom: 13) + } + + open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + guard let model = model as? LabelModel else { return } + tagLabel.set(with: model, delegateObject, additionalData) + } +} diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift b/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift new file mode 100644 index 00000000..0f582017 --- /dev/null +++ b/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift @@ -0,0 +1,120 @@ +// +// TagsList.swift +// MVMCoreUI +// +// Created by Dhamodaram Nandi on 27/05/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation +open class TagsList: View { + + public var collectionView: CollectionView! + public var collectionViewHeight: NSLayoutConstraint! + private let itemSpacing: CGFloat = 12.0 + private var tagsListModel: TagsListModel? { + return model as? TagsListModel + } + + private var delegateObject: MVMCoreUIDelegateObject? + + /// The models for the molecules. + public var tags: [LabelModel]? + + + open override func layoutSubviews() { + super.layoutSubviews() + // Accounts for any collection size changes + DispatchQueue.main.async { + self.collectionView.collectionViewLayout.invalidateLayout() + } + } + + // MARK: - MVMCoreViewProtocol + open override func setupView() { + super.setupView() + collectionView = createCollectionView() + addSubview(collectionView) + NSLayoutConstraint.constraintPinSubview(toSuperview: collectionView) + collectionViewHeight = collectionView.heightAnchor.constraint(equalToConstant: 200) + collectionViewHeight?.isActive = true + } + + // MARK: - MoleculeViewProtocol + open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + super.set(with: model, delegateObject, additionalData) + self.delegateObject = delegateObject + + guard let tagsListModel = model as? TagsListModel else { return } + tags = tagsListModel.tags + registerCells() + setHeight() + collectionView.reloadData() + } + + @objc override open func updateView(_ size: CGFloat) { + super.updateView(size) + collectionView.updateView(size) + } + + // MARK: - Creation + + /// Creates the layout for the collection. + open func createCollectionViewLayout() -> UICollectionViewLayout { + let layout = UICollectionViewFlowLayout() + layout.scrollDirection = .vertical + layout.estimatedItemSize = CGSize(width: 140, height: 40) + layout.minimumLineSpacing = 24.0 + layout.minimumInteritemSpacing = itemSpacing + return layout + } + + /// Creates the collection view. + open func createCollectionView() -> CollectionView { + let collection = CollectionView(frame: .zero, collectionViewLayout: createCollectionViewLayout()) + collection.dataSource = self + collection.delegate = self + return collection + } + + /// Registers the cells with the collection view + open func registerCells() { + collectionView.register(TagCollectionViewCell.self, forCellWithReuseIdentifier: "TagCollectionViewCell") + } + + // MARK: - JSON Setters + open func setHeight() { + + } +} + + + +extension TagsList: UICollectionViewDataSource { + open func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + return tags?.count ?? 0 + } + + open func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + guard let molecule = tags?[indexPath.row], + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "TagCollectionViewCell", for: indexPath) as? TagCollectionViewCell else { + fatalError() + } + cell.reset() + cell.set(with: molecule, delegateObject, nil) + cell.layoutIfNeeded() + return cell + } +} + +extension TagsList: UICollectionViewDelegate { + + + + open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + + } + + +} + diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/TagsListModel.swift b/MVMCoreUI/Atomic/Atoms/Selectors/TagsListModel.swift new file mode 100644 index 00000000..4784c381 --- /dev/null +++ b/MVMCoreUI/Atomic/Atoms/Selectors/TagsListModel.swift @@ -0,0 +1,44 @@ +// +// TagsListModel.swift +// MVMCoreUI +// +// Created by Dhamodaram Nandi on 27/05/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation +import Foundation +@objcMembers public class TagsListModel: MoleculeModelProtocol { + + public var backgroundColor: Color? + public static var identifier: String = "tagsList" + public var tags: [LabelModel] + public var borderColor: Color? + + private enum CodingKeys: String, CodingKey { + case moleculeName + case borderColor + case backgroundColor + case tags + + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + borderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .borderColor) + tags = try typeContainer.decode([LabelModel].self, forKey: .tags) + backgroundColor = try typeContainer.decodeIfPresent(Color.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(tags, forKey: .tags) + try container.encodeIfPresent(borderColor, forKey: .borderColor) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + + + } +} diff --git a/MVMCoreUI/Atomic/MoleculeObjectMapping.swift b/MVMCoreUI/Atomic/MoleculeObjectMapping.swift index 18b3fee7..6384ea3c 100644 --- a/MVMCoreUI/Atomic/MoleculeObjectMapping.swift +++ b/MVMCoreUI/Atomic/MoleculeObjectMapping.swift @@ -73,6 +73,8 @@ import Foundation MoleculeObjectMapping.shared()?.register(viewClass: RadioBoxes.self, viewModelClass: RadioBoxesModel.self) MoleculeObjectMapping.shared()?.register(viewClass: Checkbox.self, viewModelClass: CheckboxModel.self) MoleculeObjectMapping.shared()?.register(viewClass: RadioSwatches.self, viewModelClass: RadioSwatchesModel.self) + MoleculeObjectMapping.shared()?.register(viewClass: TagsList.self, viewModelClass: TagsListModel.self) + // Other Atoms MoleculeObjectMapping.shared()?.register(viewClass: ProgressBar.self, viewModelClass: ProgressBarModel.self) From 1dfe49bde60ce4834eafd3d2858d6d398394cae6 Mon Sep 17 00:00:00 2001 From: Damodaram <> Date: Mon, 1 Jun 2020 15:54:01 +0530 Subject: [PATCH 02/11] Custom flow layout implemented --- MVMCoreUI.xcodeproj/project.pbxproj | 16 +++-- .../CollectionViewCenterLayout.swift | 61 ------------------- .../CustomCollectionViewFlowLayout.swift | 34 +++++++++++ MVMCoreUI/Atomic/Atoms/Selectors/Tag.swift | 35 +++++++++++ .../Selectors/TagCollectionViewCell.swift | 10 +-- .../Atomic/Atoms/Selectors/TagModel.swift | 37 +++++++++++ .../Atomic/Atoms/Selectors/TagsList.swift | 37 +++++------ .../Atoms/Selectors/TagsListModel.swift | 15 +++-- MVMCoreUI/Atomic/MoleculeObjectMapping.swift | 2 + 9 files changed, 150 insertions(+), 97 deletions(-) delete mode 100644 MVMCoreUI/Atomic/Atoms/Selectors/CollectionViewCenterLayout.swift create mode 100644 MVMCoreUI/Atomic/Atoms/Selectors/CustomCollectionViewFlowLayout.swift create mode 100644 MVMCoreUI/Atomic/Atoms/Selectors/Tag.swift create mode 100644 MVMCoreUI/Atomic/Atoms/Selectors/TagModel.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index d424780e..8b6e581a 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -222,7 +222,7 @@ BB2FB3BB247E7EBC00DF73CD /* TagCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2FB3BA247E7EBC00DF73CD /* TagCollectionViewCell.swift */; }; BB2FB3BD247E7EF200DF73CD /* TagsList.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2FB3BC247E7EF200DF73CD /* TagsList.swift */; }; BB2FB3BF247E7F0900DF73CD /* TagsListModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2FB3BE247E7F0900DF73CD /* TagsListModel.swift */; }; - BB2FB3C1247EC1EB00DF73CD /* CollectionViewCenterLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2FB3C0247EC1EB00DF73CD /* CollectionViewCenterLayout.swift */; }; + BB2FB3C1247EC1EB00DF73CD /* CustomCollectionViewFlowLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2FB3C0247EC1EB00DF73CD /* CustomCollectionViewFlowLayout.swift */; }; BB47A586241615EF002BB23C /* ListOneColumnFullWidthTextDividerSubsectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB47A585241615EF002BB23C /* ListOneColumnFullWidthTextDividerSubsectionModel.swift */; }; BB47A588241615FA002BB23C /* ListOneColumnFullWidthTextDividerSubsection.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB47A587241615FA002BB23C /* ListOneColumnFullWidthTextDividerSubsection.swift */; }; BB54C5202434D92F0038326C /* ListRightVariableButtonAllTextAndLinks.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB54C51E2434D92F0038326C /* ListRightVariableButtonAllTextAndLinks.swift */; }; @@ -238,6 +238,8 @@ BBAA4F05243D8E3B005AAD5F /* RadioBoxesModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBAA4F01243D8E3B005AAD5F /* RadioBoxesModel.swift */; }; BBBBC87C24374A4900B0F079 /* ListThreeColumnBillChangesDivider.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBBBC87A24374A4900B0F079 /* ListThreeColumnBillChangesDivider.swift */; }; BBBBC87D24374A4900B0F079 /* ListThreeColumnBillChangesDividerModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBBBC87B24374A4900B0F079 /* ListThreeColumnBillChangesDividerModel.swift */; }; + BBC0C4FD24811DBC0087C44F /* Tag.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBC0C4FC24811DBC0087C44F /* Tag.swift */; }; + BBC0C4FF24811DCA0087C44F /* TagModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBC0C4FE24811DCA0087C44F /* TagModel.swift */; }; C003506123AA94CD00B6AC29 /* Button.swift in Sources */ = {isa = PBXBuildFile; fileRef = C003506023AA94CD00B6AC29 /* Button.swift */; }; C07065C42395677300FBF997 /* Link.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07065C32395677300FBF997 /* Link.swift */; }; C695A67F23C9830600BFB94E /* UnOrderedListModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C695A67E23C9830600BFB94E /* UnOrderedListModel.swift */; }; @@ -659,7 +661,7 @@ BB2FB3BA247E7EBC00DF73CD /* TagCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagCollectionViewCell.swift; sourceTree = ""; }; BB2FB3BC247E7EF200DF73CD /* TagsList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagsList.swift; sourceTree = ""; }; BB2FB3BE247E7F0900DF73CD /* TagsListModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagsListModel.swift; sourceTree = ""; }; - BB2FB3C0247EC1EB00DF73CD /* CollectionViewCenterLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionViewCenterLayout.swift; sourceTree = ""; }; + BB2FB3C0247EC1EB00DF73CD /* CustomCollectionViewFlowLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomCollectionViewFlowLayout.swift; sourceTree = ""; }; BB47A585241615EF002BB23C /* ListOneColumnFullWidthTextDividerSubsectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListOneColumnFullWidthTextDividerSubsectionModel.swift; sourceTree = ""; }; BB47A587241615FA002BB23C /* ListOneColumnFullWidthTextDividerSubsection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListOneColumnFullWidthTextDividerSubsection.swift; sourceTree = ""; }; BB54C51E2434D92F0038326C /* ListRightVariableButtonAllTextAndLinks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListRightVariableButtonAllTextAndLinks.swift; sourceTree = ""; }; @@ -675,6 +677,8 @@ BBAA4F01243D8E3B005AAD5F /* RadioBoxesModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RadioBoxesModel.swift; sourceTree = ""; }; BBBBC87A24374A4900B0F079 /* ListThreeColumnBillChangesDivider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListThreeColumnBillChangesDivider.swift; sourceTree = ""; }; BBBBC87B24374A4900B0F079 /* ListThreeColumnBillChangesDividerModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListThreeColumnBillChangesDividerModel.swift; sourceTree = ""; }; + BBC0C4FC24811DBC0087C44F /* Tag.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tag.swift; sourceTree = ""; }; + BBC0C4FE24811DCA0087C44F /* TagModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagModel.swift; sourceTree = ""; }; C003506023AA94CD00B6AC29 /* Button.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Button.swift; sourceTree = ""; }; C07065C32395677300FBF997 /* Link.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Link.swift; sourceTree = ""; }; C695A67E23C9830600BFB94E /* UnOrderedListModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UnOrderedListModel.swift; sourceTree = ""; }; @@ -1441,8 +1445,10 @@ D264FAA8243FE17A00D98315 /* Selectors */ = { isa = PBXGroup; children = ( + BBC0C4FE24811DCA0087C44F /* TagModel.swift */, + BBC0C4FC24811DBC0087C44F /* Tag.swift */, BB2FB3BA247E7EBC00DF73CD /* TagCollectionViewCell.swift */, - BB2FB3C0247EC1EB00DF73CD /* CollectionViewCenterLayout.swift */, + BB2FB3C0247EC1EB00DF73CD /* CustomCollectionViewFlowLayout.swift */, BB2FB3BC247E7EF200DF73CD /* TagsList.swift */, BB2FB3BE247E7F0900DF73CD /* TagsListModel.swift */, D264FAAB2441009400D98315 /* RadioBoxCollectionViewCell.swift */, @@ -2033,6 +2039,7 @@ 94C2D9A923872E5E0006CF46 /* LabelAttributeImageModel.swift in Sources */, DBC4391922442197001AB423 /* DashLine.swift in Sources */, D264FAAA2440F97600D98315 /* CollectionView.swift in Sources */, + BBC0C4FF24811DCA0087C44F /* TagModel.swift in Sources */, 0A7BAD74232A8DC700FB8E22 /* HeadlineBodyButton.swift in Sources */, D2FB151D23A40F1500C20E10 /* MoleculeStackItem.swift in Sources */, AA11A41F23F15D3100D7962F /* ListRightVariablePayments.swift in Sources */, @@ -2198,7 +2205,7 @@ D260105D23D0BCD400764D80 /* Stack.swift in Sources */, 0A7EF85D23D8A95600B2AAD1 /* TextEntryFieldModel.swift in Sources */, BB54C5212434D92F0038326C /* ListRightVariableButtonAllTextAndLinksModel.swift in Sources */, - BB2FB3C1247EC1EB00DF73CD /* CollectionViewCenterLayout.swift in Sources */, + BB2FB3C1247EC1EB00DF73CD /* CustomCollectionViewFlowLayout.swift in Sources */, D2092349244A51D40044AD09 /* RadioSwatchModel.swift in Sources */, 8DD1E370243B3D0500D8F2DF /* ListThreeColumnInternationalData.swift in Sources */, D23EA802247EBED400D60C34 /* ImageBarButtonItem.swift in Sources */, @@ -2232,6 +2239,7 @@ 011B58F223A2AE2C0085F53C /* DropDownListItemModel.swift in Sources */, D2509ED12472ED9B001BFB9D /* NavigationItemModelProtocol.swift in Sources */, 8D448E5524050A46006211BB /* ListOneColumnFullWidthTextAllTextAndLinksModel.swift in Sources */, + BBC0C4FD24811DBC0087C44F /* Tag.swift in Sources */, 94C2D9842386F3F80006CF46 /* LabelAttributeModel.swift in Sources */, 944589212385D6E900DE9FD4 /* DashLineModel.swift in Sources */, D2E2A99623D8CF85000B42E6 /* HeadlineBodyLinkToggleModel.swift in Sources */, diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/CollectionViewCenterLayout.swift b/MVMCoreUI/Atomic/Atoms/Selectors/CollectionViewCenterLayout.swift deleted file mode 100644 index 671629b9..00000000 --- a/MVMCoreUI/Atomic/Atoms/Selectors/CollectionViewCenterLayout.swift +++ /dev/null @@ -1,61 +0,0 @@ -// -// CollectionViewCenterLayout.swift -// MVMCoreUI -// -// Created by Dhamodaram Nandi on 27/05/20. -// Copyright © 2020 Verizon Wireless. All rights reserved. -// - -import UIKit - -class CollectionViewRow { - var attributes = [UICollectionViewLayoutAttributes]() - var spacing: CGFloat = 0 - - - - init(spacing: CGFloat) { - self.spacing = spacing - } - - func add(attribute: UICollectionViewLayoutAttributes) { - attributes.append(attribute) - } - - var rowWidth: CGFloat { - return attributes.reduce(0, { result, attribute -> CGFloat in - return result + attribute.frame.width - }) + CGFloat(attributes.count - 1) * spacing - } - - func centerLayout(collectionViewWidth: CGFloat) { - let padding = (collectionViewWidth - rowWidth) / 2 - var offset = padding - for attribute in attributes { - attribute.frame.origin.x = offset - offset += attribute.frame.width + spacing - } - } -} - -class UICollectionViewCenterLayout: UICollectionViewFlowLayout { - override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { - guard let attributes = super.layoutAttributesForElements(in: rect) else { - return nil - } - - var rows = [CollectionViewRow]() - var currentRowY: CGFloat = -1 - - for attribute in attributes { - if currentRowY != attribute.frame.origin.y { - currentRowY = attribute.frame.origin.y - rows.append(CollectionViewRow(spacing: 10)) - } - rows.last?.add(attribute: attribute) - } - - rows.forEach { $0.centerLayout(collectionViewWidth: collectionView?.frame.width ?? 0) } - return rows.flatMap { $0.attributes } - } -} diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/CustomCollectionViewFlowLayout.swift b/MVMCoreUI/Atomic/Atoms/Selectors/CustomCollectionViewFlowLayout.swift new file mode 100644 index 00000000..aadad8b9 --- /dev/null +++ b/MVMCoreUI/Atomic/Atoms/Selectors/CustomCollectionViewFlowLayout.swift @@ -0,0 +1,34 @@ +// +// CollectionViewCenterLayout.swift +// MVMCoreUI +// +// Created by Dhamodaram Nandi on 27/05/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import UIKit + + +class UICollectionViewCenterLayout: UICollectionViewFlowLayout { + + override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { + let attributesForElementsInRect = super.layoutAttributesForElements(in: rect) + var newAttributesForElementsInRect = [UICollectionViewLayoutAttributes]() + + var leftMargin: CGFloat = 0.0; + + for attributes in attributesForElementsInRect! { + if (attributes.frame.origin.x == self.sectionInset.left) { + leftMargin = self.sectionInset.left + } else { + var newLeftAlignedFrame = attributes.frame + newLeftAlignedFrame.origin.x = leftMargin + attributes.frame = newLeftAlignedFrame + } + leftMargin += attributes.frame.size.width + 8 + newAttributesForElementsInRect.append(attributes) + } + + return newAttributesForElementsInRect + } +} diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/Tag.swift b/MVMCoreUI/Atomic/Atoms/Selectors/Tag.swift new file mode 100644 index 00000000..cd66ff12 --- /dev/null +++ b/MVMCoreUI/Atomic/Atoms/Selectors/Tag.swift @@ -0,0 +1,35 @@ +// +// Tag.swift +// MVMCoreUI +// +// Created by Dhamodaram Nandi on 29/05/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation +@objcMembers open class Tag: View { + + public let label = Label.createLabelRegularBodySmall(true) + + // MARK: - MVMCoreViewProtocol + open override func setupView() { + super.setupView() + layer.borderColor = UIColor.mvmCoolGray6.cgColor + layer.borderWidth = 1 + label.numberOfLines = 1 + addSubview(label) + NSLayoutConstraint.constraintPinSubview(label, pinTop: true, topConstant: 13, pinBottom: true, bottomConstant: 13, pinLeft: true, leftConstant: 15, pinRight: true, rightConstant: 15) + + } + + // MARK: - MoleculeViewProtocol + open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + guard let model = model as? TagModel else { return } + label.set(with: model.label, delegateObject, additionalData) + } + + @objc override open func updateView(_ size: CGFloat) { + super.updateView(size) + } + +} diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/TagCollectionViewCell.swift b/MVMCoreUI/Atomic/Atoms/Selectors/TagCollectionViewCell.swift index 086530f0..11ce0bff 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/TagCollectionViewCell.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/TagCollectionViewCell.swift @@ -8,7 +8,7 @@ import Foundation open class TagCollectionViewCell: CollectionViewCell { - public let tagLabel = Label() + public let tagLabel = Tag() open override func reset() { super.reset() @@ -17,16 +17,12 @@ open class TagCollectionViewCell: CollectionViewCell { open override func setupView() { super.setupView() - layer.borderColor = UIColor.mvmCoolGray6.cgColor - layer.borderWidth = 1 - - tagLabel.numberOfLines = 0 addMolecule(tagLabel) - MVMCoreUIUtility.setMarginsFor(contentView, leading: 15, top: 13, trailing: 15, bottom: 13) + MVMCoreUIUtility.setMarginsFor(contentView, leading: 0, top: 0, trailing: 0, bottom: 0) } open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { - guard let model = model as? LabelModel else { return } + guard let model = model as? TagModel else { return } tagLabel.set(with: model, delegateObject, additionalData) } } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/TagModel.swift b/MVMCoreUI/Atomic/Atoms/Selectors/TagModel.swift new file mode 100644 index 00000000..b2154925 --- /dev/null +++ b/MVMCoreUI/Atomic/Atoms/Selectors/TagModel.swift @@ -0,0 +1,37 @@ +// +// TagModel.swift +// MVMCoreUI +// +// Created by Dhamodaram Nandi on 29/05/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation +@objcMembers public class TagModel: MoleculeModelProtocol { + public static var identifier: String = "tag" + public var label: LabelModel + public var action: ActionModelProtocol + public var backgroundColor: Color? + + private enum CodingKeys: String, CodingKey { + case moleculeName + case label + case action + case backgroundColor + + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + label = try typeContainer.decode(LabelModel.self, forKey: .label) + action = try typeContainer.decodeModel(codingKey: .action) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(moleculeName, forKey: .moleculeName) + try container.encode(label, forKey: .label) + try container.encodeModel(action, forKey: .action) + + } +} diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift b/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift index 0f582017..46bad4ac 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift @@ -15,13 +15,13 @@ open class TagsList: View { private var tagsListModel: TagsListModel? { return model as? TagsListModel } - + private var delegateObject: MVMCoreUIDelegateObject? /// The models for the molecules. - public var tags: [LabelModel]? - - + public var tags: [TagModel]? + + open override func layoutSubviews() { super.layoutSubviews() // Accounts for any collection size changes @@ -48,8 +48,11 @@ open class TagsList: View { guard let tagsListModel = model as? TagsListModel else { return } tags = tagsListModel.tags registerCells() - setHeight() collectionView.reloadData() + if let height = tagsListModel.height { + collectionViewHeight?.constant = CGFloat(height) + collectionViewHeight?.isActive = true + } } @objc override open func updateView(_ size: CGFloat) { @@ -61,14 +64,14 @@ open class TagsList: View { /// Creates the layout for the collection. open func createCollectionViewLayout() -> UICollectionViewLayout { - let layout = UICollectionViewFlowLayout() + let layout = UICollectionViewCenterLayout() layout.scrollDirection = .vertical layout.estimatedItemSize = CGSize(width: 140, height: 40) layout.minimumLineSpacing = 24.0 layout.minimumInteritemSpacing = itemSpacing return layout } - + /// Creates the collection view. open func createCollectionView() -> CollectionView { let collection = CollectionView(frame: .zero, collectionViewLayout: createCollectionViewLayout()) @@ -81,15 +84,15 @@ open class TagsList: View { open func registerCells() { collectionView.register(TagCollectionViewCell.self, forCellWithReuseIdentifier: "TagCollectionViewCell") } - + // MARK: - JSON Setters open func setHeight() { - + let height = collectionView.collectionViewLayout.collectionViewContentSize.height + collectionViewHeight.constant = height + } } - - extension TagsList: UICollectionViewDataSource { open func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return tags?.count ?? 0 @@ -98,7 +101,7 @@ extension TagsList: UICollectionViewDataSource { open func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { guard let molecule = tags?[indexPath.row], let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "TagCollectionViewCell", for: indexPath) as? TagCollectionViewCell else { - fatalError() + fatalError() } cell.reset() cell.set(with: molecule, delegateObject, nil) @@ -108,13 +111,13 @@ extension TagsList: UICollectionViewDataSource { } extension TagsList: UICollectionViewDelegate { - - open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - + guard let tagModel = tags?[indexPath.row] else {return} + if let data = try? tagModel.action.encode(using: JSONEncoder()), + let actionMap = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any]{ + MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: nil, delegateObject: delegateObject) + } } - - } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/TagsListModel.swift b/MVMCoreUI/Atomic/Atoms/Selectors/TagsListModel.swift index 4784c381..0f3eeeab 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/TagsListModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/TagsListModel.swift @@ -12,24 +12,24 @@ import Foundation public var backgroundColor: Color? public static var identifier: String = "tagsList" - public var tags: [LabelModel] + public var tags: [TagModel] public var borderColor: Color? - + public var height: Float? + private enum CodingKeys: String, CodingKey { case moleculeName case borderColor case backgroundColor case tags - + case height } required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) borderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .borderColor) - tags = try typeContainer.decode([LabelModel].self, forKey: .tags) + tags = try typeContainer.decode([TagModel].self, forKey: .tags) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) - - + height = try typeContainer.decodeIfPresent(Float.self, forKey: .height) } public func encode(to encoder: Encoder) throws { @@ -38,7 +38,6 @@ import Foundation try container.encode(tags, forKey: .tags) try container.encodeIfPresent(borderColor, forKey: .borderColor) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) - - + try container.encode(height, forKey: .height) } } diff --git a/MVMCoreUI/Atomic/MoleculeObjectMapping.swift b/MVMCoreUI/Atomic/MoleculeObjectMapping.swift index df74e2a4..b95d0d40 100644 --- a/MVMCoreUI/Atomic/MoleculeObjectMapping.swift +++ b/MVMCoreUI/Atomic/MoleculeObjectMapping.swift @@ -74,6 +74,8 @@ import Foundation MoleculeObjectMapping.shared()?.register(viewClass: Checkbox.self, viewModelClass: CheckboxModel.self) MoleculeObjectMapping.shared()?.register(viewClass: RadioSwatches.self, viewModelClass: RadioSwatchesModel.self) MoleculeObjectMapping.shared()?.register(viewClass: TagsList.self, viewModelClass: TagsListModel.self) + MoleculeObjectMapping.shared()?.register(viewClass: Tag.self, viewModelClass: TagModel.self) + // Other Atoms From 4ae51e4c84c11cbb7cf8b528bd3cc165491057dd Mon Sep 17 00:00:00 2001 From: Damodaram <> Date: Mon, 1 Jun 2020 19:33:11 +0530 Subject: [PATCH 03/11] removed border llogic --- MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift | 8 +------- MVMCoreUI/Atomic/Atoms/Selectors/TagsListModel.swift | 4 ---- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift b/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift index 46bad4ac..2be81d56 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift @@ -84,13 +84,7 @@ open class TagsList: View { open func registerCells() { collectionView.register(TagCollectionViewCell.self, forCellWithReuseIdentifier: "TagCollectionViewCell") } - - // MARK: - JSON Setters - open func setHeight() { - let height = collectionView.collectionViewLayout.collectionViewContentSize.height - collectionViewHeight.constant = height - - } + } extension TagsList: UICollectionViewDataSource { diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/TagsListModel.swift b/MVMCoreUI/Atomic/Atoms/Selectors/TagsListModel.swift index 0f3eeeab..ff24c236 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/TagsListModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/TagsListModel.swift @@ -13,12 +13,10 @@ import Foundation public var backgroundColor: Color? public static var identifier: String = "tagsList" public var tags: [TagModel] - public var borderColor: Color? public var height: Float? private enum CodingKeys: String, CodingKey { case moleculeName - case borderColor case backgroundColor case tags case height @@ -26,7 +24,6 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - borderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .borderColor) tags = try typeContainer.decode([TagModel].self, forKey: .tags) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) height = try typeContainer.decodeIfPresent(Float.self, forKey: .height) @@ -36,7 +33,6 @@ import Foundation var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) try container.encode(tags, forKey: .tags) - try container.encodeIfPresent(borderColor, forKey: .borderColor) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encode(height, forKey: .height) } From 3b12f5942a2408399cbb2510149be99027a67751 Mon Sep 17 00:00:00 2001 From: Damodaram <> Date: Mon, 1 Jun 2020 19:53:55 +0530 Subject: [PATCH 04/11] action model protocol make its to optional --- MVMCoreUI/Atomic/Atoms/Selectors/TagModel.swift | 6 +++--- MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/TagModel.swift b/MVMCoreUI/Atomic/Atoms/Selectors/TagModel.swift index b2154925..a6ee8685 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/TagModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/TagModel.swift @@ -10,7 +10,7 @@ import Foundation @objcMembers public class TagModel: MoleculeModelProtocol { public static var identifier: String = "tag" public var label: LabelModel - public var action: ActionModelProtocol + public var action: ActionModelProtocol? public var backgroundColor: Color? private enum CodingKeys: String, CodingKey { @@ -24,14 +24,14 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) label = try typeContainer.decode(LabelModel.self, forKey: .label) - action = try typeContainer.decodeModel(codingKey: .action) + action = try typeContainer.decodeModelIfPresent(codingKey: .action) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) try container.encode(label, forKey: .label) - try container.encodeModel(action, forKey: .action) + try container.encodeModelIfPresent(action, forKey: .action) } } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift b/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift index 2be81d56..f79d4290 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift @@ -108,7 +108,7 @@ extension TagsList: UICollectionViewDelegate { open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { guard let tagModel = tags?[indexPath.row] else {return} - if let data = try? tagModel.action.encode(using: JSONEncoder()), + if let data = try? tagModel.action?.encode(using: JSONEncoder()), let actionMap = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any]{ MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: nil, delegateObject: delegateObject) } From 0742fe8afbaf3ebfb0781f4b9811396826b383de Mon Sep 17 00:00:00 2001 From: Damodaram <> Date: Fri, 5 Jun 2020 15:25:04 +0530 Subject: [PATCH 05/11] Updated code as per review comments --- MVMCoreUI.xcodeproj/project.pbxproj | 12 ++--- .../CustomCollectionViewFlowLayout.swift | 34 ------------ MVMCoreUI/Atomic/Atoms/Selectors/Tag.swift | 3 +- .../Atomic/Atoms/Selectors/TagModel.swift | 5 +- .../Atomic/Atoms/Selectors/TagsList.swift | 14 +++-- .../Atoms/Selectors/TagsListModel.swift | 5 +- .../UICollectionViewLeftAlignedLayout.swift | 53 +++++++++++++++++++ 7 files changed, 69 insertions(+), 57 deletions(-) delete mode 100644 MVMCoreUI/Atomic/Atoms/Selectors/CustomCollectionViewFlowLayout.swift create mode 100644 MVMCoreUI/Atomic/Atoms/Selectors/UICollectionViewLeftAlignedLayout.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 8b6e581a..98d19f8a 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -215,6 +215,7 @@ AAC6F167243332E400F295C1 /* RadioSwatchesModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAC6F166243332E400F295C1 /* RadioSwatchesModel.swift */; }; BB1D17E0244EAA30001D2002 /* ListDeviceComplexButtonMediumModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB1D17DF244EAA30001D2002 /* ListDeviceComplexButtonMediumModel.swift */; }; BB1D17E2244EAA46001D2002 /* ListDeviceComplexButtonMedium.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB1D17E1244EAA46001D2002 /* ListDeviceComplexButtonMedium.swift */; }; + BB258D37248A259000125E9D /* UICollectionViewLeftAlignedLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB258D36248A259000125E9D /* UICollectionViewLeftAlignedLayout.swift */; }; BB2BF0EA2452A9BB001D0FC2 /* ListDeviceComplexButtonSmall.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2BF0E92452A9BB001D0FC2 /* ListDeviceComplexButtonSmall.swift */; }; BB2BF0EC2452A9D5001D0FC2 /* ListDeviceComplexButtonSmallModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2BF0EB2452A9D5001D0FC2 /* ListDeviceComplexButtonSmallModel.swift */; }; BB2C968F24330EA7006FF80C /* ListRightVariableTextLinkAllTextAndLinksModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2C968D24330EA7006FF80C /* ListRightVariableTextLinkAllTextAndLinksModel.swift */; }; @@ -222,7 +223,6 @@ BB2FB3BB247E7EBC00DF73CD /* TagCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2FB3BA247E7EBC00DF73CD /* TagCollectionViewCell.swift */; }; BB2FB3BD247E7EF200DF73CD /* TagsList.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2FB3BC247E7EF200DF73CD /* TagsList.swift */; }; BB2FB3BF247E7F0900DF73CD /* TagsListModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2FB3BE247E7F0900DF73CD /* TagsListModel.swift */; }; - BB2FB3C1247EC1EB00DF73CD /* CustomCollectionViewFlowLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2FB3C0247EC1EB00DF73CD /* CustomCollectionViewFlowLayout.swift */; }; BB47A586241615EF002BB23C /* ListOneColumnFullWidthTextDividerSubsectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB47A585241615EF002BB23C /* ListOneColumnFullWidthTextDividerSubsectionModel.swift */; }; BB47A588241615FA002BB23C /* ListOneColumnFullWidthTextDividerSubsection.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB47A587241615FA002BB23C /* ListOneColumnFullWidthTextDividerSubsection.swift */; }; BB54C5202434D92F0038326C /* ListRightVariableButtonAllTextAndLinks.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB54C51E2434D92F0038326C /* ListRightVariableButtonAllTextAndLinks.swift */; }; @@ -654,6 +654,7 @@ AAC6F166243332E400F295C1 /* RadioSwatchesModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioSwatchesModel.swift; sourceTree = ""; }; BB1D17DF244EAA30001D2002 /* ListDeviceComplexButtonMediumModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListDeviceComplexButtonMediumModel.swift; sourceTree = ""; }; BB1D17E1244EAA46001D2002 /* ListDeviceComplexButtonMedium.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListDeviceComplexButtonMedium.swift; sourceTree = ""; }; + BB258D36248A259000125E9D /* UICollectionViewLeftAlignedLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UICollectionViewLeftAlignedLayout.swift; sourceTree = ""; }; BB2BF0E92452A9BB001D0FC2 /* ListDeviceComplexButtonSmall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListDeviceComplexButtonSmall.swift; sourceTree = ""; }; BB2BF0EB2452A9D5001D0FC2 /* ListDeviceComplexButtonSmallModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListDeviceComplexButtonSmallModel.swift; sourceTree = ""; }; BB2C968D24330EA7006FF80C /* ListRightVariableTextLinkAllTextAndLinksModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListRightVariableTextLinkAllTextAndLinksModel.swift; sourceTree = ""; }; @@ -661,7 +662,6 @@ BB2FB3BA247E7EBC00DF73CD /* TagCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagCollectionViewCell.swift; sourceTree = ""; }; BB2FB3BC247E7EF200DF73CD /* TagsList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagsList.swift; sourceTree = ""; }; BB2FB3BE247E7F0900DF73CD /* TagsListModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagsListModel.swift; sourceTree = ""; }; - BB2FB3C0247EC1EB00DF73CD /* CustomCollectionViewFlowLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomCollectionViewFlowLayout.swift; sourceTree = ""; }; BB47A585241615EF002BB23C /* ListOneColumnFullWidthTextDividerSubsectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListOneColumnFullWidthTextDividerSubsectionModel.swift; sourceTree = ""; }; BB47A587241615FA002BB23C /* ListOneColumnFullWidthTextDividerSubsection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListOneColumnFullWidthTextDividerSubsection.swift; sourceTree = ""; }; BB54C51E2434D92F0038326C /* ListRightVariableButtonAllTextAndLinks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListRightVariableButtonAllTextAndLinks.swift; sourceTree = ""; }; @@ -1445,12 +1445,12 @@ D264FAA8243FE17A00D98315 /* Selectors */ = { isa = PBXGroup; children = ( + BB2FB3BE247E7F0900DF73CD /* TagsListModel.swift */, + BB2FB3BC247E7EF200DF73CD /* TagsList.swift */, + BB258D36248A259000125E9D /* UICollectionViewLeftAlignedLayout.swift */, BBC0C4FE24811DCA0087C44F /* TagModel.swift */, BBC0C4FC24811DBC0087C44F /* Tag.swift */, BB2FB3BA247E7EBC00DF73CD /* TagCollectionViewCell.swift */, - BB2FB3C0247EC1EB00DF73CD /* CustomCollectionViewFlowLayout.swift */, - BB2FB3BC247E7EF200DF73CD /* TagsList.swift */, - BB2FB3BE247E7F0900DF73CD /* TagsListModel.swift */, D264FAAB2441009400D98315 /* RadioBoxCollectionViewCell.swift */, BBAA4F01243D8E3B005AAD5F /* RadioBoxesModel.swift */, BBAA4EFF243D8E3B005AAD5F /* RadioBoxes.swift */, @@ -2205,7 +2205,6 @@ D260105D23D0BCD400764D80 /* Stack.swift in Sources */, 0A7EF85D23D8A95600B2AAD1 /* TextEntryFieldModel.swift in Sources */, BB54C5212434D92F0038326C /* ListRightVariableButtonAllTextAndLinksModel.swift in Sources */, - BB2FB3C1247EC1EB00DF73CD /* CustomCollectionViewFlowLayout.swift in Sources */, D2092349244A51D40044AD09 /* RadioSwatchModel.swift in Sources */, 8DD1E370243B3D0500D8F2DF /* ListThreeColumnInternationalData.swift in Sources */, D23EA802247EBED400D60C34 /* ImageBarButtonItem.swift in Sources */, @@ -2298,6 +2297,7 @@ 012A88DB238ED45900FE3DA1 /* CarouselModel.swift in Sources */, D2092355244FA0FD0044AD09 /* ThreeLayerTemplateModelProtocol.swift in Sources */, 0AE14F64238315D2005417F8 /* TextField.swift in Sources */, + BB258D37248A259000125E9D /* UICollectionViewLeftAlignedLayout.swift in Sources */, 0AB764D124460F6300E7FE72 /* UIDatePicker+Extension.swift in Sources */, D253BB9C245874F8002DE544 /* BGImageMolecule.swift in Sources */, D2C78CD224228BBD00B69FDE /* ActionOpenPanelModel.swift in Sources */, diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/CustomCollectionViewFlowLayout.swift b/MVMCoreUI/Atomic/Atoms/Selectors/CustomCollectionViewFlowLayout.swift deleted file mode 100644 index aadad8b9..00000000 --- a/MVMCoreUI/Atomic/Atoms/Selectors/CustomCollectionViewFlowLayout.swift +++ /dev/null @@ -1,34 +0,0 @@ -// -// CollectionViewCenterLayout.swift -// MVMCoreUI -// -// Created by Dhamodaram Nandi on 27/05/20. -// Copyright © 2020 Verizon Wireless. All rights reserved. -// - -import UIKit - - -class UICollectionViewCenterLayout: UICollectionViewFlowLayout { - - override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { - let attributesForElementsInRect = super.layoutAttributesForElements(in: rect) - var newAttributesForElementsInRect = [UICollectionViewLayoutAttributes]() - - var leftMargin: CGFloat = 0.0; - - for attributes in attributesForElementsInRect! { - if (attributes.frame.origin.x == self.sectionInset.left) { - leftMargin = self.sectionInset.left - } else { - var newLeftAlignedFrame = attributes.frame - newLeftAlignedFrame.origin.x = leftMargin - attributes.frame = newLeftAlignedFrame - } - leftMargin += attributes.frame.size.width + 8 - newAttributesForElementsInRect.append(attributes) - } - - return newAttributesForElementsInRect - } -} diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/Tag.swift b/MVMCoreUI/Atomic/Atoms/Selectors/Tag.swift index cd66ff12..92624647 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/Tag.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/Tag.swift @@ -19,7 +19,6 @@ import Foundation label.numberOfLines = 1 addSubview(label) NSLayoutConstraint.constraintPinSubview(label, pinTop: true, topConstant: 13, pinBottom: true, bottomConstant: 13, pinLeft: true, leftConstant: 15, pinRight: true, rightConstant: 15) - } // MARK: - MoleculeViewProtocol @@ -30,6 +29,6 @@ import Foundation @objc override open func updateView(_ size: CGFloat) { super.updateView(size) + label.updateView(size) } - } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/TagModel.swift b/MVMCoreUI/Atomic/Atoms/Selectors/TagModel.swift index a6ee8685..3ab66b0d 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/TagModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/TagModel.swift @@ -18,13 +18,13 @@ import Foundation case label case action case backgroundColor - } required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) label = try typeContainer.decode(LabelModel.self, forKey: .label) - action = try typeContainer.decodeModelIfPresent(codingKey: .action) + action = try typeContainer.decodeModelIfPresent(codingKey: .action) + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) } public func encode(to encoder: Encoder) throws { @@ -32,6 +32,5 @@ import Foundation try container.encode(moleculeName, forKey: .moleculeName) try container.encode(label, forKey: .label) try container.encodeModelIfPresent(action, forKey: .action) - } } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift b/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift index f79d4290..bd3603dd 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift @@ -11,7 +11,6 @@ open class TagsList: View { public var collectionView: CollectionView! public var collectionViewHeight: NSLayoutConstraint! - private let itemSpacing: CGFloat = 12.0 private var tagsListModel: TagsListModel? { return model as? TagsListModel } @@ -27,6 +26,9 @@ open class TagsList: View { // Accounts for any collection size changes DispatchQueue.main.async { self.collectionView.collectionViewLayout.invalidateLayout() + self.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self) + self.collectionViewHeight.constant = self.collectionView.contentSize.height + self.collectionViewHeight.isActive = true } } @@ -36,7 +38,7 @@ open class TagsList: View { collectionView = createCollectionView() addSubview(collectionView) NSLayoutConstraint.constraintPinSubview(toSuperview: collectionView) - collectionViewHeight = collectionView.heightAnchor.constraint(equalToConstant: 200) + collectionViewHeight = collectionView.heightAnchor.constraint(equalToConstant: 300) collectionViewHeight?.isActive = true } @@ -49,10 +51,6 @@ open class TagsList: View { tags = tagsListModel.tags registerCells() collectionView.reloadData() - if let height = tagsListModel.height { - collectionViewHeight?.constant = CGFloat(height) - collectionViewHeight?.isActive = true - } } @objc override open func updateView(_ size: CGFloat) { @@ -64,11 +62,10 @@ open class TagsList: View { /// Creates the layout for the collection. open func createCollectionViewLayout() -> UICollectionViewLayout { - let layout = UICollectionViewCenterLayout() + let layout = UICollectionViewLeftAlignedLayout() layout.scrollDirection = .vertical layout.estimatedItemSize = CGSize(width: 140, height: 40) layout.minimumLineSpacing = 24.0 - layout.minimumInteritemSpacing = itemSpacing return layout } @@ -108,6 +105,7 @@ extension TagsList: UICollectionViewDelegate { open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { guard let tagModel = tags?[indexPath.row] else {return} + Button. if let data = try? tagModel.action?.encode(using: JSONEncoder()), let actionMap = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any]{ MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: nil, delegateObject: delegateObject) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/TagsListModel.swift b/MVMCoreUI/Atomic/Atoms/Selectors/TagsListModel.swift index ff24c236..75d7c4e9 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/TagsListModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/TagsListModel.swift @@ -13,8 +13,7 @@ import Foundation public var backgroundColor: Color? public static var identifier: String = "tagsList" public var tags: [TagModel] - public var height: Float? - + private enum CodingKeys: String, CodingKey { case moleculeName case backgroundColor @@ -26,7 +25,6 @@ import Foundation let typeContainer = try decoder.container(keyedBy: CodingKeys.self) tags = try typeContainer.decode([TagModel].self, forKey: .tags) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) - height = try typeContainer.decodeIfPresent(Float.self, forKey: .height) } public func encode(to encoder: Encoder) throws { @@ -34,6 +32,5 @@ import Foundation try container.encode(moleculeName, forKey: .moleculeName) try container.encode(tags, forKey: .tags) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) - try container.encode(height, forKey: .height) } } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/UICollectionViewLeftAlignedLayout.swift b/MVMCoreUI/Atomic/Atoms/Selectors/UICollectionViewLeftAlignedLayout.swift new file mode 100644 index 00000000..96dc3a63 --- /dev/null +++ b/MVMCoreUI/Atomic/Atoms/Selectors/UICollectionViewLeftAlignedLayout.swift @@ -0,0 +1,53 @@ +// +// UICollectionViewLeftAlignedLayout.swift +// MVMCoreUI +// +// Created by Dhamodaram Nandi on 05/06/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation + +class UICollectionViewLeftAlignedLayout: UICollectionViewFlowLayout { + override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { + guard let attributes = super.layoutAttributesForElements(in: rect) else { + return nil + } + + var rows = [Row]() + var currentRowY: CGFloat = -1 + + for attribute in attributes { + if currentRowY != attribute.frame.origin.y { + currentRowY = attribute.frame.origin.y + rows.append(Row(spacing: 10)) + } + rows.last?.add(attribute: attribute) + } + + rows.forEach { $0.tagLayout(collectionViewWidth: collectionView?.frame.width ?? 0) } + return rows.flatMap { $0.attributes } + } +} +class Row { + + var attributes = [UICollectionViewLayoutAttributes]() + var spacing: CGFloat = 0 + + init(spacing: CGFloat) { + self.spacing = spacing + } + + func add(attribute: UICollectionViewLayoutAttributes) { + attributes.append(attribute) + } + + func tagLayout(collectionViewWidth: CGFloat) { + let padding = 8 + var offset = padding + for attribute in attributes { + attribute.frame.origin.x = CGFloat(offset) + offset += Int(attribute.frame.width + spacing) + } + } +} From 02d93c56ac1df2f51531eba5699e1630f20ceac8 Mon Sep 17 00:00:00 2001 From: Damodaram <> Date: Fri, 5 Jun 2020 15:36:19 +0530 Subject: [PATCH 06/11] removed spaces --- MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift | 1 - .../Atoms/Selectors/UICollectionViewLeftAlignedLayout.swift | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift b/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift index bd3603dd..b13ff216 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift @@ -105,7 +105,6 @@ extension TagsList: UICollectionViewDelegate { open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { guard let tagModel = tags?[indexPath.row] else {return} - Button. if let data = try? tagModel.action?.encode(using: JSONEncoder()), let actionMap = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any]{ MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: nil, delegateObject: delegateObject) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/UICollectionViewLeftAlignedLayout.swift b/MVMCoreUI/Atomic/Atoms/Selectors/UICollectionViewLeftAlignedLayout.swift index 96dc3a63..ef01da4a 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/UICollectionViewLeftAlignedLayout.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/UICollectionViewLeftAlignedLayout.swift @@ -29,6 +29,7 @@ class UICollectionViewLeftAlignedLayout: UICollectionViewFlowLayout { return rows.flatMap { $0.attributes } } } + class Row { var attributes = [UICollectionViewLayoutAttributes]() From c3e4786d5bda79119be3570b3ffec6b7e9380138 Mon Sep 17 00:00:00 2001 From: Damodaram <> Date: Fri, 5 Jun 2020 17:16:38 +0530 Subject: [PATCH 07/11] Updated to performButtonAction method --- MVMCoreUI/Atomic/Atoms/Selectors/Tag.swift | 1 + .../Selectors/TagCollectionViewCell.swift | 1 + .../Atomic/Atoms/Selectors/TagModel.swift | 1 + .../Atomic/Atoms/Selectors/TagsList.swift | 18 +++++------------- .../Atomic/Atoms/Selectors/TagsListModel.swift | 4 ++-- .../UICollectionViewLeftAlignedLayout.swift | 9 +++------ 6 files changed, 13 insertions(+), 21 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/Tag.swift b/MVMCoreUI/Atomic/Atoms/Selectors/Tag.swift index 92624647..1080c7a9 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/Tag.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/Tag.swift @@ -7,6 +7,7 @@ // import Foundation + @objcMembers open class Tag: View { public let label = Label.createLabelRegularBodySmall(true) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/TagCollectionViewCell.swift b/MVMCoreUI/Atomic/Atoms/Selectors/TagCollectionViewCell.swift index 11ce0bff..2b1406d5 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/TagCollectionViewCell.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/TagCollectionViewCell.swift @@ -7,6 +7,7 @@ // import Foundation + open class TagCollectionViewCell: CollectionViewCell { public let tagLabel = Tag() diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/TagModel.swift b/MVMCoreUI/Atomic/Atoms/Selectors/TagModel.swift index 3ab66b0d..e0247e71 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/TagModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/TagModel.swift @@ -7,6 +7,7 @@ // import Foundation + @objcMembers public class TagModel: MoleculeModelProtocol { public static var identifier: String = "tag" public var label: LabelModel diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift b/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift index b13ff216..5a30f597 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift @@ -7,7 +7,8 @@ // import Foundation -open class TagsList: View { + +open class TagsList: View,MFButtonProtocol { public var collectionView: CollectionView! public var collectionViewHeight: NSLayoutConstraint! @@ -20,15 +21,14 @@ open class TagsList: View { /// The models for the molecules. public var tags: [TagModel]? - open override func layoutSubviews() { super.layoutSubviews() // Accounts for any collection size changes DispatchQueue.main.async { self.collectionView.collectionViewLayout.invalidateLayout() - self.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self) self.collectionViewHeight.constant = self.collectionView.contentSize.height self.collectionViewHeight.isActive = true + self.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self) } } @@ -46,7 +46,6 @@ open class TagsList: View { open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) self.delegateObject = delegateObject - guard let tagsListModel = model as? TagsListModel else { return } tags = tagsListModel.tags registerCells() @@ -59,7 +58,6 @@ open class TagsList: View { } // MARK: - Creation - /// Creates the layout for the collection. open func createCollectionViewLayout() -> UICollectionViewLayout { let layout = UICollectionViewLeftAlignedLayout() @@ -81,7 +79,6 @@ open class TagsList: View { open func registerCells() { collectionView.register(TagCollectionViewCell.self, forCellWithReuseIdentifier: "TagCollectionViewCell") } - } extension TagsList: UICollectionViewDataSource { @@ -102,13 +99,8 @@ extension TagsList: UICollectionViewDataSource { } extension TagsList: UICollectionViewDelegate { - open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - guard let tagModel = tags?[indexPath.row] else {return} - if let data = try? tagModel.action?.encode(using: JSONEncoder()), - let actionMap = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any]{ - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: nil, delegateObject: delegateObject) - } + guard let tagModel = tags?[indexPath.row], let tagAction = tagModel.action else {return} + Button.performButtonAction(with: tagAction, button: self, delegateObject: delegateObject, additionalData: nil) } } - diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/TagsListModel.swift b/MVMCoreUI/Atomic/Atoms/Selectors/TagsListModel.swift index 75d7c4e9..86de5206 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/TagsListModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/TagsListModel.swift @@ -7,13 +7,13 @@ // import Foundation -import Foundation + @objcMembers public class TagsListModel: MoleculeModelProtocol { public var backgroundColor: Color? public static var identifier: String = "tagsList" public var tags: [TagModel] - + private enum CodingKeys: String, CodingKey { case moleculeName case backgroundColor diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/UICollectionViewLeftAlignedLayout.swift b/MVMCoreUI/Atomic/Atoms/Selectors/UICollectionViewLeftAlignedLayout.swift index ef01da4a..d5568b57 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/UICollectionViewLeftAlignedLayout.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/UICollectionViewLeftAlignedLayout.swift @@ -13,10 +13,8 @@ class UICollectionViewLeftAlignedLayout: UICollectionViewFlowLayout { guard let attributes = super.layoutAttributesForElements(in: rect) else { return nil } - var rows = [Row]() var currentRowY: CGFloat = -1 - for attribute in attributes { if currentRowY != attribute.frame.origin.y { currentRowY = attribute.frame.origin.y @@ -24,7 +22,6 @@ class UICollectionViewLeftAlignedLayout: UICollectionViewFlowLayout { } rows.last?.add(attribute: attribute) } - rows.forEach { $0.tagLayout(collectionViewWidth: collectionView?.frame.width ?? 0) } return rows.flatMap { $0.attributes } } @@ -34,15 +31,15 @@ class Row { var attributes = [UICollectionViewLayoutAttributes]() var spacing: CGFloat = 0 - + init(spacing: CGFloat) { self.spacing = spacing } - + func add(attribute: UICollectionViewLayoutAttributes) { attributes.append(attribute) } - + func tagLayout(collectionViewWidth: CGFloat) { let padding = 8 var offset = padding From 72fa1fe9cdcfe84f222b4e93fef4519bd536d48b Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Fri, 5 Jun 2020 12:19:21 -0400 Subject: [PATCH 08/11] minor cleaning --- MVMCoreUI.xcodeproj/project.pbxproj | 42 +++++++++++++------ .../{Selectors => FormFields/Tags}/Tag.swift | 6 +++ .../Tags}/TagCollectionViewCell.swift | 0 .../Tags}/TagModel.swift | 0 .../Tags/Tags.swift} | 20 ++++----- .../Tags/TagsModel.swift} | 8 ++-- .../TextFields/BaseDropdownEntryField.swift | 0 .../BaseDropdownEntryFieldModel.swift | 0 .../TextFields/DateDropdownEntryField.swift | 0 .../DateDropdownEntryFieldModel.swift | 0 .../TextFields/DigitBox.swift | 0 .../TextFields/DigitEntryField.swift | 0 .../TextFields/DigitEntryFieldModel.swift | 0 .../TextFields/EntryField.swift | 0 .../TextFields/EntryFieldModel.swift | 0 .../TextFields/ItemDropdownEntryField.swift | 0 .../ItemDropdownEntryFieldModel.swift | 0 .../TextFields/MdnEntryField.swift | 0 .../TextFields/MdnEntryFieldModel.swift | 0 .../TextFields/TextEntryField.swift | 0 .../TextFields/TextEntryFieldModel.swift | 0 .../TextFields/TextViewEntryField.swift | 0 .../TextFields/TextViewEntryFieldModel.swift | 0 MVMCoreUI/Atomic/MoleculeObjectMapping.swift | 2 +- 24 files changed, 48 insertions(+), 30 deletions(-) rename MVMCoreUI/Atomic/Atoms/{Selectors => FormFields/Tags}/Tag.swift (90%) rename MVMCoreUI/Atomic/Atoms/{Selectors => FormFields/Tags}/TagCollectionViewCell.swift (100%) rename MVMCoreUI/Atomic/Atoms/{Selectors => FormFields/Tags}/TagModel.swift (100%) rename MVMCoreUI/Atomic/Atoms/{Selectors/TagsList.swift => FormFields/Tags/Tags.swift} (87%) rename MVMCoreUI/Atomic/Atoms/{Selectors/TagsListModel.swift => FormFields/Tags/TagsModel.swift} (85%) rename MVMCoreUI/Atomic/Atoms/{ => FormFields}/TextFields/BaseDropdownEntryField.swift (100%) rename MVMCoreUI/Atomic/Atoms/{ => FormFields}/TextFields/BaseDropdownEntryFieldModel.swift (100%) rename MVMCoreUI/Atomic/Atoms/{ => FormFields}/TextFields/DateDropdownEntryField.swift (100%) rename MVMCoreUI/Atomic/Atoms/{ => FormFields}/TextFields/DateDropdownEntryFieldModel.swift (100%) rename MVMCoreUI/Atomic/Atoms/{ => FormFields}/TextFields/DigitBox.swift (100%) rename MVMCoreUI/Atomic/Atoms/{ => FormFields}/TextFields/DigitEntryField.swift (100%) rename MVMCoreUI/Atomic/Atoms/{ => FormFields}/TextFields/DigitEntryFieldModel.swift (100%) rename MVMCoreUI/Atomic/Atoms/{ => FormFields}/TextFields/EntryField.swift (100%) rename MVMCoreUI/Atomic/Atoms/{ => FormFields}/TextFields/EntryFieldModel.swift (100%) rename MVMCoreUI/Atomic/Atoms/{ => FormFields}/TextFields/ItemDropdownEntryField.swift (100%) rename MVMCoreUI/Atomic/Atoms/{ => FormFields}/TextFields/ItemDropdownEntryFieldModel.swift (100%) rename MVMCoreUI/Atomic/Atoms/{ => FormFields}/TextFields/MdnEntryField.swift (100%) rename MVMCoreUI/Atomic/Atoms/{ => FormFields}/TextFields/MdnEntryFieldModel.swift (100%) rename MVMCoreUI/Atomic/Atoms/{ => FormFields}/TextFields/TextEntryField.swift (100%) rename MVMCoreUI/Atomic/Atoms/{ => FormFields}/TextFields/TextEntryFieldModel.swift (100%) rename MVMCoreUI/Atomic/Atoms/{ => FormFields}/TextFields/TextViewEntryField.swift (100%) rename MVMCoreUI/Atomic/Atoms/{ => FormFields}/TextFields/TextViewEntryFieldModel.swift (100%) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 0369c673..2521b6d2 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -221,8 +221,8 @@ BB2C968F24330EA7006FF80C /* ListRightVariableTextLinkAllTextAndLinksModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2C968D24330EA7006FF80C /* ListRightVariableTextLinkAllTextAndLinksModel.swift */; }; BB2C969224330F73006FF80C /* ListRightVariableTextLinkAllTextAndLinks.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2C969124330F73006FF80C /* ListRightVariableTextLinkAllTextAndLinks.swift */; }; BB2FB3BB247E7EBC00DF73CD /* TagCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2FB3BA247E7EBC00DF73CD /* TagCollectionViewCell.swift */; }; - BB2FB3BD247E7EF200DF73CD /* TagsList.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2FB3BC247E7EF200DF73CD /* TagsList.swift */; }; - BB2FB3BF247E7F0900DF73CD /* TagsListModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2FB3BE247E7F0900DF73CD /* TagsListModel.swift */; }; + BB2FB3BD247E7EF200DF73CD /* Tags.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2FB3BC247E7EF200DF73CD /* Tags.swift */; }; + BB2FB3BF247E7F0900DF73CD /* TagsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2FB3BE247E7F0900DF73CD /* TagsModel.swift */; }; BB47A586241615EF002BB23C /* ListOneColumnFullWidthTextDividerSubsectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB47A585241615EF002BB23C /* ListOneColumnFullWidthTextDividerSubsectionModel.swift */; }; BB47A588241615FA002BB23C /* ListOneColumnFullWidthTextDividerSubsection.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB47A587241615FA002BB23C /* ListOneColumnFullWidthTextDividerSubsection.swift */; }; BB54C5202434D92F0038326C /* ListRightVariableButtonAllTextAndLinks.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB54C51E2434D92F0038326C /* ListRightVariableButtonAllTextAndLinks.swift */; }; @@ -664,8 +664,8 @@ BB2C968D24330EA7006FF80C /* ListRightVariableTextLinkAllTextAndLinksModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListRightVariableTextLinkAllTextAndLinksModel.swift; sourceTree = ""; }; BB2C969124330F73006FF80C /* ListRightVariableTextLinkAllTextAndLinks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListRightVariableTextLinkAllTextAndLinks.swift; sourceTree = ""; }; BB2FB3BA247E7EBC00DF73CD /* TagCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagCollectionViewCell.swift; sourceTree = ""; }; - BB2FB3BC247E7EF200DF73CD /* TagsList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagsList.swift; sourceTree = ""; }; - BB2FB3BE247E7F0900DF73CD /* TagsListModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagsListModel.swift; sourceTree = ""; }; + BB2FB3BC247E7EF200DF73CD /* Tags.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tags.swift; sourceTree = ""; }; + BB2FB3BE247E7F0900DF73CD /* TagsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagsModel.swift; sourceTree = ""; }; BB47A585241615EF002BB23C /* ListOneColumnFullWidthTextDividerSubsectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListOneColumnFullWidthTextDividerSubsectionModel.swift; sourceTree = ""; }; BB47A587241615FA002BB23C /* ListOneColumnFullWidthTextDividerSubsection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListOneColumnFullWidthTextDividerSubsection.swift; sourceTree = ""; }; BB54C51E2434D92F0038326C /* ListRightVariableButtonAllTextAndLinks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListRightVariableButtonAllTextAndLinks.swift; sourceTree = ""; }; @@ -1456,12 +1456,6 @@ D264FAA8243FE17A00D98315 /* Selectors */ = { isa = PBXGroup; children = ( - BB2FB3BE247E7F0900DF73CD /* TagsListModel.swift */, - BB2FB3BC247E7EF200DF73CD /* TagsList.swift */, - BB258D36248A259000125E9D /* UICollectionViewLeftAlignedLayout.swift */, - BBC0C4FE24811DCA0087C44F /* TagModel.swift */, - BBC0C4FC24811DBC0087C44F /* Tag.swift */, - BB2FB3BA247E7EBC00DF73CD /* TagCollectionViewCell.swift */, D264FAAB2441009400D98315 /* RadioBoxCollectionViewCell.swift */, BBAA4F01243D8E3B005AAD5F /* RadioBoxesModel.swift */, BBAA4EFF243D8E3B005AAD5F /* RadioBoxes.swift */, @@ -1561,8 +1555,8 @@ D29DF10D21E67A70003B2FB9 /* Atoms */ = { isa = PBXGroup; children = ( + D2BEFEF5248A954C00FAB3A9 /* FormFields */, D264FAA8243FE17A00D98315 /* Selectors */, - D29DF22B21E6A0FA003B2FB9 /* TextFields */, D29DF17D21E69E26003B2FB9 /* Views */, D29DF16821E69E1F003B2FB9 /* Buttons */, ); @@ -1875,6 +1869,7 @@ D20923582450ECE00044AD09 /* TableView.swift */, D2755D7A23689C7500485468 /* TableViewCell.swift */, D21B7F70243BAC1600051ABF /* CollectionViewCell.swift */, + BB258D36248A259000125E9D /* UICollectionViewLeftAlignedLayout.swift */, D264FAA92440F97600D98315 /* CollectionView.swift */, 0A5D59C323AD488600EFD9E9 /* Protocols */, 0A7918F423F5E7EA00772FF4 /* ImageView.swift */, @@ -1883,6 +1878,27 @@ path = BaseClasses; sourceTree = ""; }; + D2BEFEF5248A954C00FAB3A9 /* FormFields */ = { + isa = PBXGroup; + children = ( + D2BEFEF6248A957A00FAB3A9 /* Tags */, + D29DF22B21E6A0FA003B2FB9 /* TextFields */, + ); + path = FormFields; + sourceTree = ""; + }; + D2BEFEF6248A957A00FAB3A9 /* Tags */ = { + isa = PBXGroup; + children = ( + BBC0C4FE24811DCA0087C44F /* TagModel.swift */, + BBC0C4FC24811DBC0087C44F /* Tag.swift */, + BB2FB3BE247E7F0900DF73CD /* TagsModel.swift */, + BB2FB3BC247E7EF200DF73CD /* Tags.swift */, + BB2FB3BA247E7EBC00DF73CD /* TagCollectionViewCell.swift */, + ); + path = Tags; + sourceTree = ""; + }; D2C78CD324252F4E00B69FDE /* Atomic */ = { isa = PBXGroup; children = ( @@ -2154,7 +2170,7 @@ D2755D7B23689C7500485468 /* TableViewCell.swift in Sources */, 0A25209624645AFD000FA9F6 /* TextViewEntryField.swift in Sources */, 014AA72623C501E2006F3E93 /* ContainerModelProtocol.swift in Sources */, - BB2FB3BF247E7F0900DF73CD /* TagsListModel.swift in Sources */, + BB2FB3BF247E7F0900DF73CD /* TagsModel.swift in Sources */, AA11A42123F15D7000D7962F /* ListRightVariablePaymentsModel.swift in Sources */, 011D9626240EBB16000E3791 /* RadioButtonLabelModel.swift in Sources */, 8DDD6C1D244D90B8006A2232 /* ListThreeColumnDataUsage.swift in Sources */, @@ -2292,7 +2308,7 @@ D253BB9E2458751F002DE544 /* BGImageMoleculeModel.swift in Sources */, 0ABD1371237DB0450081388D /* ItemDropdownEntryField.swift in Sources */, 8D24041123E7FB9E009E23BE /* ListLeftVariableIconWithRightCaret.swift in Sources */, - BB2FB3BD247E7EF200DF73CD /* TagsList.swift in Sources */, + BB2FB3BD247E7EF200DF73CD /* Tags.swift in Sources */, BBAA4F03243D8E3B005AAD5F /* RadioBoxes.swift in Sources */, D2E1FAE12268E81D00AEFD8C /* MoleculeListTemplate.swift in Sources */, 525019E72406853600EED91C /* ListFourColumnDataUsageDivider.swift in Sources */, diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/Tag.swift b/MVMCoreUI/Atomic/Atoms/FormFields/Tags/Tag.swift similarity index 90% rename from MVMCoreUI/Atomic/Atoms/Selectors/Tag.swift rename to MVMCoreUI/Atomic/Atoms/FormFields/Tags/Tag.swift index 1080c7a9..c962f8c9 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/Tag.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/Tags/Tag.swift @@ -32,4 +32,10 @@ import Foundation super.updateView(size) label.updateView(size) } + + open override func reset() { + super.reset() + label.reset() + label.styleRegularBodySmall(true) + } } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/TagCollectionViewCell.swift b/MVMCoreUI/Atomic/Atoms/FormFields/Tags/TagCollectionViewCell.swift similarity index 100% rename from MVMCoreUI/Atomic/Atoms/Selectors/TagCollectionViewCell.swift rename to MVMCoreUI/Atomic/Atoms/FormFields/Tags/TagCollectionViewCell.swift diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/TagModel.swift b/MVMCoreUI/Atomic/Atoms/FormFields/Tags/TagModel.swift similarity index 100% rename from MVMCoreUI/Atomic/Atoms/Selectors/TagModel.swift rename to MVMCoreUI/Atomic/Atoms/FormFields/Tags/TagModel.swift diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift b/MVMCoreUI/Atomic/Atoms/FormFields/Tags/Tags.swift similarity index 87% rename from MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift rename to MVMCoreUI/Atomic/Atoms/FormFields/Tags/Tags.swift index 5a30f597..bbb5502a 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/Tags/Tags.swift @@ -1,5 +1,5 @@ // -// TagsList.swift +// Tags.swift // MVMCoreUI // // Created by Dhamodaram Nandi on 27/05/20. @@ -8,12 +8,11 @@ import Foundation -open class TagsList: View,MFButtonProtocol { - +open class Tags: View, MFButtonProtocol { public var collectionView: CollectionView! public var collectionViewHeight: NSLayoutConstraint! - private var tagsListModel: TagsListModel? { - return model as? TagsListModel + private var tagsListModel: TagsModel? { + return model as? TagsModel } private var delegateObject: MVMCoreUIDelegateObject? @@ -27,7 +26,6 @@ open class TagsList: View,MFButtonProtocol { DispatchQueue.main.async { self.collectionView.collectionViewLayout.invalidateLayout() self.collectionViewHeight.constant = self.collectionView.contentSize.height - self.collectionViewHeight.isActive = true self.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self) } } @@ -46,7 +44,7 @@ open class TagsList: View,MFButtonProtocol { open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) self.delegateObject = delegateObject - guard let tagsListModel = model as? TagsListModel else { return } + guard let tagsListModel = model as? TagsModel else { return } tags = tagsListModel.tags registerCells() collectionView.reloadData() @@ -61,7 +59,6 @@ open class TagsList: View,MFButtonProtocol { /// Creates the layout for the collection. open func createCollectionViewLayout() -> UICollectionViewLayout { let layout = UICollectionViewLeftAlignedLayout() - layout.scrollDirection = .vertical layout.estimatedItemSize = CGSize(width: 140, height: 40) layout.minimumLineSpacing = 24.0 return layout @@ -81,7 +78,7 @@ open class TagsList: View,MFButtonProtocol { } } -extension TagsList: UICollectionViewDataSource { +extension Tags: UICollectionViewDataSource { open func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return tags?.count ?? 0 } @@ -98,9 +95,10 @@ extension TagsList: UICollectionViewDataSource { } } -extension TagsList: UICollectionViewDelegate { +extension Tags: UICollectionViewDelegate { open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - guard let tagModel = tags?[indexPath.row], let tagAction = tagModel.action else {return} + guard let tagModel = tags?[indexPath.row], + let tagAction = tagModel.action else { return } Button.performButtonAction(with: tagAction, button: self, delegateObject: delegateObject, additionalData: nil) } } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/TagsListModel.swift b/MVMCoreUI/Atomic/Atoms/FormFields/Tags/TagsModel.swift similarity index 85% rename from MVMCoreUI/Atomic/Atoms/Selectors/TagsListModel.swift rename to MVMCoreUI/Atomic/Atoms/FormFields/Tags/TagsModel.swift index 86de5206..009f8fa1 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/TagsListModel.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/Tags/TagsModel.swift @@ -1,5 +1,5 @@ // -// TagsListModel.swift +// TagsModel.swift // MVMCoreUI // // Created by Dhamodaram Nandi on 27/05/20. @@ -8,17 +8,15 @@ import Foundation -@objcMembers public class TagsListModel: MoleculeModelProtocol { - +@objcMembers public class TagsModel: MoleculeModelProtocol { + public static var identifier: String = "tags" public var backgroundColor: Color? - public static var identifier: String = "tagsList" public var tags: [TagModel] private enum CodingKeys: String, CodingKey { case moleculeName case backgroundColor case tags - case height } required public init(from decoder: Decoder) throws { diff --git a/MVMCoreUI/Atomic/Atoms/TextFields/BaseDropdownEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift similarity index 100% rename from MVMCoreUI/Atomic/Atoms/TextFields/BaseDropdownEntryField.swift rename to MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift diff --git a/MVMCoreUI/Atomic/Atoms/TextFields/BaseDropdownEntryFieldModel.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryFieldModel.swift similarity index 100% rename from MVMCoreUI/Atomic/Atoms/TextFields/BaseDropdownEntryFieldModel.swift rename to MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryFieldModel.swift diff --git a/MVMCoreUI/Atomic/Atoms/TextFields/DateDropdownEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DateDropdownEntryField.swift similarity index 100% rename from MVMCoreUI/Atomic/Atoms/TextFields/DateDropdownEntryField.swift rename to MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DateDropdownEntryField.swift diff --git a/MVMCoreUI/Atomic/Atoms/TextFields/DateDropdownEntryFieldModel.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DateDropdownEntryFieldModel.swift similarity index 100% rename from MVMCoreUI/Atomic/Atoms/TextFields/DateDropdownEntryFieldModel.swift rename to MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DateDropdownEntryFieldModel.swift diff --git a/MVMCoreUI/Atomic/Atoms/TextFields/DigitBox.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DigitBox.swift similarity index 100% rename from MVMCoreUI/Atomic/Atoms/TextFields/DigitBox.swift rename to MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DigitBox.swift diff --git a/MVMCoreUI/Atomic/Atoms/TextFields/DigitEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DigitEntryField.swift similarity index 100% rename from MVMCoreUI/Atomic/Atoms/TextFields/DigitEntryField.swift rename to MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DigitEntryField.swift diff --git a/MVMCoreUI/Atomic/Atoms/TextFields/DigitEntryFieldModel.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DigitEntryFieldModel.swift similarity index 100% rename from MVMCoreUI/Atomic/Atoms/TextFields/DigitEntryFieldModel.swift rename to MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DigitEntryFieldModel.swift diff --git a/MVMCoreUI/Atomic/Atoms/TextFields/EntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/EntryField.swift similarity index 100% rename from MVMCoreUI/Atomic/Atoms/TextFields/EntryField.swift rename to MVMCoreUI/Atomic/Atoms/FormFields/TextFields/EntryField.swift diff --git a/MVMCoreUI/Atomic/Atoms/TextFields/EntryFieldModel.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/EntryFieldModel.swift similarity index 100% rename from MVMCoreUI/Atomic/Atoms/TextFields/EntryFieldModel.swift rename to MVMCoreUI/Atomic/Atoms/FormFields/TextFields/EntryFieldModel.swift diff --git a/MVMCoreUI/Atomic/Atoms/TextFields/ItemDropdownEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/ItemDropdownEntryField.swift similarity index 100% rename from MVMCoreUI/Atomic/Atoms/TextFields/ItemDropdownEntryField.swift rename to MVMCoreUI/Atomic/Atoms/FormFields/TextFields/ItemDropdownEntryField.swift diff --git a/MVMCoreUI/Atomic/Atoms/TextFields/ItemDropdownEntryFieldModel.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/ItemDropdownEntryFieldModel.swift similarity index 100% rename from MVMCoreUI/Atomic/Atoms/TextFields/ItemDropdownEntryFieldModel.swift rename to MVMCoreUI/Atomic/Atoms/FormFields/TextFields/ItemDropdownEntryFieldModel.swift diff --git a/MVMCoreUI/Atomic/Atoms/TextFields/MdnEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/MdnEntryField.swift similarity index 100% rename from MVMCoreUI/Atomic/Atoms/TextFields/MdnEntryField.swift rename to MVMCoreUI/Atomic/Atoms/FormFields/TextFields/MdnEntryField.swift diff --git a/MVMCoreUI/Atomic/Atoms/TextFields/MdnEntryFieldModel.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/MdnEntryFieldModel.swift similarity index 100% rename from MVMCoreUI/Atomic/Atoms/TextFields/MdnEntryFieldModel.swift rename to MVMCoreUI/Atomic/Atoms/FormFields/TextFields/MdnEntryFieldModel.swift diff --git a/MVMCoreUI/Atomic/Atoms/TextFields/TextEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/TextEntryField.swift similarity index 100% rename from MVMCoreUI/Atomic/Atoms/TextFields/TextEntryField.swift rename to MVMCoreUI/Atomic/Atoms/FormFields/TextFields/TextEntryField.swift diff --git a/MVMCoreUI/Atomic/Atoms/TextFields/TextEntryFieldModel.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/TextEntryFieldModel.swift similarity index 100% rename from MVMCoreUI/Atomic/Atoms/TextFields/TextEntryFieldModel.swift rename to MVMCoreUI/Atomic/Atoms/FormFields/TextFields/TextEntryFieldModel.swift diff --git a/MVMCoreUI/Atomic/Atoms/TextFields/TextViewEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/TextViewEntryField.swift similarity index 100% rename from MVMCoreUI/Atomic/Atoms/TextFields/TextViewEntryField.swift rename to MVMCoreUI/Atomic/Atoms/FormFields/TextFields/TextViewEntryField.swift diff --git a/MVMCoreUI/Atomic/Atoms/TextFields/TextViewEntryFieldModel.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/TextViewEntryFieldModel.swift similarity index 100% rename from MVMCoreUI/Atomic/Atoms/TextFields/TextViewEntryFieldModel.swift rename to MVMCoreUI/Atomic/Atoms/FormFields/TextFields/TextViewEntryFieldModel.swift diff --git a/MVMCoreUI/Atomic/MoleculeObjectMapping.swift b/MVMCoreUI/Atomic/MoleculeObjectMapping.swift index b95d0d40..665a9919 100644 --- a/MVMCoreUI/Atomic/MoleculeObjectMapping.swift +++ b/MVMCoreUI/Atomic/MoleculeObjectMapping.swift @@ -73,7 +73,7 @@ import Foundation MoleculeObjectMapping.shared()?.register(viewClass: RadioBoxes.self, viewModelClass: RadioBoxesModel.self) MoleculeObjectMapping.shared()?.register(viewClass: Checkbox.self, viewModelClass: CheckboxModel.self) MoleculeObjectMapping.shared()?.register(viewClass: RadioSwatches.self, viewModelClass: RadioSwatchesModel.self) - MoleculeObjectMapping.shared()?.register(viewClass: TagsList.self, viewModelClass: TagsListModel.self) + MoleculeObjectMapping.shared()?.register(viewClass: Tags.self, viewModelClass: TagsModel.self) MoleculeObjectMapping.shared()?.register(viewClass: Tag.self, viewModelClass: TagModel.self) From 2ec4881be6df28e9db078483d4808820a3e0f50b Mon Sep 17 00:00:00 2001 From: Damodaram <> Date: Mon, 8 Jun 2020 10:01:17 +0530 Subject: [PATCH 09/11] layout file added --- MVMCoreUI.xcodeproj/project.pbxproj | 8 ++++---- .../UICollectionViewLeftAlignedLayout.swift | 0 2 files changed, 4 insertions(+), 4 deletions(-) rename MVMCoreUI/{Atomic/Atoms/Selectors => BaseClasses}/UICollectionViewLeftAlignedLayout.swift (100%) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 2521b6d2..4fbd6e9d 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -213,9 +213,9 @@ AAB9C10824346F4B00151545 /* RadioSwatches.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAB9C10724346F4B00151545 /* RadioSwatches.swift */; }; AAB9C10A243496DD00151545 /* RadioSwatch.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAB9C109243496DD00151545 /* RadioSwatch.swift */; }; AAC6F167243332E400F295C1 /* RadioSwatchesModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAC6F166243332E400F295C1 /* RadioSwatchesModel.swift */; }; + BB105859248DEFF70069D008 /* UICollectionViewLeftAlignedLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB105858248DEFF60069D008 /* UICollectionViewLeftAlignedLayout.swift */; }; BB1D17E0244EAA30001D2002 /* ListDeviceComplexButtonMediumModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB1D17DF244EAA30001D2002 /* ListDeviceComplexButtonMediumModel.swift */; }; BB1D17E2244EAA46001D2002 /* ListDeviceComplexButtonMedium.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB1D17E1244EAA46001D2002 /* ListDeviceComplexButtonMedium.swift */; }; - BB258D37248A259000125E9D /* UICollectionViewLeftAlignedLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB258D36248A259000125E9D /* UICollectionViewLeftAlignedLayout.swift */; }; BB2BF0EA2452A9BB001D0FC2 /* ListDeviceComplexButtonSmall.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2BF0E92452A9BB001D0FC2 /* ListDeviceComplexButtonSmall.swift */; }; BB2BF0EC2452A9D5001D0FC2 /* ListDeviceComplexButtonSmallModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2BF0EB2452A9D5001D0FC2 /* ListDeviceComplexButtonSmallModel.swift */; }; BB2C968F24330EA7006FF80C /* ListRightVariableTextLinkAllTextAndLinksModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB2C968D24330EA7006FF80C /* ListRightVariableTextLinkAllTextAndLinksModel.swift */; }; @@ -656,9 +656,9 @@ AAB9C10724346F4B00151545 /* RadioSwatches.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioSwatches.swift; sourceTree = ""; }; AAB9C109243496DD00151545 /* RadioSwatch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioSwatch.swift; sourceTree = ""; }; AAC6F166243332E400F295C1 /* RadioSwatchesModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioSwatchesModel.swift; sourceTree = ""; }; + BB105858248DEFF60069D008 /* UICollectionViewLeftAlignedLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UICollectionViewLeftAlignedLayout.swift; sourceTree = ""; }; BB1D17DF244EAA30001D2002 /* ListDeviceComplexButtonMediumModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListDeviceComplexButtonMediumModel.swift; sourceTree = ""; }; BB1D17E1244EAA46001D2002 /* ListDeviceComplexButtonMedium.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListDeviceComplexButtonMedium.swift; sourceTree = ""; }; - BB258D36248A259000125E9D /* UICollectionViewLeftAlignedLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UICollectionViewLeftAlignedLayout.swift; sourceTree = ""; }; BB2BF0E92452A9BB001D0FC2 /* ListDeviceComplexButtonSmall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListDeviceComplexButtonSmall.swift; sourceTree = ""; }; BB2BF0EB2452A9D5001D0FC2 /* ListDeviceComplexButtonSmallModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListDeviceComplexButtonSmallModel.swift; sourceTree = ""; }; BB2C968D24330EA7006FF80C /* ListRightVariableTextLinkAllTextAndLinksModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListRightVariableTextLinkAllTextAndLinksModel.swift; sourceTree = ""; }; @@ -1868,8 +1868,8 @@ 0AE14F63238315D2005417F8 /* TextField.swift */, D20923582450ECE00044AD09 /* TableView.swift */, D2755D7A23689C7500485468 /* TableViewCell.swift */, + BB105858248DEFF60069D008 /* UICollectionViewLeftAlignedLayout.swift */, D21B7F70243BAC1600051ABF /* CollectionViewCell.swift */, - BB258D36248A259000125E9D /* UICollectionViewLeftAlignedLayout.swift */, D264FAA92440F97600D98315 /* CollectionView.swift */, 0A5D59C323AD488600EFD9E9 /* Protocols */, 0A7918F423F5E7EA00772FF4 /* ImageView.swift */, @@ -2328,8 +2328,8 @@ 012A88DB238ED45900FE3DA1 /* CarouselModel.swift in Sources */, D2092355244FA0FD0044AD09 /* ThreeLayerTemplateModelProtocol.swift in Sources */, 0AE14F64238315D2005417F8 /* TextField.swift in Sources */, - BB258D37248A259000125E9D /* UICollectionViewLeftAlignedLayout.swift in Sources */, 0AB764D124460F6300E7FE72 /* UIDatePicker+Extension.swift in Sources */, + BB105859248DEFF70069D008 /* UICollectionViewLeftAlignedLayout.swift in Sources */, D253BB9C245874F8002DE544 /* BGImageMolecule.swift in Sources */, D2C78CD224228BBD00B69FDE /* ActionOpenPanelModel.swift in Sources */, AA617AB02453010A00910B8F /* ListDeviceComplexLinkSmall.swift in Sources */, diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/UICollectionViewLeftAlignedLayout.swift b/MVMCoreUI/BaseClasses/UICollectionViewLeftAlignedLayout.swift similarity index 100% rename from MVMCoreUI/Atomic/Atoms/Selectors/UICollectionViewLeftAlignedLayout.swift rename to MVMCoreUI/BaseClasses/UICollectionViewLeftAlignedLayout.swift From f4fa6d8291d7fc490e5d74723b69e461d7995dbb Mon Sep 17 00:00:00 2001 From: Damodaram <> Date: Mon, 8 Jun 2020 15:20:37 +0530 Subject: [PATCH 10/11] layout changes updated --- .../Atomic/Atoms/FormFields/Tags/Tags.swift | 1 + .../UICollectionViewLeftAlignedLayout.swift | 47 +++++++------------ 2 files changed, 17 insertions(+), 31 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/Tags/Tags.swift b/MVMCoreUI/Atomic/Atoms/FormFields/Tags/Tags.swift index bbb5502a..4b1fa4f9 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/Tags/Tags.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/Tags/Tags.swift @@ -61,6 +61,7 @@ open class Tags: View, MFButtonProtocol { let layout = UICollectionViewLeftAlignedLayout() layout.estimatedItemSize = CGSize(width: 140, height: 40) layout.minimumLineSpacing = 24.0 + layout.minimumInteritemSpacing = 12.0 return layout } diff --git a/MVMCoreUI/BaseClasses/UICollectionViewLeftAlignedLayout.swift b/MVMCoreUI/BaseClasses/UICollectionViewLeftAlignedLayout.swift index d5568b57..37be12bf 100644 --- a/MVMCoreUI/BaseClasses/UICollectionViewLeftAlignedLayout.swift +++ b/MVMCoreUI/BaseClasses/UICollectionViewLeftAlignedLayout.swift @@ -13,39 +13,24 @@ class UICollectionViewLeftAlignedLayout: UICollectionViewFlowLayout { guard let attributes = super.layoutAttributesForElements(in: rect) else { return nil } - var rows = [Row]() - var currentRowY: CGFloat = -1 + var newAttributesForElementsInRect = [UICollectionViewLayoutAttributes]() + var leftMargin: CGFloat = 0.0; + let leftPadding: CGFloat = 0 + let interItemSpacing = minimumInteritemSpacing + var maxY: CGFloat = -1.0 for attribute in attributes { - if currentRowY != attribute.frame.origin.y { - currentRowY = attribute.frame.origin.y - rows.append(Row(spacing: 10)) + if attribute.frame.origin.y >= maxY { + leftMargin = leftPadding + } else { + var newLeftAlignedFrame = attribute.frame + newLeftAlignedFrame.origin.x = leftMargin + attribute.frame = newLeftAlignedFrame } - rows.last?.add(attribute: attribute) - } - rows.forEach { $0.tagLayout(collectionViewWidth: collectionView?.frame.width ?? 0) } - return rows.flatMap { $0.attributes } - } -} - -class Row { - - var attributes = [UICollectionViewLayoutAttributes]() - var spacing: CGFloat = 0 - - init(spacing: CGFloat) { - self.spacing = spacing - } - - func add(attribute: UICollectionViewLayoutAttributes) { - attributes.append(attribute) - } - - func tagLayout(collectionViewWidth: CGFloat) { - let padding = 8 - var offset = padding - for attribute in attributes { - attribute.frame.origin.x = CGFloat(offset) - offset += Int(attribute.frame.width + spacing) + attribute.frame.origin.x = leftMargin + leftMargin += attribute.frame.width + interItemSpacing + maxY = max(attribute.frame.maxY, maxY) + newAttributesForElementsInRect.append(attribute) } + return newAttributesForElementsInRect } } From cd23384db34a384655f224274a18cd5a83f86a3b Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 8 Jun 2020 10:01:58 -0400 Subject: [PATCH 11/11] Made the code more concise --- .../UICollectionViewLeftAlignedLayout.swift | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/MVMCoreUI/BaseClasses/UICollectionViewLeftAlignedLayout.swift b/MVMCoreUI/BaseClasses/UICollectionViewLeftAlignedLayout.swift index 37be12bf..717bbc55 100644 --- a/MVMCoreUI/BaseClasses/UICollectionViewLeftAlignedLayout.swift +++ b/MVMCoreUI/BaseClasses/UICollectionViewLeftAlignedLayout.swift @@ -5,30 +5,21 @@ // Created by Dhamodaram Nandi on 05/06/20. // Copyright © 2020 Verizon Wireless. All rights reserved. // +// Left aligns items and makes the minimumInteritemSpacing absolute. import Foundation class UICollectionViewLeftAlignedLayout: UICollectionViewFlowLayout { override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { - guard let attributes = super.layoutAttributesForElements(in: rect) else { - return nil - } + guard let attributes = super.layoutAttributesForElements(in: rect) else { return nil } var newAttributesForElementsInRect = [UICollectionViewLayoutAttributes]() - var leftMargin: CGFloat = 0.0; - let leftPadding: CGFloat = 0 - let interItemSpacing = minimumInteritemSpacing - var maxY: CGFloat = -1.0 for attribute in attributes { - if attribute.frame.origin.y >= maxY { - leftMargin = leftPadding + if let previousFrame = newAttributesForElementsInRect.last, + MVMCoreGetterUtility.cgfequal(previousFrame.frame.minY, attribute.frame.minY) { + attribute.frame.origin.x = previousFrame.frame.maxX + minimumInteritemSpacing } else { - var newLeftAlignedFrame = attribute.frame - newLeftAlignedFrame.origin.x = leftMargin - attribute.frame = newLeftAlignedFrame + attribute.frame.origin.x = 0 } - attribute.frame.origin.x = leftMargin - leftMargin += attribute.frame.width + interItemSpacing - maxY = max(attribute.frame.maxY, maxY) newAttributesForElementsInRect.append(attribute) } return newAttributesForElementsInRect