Merge branch 'bugfix/scroller_and_carousel' into 'develop'

Fixes and organization for protocol functions in base classes

See merge request BPHV_MIPS/mvm_core_ui!578
This commit is contained in:
Pfeil, Scott Robert 2020-09-03 13:26:23 -04:00
commit bfb604faae
8 changed files with 64 additions and 38 deletions

View File

@ -33,14 +33,14 @@ open class MoleculeCollectionViewCell: CollectionViewCell {
backgroundColor = .mvmWhite 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)<>" } guard let moleculeModel = (model as? MoleculeCollectionItemModel)?.molecule else { return "\(self)<>" }
let className = MoleculeObjectMapping.shared()?.getMoleculeClass(moleculeModel) let className = MoleculeObjectMapping.shared()?.getMoleculeClass(moleculeModel)
let moleculeName = className?.nameForReuse(with: moleculeModel, delegateObject) ?? moleculeModel.moleculeName let moleculeName = className?.nameForReuse(with: moleculeModel, delegateObject) ?? moleculeModel.moleculeName
return "\(self)<\(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, guard let moleculeModel = (model as? MoleculeCollectionItemModel)?.molecule,
let theClass = MoleculeObjectMapping.shared()?.getMoleculeClass(moleculeModel) let theClass = MoleculeObjectMapping.shared()?.getMoleculeClass(moleculeModel)
else { return nil } else { return nil }
@ -48,7 +48,7 @@ open class MoleculeCollectionViewCell: CollectionViewCell {
return theClass.requiredModules(with: moleculeModel, delegateObject, error: error) 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, guard let model = model as? MoleculeCollectionItemModel,
let classType = MoleculeObjectMapping.shared()?.getMoleculeClass(model.molecule), let classType = MoleculeObjectMapping.shared()?.getMoleculeClass(model.molecule),
let height = classType.estimatedHeight(with: model.molecule, delegateObject) let height = classType.estimatedHeight(with: model.molecule, delegateObject)

View File

@ -38,7 +38,7 @@ import UIKit
return "\(self)<\(moleculeName)>" 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, guard let moleculeModel = (model as? MoleculeListItemModel)?.molecule,
let theClass = MoleculeObjectMapping.shared()?.getMoleculeClass(moleculeModel) let theClass = MoleculeObjectMapping.shared()?.getMoleculeClass(moleculeModel)
else { return nil } else { return nil }

View File

@ -8,7 +8,7 @@
import UIKit import UIKit
@objcMembers open class Scroller: Container { @objcMembers open class Scroller: MoleculeContainer {
public let scrollView = UIScrollView(frame: .zero) public let scrollView = UIScrollView(frame: .zero)
public let contentView = MVMCoreUICommonViewsUtility.commonView() public let contentView = MVMCoreUICommonViewsUtility.commonView()
@ -28,19 +28,11 @@ import UIKit
constraint.priority = UILayoutPriority(rawValue: 999) constraint.priority = UILayoutPriority(rawValue: 999)
constraint.isActive = true constraint.isActive = true
} }
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { public override func addAndContain(_ view: UIView) {
if let casteModel = model as? ScrollerModel { view.translatesAutoresizingMaskIntoConstraints = false
if view != nil { contentView.addSubview(view)
(view as? MoleculeViewProtocol)?.set(with: casteModel.molecule, delegateObject, additionalData) containerHelper.constrainView(view)
} else { self.view = view
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)
} }
} }

View File

@ -106,6 +106,12 @@ public typealias ButtonAction = (Button) -> ()
set(with: model.action, delegateObject: delegateObject, additionalData: additionalData) 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? { open class func nameForReuse(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? {
return model.moleculeName return model.moleculeName
} }
@ -118,10 +124,6 @@ public typealias ButtonAction = (Button) -> ()
return nil return nil
} }
open func reset() {
backgroundColor = .clear
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Accessibility // 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 // MARK: - MVMCoreViewProtocol
open func setupView() { open func setupView() {
isAccessibilityElement = false isAccessibilityElement = false
@ -82,11 +91,19 @@ open class CollectionViewCell: UICollectionViewCell, MoleculeViewProtocol, MVMCo
width = nil width = nil
} }
/// Convenience function. Adds a molecule to the view. // MARK: Overridables
open func addMolecule(_ molecule: MoleculeViewProtocol) { // Base classes need to implement these functions otherwise swift won't respect the subclass functions and use the ones in the protocol extension instead.
contentView.addSubview(molecule)
containerHelper.constrainView(molecule) open class func nameForReuse(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? {
self.molecule = molecule 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 // MARK: - Override
open func didSelectCell(at index: IndexPath, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { open func didSelectCell(at index: IndexPath, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) {
guard let action = model?.action else { return } guard let action = model?.action else { return }
Button.performButtonAction(with: action, button: self, delegateObject: delegateObject, additionalData: additionalData) 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? { open class func nameForReuse(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? {
return model.moleculeName return model.moleculeName
} }
@ -67,10 +73,6 @@ import UIKit
open class func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? { open class func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? {
return nil return nil
} }
open func reset() {
backgroundColor = .clear
}
} }
// MARK: - AppleGuidelinesProtocol // MARK: - AppleGuidelinesProtocol

View File

@ -124,7 +124,10 @@ import UIKit
styleStandard() styleStandard()
} }
//TODO: ModelProtocol, Change to model //--------------------------------------------------
// MARK: - MoleculeViewProtocol
//--------------------------------------------------
open func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { open func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
guard let model = model as? ListItemModelProtocol else { return } guard let model = model as? ListItemModelProtocol else { return }
@ -161,13 +164,20 @@ import UIKit
backgroundColor = .white 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? { open class func nameForReuse(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? {
return model.moleculeName return model.moleculeName
} }
open class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { open class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
return nil return nil
} }
open class func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? {
return nil
}
// MARK: - Caret View // MARK: - Caret View
/// Adds the standard mvm style caret to the accessory 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? { open class func nameForReuse(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? {
return model.moleculeName return model.moleculeName
} }
@ -65,10 +71,6 @@ import UIKit
open class func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? { open class func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? {
return nil return nil
} }
open func reset() {
backgroundColor = .clear
}
} }
// MARK:- MVMCoreViewProtocol // MARK:- MVMCoreViewProtocol