83 lines
4.1 KiB
Swift
83 lines
4.1 KiB
Swift
//
|
|
// ModuleMolecule.swift
|
|
// MVMCoreUI
|
|
//
|
|
// Created by Scott Pfeil on 6/25/19.
|
|
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
open class ModuleMolecule: Container {
|
|
|
|
open var moduleMolecule: (UIView & MVMCoreUIMoleculeViewProtocol & ModelMoleculeViewProtocol)?
|
|
var moduleMoleculeModel: ModuleMoleculeModel? {
|
|
get { return model as? ModuleMoleculeModel }
|
|
}
|
|
|
|
public override func setupView() {
|
|
super.setupView()
|
|
}
|
|
|
|
public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String: AnyHashable]?) {
|
|
#warning("This below call should be repaced with super.setWithModel once we get rid of ViewConstrainingView.")
|
|
//TODO: This below call should be repaced with super.setWithModel once we get rid of ViewConstrainingView.
|
|
|
|
guard let moduleMoleculeModel = model as? ModuleMoleculeModel,
|
|
let moduleModel = delegateObject?.moduleProtocol?.getModuleWithName(moduleMoleculeModel.moduleName) as? MoleculeProtocol else {
|
|
// Critical error
|
|
return
|
|
}
|
|
|
|
if moduleMolecule == nil {
|
|
if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(moduleModel, delegateObject, true) {
|
|
addSubview(moleculeView)
|
|
NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: moleculeView, useMargins: false).values))
|
|
moduleMolecule = moleculeView as? (UIView & MVMCoreUIMoleculeViewProtocol & ModelMoleculeViewProtocol)
|
|
|
|
isAccessibilityElement = false
|
|
if moleculeView.accessibilityElements != nil {
|
|
accessibilityElements = moleculeView.accessibilityElements
|
|
} else {
|
|
accessibilityElements = [moleculeView]
|
|
}
|
|
}
|
|
} else {
|
|
moduleMolecule?.setWithModel(model, delegateObject, additionalData)
|
|
}
|
|
}
|
|
|
|
#warning("Kamlesh: uncomment below code")
|
|
//TODO: Kamlesh: uncomment below code
|
|
|
|
// public override class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
|
// guard let moduleName = json?.optionalStringForKey("moduleName"), let module = delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) else {
|
|
// // Critical error
|
|
// return 0
|
|
// }
|
|
// return MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: module)?.estimatedHeight?(forRow: module, delegateObject: delegateObject) ?? 0
|
|
// }
|
|
//
|
|
// public override class func name(forReuse molecule: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
|
// guard let moduleName = molecule?.optionalStringForKey("moduleName"), let module = delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) else {
|
|
// // Critical error
|
|
// return "moduleMolecule<>"
|
|
// }
|
|
// return "moduleMolecule<" + (MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: module)?.name?(forReuse: module, delegateObject: delegateObject) ?? module.stringForkey(KeyMoleculeName)) + ">"
|
|
// }
|
|
//
|
|
// public override class func requiredModules(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? {
|
|
// let moduleName = json?.optionalStringForKey("moduleName")
|
|
// if moduleName == nil || delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) == nil {
|
|
// if let errorObject = MVMCoreErrorObject(title: nil, message: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess), code: CoreUIErrorCode.ErrorCodeModuleMolecule.rawValue, domain: ErrorDomainNative, location: String(describing: self)) {
|
|
// error?.pointee = errorObject
|
|
// MVMCoreUILoggingHandler.shared()?.addError(toLog: errorObject)
|
|
// }
|
|
// }
|
|
// if let moduleName = moduleName {
|
|
// return [moduleName]
|
|
// }
|
|
// return nil
|
|
// }
|
|
}
|