fixes
This commit is contained in:
parent
c6d5775d57
commit
1db2a5b058
@ -7,19 +7,48 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
import MVMCore
|
||||
|
||||
public class CaretButtonModel: MoleculeProtocol {
|
||||
public static var identifier: String = "caretButton"
|
||||
public var backgroundColor: String?
|
||||
public var label: String
|
||||
public var action: ActionModel
|
||||
public var label: LabelModel
|
||||
public var action: ActionProtocol
|
||||
public var enabledColor: String?
|
||||
public var disabledColor: String?
|
||||
public var enabled: Bool?
|
||||
|
||||
public init(label: String, action: ActionModel) {
|
||||
|
||||
public init(label: LabelModel, action: ActionProtocol) {
|
||||
self.label = label
|
||||
self.action = action
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case backgroundColor
|
||||
case label
|
||||
case action
|
||||
case enabledColor
|
||||
case disabledColor
|
||||
case enabled
|
||||
}
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor)
|
||||
label = try typeContainer.decode(LabelModel.self, forKey: .label)
|
||||
enabledColor = try typeContainer.decodeIfPresent(String.self, forKey: .enabledColor)
|
||||
disabledColor = try typeContainer.decodeIfPresent(String.self, forKey: .disabledColor)
|
||||
enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled)
|
||||
action = try typeContainer.decode(codingKey: .action, typeCodingKey: ActionCodingKey.type)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(label, forKey: .label)
|
||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||
try container.encodeIfPresent(action, forKey: .action)
|
||||
try container.encodeIfPresent(enabledColor, forKey: .enabledColor)
|
||||
try container.encodeIfPresent(disabledColor, forKey: .disabledColor)
|
||||
try container.encodeIfPresent(enabled, forKey: .enabled)
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,7 +38,9 @@ extension MFTextField: ModelMoleculeViewProtocol {
|
||||
|
||||
formText = textFieldModel.label as NSString?
|
||||
text = textFieldModel.value as NSString?
|
||||
enable(textFieldModel.disabled)
|
||||
if let disabled = textFieldModel.disabled {
|
||||
enable(disabled)
|
||||
}
|
||||
errMessage = textFieldModel.errorMsg
|
||||
fieldKey = textFieldModel.fieldKey
|
||||
groupName = textFieldModel.groupName
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
import Foundation
|
||||
|
||||
public protocol ContainerMoleculeProtocol: MoleculeProtocol {
|
||||
var molecule: MoleculeProtocol? { get }
|
||||
var molecule: MoleculeProtocol { get }
|
||||
var useHorizontalMargins: Bool? { get }
|
||||
var useVerticalMargins: Bool? { get }
|
||||
var horizontalAlignment: String? { get }
|
||||
@ -17,11 +17,6 @@ public protocol ContainerMoleculeProtocol: MoleculeProtocol {
|
||||
}
|
||||
|
||||
extension ContainerMoleculeProtocol {
|
||||
|
||||
public var molecule: MoleculeProtocol? {
|
||||
get { return nil }
|
||||
}
|
||||
|
||||
public var backgroundColor: String? {
|
||||
get { return nil }
|
||||
}
|
||||
|
||||
@ -9,6 +9,6 @@
|
||||
import Foundation
|
||||
|
||||
public protocol ListItemModelProtocol: ContainerMoleculeProtocol {
|
||||
var molecule: MoleculeProtocol? { get }
|
||||
var molecule: MoleculeProtocol { get }
|
||||
var separator: LineModel? { get set }
|
||||
}
|
||||
|
||||
@ -3,15 +3,10 @@ import Foundation
|
||||
public protocol MoleculeProtocol: Model {
|
||||
var moleculeName: String? { get }
|
||||
var backgroundColor: String? { get }
|
||||
var dictionary: [AnyHashable: Any]? { get }
|
||||
}
|
||||
|
||||
extension MoleculeProtocol {
|
||||
public var moleculeName: String? {
|
||||
get { return Self.identifier }
|
||||
}
|
||||
|
||||
public var dictionary: [AnyHashable: Any]? {
|
||||
return toJSON()
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,10 +11,10 @@ import Foundation
|
||||
|
||||
@objcMembers public class CarouselItemModel: ContainerMoleculeProtocol {
|
||||
public static var identifier: String = "carouselItem"
|
||||
public var backgroundColor: String?
|
||||
public var molecule: MoleculeProtocol
|
||||
|
||||
public init(backgroundColor: String?) {
|
||||
self.backgroundColor = backgroundColor
|
||||
public init(molecule: MoleculeProtocol) {
|
||||
self.molecule = molecule
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
@ -25,13 +25,14 @@ import Foundation
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.backgroundColor = try typeContainer.decode(String.self, forKey: .backgroundColor)
|
||||
molecule = try typeContainer.decode(codingKey: .molecule)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(moleculeName, forKey: .moleculeName)
|
||||
try container.encode(backgroundColor, forKey: .backgroundColor)
|
||||
try container.encode(molecule, forKey: .molecule)
|
||||
try container.encodeIfPresent(self.molecule, forKey: .molecule)
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,17 +10,20 @@ import Foundation
|
||||
|
||||
@objcMembers public class DropDownListItemModel: ListItemModelProtocol {
|
||||
public static var identifier: String = "dropDownListItem"
|
||||
public var molecule: MoleculeProtocol
|
||||
public var molecules: [[ListItemModel]]
|
||||
public var backgroundColor: String?
|
||||
public var separator: LineModel?
|
||||
public var dropDown: DropDownModel
|
||||
|
||||
public init(molecules: [[ListItemModel]], dropDown: DropDownModel) {
|
||||
public init(molecule: MoleculeProtocol, molecules: [[ListItemModel]], dropDown: DropDownModel) {
|
||||
self.molecule = molecule
|
||||
self.molecules = molecules
|
||||
self.dropDown = dropDown
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case molecule
|
||||
case moleculeName
|
||||
case molecules
|
||||
case separator
|
||||
@ -30,6 +33,7 @@ import Foundation
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
molecule = try typeContainer.decode(codingKey: .molecule)
|
||||
self.molecules = try typeContainer.decode([[ListItemModel]].self, forKey: .molecules)
|
||||
self.separator = try typeContainer.decode(LineModel.self, forKey: .separator)
|
||||
self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor)
|
||||
@ -38,6 +42,7 @@ import Foundation
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(molecule, forKey: .molecule)
|
||||
try container.encode(moleculeName, forKey: .moleculeName)
|
||||
try container.encode(molecules, forKey: .molecules)
|
||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||
|
||||
@ -13,11 +13,10 @@ import Foundation
|
||||
public static var identifier: String = "footer"
|
||||
public var moleculeName: String?
|
||||
public var backgroundColor: String?
|
||||
public var molecule: MoleculeProtocol?
|
||||
public var molecule: MoleculeProtocol
|
||||
|
||||
public init(molecule: MoleculeProtocol?, backgroundColor: String?){
|
||||
public init(molecule: MoleculeProtocol){
|
||||
self.molecule = molecule
|
||||
self.backgroundColor = backgroundColor
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
@ -31,7 +30,7 @@ import Foundation
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName)
|
||||
self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor)
|
||||
self.molecule = try typeContainer.decodeIfPresent(codingKey: .molecule)
|
||||
self.molecule = try typeContainer.decode(codingKey: .molecule)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
@ -39,5 +38,6 @@ import Foundation
|
||||
try container.encode(moleculeName, forKey: .moleculeName)
|
||||
try container.encodeIfPresent(self.molecule, forKey: .molecule)
|
||||
try container.encodeIfPresent(self.backgroundColor, forKey: .backgroundColor)
|
||||
try container.encode(molecule, forKey: .molecule)
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,13 +12,11 @@ import Foundation
|
||||
public static var identifier: String = "header"
|
||||
public var moleculeName: String?
|
||||
public var backgroundColor: String?
|
||||
public var molecule: MoleculeProtocol?
|
||||
public var molecule: MoleculeProtocol
|
||||
public var seperator: LineModel?
|
||||
|
||||
public init(molecule: MoleculeProtocol?, backgroundColor: String?, seperator: LineModel?){
|
||||
public init(molecule: MoleculeProtocol){
|
||||
self.molecule = molecule
|
||||
self.backgroundColor = backgroundColor
|
||||
self.seperator = seperator
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
@ -32,7 +30,7 @@ import Foundation
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName)
|
||||
self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor)
|
||||
self.molecule = try typeContainer.decodeIfPresent(codingKey: .molecule)
|
||||
self.molecule = try typeContainer.decode(codingKey: .molecule)
|
||||
self.seperator = try typeContainer.decodeIfPresent(LineModel.self, forKey: .separator)
|
||||
}
|
||||
|
||||
@ -42,5 +40,6 @@ import Foundation
|
||||
try container.encodeIfPresent(self.molecule, forKey: .molecule)
|
||||
try container.encodeIfPresent(self.backgroundColor, forKey: .backgroundColor)
|
||||
try container.encodeIfPresent(self.seperator, forKey: .separator)
|
||||
try container.encode(molecule, forKey: .molecule)
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,8 +13,8 @@ import UIKit
|
||||
public static var identifier: String = "textField"
|
||||
public var backgroundColor: String?
|
||||
|
||||
public var editable = true
|
||||
public var disabled = false
|
||||
public var editable: Bool?
|
||||
public var disabled: Bool?
|
||||
public var errorMsg: String?
|
||||
public var label: String?
|
||||
public var type: String?
|
||||
|
||||
@ -7,16 +7,21 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import MVMCore
|
||||
|
||||
@objcMembers public class ListItemModel: ListItemModelProtocol {
|
||||
public static var identifier: String = "listItem"
|
||||
public var molecule: MoleculeProtocol?
|
||||
public var molecule: MoleculeProtocol
|
||||
public var backgroundColor: String?
|
||||
public var action: ActionModel?
|
||||
public var action: ActionProtocol?
|
||||
public var hideArrow: Bool?
|
||||
public var separator: LineModel?
|
||||
public var style: String?
|
||||
|
||||
public init(molecule: MoleculeProtocol) {
|
||||
self.molecule = molecule
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case moleculeName
|
||||
case molecule
|
||||
@ -28,8 +33,8 @@ import Foundation
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
molecule = try typeContainer.decodeIfPresent(codingKey: .molecule)
|
||||
action = try typeContainer.decodeIfPresent(ActionModel.self, forKey: .action)
|
||||
molecule = try typeContainer.decode(codingKey: .molecule)
|
||||
action = try typeContainer.decodeIfPresent(codingKey: .action, typeCodingKey: ActionCodingKey.type)
|
||||
hideArrow = try typeContainer.decodeIfPresent(Bool.self, forKey: .hideArrow)
|
||||
separator = try typeContainer.decodeIfPresent(LineModel.self, forKey: .separator)
|
||||
style = try typeContainer.decodeIfPresent(String.self, forKey: .style)
|
||||
@ -38,7 +43,7 @@ import Foundation
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(moleculeName, forKey: .moleculeName)
|
||||
try container.encodeIfPresent(molecule, forKey: .molecule)
|
||||
try container.encode(molecule, forKey: .molecule)
|
||||
try container.encodeIfPresent(action, forKey: .action)
|
||||
try container.encodeIfPresent(hideArrow, forKey: .hideArrow)
|
||||
try container.encodeIfPresent(separator, forKey: .separator)
|
||||
|
||||
@ -90,18 +90,14 @@ open class MoleculeCollectionViewCell: UICollectionViewCell, MVMCoreUIMoleculeVi
|
||||
backgroundColor = UIColor.mfGet(forHex: backgroundColorString)
|
||||
}
|
||||
|
||||
guard let moleculeModel = collectionModel.molecule else {
|
||||
return
|
||||
}
|
||||
|
||||
if molecule == nil {
|
||||
if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(moleculeModel, delegateObject, true) {
|
||||
if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(collectionModel.molecule, delegateObject, true) {
|
||||
contentView.insertSubview(moleculeView, at: 0)
|
||||
NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: moleculeView, useMargins: true).values))
|
||||
molecule = moleculeView
|
||||
}
|
||||
} else {
|
||||
(molecule as? ModelMoleculeViewProtocol)?.setWithModel(moleculeModel, delegateObject, additionalData)
|
||||
(molecule as? ModelMoleculeViewProtocol)?.setWithModel(collectionModel.molecule, delegateObject, additionalData)
|
||||
}
|
||||
|
||||
// This molecule will handle spacing by default.
|
||||
|
||||
@ -14,7 +14,7 @@ import UIKit
|
||||
super.setWithModel(model, delegateObject, additionalData)
|
||||
|
||||
guard let model = model,
|
||||
let moleculeModel = (model as? ContainerMoleculeProtocol)?.molecule,
|
||||
let moleculeModel = (model as? ListItemModelProtocol)?.molecule,
|
||||
let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(moleculeModel, delegateObject, true) else {
|
||||
return
|
||||
}
|
||||
@ -22,7 +22,7 @@ import UIKit
|
||||
}
|
||||
|
||||
public override class func name(forReuse molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
||||
guard let moleculeModel = (molecule as? ContainerMoleculeProtocol)?.molecule else {
|
||||
guard let moleculeModel = (molecule as? ListItemModelProtocol)?.molecule else {
|
||||
return "\(self)<>"
|
||||
}
|
||||
let className = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moleculeModel) as? ModelMoleculeViewProtocol
|
||||
|
||||
@ -179,8 +179,7 @@ import UIKit
|
||||
bottomSeparatorView?.setWithModel(separator, nil, nil)
|
||||
}
|
||||
|
||||
guard let moleculeModel = model.molecule else { return }
|
||||
(molecule as? ModelMoleculeViewProtocol)?.setWithModel(moleculeModel, delegateObject, additionalData)
|
||||
(molecule as? ModelMoleculeViewProtocol)?.setWithModel(model.molecule, delegateObject, additionalData)
|
||||
|
||||
// This molecule will by default handle margins.
|
||||
if let castView = molecule as? MVMCoreUIViewConstrainingProtocol {
|
||||
|
||||
@ -31,7 +31,7 @@ public extension MVMCoreUIMoleculeMappingObject {
|
||||
if let molecule = molecule as? ModelMoleculeViewProtocol {
|
||||
molecule.setWithModel(model, delegateObject, nil)
|
||||
} else {
|
||||
molecule.setWithJSON?(model.dictionary, delegateObject: delegateObject, additionalData: nil)
|
||||
molecule.setWithJSON?(model.toJSON(), delegateObject: delegateObject, additionalData: nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -9,6 +9,6 @@
|
||||
import Foundation
|
||||
|
||||
public protocol ModelMoleculeDelegateProtocol {
|
||||
func addMolecules(_ molecules: [MoleculeProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation)
|
||||
func removeMolecules(_ molecules: [MoleculeProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation)
|
||||
func addMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation)
|
||||
func removeMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation)
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ import UIKit
|
||||
|
||||
open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol, ModelMoleculeDelegateProtocol {
|
||||
|
||||
public var moleculesInfo: [(identifier: String, class: AnyClass, molecule: MoleculeProtocol)]?
|
||||
public var moleculesInfo: [(identifier: String, class: AnyClass, molecule: ListItemModelProtocol)]?
|
||||
var observer: NSKeyValueObservation?
|
||||
|
||||
public var templateModel: TemplateModelProtocol?
|
||||
@ -139,7 +139,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
|
||||
}
|
||||
}
|
||||
|
||||
public func addMolecules(_ molecules: [MoleculeProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) {
|
||||
public func addMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) {
|
||||
// This dispatch is needed to fix a race condition that can occur if this function is called during the table setup.
|
||||
DispatchQueue.main.async {
|
||||
guard let indexPath = self.tableView?.indexPath(for: sender) else { return }
|
||||
@ -157,7 +157,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
|
||||
self.view.layoutIfNeeded()
|
||||
}
|
||||
}
|
||||
public func removeMolecules(_ molecules: [MoleculeProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) {
|
||||
public func removeMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) {
|
||||
var indexPaths: [IndexPath] = []
|
||||
//TODO: cehck for molecule protocola eqality
|
||||
for molecule in molecules {
|
||||
@ -172,23 +172,21 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
|
||||
self.updateViewConstraints()
|
||||
self.view.layoutIfNeeded()
|
||||
}
|
||||
|
||||
|
||||
|
||||
// MARK: - Convenience
|
||||
/// Returns the (identifier, class) of the molecule for the given map.
|
||||
func getMoleculeInfo(with molecule: MoleculeProtocol?) -> (identifier: String, class: AnyClass, molecule: MoleculeProtocol)? {
|
||||
guard let molecule = molecule,
|
||||
let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(molecule),
|
||||
let moleculeName = (moleculeClass as? ModelMoleculeViewProtocol.Type)?.name(forReuse: molecule, delegateObject: delegateObject() as? MVMCoreUIDelegateObject) ?? molecule.moleculeName else {
|
||||
func getMoleculeInfo(with listItem: ListItemModelProtocol?) -> (identifier: String, class: AnyClass, molecule: ListItemModelProtocol)? {
|
||||
guard let listItem = listItem,
|
||||
let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(listItem),
|
||||
let moleculeName = (moleculeClass as? ModelMoleculeViewProtocol.Type)?.name(forReuse: listItem, delegateObject: delegateObject() as? MVMCoreUIDelegateObject) ?? listItem.molecule.moleculeName else {
|
||||
return nil
|
||||
}
|
||||
return (moleculeName, moleculeClass, molecule)
|
||||
return (moleculeName, moleculeClass, listItem)
|
||||
}
|
||||
|
||||
/// Sets up the molecule list and ensures no errors loading all content.
|
||||
func getMoleculeInfoList() -> [(identifier: String, class: AnyClass, molecule: MoleculeProtocol)]? {
|
||||
var moleculeList: [(identifier: String, class: AnyClass, molecule: MoleculeProtocol)] = []
|
||||
func getMoleculeInfoList() -> [(identifier: String, class: AnyClass, molecule: ListItemModelProtocol)]? {
|
||||
var moleculeList: [(identifier: String, class: AnyClass, molecule: ListItemModelProtocol)] = []
|
||||
if let molecules = (templateModel as? ListPageTemplateModel)?.molecules {
|
||||
for molecule in molecules {
|
||||
if let info = getMoleculeInfo(with: molecule) {
|
||||
@ -201,14 +199,14 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
|
||||
|
||||
/// Sets up the header, footer, molecule list and ensures no errors loading all content.
|
||||
func setup() {
|
||||
var moleculeList: [(identifier: String, class: AnyClass, molecule: MoleculeProtocol)] = []
|
||||
if let molecules = loadObject?.pageJSON?.optionalArrayForKey(KeyMolecules) as? [MoleculeProtocol] {
|
||||
for molecule in molecules {
|
||||
if let info = getMoleculeInfo(with: molecule) {
|
||||
moleculeList.append(info)
|
||||
}
|
||||
}
|
||||
}
|
||||
var moleculeList: [(identifier: String, class: AnyClass, molecule: ListItemModelProtocol)] = []
|
||||
if let molecules = (templateModel as? ListPageTemplateModel)?.molecules {
|
||||
for molecule in molecules {
|
||||
if let info = getMoleculeInfo(with: molecule) {
|
||||
moleculeList.append(info)
|
||||
}
|
||||
}
|
||||
}
|
||||
moleculesInfo = moleculeList
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user