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