From e676d78eb2294d9b88ec6f580656791fc9d0bb14 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 13 May 2020 11:19:13 -0400 Subject: [PATCH] current state --- MVMCoreUI/Atomic/Atoms/Views/CaretView.swift | 26 +++++++++---------- .../Atomic/Atoms/Views/CaretViewModel.swift | 21 ++++++++++++--- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/CaretView.swift b/MVMCoreUI/Atomic/Atoms/Views/CaretView.swift index 86e8321c..20023091 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CaretView.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CaretView.swift @@ -13,7 +13,6 @@ open class CaretView: View { //------------------------------------------------------ private var caretPath: UIBezierPath = UIBezierPath() - public var strokeColor: UIColor = .mvmBlack public var lineWidth: CGFloat = 1 public var direction: Direction = .right @@ -28,7 +27,7 @@ open class CaretView: View { public var isEnabled: Bool = true { didSet { - strokeColor = isEnabled ? enabledColor : disabledColor + guard isEnabled != oldValue else { return } setNeedsDisplay() } } @@ -49,7 +48,7 @@ open class CaretView: View { case horizontal } - // Dimensions of container; provided by InVision design. + /// Dimensions of container; provided by InVision design. func dimensions() -> CGSize { switch self { @@ -92,7 +91,7 @@ open class CaretView: View { //------------------------------------------------------ @objc override open func setupView() { - + super.setupView() defaultState() } @@ -141,7 +140,7 @@ open class CaretView: View { caretPath.addLine(to: CGPoint(x: frame.size.width - inset, y: frame.size.height - inset)) } - strokeColor.setStroke() + enabledColor.setStroke() caretPath.stroke() } @@ -151,17 +150,16 @@ open class CaretView: View { @objc public func setLineColor(_ color: UIColor) { - strokeColor = color + enabledColor = color setNeedsDisplay() } @objc public func defaultState() { - translatesAutoresizingMaskIntoConstraints = false isOpaque = false isHidden = false backgroundColor = .clear - strokeColor = .mvmBlack + enabledColor = .mvmBlack } /// Ensure you have defined a CaretSize with Orientation before calling. @@ -178,7 +176,7 @@ open class CaretView: View { //------------------------------------------------------ /// Default values for view. - public required init(model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { + public required init(model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.init(frame: .zero) defaultState() set(with: model, delegateObject, additionalData) @@ -189,12 +187,12 @@ open class CaretView: View { guard let model = model as? CaretViewModel else { return } - strokeColor = (model.inverted ? model.strokeColor_inverted : model.strokeColor).uiColor - isHidden = model.isHidden ?? false - isOpaque = model.isOpaque ?? false - + enabledColor = (model.inverted ? model.strokeColor_inverted : model.strokeColor).uiColor + isHidden = model.isHidden + isOpaque = model.isOpaque + if let lineWidthValue = model.lineWidth { - lineWidth = lineWidthValue + lineWidth = lineWidthValue } } } diff --git a/MVMCoreUI/Atomic/Atoms/Views/CaretViewModel.swift b/MVMCoreUI/Atomic/Atoms/Views/CaretViewModel.swift index 5bcfe092..9dc43286 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CaretViewModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CaretViewModel.swift @@ -18,8 +18,8 @@ import Foundation public var backgroundColor: Color? public var strokeColor: Color = Color(uiColor: .mvmBlack) public var strokeColor_inverted: Color = Color(uiColor: .mvmWhite) - public var isHidden: Bool? - public var isOpaque: Bool? + public var isHidden: Bool = false + public var isOpaque: Bool = false public var inverted: Bool = false public var lineWidth: CGFloat? @@ -31,6 +31,7 @@ import Foundation case moleculeName case backgroundColor case strokeColor + case strokeColor_inverted case isHidden case isOpaque case lineWidth @@ -48,13 +49,24 @@ import Foundation self.strokeColor = strokeColor } + if let strokeColor_inverted = try typeContainer.decodeIfPresent(Color.self, forKey: .strokeColor_inverted) { + self.strokeColor_inverted = strokeColor_inverted + } + if let inverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) { self.inverted = inverted } backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) - isHidden = try typeContainer.decodeIfPresent(Bool.self, forKey: .isHidden) - isOpaque = try typeContainer.decodeIfPresent(Bool.self, forKey: .isOpaque) + + if let isHidden = try typeContainer.decodeIfPresent(Bool.self, forKey: .isHidden) { + self.isHidden = isHidden + } + + if let isOpaque = try typeContainer.decodeIfPresent(Bool.self, forKey: .isOpaque) { + self.isOpaque = isOpaque + } + lineWidth = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .lineWidth) } @@ -62,6 +74,7 @@ import Foundation var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) try container.encode(strokeColor, forKey: .strokeColor) + try container.encode(strokeColor_inverted, forKey: .strokeColor_inverted) try container.encode(inverted, forKey: .inverted) try container.encodeIfPresent(isHidden, forKey: .isHidden) try container.encodeIfPresent(isOpaque, forKey: .isOpaque)