Updated to performButtonAction method
This commit is contained in:
parent
c9775376d3
commit
c3e4786d5b
@ -7,6 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
@objcMembers open class Tag: View {
|
@objcMembers open class Tag: View {
|
||||||
|
|
||||||
public let label = Label.createLabelRegularBodySmall(true)
|
public let label = Label.createLabelRegularBodySmall(true)
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
open class TagCollectionViewCell: CollectionViewCell {
|
open class TagCollectionViewCell: CollectionViewCell {
|
||||||
public let tagLabel = Tag()
|
public let tagLabel = Tag()
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
@objcMembers public class TagModel: MoleculeModelProtocol {
|
@objcMembers public class TagModel: MoleculeModelProtocol {
|
||||||
public static var identifier: String = "tag"
|
public static var identifier: String = "tag"
|
||||||
public var label: LabelModel
|
public var label: LabelModel
|
||||||
|
|||||||
@ -7,7 +7,8 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
open class TagsList: View {
|
|
||||||
|
open class TagsList: View,MFButtonProtocol {
|
||||||
|
|
||||||
public var collectionView: CollectionView!
|
public var collectionView: CollectionView!
|
||||||
public var collectionViewHeight: NSLayoutConstraint!
|
public var collectionViewHeight: NSLayoutConstraint!
|
||||||
@ -20,15 +21,14 @@ open class TagsList: View {
|
|||||||
/// The models for the molecules.
|
/// The models for the molecules.
|
||||||
public var tags: [TagModel]?
|
public var tags: [TagModel]?
|
||||||
|
|
||||||
|
|
||||||
open override func layoutSubviews() {
|
open override func layoutSubviews() {
|
||||||
super.layoutSubviews()
|
super.layoutSubviews()
|
||||||
// Accounts for any collection size changes
|
// Accounts for any collection size changes
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.collectionView.collectionViewLayout.invalidateLayout()
|
self.collectionView.collectionViewLayout.invalidateLayout()
|
||||||
self.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self)
|
|
||||||
self.collectionViewHeight.constant = self.collectionView.contentSize.height
|
self.collectionViewHeight.constant = self.collectionView.contentSize.height
|
||||||
self.collectionViewHeight.isActive = true
|
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]?) {
|
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||||
super.set(with: model, delegateObject, additionalData)
|
super.set(with: model, delegateObject, additionalData)
|
||||||
self.delegateObject = delegateObject
|
self.delegateObject = delegateObject
|
||||||
|
|
||||||
guard let tagsListModel = model as? TagsListModel else { return }
|
guard let tagsListModel = model as? TagsListModel else { return }
|
||||||
tags = tagsListModel.tags
|
tags = tagsListModel.tags
|
||||||
registerCells()
|
registerCells()
|
||||||
@ -59,7 +58,6 @@ open class TagsList: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Creation
|
// MARK: - Creation
|
||||||
|
|
||||||
/// Creates the layout for the collection.
|
/// Creates the layout for the collection.
|
||||||
open func createCollectionViewLayout() -> UICollectionViewLayout {
|
open func createCollectionViewLayout() -> UICollectionViewLayout {
|
||||||
let layout = UICollectionViewLeftAlignedLayout()
|
let layout = UICollectionViewLeftAlignedLayout()
|
||||||
@ -81,7 +79,6 @@ open class TagsList: View {
|
|||||||
open func registerCells() {
|
open func registerCells() {
|
||||||
collectionView.register(TagCollectionViewCell.self, forCellWithReuseIdentifier: "TagCollectionViewCell")
|
collectionView.register(TagCollectionViewCell.self, forCellWithReuseIdentifier: "TagCollectionViewCell")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension TagsList: UICollectionViewDataSource {
|
extension TagsList: UICollectionViewDataSource {
|
||||||
@ -102,13 +99,8 @@ extension TagsList: UICollectionViewDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension TagsList: UICollectionViewDelegate {
|
extension TagsList: UICollectionViewDelegate {
|
||||||
|
|
||||||
open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
||||||
guard let tagModel = tags?[indexPath.row] else {return}
|
guard let tagModel = tags?[indexPath.row], let tagAction = tagModel.action else {return}
|
||||||
if let data = try? tagModel.action?.encode(using: JSONEncoder()),
|
Button.performButtonAction(with: tagAction, button: self, delegateObject: delegateObject, additionalData: nil)
|
||||||
let actionMap = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any]{
|
|
||||||
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: nil, delegateObject: delegateObject)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import Foundation
|
|
||||||
@objcMembers public class TagsListModel: MoleculeModelProtocol {
|
@objcMembers public class TagsListModel: MoleculeModelProtocol {
|
||||||
|
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
|
|||||||
@ -13,10 +13,8 @@ class UICollectionViewLeftAlignedLayout: UICollectionViewFlowLayout {
|
|||||||
guard let attributes = super.layoutAttributesForElements(in: rect) else {
|
guard let attributes = super.layoutAttributesForElements(in: rect) else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var rows = [Row]()
|
var rows = [Row]()
|
||||||
var currentRowY: CGFloat = -1
|
var currentRowY: CGFloat = -1
|
||||||
|
|
||||||
for attribute in attributes {
|
for attribute in attributes {
|
||||||
if currentRowY != attribute.frame.origin.y {
|
if currentRowY != attribute.frame.origin.y {
|
||||||
currentRowY = attribute.frame.origin.y
|
currentRowY = attribute.frame.origin.y
|
||||||
@ -24,7 +22,6 @@ class UICollectionViewLeftAlignedLayout: UICollectionViewFlowLayout {
|
|||||||
}
|
}
|
||||||
rows.last?.add(attribute: attribute)
|
rows.last?.add(attribute: attribute)
|
||||||
}
|
}
|
||||||
|
|
||||||
rows.forEach { $0.tagLayout(collectionViewWidth: collectionView?.frame.width ?? 0) }
|
rows.forEach { $0.tagLayout(collectionViewWidth: collectionView?.frame.width ?? 0) }
|
||||||
return rows.flatMap { $0.attributes }
|
return rows.flatMap { $0.attributes }
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user