molecule container protocol fix missing functions update numbered and unordered list to more model approach
70 lines
3.8 KiB
Swift
70 lines
3.8 KiB
Swift
//
|
|
// MoleculeContainer.swift
|
|
// MVMCoreUI
|
|
//
|
|
// Created by Scott Pfeil on 12/12/19.
|
|
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
open class MoleculeContainer: Container {
|
|
|
|
/// Can be overriden to change how the molecule is added to the hierarchy.
|
|
public func addMolecule(_ molecule: UIView) {
|
|
addAndContain(molecule)
|
|
}
|
|
|
|
override public func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) {
|
|
guard let moleculeJSON = json?.optionalDictionaryForKey(KeyMolecule) else {
|
|
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
|
return
|
|
}
|
|
if view == nil {
|
|
if let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject, constrainIfNeeded: false) {
|
|
addAndContain(molecule)
|
|
}
|
|
} else {
|
|
(view as? MVMCoreUIMoleculeViewProtocol)?.setWithJSON?(moleculeJSON, delegateObject: delegateObject, additionalData: additionalData)
|
|
}
|
|
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
|
}
|
|
|
|
public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
|
if let casteModel = model as? MoleculeContainerModel {
|
|
if view != nil {
|
|
(view as? ModelMoleculeViewProtocol)?.setWithModel(casteModel.molecule, delegateObject, additionalData)
|
|
} else {
|
|
if let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(casteModel.molecule, delegateObject) {
|
|
addMolecule(molecule)
|
|
}
|
|
}
|
|
}
|
|
super.setWithModel(model, delegateObject, additionalData)
|
|
}
|
|
|
|
public override static func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
|
guard let containerModel = model as? MoleculeContainerModel,
|
|
let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(containerModel.molecule) as? ModelMoleculeViewProtocol.Type,
|
|
let moleculeName = moleculeClass.nameForReuse(containerModel.molecule, delegateObject) else {
|
|
return "\(model?.moleculeName ?? "moleculeContainer")<>"
|
|
}
|
|
return "\(model?.moleculeName ?? "moleculeContainer")<\(moleculeName)>"
|
|
}
|
|
|
|
public override class func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
|
guard let containerModel = molecule as? MoleculeContainerModel else { return 0 }
|
|
guard let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(containerModel.molecule) as? ModelMoleculeViewProtocol.Type,
|
|
let moleculeHeight = moleculeClass.estimatedHeight(forRow: containerModel.molecule, delegateObject: delegateObject) else {
|
|
return (containerModel.topMarginPadding ?? 0) + (containerModel.bottomMarginPadding ?? 0)
|
|
}
|
|
return moleculeHeight + (containerModel.topMarginPadding ?? 0) + (containerModel.bottomMarginPadding ?? 0)
|
|
}
|
|
|
|
public override class func requiredModules(_ molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? {
|
|
guard let containerModel = molecule as? MoleculeContainerModel,
|
|
let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(containerModel.molecule) as? ModelMoleculeViewProtocol.Type else { return nil }
|
|
return moleculeClass.requiredModules(containerModel.molecule, delegateObject: delegateObject, error: error)
|
|
}
|
|
}
|