merging
This commit is contained in:
commit
02107a3498
@ -310,6 +310,7 @@
|
||||
D2E2A99823D8D63C000B42E6 /* ActionDetailWithImageModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E2A99723D8D63C000B42E6 /* ActionDetailWithImageModel.swift */; };
|
||||
D2E2A99A23D8D6B4000B42E6 /* HeadlineBodyButtonModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E2A99923D8D6B4000B42E6 /* HeadlineBodyButtonModel.swift */; };
|
||||
D2E2A99C23D8D975000B42E6 /* ImageHeadlineBodyModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E2A99B23D8D975000B42E6 /* ImageHeadlineBodyModel.swift */; };
|
||||
D2E2A99D23DA3217000B42E6 /* UIStackViewAlignment+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A209CD223A7E2810068F8B0 /* UIStackViewAlignment+Extension.swift */; };
|
||||
D2FB151B23A2B65B00C20E10 /* MoleculeContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2FB151A23A2B65B00C20E10 /* MoleculeContainer.swift */; };
|
||||
D2FB151D23A40F1500C20E10 /* MoleculeStackItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2FB151C23A40F1500C20E10 /* MoleculeStackItem.swift */; };
|
||||
DB06250B2293456500B72DD3 /* LeftRightLabelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB06250A2293456500B72DD3 /* LeftRightLabelView.swift */; };
|
||||
@ -1549,6 +1550,7 @@
|
||||
D29DF2B421E7B76D003B2FB9 /* MFLoadingSpinner.m in Sources */,
|
||||
D260106323D0C05000764D80 /* StackItemModel.swift in Sources */,
|
||||
D2E2A99823D8D63C000B42E6 /* ActionDetailWithImageModel.swift in Sources */,
|
||||
D2E2A99D23DA3217000B42E6 /* UIStackViewAlignment+Extension.swift in Sources */,
|
||||
01EB369423609801006832FA /* HeadlineBodyModel.swift in Sources */,
|
||||
0A21DB7F235DECC500C160A2 /* EntryField.swift in Sources */,
|
||||
D2C5001921F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m in Sources */,
|
||||
|
||||
@ -19,8 +19,6 @@ open class DashLine: View {
|
||||
get { return model as? DashLineModel }
|
||||
}
|
||||
|
||||
// Legacy
|
||||
@objc public var dashColor: UIColor?
|
||||
@objc private var dashLayer: CAShapeLayer?
|
||||
|
||||
//------------------------------------------------------
|
||||
@ -70,7 +68,7 @@ open class DashLine: View {
|
||||
dashLayer.lineCap = .round
|
||||
dashLayer.lineDashPattern = [NSNumber(value: 2), NSNumber(value: 2)]
|
||||
dashLayer.path = path.cgPath
|
||||
dashLayer.strokeColor = dashModel?.dashColor.uiColor.cgColor ?? dashColor?.cgColor ?? UIColor.mfLighterGray().cgColor
|
||||
dashLayer.strokeColor = dashModel?.dashColor.cgColor
|
||||
dashLayer.fillColor = UIColor.clear.cgColor
|
||||
dashLayer.backgroundColor = backgroundColor?.cgColor ?? UIColor.white.cgColor
|
||||
self.dashLayer = dashLayer
|
||||
@ -81,7 +79,7 @@ open class DashLine: View {
|
||||
//------------------------------------------------------
|
||||
|
||||
// Default values for view.
|
||||
@objc open override func setAsMolecule() {
|
||||
@objc open override func reset() {
|
||||
backgroundColor = .clear
|
||||
isHidden = false
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
import Foundation
|
||||
|
||||
@objcMembers public class ProgressBarModel: MoleculeModelProtocol {
|
||||
public static var identifier: String = "progressbar"
|
||||
public static var identifier: String = "progressBar"
|
||||
@Percent public var percent: CGFloat
|
||||
public var progressColor: Color = Color(uiColor: .mfCerulean())
|
||||
public var backgroundColor: Color? = Color(uiColor: .mfLightSilver())
|
||||
|
||||
@ -12,8 +12,8 @@ public typealias ButtonAction = (Button) -> ()
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
public var model: MoleculeModelProtocol?
|
||||
public var actionModel: ActionModelProtocol?
|
||||
open var model: MoleculeModelProtocol?
|
||||
open var actionModel: ActionModelProtocol?
|
||||
|
||||
private var initialSetupPerformed = false
|
||||
|
||||
@ -23,7 +23,7 @@ public typealias ButtonAction = (Button) -> ()
|
||||
// MARK: - Delegate
|
||||
//--------------------------------------------------
|
||||
|
||||
public weak var buttonDelegate: ButtonDelegateProtocol?
|
||||
open weak var buttonDelegate: ButtonDelegateProtocol?
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
@ -48,6 +48,7 @@ public typealias ButtonAction = (Button) -> ()
|
||||
// MARK: - Setup
|
||||
//--------------------------------------------------
|
||||
|
||||
/// Required to be called any init. Ensures setupView() only gets called once
|
||||
public func initialSetup() {
|
||||
|
||||
if !initialSetupPerformed {
|
||||
@ -60,16 +61,17 @@ public typealias ButtonAction = (Button) -> ()
|
||||
// MARK: - Methods
|
||||
//--------------------------------------------------
|
||||
|
||||
public func addActionBlock( event: Event, _ buttonBlock: @escaping ButtonAction) {
|
||||
/// Adds a block to be performed for the given event.
|
||||
open func addActionBlock(event: Event, _ buttonBlock: @escaping ButtonAction) {
|
||||
self.buttonAction = buttonBlock
|
||||
addTarget(self, action: #selector(callActionBlock(_:)), for: event)
|
||||
}
|
||||
|
||||
func callActionBlock(_ sender: Button) {
|
||||
@objc private func callActionBlock(_ sender: Button) {
|
||||
buttonAction?(self)
|
||||
}
|
||||
|
||||
public func set(with actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||
open func set(with actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||
self.actionModel = actionModel
|
||||
buttonDelegate = delegateObject?.buttonDelegate
|
||||
|
||||
@ -104,14 +106,13 @@ public typealias ButtonAction = (Button) -> ()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - MVMCoreViewProtocol
|
||||
extension Button: MVMCoreViewProtocol {
|
||||
|
||||
public func updateView(_ size: CGFloat) {}
|
||||
open func updateView(_ size: CGFloat) {}
|
||||
|
||||
/// Will be called only once.
|
||||
public func setupView() {
|
||||
open func setupView() {
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
insetsLayoutMarginsFromSafeArea = false
|
||||
titleLabel?.numberOfLines = 0
|
||||
@ -121,7 +122,7 @@ extension Button: MVMCoreViewProtocol {
|
||||
|
||||
// MARK: - MVMCoreUIMoleculeViewProtocol
|
||||
extension Button: MVMCoreUIMoleculeViewProtocol {
|
||||
public func reset() {
|
||||
open func reset() {
|
||||
backgroundColor = .clear
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ import UIKit
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
open var json: [AnyHashable: Any]?
|
||||
public var model: MoleculeModelProtocol?
|
||||
open var model: MoleculeModelProtocol?
|
||||
|
||||
private var initialSetupPerformed = false
|
||||
|
||||
@ -78,10 +78,10 @@ extension Control: AppleGuidelinesProtocol {
|
||||
// MARK: - MVMCoreViewProtocol
|
||||
extension Control: MVMCoreViewProtocol {
|
||||
|
||||
public func updateView(_ size: CGFloat) {}
|
||||
open func updateView(_ size: CGFloat) {}
|
||||
|
||||
/// Will be called only once.
|
||||
public func setupView() {
|
||||
open func setupView() {
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
insetsLayoutMarginsFromSafeArea = false
|
||||
}
|
||||
@ -97,7 +97,7 @@ extension Control: MVMCoreUIMoleculeViewProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
public func reset() {
|
||||
open func reset() {
|
||||
backgroundColor = .clear
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,265 +0,0 @@
|
||||
//
|
||||
// Container.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Scott Pfeil on 12/11/19.
|
||||
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
public protocol ContainerModelProtocol: Model {
|
||||
var horizontalAlignment: UIStackView.Alignment? { get set }
|
||||
var verticalAlignment: UIStackView.Alignment? { get set }
|
||||
var useHorizontalMargins: Bool? { get set }
|
||||
var useVerticalMargins: Bool? { get set }
|
||||
}
|
||||
|
||||
public class ContainerHelper: NSObject {
|
||||
var leftConstraint: NSLayoutConstraint?
|
||||
var topConstraint: NSLayoutConstraint?
|
||||
var bottomConstraint: NSLayoutConstraint?
|
||||
var rightConstraint: NSLayoutConstraint?
|
||||
|
||||
var alignCenterHorizontalConstraint: NSLayoutConstraint?
|
||||
var alignCenterLeftConstraint: NSLayoutConstraint?
|
||||
var alignCenterRightConstraint: NSLayoutConstraint?
|
||||
|
||||
var alignCenterVerticalConstraint: NSLayoutConstraint?
|
||||
var alignCenterTopConstraint: NSLayoutConstraint?
|
||||
var alignCenterBottomConstraint: NSLayoutConstraint?
|
||||
|
||||
var leftLowConstraint: NSLayoutConstraint?
|
||||
var topLowConstraint: NSLayoutConstraint?
|
||||
var bottomLowConstraint: NSLayoutConstraint?
|
||||
var rightLowConstraint: NSLayoutConstraint?
|
||||
|
||||
func constrainView(_ view: UIView) {
|
||||
guard let margins = view.superview?.layoutMarginsGuide else { return }
|
||||
leftConstraint = view.leftAnchor.constraint(equalTo: margins.leftAnchor)
|
||||
leftConstraint?.isActive = true
|
||||
|
||||
topConstraint = view.topAnchor.constraint(equalTo: margins.topAnchor)
|
||||
topConstraint?.isActive = true
|
||||
|
||||
rightConstraint = margins.rightAnchor.constraint(equalTo: view.rightAnchor)
|
||||
rightConstraint?.isActive = true
|
||||
|
||||
bottomConstraint = margins.bottomAnchor.constraint(equalTo: view.bottomAnchor)
|
||||
bottomConstraint?.isActive = true
|
||||
|
||||
alignCenterHorizontalConstraint = view.centerXAnchor.constraint(equalTo: margins.centerXAnchor)
|
||||
alignCenterLeftConstraint = view.leftAnchor.constraint(greaterThanOrEqualTo: margins.leftAnchor)
|
||||
alignCenterRightConstraint = margins.rightAnchor.constraint(greaterThanOrEqualTo: view.rightAnchor)
|
||||
|
||||
alignCenterVerticalConstraint = view.centerYAnchor.constraint(equalTo: margins.centerYAnchor)
|
||||
alignCenterTopConstraint = view.topAnchor.constraint(greaterThanOrEqualTo: margins.topAnchor)
|
||||
alignCenterBottomConstraint = margins.bottomAnchor.constraint(greaterThanOrEqualTo: view.bottomAnchor)
|
||||
|
||||
leftLowConstraint = view.leftAnchor.constraint(equalTo: margins.leftAnchor)
|
||||
leftLowConstraint?.priority = UILayoutPriority(rawValue: 200)
|
||||
leftLowConstraint?.isActive = true
|
||||
|
||||
topLowConstraint = view.topAnchor.constraint(equalTo: margins.topAnchor)
|
||||
topLowConstraint?.priority = UILayoutPriority(rawValue: 200)
|
||||
topLowConstraint?.isActive = true
|
||||
|
||||
rightLowConstraint = margins.rightAnchor.constraint(equalTo: view.rightAnchor)
|
||||
rightLowConstraint?.priority = UILayoutPriority(rawValue: 200)
|
||||
rightLowConstraint?.isActive = true
|
||||
|
||||
bottomLowConstraint = margins.bottomAnchor.constraint(equalTo: view.bottomAnchor)
|
||||
bottomLowConstraint?.priority = UILayoutPriority(rawValue: 200)
|
||||
bottomLowConstraint?.isActive = true
|
||||
|
||||
setAccessibility(view)
|
||||
}
|
||||
|
||||
func setAccessibility(_ view: UIView) {
|
||||
guard let superView = view.superview else { return }
|
||||
superView.isAccessibilityElement = false
|
||||
if let elements = view.accessibilityElements {
|
||||
superView.accessibilityElements = elements
|
||||
} else {
|
||||
superView.accessibilityElements = [view]
|
||||
}
|
||||
}
|
||||
|
||||
func alignHorizontal(_ alignment: UIStackView.Alignment) {
|
||||
switch alignment {
|
||||
case .center:
|
||||
alignCenterHorizontalConstraint?.isActive = true
|
||||
alignCenterLeftConstraint?.isActive = true
|
||||
alignCenterRightConstraint?.isActive = true
|
||||
leftConstraint?.isActive = false
|
||||
rightConstraint?.isActive = false
|
||||
case .leading:
|
||||
alignCenterHorizontalConstraint?.isActive = false
|
||||
alignCenterLeftConstraint?.isActive = false
|
||||
alignCenterRightConstraint?.isActive = true
|
||||
leftConstraint?.isActive = true
|
||||
rightConstraint?.isActive = false
|
||||
case .trailing:
|
||||
alignCenterHorizontalConstraint?.isActive = false
|
||||
alignCenterLeftConstraint?.isActive = true
|
||||
alignCenterRightConstraint?.isActive = false
|
||||
leftConstraint?.isActive = false
|
||||
rightConstraint?.isActive = true
|
||||
case .fill:
|
||||
alignCenterHorizontalConstraint?.isActive = false
|
||||
alignCenterLeftConstraint?.isActive = false
|
||||
alignCenterRightConstraint?.isActive = false
|
||||
leftConstraint?.isActive = true
|
||||
rightConstraint?.isActive = true
|
||||
default: break
|
||||
}
|
||||
}
|
||||
|
||||
func alignVertical(_ alignment: UIStackView.Alignment) {
|
||||
switch alignment {
|
||||
case .center:
|
||||
alignCenterVerticalConstraint?.isActive = true
|
||||
alignCenterTopConstraint?.isActive = true
|
||||
alignCenterBottomConstraint?.isActive = true
|
||||
topConstraint?.isActive = false
|
||||
bottomConstraint?.isActive = false
|
||||
case .leading:
|
||||
alignCenterVerticalConstraint?.isActive = false
|
||||
alignCenterTopConstraint?.isActive = false
|
||||
alignCenterBottomConstraint?.isActive = true
|
||||
topConstraint?.isActive = true
|
||||
bottomConstraint?.isActive = false
|
||||
case .trailing:
|
||||
alignCenterVerticalConstraint?.isActive = false
|
||||
alignCenterTopConstraint?.isActive = true
|
||||
alignCenterBottomConstraint?.isActive = false
|
||||
topConstraint?.isActive = false
|
||||
bottomConstraint?.isActive = true
|
||||
case .fill:
|
||||
alignCenterVerticalConstraint?.isActive = false
|
||||
alignCenterTopConstraint?.isActive = false
|
||||
alignCenterBottomConstraint?.isActive = false
|
||||
topConstraint?.isActive = true
|
||||
bottomConstraint?.isActive = true
|
||||
default: break
|
||||
}
|
||||
}
|
||||
|
||||
func set(with model: ContainerModelProtocol) {
|
||||
if let horizontalAlignment = model.horizontalAlignment {
|
||||
alignHorizontal(horizontalAlignment)
|
||||
}
|
||||
if let verticalAlignment = model.verticalAlignment {
|
||||
alignVertical(verticalAlignment)
|
||||
}
|
||||
}
|
||||
|
||||
static func getAlignment(for string: String) -> UIStackView.Alignment? {
|
||||
switch string {
|
||||
case "leading":
|
||||
return .leading
|
||||
case "trailing":
|
||||
return .trailing
|
||||
case "center":
|
||||
return .center
|
||||
case "fill":
|
||||
return .fill
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
static func getAlignmentString(for alignment: UIStackView.Alignment?) -> String? {
|
||||
switch alignment {
|
||||
case .leading:
|
||||
return "leading"
|
||||
case .trailing:
|
||||
return "trailing"
|
||||
case .center:
|
||||
return "center"
|
||||
case .fill:
|
||||
return "fill"
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
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?() {
|
||||
alignHorizontal(alignment)
|
||||
}
|
||||
|
||||
if let verticalAlignmentString = JSON?.optionalStringForKey("verticalAlignment"), let alignment = ContainerHelper.getAlignment(for: verticalAlignmentString) ?? (contained as? MVMCoreUIViewConstrainingProtocol)?.verticalAlignment?() {
|
||||
alignVertical(alignment)
|
||||
} else if let alignment = (contained as? MVMCoreUIViewConstrainingProtocol)?.verticalAlignment?() {
|
||||
alignVertical(alignment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open class Container: View {
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
var containerModel: ContainerModelProtocol?
|
||||
>>>>>>> e36d487d326f710d7302c6d9bcb758d209ad329c
|
||||
var view: UIView?
|
||||
let containerHelper = ContainerHelper()
|
||||
var containerModel: ContainerModelProtocol? {
|
||||
get { return model as? ContainerModelProtocol }
|
||||
}
|
||||
var topMarginPadding: CGFloat = 0
|
||||
var bottomMarginPadding: CGFloat = 0
|
||||
|
||||
override open func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) {
|
||||
super.setWithModel(model, delegateObject, additionalData)
|
||||
guard let containerModel = model as? ContainerModelProtocol else { return }
|
||||
containerHelper.set(with: containerModel)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - MVMCoreViewProtocol
|
||||
public extension Container {
|
||||
override func updateView(_ size: CGFloat) {
|
||||
super.updateView(size)
|
||||
(view as? MVMCoreViewProtocol)?.updateView(size)
|
||||
MFStyler.setMarginsFor(self, size: size, defaultHorizontal: containerModel?.useHorizontalMargins ?? true, top: containerModel?.useHorizontalMargins ?? true ? topMarginPadding : 0, bottom: containerModel?.useHorizontalMargins ?? true ? bottomMarginPadding : 0)
|
||||
}
|
||||
|
||||
/// Will be called only once.
|
||||
override func setupView() {
|
||||
super.setupView()
|
||||
backgroundColor = .clear
|
||||
}
|
||||
|
||||
func addAndContain(_ view: UIView) {
|
||||
view.translatesAutoresizingMaskIntoConstraints = false
|
||||
addSubview(view)
|
||||
containerHelper.constrainView(view)
|
||||
self.view = view
|
||||
}
|
||||
|
||||
convenience init(andContain view: UIView) {
|
||||
self.init()
|
||||
addAndContain(view)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - MVMCoreUIMoleculeViewProtocol
|
||||
public extension Container {
|
||||
override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) {
|
||||
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
||||
guard let view = view else { return }
|
||||
containerHelper.set(with: json, for: view)
|
||||
}
|
||||
|
||||
override func reset() {
|
||||
super.reset()
|
||||
(view as? MVMCoreUIMoleculeViewProtocol)?.reset?()
|
||||
}
|
||||
|
||||
func setAsMolecule() {
|
||||
(view as? MVMCoreUIMoleculeViewProtocol)?.setAsMolecule?()
|
||||
}
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
//
|
||||
// FooterModel.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Suresh, Kamlesh on 11/27/19.
|
||||
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
@objcMembers public class FooterModel: MoleculeContainerModel, MoleculeProtocol {
|
||||
public static var identifier: String = "footer"
|
||||
public var backgroundColor: Color?
|
||||
|
||||
enum FooterCodingKeys: String, CodingKey {
|
||||
case backgroundColor
|
||||
}
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
<<<<<<< HEAD
|
||||
let typeContainer = try decoder.container(keyedBy: FooterCodingKeys.self)
|
||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||
try super.init(from: decoder)
|
||||
=======
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||
self.molecule = try typeContainer.decodeMolecule(codingKey: .molecule)
|
||||
>>>>>>> 83b0a554049f764888ce9db27dbd7fa503fddf01
|
||||
}
|
||||
|
||||
public override func encode(to encoder: Encoder) throws {
|
||||
try super.encode(to: encoder)
|
||||
var container = encoder.container(keyedBy: FooterCodingKeys.self)
|
||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||
}
|
||||
}
|
||||
@ -1,100 +0,0 @@
|
||||
//
|
||||
// StackItem.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Scott Pfeil on 12/13/19.
|
||||
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
open class StackItemModel: ContainerModelProtocol, MoleculeProtocol {
|
||||
public static var identifier: String = "stackItem"
|
||||
public var backgroundColor: String?
|
||||
public var view: StackItem?
|
||||
|
||||
public var molecule: MoleculeProtocol
|
||||
public var spacing: CGFloat? = 16
|
||||
public var percentage: Int? = 0
|
||||
public var verticalAlignment: UIStackView.Alignment?
|
||||
public var horizontalAlignment: UIStackView.Alignment?
|
||||
public var useHorizontalMargins: Bool? = false
|
||||
public var useVerticalMargins: Bool? = false
|
||||
public var gone: Bool? = false
|
||||
|
||||
<<<<<<< HEAD
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case molecule
|
||||
case spacing
|
||||
case percentage
|
||||
case verticalAlignment
|
||||
case horizontalAlignment
|
||||
case useHorizontalMargins
|
||||
case useVerticalMargins
|
||||
case gone
|
||||
}
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
molecule = try typeContainer.decodeMolecule(codingKey: .molecule)
|
||||
spacing = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .spacing)
|
||||
percentage = try typeContainer.decodeIfPresent(Int.self, forKey: .percentage)
|
||||
if let verticalAlignmentString = try typeContainer.decodeIfPresent(String.self, forKey: .verticalAlignment) {
|
||||
verticalAlignment = ContainerHelper.getAlignment(for: verticalAlignmentString)
|
||||
}
|
||||
if let horizontalAlignmentString = try typeContainer.decodeIfPresent(String.self, forKey: .horizontalAlignment) {
|
||||
horizontalAlignment = ContainerHelper.getAlignment(for: horizontalAlignmentString)
|
||||
}
|
||||
useVerticalMargins = try typeContainer.decodeIfPresent(Bool.self, forKey: .useVerticalMargins)
|
||||
useHorizontalMargins = try typeContainer.decodeIfPresent(Bool.self, forKey: .useHorizontalMargins)
|
||||
gone = try typeContainer.decodeIfPresent(Bool.self, forKey: .gone)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encodeModel(molecule, forKey: .molecule)
|
||||
try container.encodeIfPresent(spacing, forKey: .spacing)
|
||||
try container.encodeIfPresent(percentage, forKey: .percentage)
|
||||
try container.encodeIfPresent(ContainerHelper.getAlignmentString(for: verticalAlignment), forKey: .verticalAlignment)
|
||||
try container.encodeIfPresent(ContainerHelper.getAlignmentString(for: horizontalAlignment), forKey: .horizontalAlignment)
|
||||
try container.encodeIfPresent(useVerticalMargins, forKey: .useVerticalMargins)
|
||||
try container.encodeIfPresent(useHorizontalMargins, forKey: .useHorizontalMargins)
|
||||
try container.encodeIfPresent(gone, forKey: .gone)
|
||||
=======
|
||||
init(with view: StackItem) {
|
||||
self.view = view
|
||||
view.containerModel = self
|
||||
}
|
||||
|
||||
init(with view: StackItem, json: [AnyHashable: Any]?) {
|
||||
self.view = view
|
||||
view.containerModel = self
|
||||
update(with: json)
|
||||
>>>>>>> e36d487d326f710d7302c6d9bcb758d209ad329c
|
||||
}
|
||||
|
||||
func update(with json: [AnyHashable: Any]?) {
|
||||
gone = json?.boolForKey("gone") ?? (json == nil)
|
||||
spacing = json?.optionalCGFloatForKey("spacing")
|
||||
percentage = json?["percent"] as? Int
|
||||
if let horizontalAlignmentString = json?.optionalStringForKey("horizontalAlignment") {
|
||||
horizontalAlignment = ContainerHelper.getAlignment(for: horizontalAlignmentString)
|
||||
} else {
|
||||
horizontalAlignment = nil
|
||||
}
|
||||
|
||||
if let verticalAlignmentString = json?.optionalStringForKey("verticalAlignment") {
|
||||
verticalAlignment = ContainerHelper.getAlignment(for: verticalAlignmentString)
|
||||
} else {
|
||||
verticalAlignment = nil
|
||||
}
|
||||
|
||||
useHorizontalMargins = json?.optionalBoolForKey("useHorizontalMargins") ?? false
|
||||
useVerticalMargins = json?.optionalBoolForKey("useVerticalMargins") ?? false
|
||||
}
|
||||
}
|
||||
|
||||
open class StackItem: MoleculeContainer {
|
||||
|
||||
|
||||
}
|
||||
@ -1,116 +0,0 @@
|
||||
//
|
||||
// ModuleMolecule.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Scott Pfeil on 6/25/19.
|
||||
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
open class ModuleMoleculeModel: ContainerModelProtocol {
|
||||
public static var identifier: String = "moduleMolecule"
|
||||
|
||||
public var molecule: MoleculeProtocol?
|
||||
public var moduleName: String
|
||||
public var horizontalAlignment: UIStackView.Alignment? = .fill
|
||||
public var verticalAlignment: UIStackView.Alignment? = .fill
|
||||
public var useHorizontalMargins: Bool? = false
|
||||
public var useVerticalMargins: Bool? = false
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case molecule
|
||||
case moduleName
|
||||
case horizontalAlignment
|
||||
case verticalAlignment
|
||||
case useHorizontalMargins
|
||||
case useVerticalMargins
|
||||
}
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
moduleName = try typeContainer.decode(String.self, forKey:.moduleName)
|
||||
if let verticalAlignmentString = try typeContainer.decodeIfPresent(String.self, forKey: .verticalAlignment) {
|
||||
verticalAlignment = ContainerHelper.getAlignment(for: verticalAlignmentString)
|
||||
}
|
||||
if let horizontalAlignmentString = try typeContainer.decodeIfPresent(String.self, forKey: .horizontalAlignment) {
|
||||
horizontalAlignment = ContainerHelper.getAlignment(for: horizontalAlignmentString)
|
||||
}
|
||||
useVerticalMargins = try typeContainer.decodeIfPresent(Bool.self, forKey: .useVerticalMargins)
|
||||
useHorizontalMargins = try typeContainer.decodeIfPresent(Bool.self, forKey: .useHorizontalMargins)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(moduleName, forKey: .moduleName)
|
||||
try container.encodeIfPresent(ContainerHelper.getAlignmentString(for: verticalAlignment), forKey: .verticalAlignment)
|
||||
try container.encodeIfPresent(ContainerHelper.getAlignmentString(for: horizontalAlignment), forKey: .horizontalAlignment)
|
||||
try container.encodeIfPresent(useVerticalMargins, forKey: .useVerticalMargins)
|
||||
try container.encodeIfPresent(useHorizontalMargins, forKey: .useHorizontalMargins)
|
||||
}
|
||||
}
|
||||
|
||||
open class ModuleMolecule: Container {
|
||||
<<<<<<< HEAD
|
||||
var moduleMoleculeModel: ModuleMoleculeModel? {
|
||||
get { return model as? ModuleMoleculeModel }
|
||||
=======
|
||||
public override func setupView() {
|
||||
super.setupView()
|
||||
containerModel = ModuleMoleculeModel()
|
||||
>>>>>>> e36d487d326f710d7302c6d9bcb758d209ad329c
|
||||
}
|
||||
|
||||
open override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) {
|
||||
#warning("need to change getter to get moduleModel instead to use.")
|
||||
super.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 view == nil {
|
||||
if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: module, delegateObject: delegateObject, constrainIfNeeded: false) {
|
||||
addAndContain(moleculeView)
|
||||
}
|
||||
} else {
|
||||
(view as? MVMCoreUIMoleculeViewProtocol)?.setWithJSON(module, delegateObject: delegateObject, additionalData: additionalData)
|
||||
}
|
||||
}
|
||||
|
||||
public class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
||||
guard let moduleName = json?.optionalStringForKey("moduleName"), let module = delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) else {
|
||||
// Critical error
|
||||
return 0
|
||||
}
|
||||
return MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: module)?.estimatedHeight?(forRow: module, delegateObject: delegateObject) ?? 0
|
||||
}
|
||||
|
||||
public class func name(forReuse molecule: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
||||
guard let moduleName = molecule?.optionalStringForKey("moduleName"), let module = delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) else {
|
||||
// Critical error
|
||||
return "moduleMolecule<>"
|
||||
}
|
||||
return "moduleMolecule<" + (MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: module)?.name?(forReuse: module, delegateObject: delegateObject) ?? module.stringForkey(KeyMoleculeName)) + ">"
|
||||
}
|
||||
|
||||
public class func requiredModules(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? {
|
||||
let moduleName = json?.optionalStringForKey("moduleName")
|
||||
if moduleName == nil || delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) == nil {
|
||||
if let errorObject = MVMCoreErrorObject(title: nil, message: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess), code: CoreUIErrorCode.ErrorCodeModuleMolecule.rawValue, domain: ErrorDomainNative, location: String(describing: self)) {
|
||||
error?.pointee = errorObject
|
||||
MVMCoreUILoggingHandler.shared()?.addError(toLog: errorObject)
|
||||
}
|
||||
}
|
||||
if let moduleName = moduleName {
|
||||
return [moduleName]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@ -1,90 +0,0 @@
|
||||
//
|
||||
// StandardHeaderView.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Scott Pfeil on 2/12/19.
|
||||
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
public class StandardHeaderView: MoleculeContainer {
|
||||
var line: Line?
|
||||
|
||||
// MARK: - MVMCoreViewProtocol
|
||||
open override func updateView(_ size: CGFloat) {
|
||||
super.updateView(size)
|
||||
line?.updateView(size)
|
||||
}
|
||||
|
||||
public override func setupView() {
|
||||
super.setupView()
|
||||
topMarginPadding = PaddingDefaultVerticalSpacing
|
||||
bottomMarginPadding = PaddingDefaultVerticalSpacing
|
||||
|
||||
guard line == nil else { return }
|
||||
let line = Line()
|
||||
line.style = .heavy
|
||||
addSubview(line)
|
||||
NSLayoutConstraint.pinViewBottom(toSuperview: line, useMargins: false, constant: 0).isActive = true
|
||||
NSLayoutConstraint.pinViewLeft(toSuperview: line, useMargins: true, constant: 0).isActive = true
|
||||
NSLayoutConstraint.pinViewRight(toSuperview: line, useMargins: true, constant: 0).isActive = true
|
||||
self.line = line
|
||||
}
|
||||
|
||||
// MARK: - MVMCoreUIMoleculeViewProtocol
|
||||
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
||||
if let separatorJSON = json?.optionalDictionaryForKey("separator") {
|
||||
line?.setWithJSON(separatorJSON, delegateObject: delegateObject, additionalData: additionalData)
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
open override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) {
|
||||
super.setWithModel(model, delegateObject, additionalData)
|
||||
|
||||
guard let headerModel = model as? HeaderModel else {
|
||||
return
|
||||
}
|
||||
|
||||
if let seperatorModel = headerModel.seperator as? LineModel {
|
||||
line?.setWithJSON(seperatorModel.toJSON(), delegateObject: delegateObject, additionalData: additionalData)
|
||||
}
|
||||
}
|
||||
=======
|
||||
// open func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) {
|
||||
// //TODO: Need to create setWithModel in ViewConstraining View
|
||||
//
|
||||
// #warning("This below call should be repaced with super.setWithModel once we get rid of ViewConstrainingView.")
|
||||
// //TODO: This below call should be repaced with super.setWithModel once we get rid of ViewConstrainingView.
|
||||
// setUpWithModel(model, delegateObject, additionalData)
|
||||
//
|
||||
// // This molecule will by default handle margins.
|
||||
// (molecule as? MVMCoreUIViewConstrainingProtocol)?.shouldSetHorizontalMargins?(false)
|
||||
// (molecule as? MVMCoreUIViewConstrainingProtocol)?.shouldSetVerticalMargins?(false)
|
||||
//
|
||||
// guard let headerModel = model as? HeaderModel else {
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// if let seperatorModel = headerModel.seperator as? LineModel {
|
||||
// line?.setWithJSON(seperatorModel.toJSON(), delegateObject: delegateObject, additionalData: additionalData)
|
||||
// }
|
||||
// }
|
||||
>>>>>>> e36d487d326f710d7302c6d9bcb758d209ad329c
|
||||
|
||||
open override func reset() {
|
||||
super.reset()
|
||||
line?.style = .heavy
|
||||
topMarginPadding = PaddingDefaultVerticalSpacing
|
||||
bottomMarginPadding = PaddingDefaultVerticalSpacing
|
||||
}
|
||||
|
||||
public class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
||||
if let moleculeJSON = json?.optionalDictionaryForKey(KeyMolecule), let height = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: moleculeJSON)?.estimatedHeight?(forRow: moleculeJSON, delegateObject: delegateObject) {
|
||||
return height + PaddingDefaultVerticalSpacing + PaddingDefaultVerticalSpacing
|
||||
}
|
||||
return 121
|
||||
}
|
||||
}
|
||||
@ -54,7 +54,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
|
||||
}
|
||||
|
||||
open override func shouldFinishProcessingLoad(_ loadObject: MVMCoreLoadObject, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject>) -> Bool {
|
||||
let shouldFinish = super.shouldFinishProcessingLoad(loadObject, error: error)
|
||||
guard super.shouldFinishProcessingLoad(loadObject, error: error) else { return false }
|
||||
// This template requires atleast one of the three layers.
|
||||
if templateModel?.header == nil,
|
||||
templateModel?.molecules?.count ?? 0 == 0,
|
||||
@ -63,7 +63,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
|
||||
error.pointee = errorObject
|
||||
return false
|
||||
}
|
||||
return shouldFinish
|
||||
return true
|
||||
}
|
||||
|
||||
open override func newDataBuildScreen() {
|
||||
|
||||
@ -30,6 +30,11 @@ import Foundation
|
||||
try container.encode(alignment.rawValueString, forKey: .alignment)
|
||||
}
|
||||
*/
|
||||
|
||||
enum AlignmentError: Error {
|
||||
case notAnAlignment
|
||||
}
|
||||
|
||||
extension UIStackView.Alignment: RawRepresentable {
|
||||
|
||||
init?(rawValue: String) {
|
||||
@ -70,3 +75,19 @@ extension UIStackView.Alignment: RawRepresentable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension UIStackView.Alignment: Codable {
|
||||
public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.singleValueContainer()
|
||||
let string = try typeContainer.decode(String.self)
|
||||
guard let alignment = UIStackView.Alignment(rawValue: string) else {
|
||||
throw AlignmentError.notAnAlignment
|
||||
}
|
||||
self = alignment
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.singleValueContainer()
|
||||
try container.encode(rawValueString)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user