diff --git a/MVMCoreUI/Atomic/Molecules/Items/MoleculeCollectionViewCell.swift b/MVMCoreUI/Atomic/Molecules/Items/MoleculeCollectionViewCell.swift index 2306dc94..bf3714bd 100644 --- a/MVMCoreUI/Atomic/Molecules/Items/MoleculeCollectionViewCell.swift +++ b/MVMCoreUI/Atomic/Molecules/Items/MoleculeCollectionViewCell.swift @@ -33,14 +33,14 @@ open class MoleculeCollectionViewCell: CollectionViewCell { backgroundColor = .mvmWhite } - open class func nameForReuse(_ model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { + open override class func nameForReuse(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { guard let moleculeModel = (model as? MoleculeCollectionItemModel)?.molecule else { return "\(self)<>" } let className = MoleculeObjectMapping.shared()?.getMoleculeClass(moleculeModel) let moleculeName = className?.nameForReuse(with: moleculeModel, delegateObject) ?? moleculeModel.moleculeName return "\(self)<\(moleculeName)>" } - open class func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { + open override class func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { guard let moleculeModel = (model as? MoleculeCollectionItemModel)?.molecule, let theClass = MoleculeObjectMapping.shared()?.getMoleculeClass(moleculeModel) else { return nil } @@ -48,7 +48,7 @@ open class MoleculeCollectionViewCell: CollectionViewCell { return theClass.requiredModules(with: moleculeModel, delegateObject, error: error) } - open class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { + open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { guard let model = model as? MoleculeCollectionItemModel, let classType = MoleculeObjectMapping.shared()?.getMoleculeClass(model.molecule), let height = classType.estimatedHeight(with: model.molecule, delegateObject) diff --git a/MVMCoreUI/Atomic/Molecules/Items/MoleculeTableViewCell.swift b/MVMCoreUI/Atomic/Molecules/Items/MoleculeTableViewCell.swift index 6e1f2965..532c21f4 100644 --- a/MVMCoreUI/Atomic/Molecules/Items/MoleculeTableViewCell.swift +++ b/MVMCoreUI/Atomic/Molecules/Items/MoleculeTableViewCell.swift @@ -38,7 +38,7 @@ import UIKit return "\(self)<\(moleculeName)>" } - public static func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { + public override class func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { guard let moleculeModel = (model as? MoleculeListItemModel)?.molecule, let theClass = MoleculeObjectMapping.shared()?.getMoleculeClass(moleculeModel) else { return nil } diff --git a/MVMCoreUI/Atomic/Molecules/OtherContainers/Scroller.swift b/MVMCoreUI/Atomic/Molecules/OtherContainers/Scroller.swift index 56c33df7..45df7be4 100644 --- a/MVMCoreUI/Atomic/Molecules/OtherContainers/Scroller.swift +++ b/MVMCoreUI/Atomic/Molecules/OtherContainers/Scroller.swift @@ -8,7 +8,7 @@ import UIKit -@objcMembers open class Scroller: Container { +@objcMembers open class Scroller: MoleculeContainer { public let scrollView = UIScrollView(frame: .zero) public let contentView = MVMCoreUICommonViewsUtility.commonView() @@ -28,19 +28,11 @@ import UIKit constraint.priority = UILayoutPriority(rawValue: 999) constraint.isActive = true } - - public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { - if let casteModel = model as? ScrollerModel { - if view != nil { - (view as? MoleculeViewProtocol)?.set(with: casteModel.molecule, delegateObject, additionalData) - } else { - if let molecule = MoleculeObjectMapping.shared()?.createMolecule(casteModel.molecule, delegateObject: delegateObject, additionalData: additionalData) { - contentView.addSubview(molecule) - molecule.translatesAutoresizingMaskIntoConstraints = false - containerHelper.constrainView(molecule) - } - } - } - super.set(with: model, delegateObject, additionalData) + + public override func addAndContain(_ view: UIView) { + view.translatesAutoresizingMaskIntoConstraints = false + contentView.addSubview(view) + containerHelper.constrainView(view) + self.view = view } } diff --git a/MVMCoreUI/BaseClasses/Button.swift b/MVMCoreUI/BaseClasses/Button.swift index 9f1f8a85..757855ed 100644 --- a/MVMCoreUI/BaseClasses/Button.swift +++ b/MVMCoreUI/BaseClasses/Button.swift @@ -106,6 +106,12 @@ public typealias ButtonAction = (Button) -> () set(with: model.action, delegateObject: delegateObject, additionalData: additionalData) } + open func reset() { + backgroundColor = .clear + } + + // MARK: Overridables + // Base classes need to implement these functions otherwise swift won't respect the subclass functions and use the ones in the protocol extension instead. open class func nameForReuse(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { return model.moleculeName } @@ -118,10 +124,6 @@ public typealias ButtonAction = (Button) -> () return nil } - open func reset() { - backgroundColor = .clear - } - //-------------------------------------------------- // MARK: - Accessibility //-------------------------------------------------- diff --git a/MVMCoreUI/BaseClasses/CollectionViewCell.swift b/MVMCoreUI/BaseClasses/CollectionViewCell.swift index 5f464f2d..ce910bfb 100644 --- a/MVMCoreUI/BaseClasses/CollectionViewCell.swift +++ b/MVMCoreUI/BaseClasses/CollectionViewCell.swift @@ -43,6 +43,15 @@ open class CollectionViewCell: UICollectionViewCell, MoleculeViewProtocol, MVMCo } } + // MARK: - Helpers + + /// Convenience function. Adds a molecule to the view. + open func addMolecule(_ molecule: MoleculeViewProtocol) { + contentView.addSubview(molecule) + containerHelper.constrainView(molecule) + self.molecule = molecule + } + // MARK: - MVMCoreViewProtocol open func setupView() { isAccessibilityElement = false @@ -82,11 +91,19 @@ open class CollectionViewCell: UICollectionViewCell, MoleculeViewProtocol, MVMCo width = nil } - /// Convenience function. Adds a molecule to the view. - open func addMolecule(_ molecule: MoleculeViewProtocol) { - contentView.addSubview(molecule) - containerHelper.constrainView(molecule) - self.molecule = molecule + // MARK: Overridables + // Base classes need to implement these functions otherwise swift won't respect the subclass functions and use the ones in the protocol extension instead. + + open class func nameForReuse(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { + return model.moleculeName + } + + open class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { + return nil + } + + open class func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { + return nil } //-------------------------------------------------- @@ -98,6 +115,7 @@ open class CollectionViewCell: UICollectionViewCell, MoleculeViewProtocol, MVMCo } // MARK: - Override + open func didSelectCell(at index: IndexPath, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { guard let action = model?.action else { return } Button.performButtonAction(with: action, button: self, delegateObject: delegateObject, additionalData: additionalData) diff --git a/MVMCoreUI/BaseClasses/Control.swift b/MVMCoreUI/BaseClasses/Control.swift index d8acb6f6..57c13e9e 100644 --- a/MVMCoreUI/BaseClasses/Control.swift +++ b/MVMCoreUI/BaseClasses/Control.swift @@ -56,6 +56,12 @@ import UIKit } } + open func reset() { + backgroundColor = .clear + } + + // MARK: Overridables + // Base classes need to implement these functions otherwise swift won't respect the subclass functions and use the ones in the protocol extension instead. open class func nameForReuse(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { return model.moleculeName } @@ -67,10 +73,6 @@ import UIKit open class func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { return nil } - - open func reset() { - backgroundColor = .clear - } } // MARK: - AppleGuidelinesProtocol diff --git a/MVMCoreUI/BaseClasses/TableViewCell.swift b/MVMCoreUI/BaseClasses/TableViewCell.swift index bb5871d0..b391162e 100644 --- a/MVMCoreUI/BaseClasses/TableViewCell.swift +++ b/MVMCoreUI/BaseClasses/TableViewCell.swift @@ -124,7 +124,10 @@ import UIKit styleStandard() } - //TODO: ModelProtocol, Change to model + //-------------------------------------------------- + // MARK: - MoleculeViewProtocol + //-------------------------------------------------- + open func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { guard let model = model as? ListItemModelProtocol else { return } @@ -161,13 +164,20 @@ import UIKit backgroundColor = .white } + // MARK: Overridables + // Base classes need to implement these functions otherwise swift won't respect the subclass functions and use the ones in the protocol extension instead. + open class func nameForReuse(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { return model.moleculeName } open class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { return nil - } + } + + open class func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { + return nil + } // MARK: - Caret View /// Adds the standard mvm style caret to the accessory view diff --git a/MVMCoreUI/BaseClasses/View.swift b/MVMCoreUI/BaseClasses/View.swift index c0ca8ee1..686985eb 100644 --- a/MVMCoreUI/BaseClasses/View.swift +++ b/MVMCoreUI/BaseClasses/View.swift @@ -54,6 +54,12 @@ import UIKit } } + open func reset() { + backgroundColor = .clear + } + + // MARK: Overridables + // Base classes need to implement these functions otherwise swift won't respect the subclass functions and use the ones in the protocol extension instead. open class func nameForReuse(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { return model.moleculeName } @@ -65,10 +71,6 @@ import UIKit open class func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { return nil } - - open func reset() { - backgroundColor = .clear - } } // MARK:- MVMCoreViewProtocol