latest inversion

This commit is contained in:
Kevin G Christiano 2020-05-13 17:12:51 -04:00
parent 7b2d684c4e
commit 59288c8fdf
4 changed files with 114 additions and 43 deletions

View File

@ -18,10 +18,10 @@ open class DashLine: View {
var dashModel: DashLineModel? { var dashModel: DashLineModel? {
get { return model as? DashLineModel } get { return model as? DashLineModel }
} }
//TODO: Need this for BAU. Can remove once we fix BAU //TODO: Need this for BAU. Can remove once we fix BAU
public var dashColor: UIColor? public var dashColor: UIColor?
@objc private var dashLayer: CAShapeLayer? @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.addLine(to: CGPoint(x: dashLayer.frame.size.width, y: 0))
path.stroke() path.stroke()
dashLayer.strokeStart = 0.0 dashLayer.strokeStart = 0
dashLayer.lineWidth = 1 dashLayer.lineWidth = 1
dashLayer.lineJoin = .miter dashLayer.lineJoin = .miter
dashLayer.lineCap = .round dashLayer.lineCap = .round
dashLayer.lineDashPattern = [NSNumber(value: 2), NSNumber(value: 2)] dashLayer.lineDashPattern = [NSNumber(value: 2), NSNumber(value: 2)]
dashLayer.path = path.cgPath dashLayer.path = path.cgPath
dashLayer.strokeColor = dashModel?.dashColor.cgColor ?? dashColor?.cgColor dashLayer.strokeColor = dashColor?.cgColor
dashLayer.fillColor = UIColor.clear.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 self.dashLayer = dashLayer
} }
@ -81,21 +81,21 @@ open class DashLine: View {
// MARK: - Atomization // MARK: - Atomization
//------------------------------------------------------ //------------------------------------------------------
// Default values for view.
@objc open override func reset() { @objc open override func reset() {
backgroundColor = .clear super.reset()
isHidden = false isHidden = false
} }
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
super.set(with: model, delegateObject, additionalData) super.set(with: model, delegateObject, additionalData)
guard let dashLineModel = dashModel else {
return guard let model = dashModel else { return }
}
if let isHiddenValue = dashLineModel.isHidden { isHidden = model.isHidden
isHidden = isHiddenValue dashColor = (model.inverted ? model.dashColor_inverted : model.dashColor).uiColor
}
if let backgroundColor = dashLineModel.backgroundColor { if let backgroundColor = model.backgroundColor {
dashLayer?.backgroundColor = backgroundColor.uiColor.cgColor dashLayer?.backgroundColor = backgroundColor.uiColor.cgColor
} }
} }

View File

@ -8,38 +8,66 @@
import Foundation import Foundation
@objcMembers public class DashLineModel: MoleculeModelProtocol { @objcMembers public class DashLineModel: MoleculeModelProtocol {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
public static var identifier: String = "dashLine" public static var identifier: String = "dashLine"
public var backgroundColor: Color? 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) { public init(dashColor: Color) {
self.dashColor = dashColor self.dashColor = dashColor
} }
//--------------------------------------------------
// MARK: - Keys
//--------------------------------------------------
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case moleculeName case moleculeName
case backgroundColor case backgroundColor
case dashColor_inverted
case dashColor case dashColor
case isHidden case isHidden
} }
//--------------------------------------------------
// MARK: - codec
//--------------------------------------------------
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
if let dashColor = try typeContainer.decodeIfPresent(Color.self, forKey: .dashColor) { if let dashColor = try typeContainer.decodeIfPresent(Color.self, forKey: .dashColor) {
self.dashColor = 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) 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 { public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(moleculeName, forKey: .moleculeName) try container.encode(moleculeName, forKey: .moleculeName)
try container.encode(dashColor, forKey: .dashColor) try container.encode(dashColor, forKey: .dashColor)
try container.encodeIfPresent(isHidden, forKey: .isHidden) try container.encode(isHidden, forKey: .isHidden)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
} }
} }

View File

@ -8,14 +8,27 @@
import UIKit import UIKit
@objcMembers open class Line: View { @objcMembers open class Line: View {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
var lineModel: LineModel? { var lineModel: LineModel? {
get { return model as? 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 heightConstraint: NSLayoutConstraint?
public var widthConstraint: NSLayoutConstraint? public var widthConstraint: NSLayoutConstraint?
open func updateLineConstraints(constant: CGFloat) { open func updateLineConstraints(constant: CGFloat) {
if let useVerticalLine = lineModel?.useVerticalLine, useVerticalLine { if let useVerticalLine = lineModel?.useVerticalLine, useVerticalLine {
heightConstraint?.isActive = false 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) { open func setStyle(_ style: LineModel.Style) {
switch style { switch style {
case .standard: case .standard:
updateLineConstraints(constant: 1) updateLineConstraints(constant: 1)
@ -47,21 +76,18 @@ import UIKit
} }
} }
// MARK: - Helpers
open func shouldBeVisible() -> Bool { open func shouldBeVisible() -> Bool {
guard let type = lineModel?.type else { return false } guard let type = lineModel?.type else { return false }
return type != .none return type != .none
} }
public convenience init(pinTo view: UIView, edge: UIRectEdge, useMargin: Bool) { //--------------------------------------------------
self.init(frame: .zero) // MARK: - MoleculeViewProtocol
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: - MVMCoreViewProtocol
open override func setupView() { open override func setupView() {
super.setupView() super.setupView()
heightConstraint = heightAnchor.constraint(equalToConstant: 1) heightConstraint = heightAnchor.constraint(equalToConstant: 1)
heightConstraint?.isActive = true heightConstraint?.isActive = true
widthConstraint = widthAnchor.constraint(equalToConstant: 1) widthConstraint = widthAnchor.constraint(equalToConstant: 1)
@ -69,9 +95,9 @@ import UIKit
setStyle(.standard) setStyle(.standard)
} }
// MARK: - MoleculeViewProtocol
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
super.set(with: model, delegateObject, additionalData) super.set(with: model, delegateObject, additionalData)
if let lineModel = model as? LineModel { if let lineModel = model as? LineModel {
setStyle(lineModel.type) setStyle(lineModel.type)
} }
@ -82,7 +108,9 @@ import UIKit
} }
public override static func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { public override static func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
guard let type = (model as? LineModel)?.type else { return 1 } guard let type = (model as? LineModel)?.type else { return 1 }
switch type { switch type {
case .none: case .none:
return 0 return 0

View File

@ -8,18 +8,19 @@
import UIKit import UIKit
@objcMembers public class LineModel: MoleculeModelProtocol { @objcMembers public class LineModel: MoleculeModelProtocol {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Enums // MARK: - Enums
//-------------------------------------------------- //--------------------------------------------------
/** /**
The frequency of the line in a moleculeList: The frequency of the line in a moleculeList:
- all (between all cells, above top, below bottom) - all (between all cells, above top, below bottom)
- allExceptTop (between all cells, below bottom) - allExceptTop (between all cells, below bottom)
- allExceptBottom (between all cells, above top) - allExceptBottom (between all cells, above top)
- between (between all cells) - between (between all cells)
*/ */
public enum Frequency: String, Codable { public enum Frequency: String, Codable {
case all case all
case allExceptTop case allExceptTop
@ -28,13 +29,13 @@ import UIKit
} }
/** /**
The style of the line: The style of the line:
- standard (1 height, silver) - standard (1 height, silver)
- thin (1 height, black) - thin (1 height, black)
- medium (2 height, black) - medium (2 height, black)
- heavy (4 height, black) - heavy (4 height, black)
- none (hidden) - none (hidden)
*/ */
public enum Style: String, Codable { public enum Style: String, Codable {
case standard case standard
case thin case thin
@ -50,10 +51,12 @@ import UIKit
public static var identifier: String = "line" public static var identifier: String = "line"
public var type: Style = .standard public var type: Style = .standard
public var frequency: Frequency? = .allExceptTop public var frequency: Frequency? = .allExceptTop
//TODO: use color insted of backgroundColor. Needs server changes //TODO: use color insted of backgroundColor. Needs server changes
// public var color: Color? // public var color: Color?
public var backgroundColor: Color? public var backgroundColor: Color?
public var backgroundColor_inverted: Color = Color(uiColor: .mvmWhite)
public var inverted: Bool = false
// Use this to show vertical line // Use this to show vertical line
// Default is false // Default is false
@ -76,15 +79,17 @@ import UIKit
case moleculeName case moleculeName
case type case type
case backgroundColor case backgroundColor
case backgroundColor_inverted
case color case color
case frequency case frequency
case inverted
case useVerticalLine case useVerticalLine
} }
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Codec // MARK: - Codec
//-------------------------------------------------- //--------------------------------------------------
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
@ -96,14 +101,24 @@ import UIKit
self.frequency = frequency 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) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
useVerticalLine = try typeContainer.decodeIfPresent(Bool.self, forKey: .useVerticalLine) useVerticalLine = try typeContainer.decodeIfPresent(Bool.self, forKey: .useVerticalLine)
} }
public func encode(to encoder: Encoder) throws { public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(moleculeName, forKey: .moleculeName) try container.encode(moleculeName, forKey: .moleculeName)
try container.encode(type, forKey: .type) try container.encode(type, forKey: .type)
try container.encode(inverted, forKey: .inverted)
try container.encodeIfPresent(frequency, forKey: .frequency) try container.encodeIfPresent(frequency, forKey: .frequency)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encodeIfPresent(useVerticalLine, forKey: .useVerticalLine) try container.encodeIfPresent(useVerticalLine, forKey: .useVerticalLine)