From 9bce3f02a1aa94ddef1a7c873e529651d92aa4cb Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Fri, 6 Mar 2020 17:06:20 -0500 Subject: [PATCH] shifting and improving --- MVMCoreUI/BaseClasses/TableViewCell.swift | 3 +++ .../ImageHeadlineBodyModel.swift | 5 +++++ .../TwoButtonView.swift | 2 ++ .../Items/MoleculeTableViewCell.swift | 18 +++++++++--------- .../HeadlineBodyModel.swift | 6 +++++- MVMCoreUI/Templates/MoleculeListTemplate.swift | 8 ++++---- 6 files changed, 28 insertions(+), 14 deletions(-) diff --git a/MVMCoreUI/BaseClasses/TableViewCell.swift b/MVMCoreUI/BaseClasses/TableViewCell.swift index 63824c04..ebf25a3c 100644 --- a/MVMCoreUI/BaseClasses/TableViewCell.swift +++ b/MVMCoreUI/BaseClasses/TableViewCell.swift @@ -176,6 +176,9 @@ import UIKit let backgroundColor = moleculeModel.backgroundColor { self.backgroundColor = backgroundColor.uiColor } + + // align if needed. + containerHelper.set(with: model, for: molecule as? MVMCoreUIViewConstrainingProtocol) } open func reset() { diff --git a/MVMCoreUI/Molecules/HorizontalCombinationViews/ImageHeadlineBodyModel.swift b/MVMCoreUI/Molecules/HorizontalCombinationViews/ImageHeadlineBodyModel.swift index 7f3d52dc..f34e7b94 100644 --- a/MVMCoreUI/Molecules/HorizontalCombinationViews/ImageHeadlineBodyModel.swift +++ b/MVMCoreUI/Molecules/HorizontalCombinationViews/ImageHeadlineBodyModel.swift @@ -14,4 +14,9 @@ public struct ImageHeadlineBodyModel: MoleculeModelProtocol { public var backgroundColor: Color? public var image: ImageViewModel public var headlineBody: HeadlineBodyModel + + public init(image: ImageViewModel, headlineBody: HeadlineBodyModel) { + self.image = image + self.headlineBody = headlineBody + } } diff --git a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift index 50288c58..98160441 100644 --- a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift +++ b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift @@ -109,7 +109,9 @@ import UIKit public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) + guard let model = model as? TwoButtonViewModel else { return } + if let secondaryModel = model.secondaryButton { showSecondaryButton() secondaryButton.set(with: secondaryModel, delegateObject, additionalData) diff --git a/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift b/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift index f1d3794b..33229092 100644 --- a/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift @@ -14,18 +14,18 @@ import UIKit // MARK: - MVMCoreUIMoleculeViewProtocol public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { - super.set(with: model, delegateObject, additionalData) - guard let model = model as? MoleculeListItemModel else { return } - - if molecule != nil { - (molecule as? ModelMoleculeViewProtocol)?.set(with: model.molecule, delegateObject, additionalData) - - } else if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(model.molecule, delegateObject, false) { - addMolecule(moleculeView) + guard let castModel = model as? MoleculeListItemModel else { + super.set(with: model, delegateObject, additionalData) + return } - containerHelper.set(with: model, for: molecule as? MVMCoreUIViewConstrainingProtocol) + if molecule != nil { + (molecule as? ModelMoleculeViewProtocol)?.set(with: castModel.molecule, delegateObject, additionalData) + } else if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(castModel.molecule, delegateObject, false) { + addMolecule(moleculeView) + } + super.set(with: model, delegateObject, additionalData) } public override class func nameForReuse(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { diff --git a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyModel.swift b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyModel.swift index d7a08091..0ec98c65 100644 --- a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyModel.swift +++ b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyModel.swift @@ -8,7 +8,7 @@ import Foundation -@objcMembers public class HeadlineBodyModel: MoleculeModelProtocol { +@objcMembers open class HeadlineBodyModel: MoleculeModelProtocol { public static var identifier: String = "headlineBody" public var moleculeName: String? = HeadlineBodyModel.identifier public var headline: LabelModel? @@ -19,4 +19,8 @@ import Foundation public init(headline: LabelModel) { self.headline = headline } + + public init(body: LabelModel) { + self.body = body + } } diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index 33d6beb0..a4078f17 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -178,7 +178,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol } } - public override func addMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) { + open override func addMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) { var tmpMolecules = [ListItemModelProtocol & MoleculeModelProtocol]() @@ -207,7 +207,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol } } - public override func removeMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) { + open override func removeMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) { var tmpMolecules = [ListItemModelProtocol & MoleculeModelProtocol]() @@ -235,7 +235,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol view.layoutIfNeeded() } - public func addMolecules(_ molecules: [ListItemModelProtocol & MoleculeModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) { + open func addMolecules(_ molecules: [ListItemModelProtocol & MoleculeModelProtocol], 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 { @@ -257,7 +257,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol } } - public func removeMolecules(_ molecules: [ListItemModelProtocol & MoleculeModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) { + open func removeMolecules(_ molecules: [ListItemModelProtocol & MoleculeModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) { var indexPaths: [IndexPath] = [] //TODO: cehck for molecule protocola eqality