module molecule

This commit is contained in:
Suresh, Kamlesh 2019-12-06 14:30:19 -05:00
parent 9676f41633
commit 3a1e3356bf
8 changed files with 60 additions and 52 deletions

View File

@ -45,6 +45,7 @@
017BEB4A236235BA0024EF95 /* ModelMoleculeViewProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB49236235BA0024EF95 /* ModelMoleculeViewProtocol.swift */; };
017BEB7B236763000024EF95 /* LineModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB7A236763000024EF95 /* LineModel.swift */; };
017BEB7F23676E870024EF95 /* MoleculeObjectMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB7E23676E870024EF95 /* MoleculeObjectMapping.swift */; };
0189255C239AA7EB004E8AFF /* ModuleDelegateProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0189255B239AA7EB004E8AFF /* ModuleDelegateProtocol.swift */; };
0198F79F225679880066C936 /* FormValidationProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0198F79E225679870066C936 /* FormValidationProtocol.swift */; };
0198F7A62256A80B0066C936 /* MFRadioButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 0198F7A02256A80A0066C936 /* MFRadioButton.h */; settings = {ATTRIBUTES = (Public, ); }; };
0198F7A82256A80B0066C936 /* MFRadioButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 0198F7A22256A80A0066C936 /* MFRadioButton.m */; };
@ -293,6 +294,7 @@
017BEB49236235BA0024EF95 /* ModelMoleculeViewProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelMoleculeViewProtocol.swift; sourceTree = "<group>"; };
017BEB7A236763000024EF95 /* LineModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LineModel.swift; sourceTree = "<group>"; };
017BEB7E23676E870024EF95 /* MoleculeObjectMapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeObjectMapping.swift; sourceTree = "<group>"; };
0189255B239AA7EB004E8AFF /* ModuleDelegateProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModuleDelegateProtocol.swift; sourceTree = "<group>"; };
0198F79E225679870066C936 /* FormValidationProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormValidationProtocol.swift; sourceTree = "<group>"; };
0198F7A02256A80A0066C936 /* MFRadioButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MFRadioButton.h; sourceTree = "<group>"; };
0198F7A22256A80A0066C936 /* MFRadioButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MFRadioButton.m; sourceTree = "<group>"; };
@ -1038,6 +1040,7 @@
D2A514572211C53C00345BFB /* MVMCoreUIMoleculeMappingObject.m */,
017BEB432362192F0024EF95 /* MVMCoreUIMoleculeMappingObject+ModelExtension.swift */,
017BEB7E23676E870024EF95 /* MoleculeObjectMapping.swift */,
0189255B239AA7EB004E8AFF /* ModuleDelegateProtocol.swift */,
);
path = OtherHandlers;
sourceTree = "<group>";
@ -1313,6 +1316,7 @@
D29DF27621E79E81003B2FB9 /* MVMCoreUILoggingHandler.m in Sources */,
D29DF24D21E6A177003B2FB9 /* MFTextField.m in Sources */,
012A88C4238D86E600FE3DA1 /* CollectionCellMoleculeProtocol.swift in Sources */,
0189255C239AA7EB004E8AFF /* ModuleDelegateProtocol.swift in Sources */,
94C2D9AB23872EB50006CF46 /* LabelAttributeActionModel.swift in Sources */,
017BEB4023620A230024EF95 /* TextFieldModel.swift in Sources */,
D29DF2A221E7AF4E003B2FB9 /* MVMCoreUIUtility.m in Sources */,

View File

@ -8,8 +8,24 @@
import Foundation
extension MFViewController: ModuleDelegateProtocol {
public func getModuleWithName(_ moleculeName: String) -> Model? {
guard let moduleJSON = loadObject?.modulesJSON?.optionalDictionaryForKey(moleculeName),
let moleculeName = moduleJSON.optionalStringForKey("moleculeName"),
let modelType = ModelRegistry.getType(for: moleculeName) else {
return nil
}
do {
return try modelType.decode(jsonDict: moduleJSON)
} catch {
MVMCoreUILoggingHandler.logDebugMessage(withDelegate: "error: \(error)")
}
return nil
}
}
public extension MFViewController {
@objc func parsePageJSON() {
(self as? TemplateProtocol)?.parseTemplateJSON()

View File

@ -8,7 +8,7 @@
import Foundation
class ModuleMoleculeModel: MoleculeProtocol {
public class ModuleMoleculeModel: MoleculeProtocol {
public static var identifier: String = "moduleMolecule"
public var moduleName: String
public var backgroundColor: String?

View File

@ -10,7 +10,7 @@ import UIKit
open class ModuleMolecule: ViewConstrainingView, ModelMoleculeViewProtocol {
open var moduleMolecule: (UIView & MVMCoreUIMoleculeViewProtocol)?
open var moduleMolecule: (UIView & MVMCoreUIMoleculeViewProtocol & ModelMoleculeViewProtocol)?
open override func updateView(_ size: CGFloat) {
super.updateView(size)
@ -23,58 +23,28 @@ open class ModuleMolecule: ViewConstrainingView, ModelMoleculeViewProtocol {
setUpWithModel(model, delegateObject, additionalData)
guard let moduleMoleculeModel = model as? ModuleMoleculeModel,
let module = delegateObject?.moleculeDelegate?.getModuleWithName(moduleMoleculeModel.moduleName) else {
let moduleModel = delegateObject?.moduleProtocol?.getModuleWithName(moduleMoleculeModel.moduleName) as? MoleculeProtocol else {
// Critical error
return
}
// if moduleMolecule == nil {
// MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(<#T##model: MoleculeProtocol##MoleculeProtocol#>, <#T##delegateObject: MVMCoreUIDelegateObject?##MVMCoreUIDelegateObject?#>, <#T##constrainIfNeeded: Bool##Bool#>)
// if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: module, delegateObject: delegateObject, constrainIfNeeded: true) {
// addSubview(moleculeView)
// NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: moleculeView, useMargins: false).values))
// moduleMolecule = moleculeView
//
// isAccessibilityElement = false
// if moleculeView.accessibilityElements != nil {
// accessibilityElements = moleculeView.accessibilityElements
// } else {
// accessibilityElements = [moleculeView]
// }
// }
// } else {
// moduleMolecule?.setWithJSON(module, delegateObject: delegateObject, additionalData: additionalData)
// }
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)
}
}
// // MARK: - MVMCoreUIMoleculeViewProtocol
// open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
// super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
//
// guard let moduleName = json?.optionalStringForKey("moduleName"),
// let module = delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) else {
// // Critical error
// return
// }
//
// if moduleMolecule == nil {
// if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: module, delegateObject: delegateObject, constrainIfNeeded: true) {
// addSubview(moleculeView)
// NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: moleculeView, useMargins: false).values))
// moduleMolecule = moleculeView
//
// isAccessibilityElement = false
// if moleculeView.accessibilityElements != nil {
// accessibilityElements = moleculeView.accessibilityElements
// } else {
// accessibilityElements = [moleculeView]
// }
// }
// } else {
// moduleMolecule?.setWithJSON(module, delegateObject: delegateObject, additionalData: additionalData)
// }
// }
open override func setAsMolecule() {
super.setAsMolecule()

View File

@ -13,6 +13,7 @@ open class MVMCoreUIDelegateObject: DelegateObject {
public weak var buttonDelegate: ButtonDelegateProtocol?
public weak var uiTextFieldDelegate: UITextFieldDelegate?
public weak var moleculeDelegate: MoleculeDelegateProtocol?
public var moduleProtocol: ModuleDelegateProtocol?
open override func setAll(withDelegate delegate: Any) {
super.setAll(withDelegate: delegate)
@ -20,9 +21,11 @@ open class MVMCoreUIDelegateObject: DelegateObject {
buttonDelegate = delegate as? ButtonDelegateProtocol
uiTextFieldDelegate = delegate as? UITextFieldDelegate
moleculeDelegate = delegate as? MoleculeDelegateProtocol
moduleProtocol = delegate as? ModuleDelegateProtocol
}
class func delegateObject(from controller: MVMCoreViewControllerProtocol?) -> MVMCoreUIDelegateObject? {
return controller?.delegateObject?() as? MVMCoreUIDelegateObject
}
}

View File

@ -29,10 +29,10 @@
- (nullable UIView <MVMCoreUIMoleculeViewProtocol>*)createMoleculeForName:(nonnull NSString *)name;
/// Creates the molecule for the molecule json.
//- (nullable UIView <MVMCoreUIMoleculeViewProtocol>*)createMoleculeForJSON:(nonnull NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject;
//
///// Creates the molecule for the molecule json. Also checks if the molecule needs to be constrained for a stack/list style situation.
//- (nullable UIView <MVMCoreUIMoleculeViewProtocol>*)createMoleculeForJSON:(nonnull NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject constrainIfNeeded:(BOOL)constrainIfNeeded;
- (nullable UIView <MVMCoreUIMoleculeViewProtocol>*)createMoleculeForJSON:(nonnull NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject;
/// Creates the molecule for the molecule json. Also checks if the molecule needs to be constrained for a stack/list style situation.
- (nullable UIView <MVMCoreUIMoleculeViewProtocol>*)createMoleculeForJSON:(nonnull NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject constrainIfNeeded:(BOOL)constrainIfNeeded;
#pragma mark - Convenience

View File

@ -0,0 +1,14 @@
//
// ModuleDelegateProtocol.swift
// MVMCoreUI
//
// Created by Suresh, Kamlesh on 12/6/19.
// Copyright © 2019 Verizon Wireless. All rights reserved.
//
import Foundation
public protocol ModuleDelegateProtocol {
func getModuleWithName(_ moleculeName: String) -> Model?
}

View File

@ -30,5 +30,6 @@ import Foundation
ModelRegistry.register(LabelAttributeUnderlineModel.self)
ModelRegistry.register(LabelAttributeStrikeThroughModel.self)
ModelRegistry.register(LabelAttributeActionModel.self)
ModelRegistry.register(ModuleMoleculeModel.self)
}
}