Fixes and organization for protocol functions in base classes

fix scroller extra adding
This commit is contained in:
Pfeil, Scott Robert 2020-09-03 13:07:58 -04:00
parent 176944f2a0
commit 1ca7d04854
8 changed files with 64 additions and 38 deletions

View File

@ -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<MVMCoreErrorObject?>?) -> [String]? {
open override class func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [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)

View File

@ -38,7 +38,7 @@ import UIKit
return "\(self)<\(moleculeName)>"
}
public static func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? {
public override class func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? {
guard let moleculeModel = (model as? MoleculeListItemModel)?.molecule,
let theClass = MoleculeObjectMapping.shared()?.getMoleculeClass(moleculeModel)
else { return nil }

View File

@ -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
}
}

View File

@ -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
//--------------------------------------------------

View File

@ -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<MVMCoreErrorObject?>?) -> [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)

View File

@ -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<MVMCoreErrorObject?>?) -> [String]? {
return nil
}
open func reset() {
backgroundColor = .clear
}
}
// MARK: - AppleGuidelinesProtocol

View File

@ -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<MVMCoreErrorObject?>?) -> [String]? {
return nil
}
// MARK: - Caret View
/// Adds the standard mvm style caret to the accessory view

View File

@ -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<MVMCoreErrorObject?>?) -> [String]? {
return nil
}
open func reset() {
backgroundColor = .clear
}
}
// MARK:- MVMCoreViewProtocol