diff --git a/MVMCoreUI/Atomic/Molecules/Items/MoleculeCollectionViewCell.swift b/MVMCoreUI/Atomic/Molecules/Items/MoleculeCollectionViewCell.swift index 10b51bff..2306dc94 100644 --- a/MVMCoreUI/Atomic/Molecules/Items/MoleculeCollectionViewCell.swift +++ b/MVMCoreUI/Atomic/Molecules/Items/MoleculeCollectionViewCell.swift @@ -10,10 +10,11 @@ import UIKit /// A collection item that is a container for any molecule. open class MoleculeCollectionViewCell: CollectionViewCell { - + open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) guard let collectionModel = model as? MoleculeCollectionItemModel else { return } + if molecule == nil { if let moleculeView = MoleculeObjectMapping.shared()?.createMolecule(collectionModel.molecule, delegateObject: delegateObject, additionalData: additionalData) { addMolecule(moleculeView) @@ -21,16 +22,15 @@ open class MoleculeCollectionViewCell: CollectionViewCell { } else { molecule?.set(with: collectionModel.molecule, delegateObject, additionalData) } - + guard let molecule = molecule as? (UIView & MVMCoreUIViewConstrainingProtocol) else { return } containerHelper.set(with: collectionModel, for: molecule) - accessibilityElements = molecule.subviews } open override func reset() { super.reset() molecule?.reset() - backgroundColor = .white + backgroundColor = .mvmWhite } open class func nameForReuse(_ model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { diff --git a/MVMCoreUI/Atomic/Templates/ModalMoleculeListTemplate.swift b/MVMCoreUI/Atomic/Templates/ModalMoleculeListTemplate.swift index a141ef0e..63140e6e 100644 --- a/MVMCoreUI/Atomic/Templates/ModalMoleculeListTemplate.swift +++ b/MVMCoreUI/Atomic/Templates/ModalMoleculeListTemplate.swift @@ -8,6 +8,7 @@ import UIKit + open class ModalMoleculeListTemplate: MoleculeListTemplate { //-------------------------------------------------- // MARK: - Properties @@ -15,13 +16,20 @@ open class ModalMoleculeListTemplate: MoleculeListTemplate { public var closeButton: Button? + //-------------------------------------------------- + // MARK: - Lifecycle + //-------------------------------------------------- + override open func handleNewData() { super.handleNewData() + closeButton = MVMCoreUICommonViewsUtility.addCloseButton(to: view, action: { _ in MVMCoreNavigationHandler.shared()?.removeCurrentViewController() }) - + } + + open override func viewDidLayoutSubviews() { + super.viewDidLayoutSubviews() accessibilityElements = [closeButton as Any, tableView as Any] - UIAccessibility.post(notification: .layoutChanged, argument: closeButton) } } diff --git a/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift index 521a0d45..4be4e025 100644 --- a/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift @@ -8,6 +8,7 @@ import UIKit + open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol { //-------------------------------------------------- // MARK: - Stored Properties diff --git a/MVMCoreUI/BaseClasses/CollectionViewCell.swift b/MVMCoreUI/BaseClasses/CollectionViewCell.swift index e11b350c..aa74d229 100644 --- a/MVMCoreUI/BaseClasses/CollectionViewCell.swift +++ b/MVMCoreUI/BaseClasses/CollectionViewCell.swift @@ -8,9 +8,13 @@ import Foundation + /// A base collection view cell with basic mvm functionality. open class CollectionViewCell: UICollectionViewCell, MoleculeViewProtocol, MVMCoreViewProtocol, CollectionTemplateItemProtocol { - + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + // Convenience helpers open var molecule: MoleculeViewProtocol? public let containerHelper = ContainerHelper() @@ -18,9 +22,13 @@ open class CollectionViewCell: UICollectionViewCell, MoleculeViewProtocol, MVMCo /// The width, used for establishing columns open var width: CGFloat? - + private var initialSetupPerformed = false - + + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + // MARK: - Inits public override init(frame: CGRect) { super.init(frame: .zero) @@ -39,6 +47,10 @@ open class CollectionViewCell: UICollectionViewCell, MoleculeViewProtocol, MVMCo } } + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + // MARK: - MVMCoreViewProtocol open func setupView() { isAccessibilityElement = false @@ -58,15 +70,19 @@ open class CollectionViewCell: UICollectionViewCell, MoleculeViewProtocol, MVMCo open func reset() { molecule?.reset() - backgroundColor = .white + backgroundColor = .mvmWhite width = nil } + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + // MARK: - MoleculeViewProtocol open func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { guard let model = model as? CollectionItemModelProtocol else { return } self.model = model - + if let moleculeModel = model as? MoleculeModelProtocol, let backgroundColor = moleculeModel.backgroundColor { self.backgroundColor = backgroundColor.uiColor @@ -84,8 +100,11 @@ open class CollectionViewCell: UICollectionViewCell, MoleculeViewProtocol, MVMCo containerHelper.constrainView(molecule) self.molecule = molecule } - + + //-------------------------------------------------- // MARK: - CollectionTemplateItemProtocol + //-------------------------------------------------- + public func set(width: CGFloat) { self.width = width } @@ -94,11 +113,11 @@ open class CollectionViewCell: UICollectionViewCell, MoleculeViewProtocol, MVMCo override open func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes { let autoLayoutAttributes = super.preferredLayoutAttributesFitting(layoutAttributes) guard let width = width else { return autoLayoutAttributes } - + let targetSize = CGSize(width: width, height: 0) - let newSize = contentView.systemLayoutSizeFitting(targetSize, withHorizontalFittingPriority: UILayoutPriority.required, verticalFittingPriority: UILayoutPriority.defaultLow) + let newSize = contentView.systemLayoutSizeFitting(targetSize, withHorizontalFittingPriority: .required, verticalFittingPriority: .defaultLow) let newFrame = CGRect(origin: autoLayoutAttributes.frame.origin, size: newSize) autoLayoutAttributes.frame = newFrame return autoLayoutAttributes - } + } }