Merge branch 'feature/isaac_screen' into 'develop'

isaac screen dashboard

See merge request BPHV_MIPS/mvm_core_ui!298
This commit is contained in:
Pfeil, Scott Robert 2020-03-10 14:24:04 -04:00
commit 164546ef23
12 changed files with 77 additions and 40 deletions

View File

@ -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)
}

View File

@ -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
}
}

View File

@ -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
@ -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() {
@ -183,11 +186,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
}

View File

@ -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) {}
}

View File

@ -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)
}
}

View File

@ -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?() {

View File

@ -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
}
}

View File

@ -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)

View File

@ -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? {

View File

@ -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
}
}

View File

@ -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
}

View File

@ -178,8 +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]], 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,7 +205,17 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
}
}
public override func removeMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) {
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]()
@ -235,7 +243,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 +265,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