Updated to performButtonAction method
This commit is contained in:
parent
c9775376d3
commit
c3e4786d5b
@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
@objcMembers open class Tag: View {
|
||||
|
||||
public let label = Label.createLabelRegularBodySmall(true)
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
open class TagCollectionViewCell: CollectionViewCell {
|
||||
public let tagLabel = Tag()
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
@objcMembers public class TagModel: MoleculeModelProtocol {
|
||||
public static var identifier: String = "tag"
|
||||
public var label: LabelModel
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user