From 59288c8fdf934988cd4eb6a81aa480563c910e28 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 13 May 2020 17:12:51 -0400 Subject: [PATCH] latest inversion --- MVMCoreUI/Atomic/Atoms/Views/DashLine.swift | 28 +++++------ .../Atomic/Atoms/Views/DashLineModel.swift | 36 ++++++++++++-- MVMCoreUI/Atomic/Atoms/Views/Line.swift | 46 ++++++++++++++---- MVMCoreUI/Atomic/Atoms/Views/LineModel.swift | 47 ++++++++++++------- 4 files changed, 114 insertions(+), 43 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/DashLine.swift b/MVMCoreUI/Atomic/Atoms/Views/DashLine.swift index 86d2fd61..c8a59c6d 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/DashLine.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/DashLine.swift @@ -18,10 +18,10 @@ open class DashLine: View { var dashModel: DashLineModel? { get { return model as? DashLineModel } } - + //TODO: Need this for BAU. Can remove once we fix BAU public var dashColor: UIColor? - + @objc private var dashLayer: CAShapeLayer? //------------------------------------------------------ @@ -65,15 +65,15 @@ open class DashLine: View { path.addLine(to: CGPoint(x: dashLayer.frame.size.width, y: 0)) path.stroke() - dashLayer.strokeStart = 0.0 + dashLayer.strokeStart = 0 dashLayer.lineWidth = 1 dashLayer.lineJoin = .miter dashLayer.lineCap = .round dashLayer.lineDashPattern = [NSNumber(value: 2), NSNumber(value: 2)] dashLayer.path = path.cgPath - dashLayer.strokeColor = dashModel?.dashColor.cgColor ?? dashColor?.cgColor + dashLayer.strokeColor = dashColor?.cgColor dashLayer.fillColor = UIColor.clear.cgColor - dashLayer.backgroundColor = backgroundColor?.cgColor ?? UIColor.white.cgColor + dashLayer.backgroundColor = (dashModel?.inverted ?? false) ? UIColor.mvmBlack.cgColor : backgroundColor?.cgColor ?? UIColor.mvmWhite.cgColor self.dashLayer = dashLayer } @@ -81,21 +81,21 @@ open class DashLine: View { // MARK: - Atomization //------------------------------------------------------ - // Default values for view. @objc open override func reset() { - backgroundColor = .clear + super.reset() + isHidden = false } public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) - guard let dashLineModel = dashModel else { - return - } - if let isHiddenValue = dashLineModel.isHidden { - isHidden = isHiddenValue - } - if let backgroundColor = dashLineModel.backgroundColor { + + guard let model = dashModel else { return } + + isHidden = model.isHidden + dashColor = (model.inverted ? model.dashColor_inverted : model.dashColor).uiColor + + if let backgroundColor = model.backgroundColor { dashLayer?.backgroundColor = backgroundColor.uiColor.cgColor } } diff --git a/MVMCoreUI/Atomic/Atoms/Views/DashLineModel.swift b/MVMCoreUI/Atomic/Atoms/Views/DashLineModel.swift index 7f5ac992..523d83a6 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/DashLineModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/DashLineModel.swift @@ -8,38 +8,66 @@ import Foundation + @objcMembers public class DashLineModel: MoleculeModelProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public static var identifier: String = "dashLine" public var backgroundColor: Color? + public var dashColor: Color = Color(uiColor: .mvmCoolGray3) + public var dashColor_inverted: Color = Color(uiColor: .mvmWhite) + public var isHidden: Bool = false + public var inverted: Bool = false - public var dashColor: Color = Color(uiColor: .mfLighterGray()) - public var isHidden: Bool? + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- public init(dashColor: Color) { self.dashColor = dashColor } + //-------------------------------------------------- + // MARK: - Keys + //-------------------------------------------------- + private enum CodingKeys: String, CodingKey { case moleculeName case backgroundColor + case dashColor_inverted case dashColor case isHidden } + + //-------------------------------------------------- + // MARK: - codec + //-------------------------------------------------- required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + if let dashColor = try typeContainer.decodeIfPresent(Color.self, forKey: .dashColor) { self.dashColor = dashColor } + + if let dashColor_inverted = try typeContainer.decodeIfPresent(Color.self, forKey: .dashColor_inverted) { + self.dashColor_inverted = dashColor_inverted + } + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) - isHidden = try typeContainer.decodeIfPresent(Bool.self, forKey: .isHidden) + + if let isHidden = try typeContainer.decodeIfPresent(Bool.self, forKey: .isHidden) { + self.isHidden = isHidden + } } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) try container.encode(dashColor, forKey: .dashColor) - try container.encodeIfPresent(isHidden, forKey: .isHidden) + try container.encode(isHidden, forKey: .isHidden) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) } } diff --git a/MVMCoreUI/Atomic/Atoms/Views/Line.swift b/MVMCoreUI/Atomic/Atoms/Views/Line.swift index 42043c8f..d0890540 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Line.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Line.swift @@ -8,14 +8,27 @@ import UIKit + @objcMembers open class Line: View { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + var lineModel: LineModel? { get { return model as? LineModel } } + var lineBackgroundColor: Color? { + return (lineModel?.inverted ?? false) ? lineModel?.backgroundColor_inverted : lineModel?.backgroundColor + } + + //-------------------------------------------------- + // MARK: - Constraints + //-------------------------------------------------- + public var heightConstraint: NSLayoutConstraint? public var widthConstraint: NSLayoutConstraint? - + open func updateLineConstraints(constant: CGFloat) { if let useVerticalLine = lineModel?.useVerticalLine, useVerticalLine { heightConstraint?.isActive = false @@ -28,7 +41,23 @@ import UIKit } } + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- + + public convenience init(pinTo view: UIView, edge: UIRectEdge, useMargin: Bool) { + self.init(frame: .zero) + + view.addSubview(self) + NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: self, useMargins: useMargin, pinTop: edge != .bottom, pinBottom: edge != .top, pinLeft: edge != .right, pinRight: edge != .left).values)) + } + + //-------------------------------------------------- + // MARK: - Methods + //-------------------------------------------------- + open func setStyle(_ style: LineModel.Style) { + switch style { case .standard: updateLineConstraints(constant: 1) @@ -47,21 +76,18 @@ import UIKit } } - // MARK: - Helpers open func shouldBeVisible() -> Bool { guard let type = lineModel?.type else { return false } return type != .none } - public convenience init(pinTo view: UIView, edge: UIRectEdge, useMargin: Bool) { - self.init(frame: .zero) - view.addSubview(self) - NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: self, useMargins: useMargin, pinTop: edge != .bottom, pinBottom: edge != .top, pinLeft: edge != .right, pinRight: edge != .left).values)) - } + //-------------------------------------------------- + // MARK: - MoleculeViewProtocol + //-------------------------------------------------- - // MARK: - MVMCoreViewProtocol open override func setupView() { super.setupView() + heightConstraint = heightAnchor.constraint(equalToConstant: 1) heightConstraint?.isActive = true widthConstraint = widthAnchor.constraint(equalToConstant: 1) @@ -69,9 +95,9 @@ import UIKit setStyle(.standard) } - // MARK: - MoleculeViewProtocol open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) + if let lineModel = model as? LineModel { setStyle(lineModel.type) } @@ -82,7 +108,9 @@ import UIKit } public override static func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { + guard let type = (model as? LineModel)?.type else { return 1 } + switch type { case .none: return 0 diff --git a/MVMCoreUI/Atomic/Atoms/Views/LineModel.swift b/MVMCoreUI/Atomic/Atoms/Views/LineModel.swift index dbd1727e..8a245066 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/LineModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/LineModel.swift @@ -8,18 +8,19 @@ import UIKit + @objcMembers public class LineModel: MoleculeModelProtocol { //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- /** - The frequency of the line in a moleculeList: - - all (between all cells, above top, below bottom) - - allExceptTop (between all cells, below bottom) - - allExceptBottom (between all cells, above top) - - between (between all cells) - */ + The frequency of the line in a moleculeList: + - all (between all cells, above top, below bottom) + - allExceptTop (between all cells, below bottom) + - allExceptBottom (between all cells, above top) + - between (between all cells) + */ public enum Frequency: String, Codable { case all case allExceptTop @@ -28,13 +29,13 @@ import UIKit } /** - The style of the line: - - standard (1 height, silver) - - thin (1 height, black) - - medium (2 height, black) - - heavy (4 height, black) - - none (hidden) - */ + The style of the line: + - standard (1 height, silver) + - thin (1 height, black) + - medium (2 height, black) + - heavy (4 height, black) + - none (hidden) + */ public enum Style: String, Codable { case standard case thin @@ -50,10 +51,12 @@ import UIKit public static var identifier: String = "line" public var type: Style = .standard public var frequency: Frequency? = .allExceptTop - + //TODO: use color insted of backgroundColor. Needs server changes // public var color: Color? public var backgroundColor: Color? + public var backgroundColor_inverted: Color = Color(uiColor: .mvmWhite) + public var inverted: Bool = false // Use this to show vertical line // Default is false @@ -76,15 +79,17 @@ import UIKit case moleculeName case type case backgroundColor + case backgroundColor_inverted case color case frequency + case inverted case useVerticalLine } //-------------------------------------------------- // MARK: - Codec //-------------------------------------------------- - + required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) @@ -96,14 +101,24 @@ import UIKit self.frequency = frequency } + if let inverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) { + self.inverted = inverted + } + + if let backgroundColor_inverted = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor_inverted) { + + self.backgroundColor_inverted = backgroundColor_inverted + } + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) useVerticalLine = try typeContainer.decodeIfPresent(Bool.self, forKey: .useVerticalLine) } - + public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) try container.encode(type, forKey: .type) + try container.encode(inverted, forKey: .inverted) try container.encodeIfPresent(frequency, forKey: .frequency) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(useVerticalLine, forKey: .useVerticalLine)