46 lines
1.9 KiB
Swift
46 lines
1.9 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)
|
|
}
|
|
}
|