From 0a6b316198e4263daa3bdd0a7b6e1e42175f7ebc Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 5 Mar 2020 13:57:45 -0500 Subject: [PATCH 1/3] the latest --- .../Atoms/Views/LabelWithInternalButton.swift | 2 +- .../Atoms/Views/LeftRightLabelModel.swift | 12 +++++++++-- MVMCoreUI/BaseClasses/TableViewCell.swift | 8 ++++---- .../Views/Container/Container.swift | 6 +++--- .../Views/Container/ContainerHelper.swift | 20 +++++++++---------- 5 files changed, 28 insertions(+), 20 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift b/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift index c8484829..251f5b45 100644 --- a/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift +++ b/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift @@ -81,7 +81,7 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt return NSRange(location: 0, length: frontText?.count ?? 0) } - private var actionRange: NSRange { + public var actionRange: NSRange { return NSRange(location: frontText?.count ?? 0, length: actionText?.count ?? 0) } diff --git a/MVMCoreUI/Atoms/Views/LeftRightLabelModel.swift b/MVMCoreUI/Atoms/Views/LeftRightLabelModel.swift index d7ee1553..44564c93 100644 --- a/MVMCoreUI/Atoms/Views/LeftRightLabelModel.swift +++ b/MVMCoreUI/Atoms/Views/LeftRightLabelModel.swift @@ -8,14 +8,22 @@ import UIKit -@objcMembers public class LeftRightLabelModel: MoleculeModelProtocol { +@objcMembers open class LeftRightLabelModel: MoleculeModelProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public static var identifier: String = "leftRightLabelView" public var moleculeName: String? = LeftRightLabelModel.identifier public var backgroundColor: Color? public var leftText: LabelModel public var rightText: LabelModel? - init(_ leftText: LabelModel) { + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- + + public init(_ leftText: LabelModel) { self.leftText = leftText } } diff --git a/MVMCoreUI/BaseClasses/TableViewCell.swift b/MVMCoreUI/BaseClasses/TableViewCell.swift index 3154bbb9..63824c04 100644 --- a/MVMCoreUI/BaseClasses/TableViewCell.swift +++ b/MVMCoreUI/BaseClasses/TableViewCell.swift @@ -120,7 +120,7 @@ import UIKit } // MARK: - MFViewProtocol - public func updateView(_ size: CGFloat) { + open func updateView(_ size: CGFloat) { containerHelper.updateViewMargins(self, model: listItemModel, size: size) if accessoryView != nil { @@ -151,7 +151,7 @@ import UIKit } //TODO: ModelProtocol, Change to model - public func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + open func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { guard let model = model as? ListItemModelProtocol else { return } self.listItemModel = model @@ -183,11 +183,11 @@ import UIKit backgroundColor = .white } - public class func nameForReuse(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { + open class func nameForReuse(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { return model.moleculeName } - public class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { + open class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { return nil } diff --git a/MVMCoreUI/Containers/Views/Container/Container.swift b/MVMCoreUI/Containers/Views/Container/Container.swift index 96e6c3e8..a08cd651 100644 --- a/MVMCoreUI/Containers/Views/Container/Container.swift +++ b/MVMCoreUI/Containers/Views/Container/Container.swift @@ -23,15 +23,15 @@ open class Container: View, ContainerProtocol { } // MARK:- ContainerProtocol - public func alignHorizontal(_ alignment: UIStackView.Alignment) { + open func alignHorizontal(_ alignment: UIStackView.Alignment) { containerHelper.alignHorizontal(alignment) } - public func alignVertical(_ alignment: UIStackView.Alignment) { + open func alignVertical(_ alignment: UIStackView.Alignment) { containerHelper.alignVertical(alignment) } - public func constrainView(_ view: UIView) { + open func constrainView(_ view: UIView) { containerHelper.constrainView(view) } } diff --git a/MVMCoreUI/Containers/Views/Container/ContainerHelper.swift b/MVMCoreUI/Containers/Views/Container/ContainerHelper.swift index 77226341..223589fe 100644 --- a/MVMCoreUI/Containers/Views/Container/ContainerHelper.swift +++ b/MVMCoreUI/Containers/Views/Container/ContainerHelper.swift @@ -9,7 +9,7 @@ import Foundation -public class ContainerHelper: NSObject { +open class ContainerHelper: NSObject { var leftConstraint: NSLayoutConstraint? var topConstraint: NSLayoutConstraint? var bottomConstraint: NSLayoutConstraint? @@ -28,7 +28,7 @@ public class ContainerHelper: NSObject { var bottomLowConstraint: NSLayoutConstraint? var rightLowConstraint: NSLayoutConstraint? - func constrainView(_ view: UIView) { + open func constrainView(_ view: UIView) { guard let margins = view.superview?.layoutMarginsGuide else { return } leftConstraint = view.leftAnchor.constraint(equalTo: margins.leftAnchor) leftConstraint?.isActive = true @@ -69,7 +69,7 @@ public class ContainerHelper: NSObject { setAccessibility(view) } - func setAccessibility(_ view: UIView) { + open func setAccessibility(_ view: UIView) { guard let superView = view.superview else { return } superView.isAccessibilityElement = false if let elements = view.accessibilityElements { @@ -79,7 +79,7 @@ public class ContainerHelper: NSObject { } } - func alignHorizontal(_ alignment: UIStackView.Alignment) { + open func alignHorizontal(_ alignment: UIStackView.Alignment) { switch alignment { case .center: alignCenterHorizontalConstraint?.isActive = true @@ -109,7 +109,7 @@ public class ContainerHelper: NSObject { } } - func alignVertical(_ alignment: UIStackView.Alignment) { + open func alignVertical(_ alignment: UIStackView.Alignment) { switch alignment { case .center: alignCenterVerticalConstraint?.isActive = true @@ -139,7 +139,7 @@ public class ContainerHelper: NSObject { } } - static func getAlignment(for string: String) -> UIStackView.Alignment? { + public static func getAlignment(for string: String) -> UIStackView.Alignment? { switch string { case "leading": return .leading @@ -154,7 +154,7 @@ public class ContainerHelper: NSObject { } } - static func getAlignmentString(for alignment: UIStackView.Alignment?) -> String? { + public static func getAlignmentString(for alignment: UIStackView.Alignment?) -> String? { switch alignment { case .leading: return "leading" @@ -169,11 +169,11 @@ public class ContainerHelper: NSObject { } } - func updateViewMargins(_ view: UIView, model: ContainerModelProtocol?, size: CGFloat) { + open func updateViewMargins(_ view: UIView, model: ContainerModelProtocol?, size: CGFloat) { MFStyler.setMarginsFor(view, size: size, defaultHorizontal: model?.useHorizontalMargins ?? false, top: (model?.useVerticalMargins ?? false) ? (model?.topMarginPadding ?? 0) : 0, bottom: (model?.useVerticalMargins ?? false) ? (model?.bottomMarginPadding ?? 0) : 0) } - func set(with model: ContainerModelProtocol, for contained: MVMCoreUIViewConstrainingProtocol?) { + open func set(with model: ContainerModelProtocol, for contained: MVMCoreUIViewConstrainingProtocol?) { if let horizontalAlignment = model.horizontalAlignment ?? contained?.horizontalAlignment?() { alignHorizontal(horizontalAlignment) } @@ -182,7 +182,7 @@ public class ContainerHelper: NSObject { } } - func set(with JSON: [AnyHashable: Any]?, for contained: UIView) { + open func set(with JSON: [AnyHashable: Any]?, for contained: UIView) { if let horizontalAlignmentString = JSON?.optionalStringForKey("horizontalAlignment"), let alignment = ContainerHelper.getAlignment(for: horizontalAlignmentString) ?? (contained as? MVMCoreUIViewConstrainingProtocol)?.horizontalAlignment?() { alignHorizontal(alignment) } else if let alignment = (contained as? MVMCoreUIViewConstrainingProtocol)?.horizontalAlignment?() { From 9bce3f02a1aa94ddef1a7c873e529651d92aa4cb Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Fri, 6 Mar 2020 17:06:20 -0500 Subject: [PATCH 2/3] 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 From c96e2fa3c22a0fece536c655dfe4d1b334d296c3 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 9 Mar 2020 11:29:35 -0400 Subject: [PATCH 3/3] index path update --- .../BaseControllers/MFViewController+Model.swift | 9 +++++---- .../ModelMoleculeDelegateProtocol.swift | 6 ++++++ MVMCoreUI/Templates/MoleculeListTemplate.swift | 14 +++++++++++--- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/MVMCoreUI/BaseControllers/MFViewController+Model.swift b/MVMCoreUI/BaseControllers/MFViewController+Model.swift index e70e68f6..05e506eb 100644 --- a/MVMCoreUI/BaseControllers/MFViewController+Model.swift +++ b/MVMCoreUI/BaseControllers/MFViewController+Model.swift @@ -31,9 +31,10 @@ extension MFViewController: MoleculeDelegateProtocol { return nil } - @objc public func moleculeLayoutUpdated(_ molecule: UIView & MVMCoreUIMoleculeViewProtocol) { } + // These are required because swift will call the extension function otherwise. + @objc public func moleculeLayoutUpdated(_ molecule: UIView & MVMCoreUIMoleculeViewProtocol) {} - @objc public func addMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) { } - - @objc public func removeMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) { } + @objc public func addMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) {} + @objc public func addMolecules(_ molecules: [[AnyHashable : Any]], indexPath: IndexPath, animation: UITableView.RowAnimation) {} + @objc public func removeMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) {} } diff --git a/MVMCoreUI/OtherHandlers/ModelMoleculeDelegateProtocol.swift b/MVMCoreUI/OtherHandlers/ModelMoleculeDelegateProtocol.swift index d3a2fe80..eb175c3a 100644 --- a/MVMCoreUI/OtherHandlers/ModelMoleculeDelegateProtocol.swift +++ b/MVMCoreUI/OtherHandlers/ModelMoleculeDelegateProtocol.swift @@ -20,6 +20,8 @@ public protocol MoleculeDelegateProtocol { /// Asks the delegate to add or remove molecules. //optional func addMolecules(_ molecules: [[AnyHashable : Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) + func addMolecules(_ molecules: [[AnyHashable : Any]], indexPath: IndexPath, animation: UITableView.RowAnimation) + func removeMolecules(_ molecules: [[AnyHashable : Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) //optional @@ -36,6 +38,10 @@ extension MoleculeDelegateProtocol { // Do nothing } + public func addMolecules(_ molecules: [[AnyHashable : Any]], indexPath: IndexPath, animation: UITableView.RowAnimation) { + // Do nothing + } + public func removeMolecules(_ molecules: [[AnyHashable : Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) { // Do nothing } diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index a4078f17..1dfb0938 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -178,8 +178,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol } } - open override func addMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) { - + open override func addMolecules(_ molecules: [[AnyHashable : Any]], indexPath: IndexPath, animation: UITableView.RowAnimation) { var tmpMolecules = [ListItemModelProtocol & MoleculeModelProtocol]() molecules.forEach { molecule in @@ -189,7 +188,6 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol } DispatchQueue.main.async { - guard let indexPath = self.tableView?.indexPath(for: sender) else { return } var indexPaths: [IndexPath] = [] for molecule in tmpMolecules { @@ -207,6 +205,16 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol } } + open override func addMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) { + + DispatchQueue.main.async { [weak self] in + guard let indexPath = self?.tableView?.indexPath(for: sender) else { return } + DispatchQueue.global().async { + self?.addMolecules(molecules, indexPath: indexPath, animation: animation) + } + } + } + open override func removeMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) { var tmpMolecules = [ListItemModelProtocol & MoleculeModelProtocol]()