From 7b2d684c4e7c086481d3214e77da5d24f048e6d1 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 13 May 2020 14:25:45 -0400 Subject: [PATCH] changes for inversion --- .../Atomic/Atoms/Buttons/CaretLink.swift | 11 ++-- .../Atomic/Atoms/Buttons/CaretLinkModel.swift | 44 ++++++++++++++-- MVMCoreUI/Atomic/Atoms/Views/LineModel.swift | 50 +++++++++++++------ 3 files changed, 82 insertions(+), 23 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift b/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift index d23a2606..0e2dfd7b 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift @@ -9,14 +9,13 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol { - //------------------------------------------------------ // MARK: - Constants //------------------------------------------------------ private let CARET_VIEW_HEIGHT: Float = 10.5 private let CARET_VIEW_WIDTH: Float = 6.5 - + //------------------------------------------------------ // MARK: - Properties //------------------------------------------------------ @@ -82,7 +81,7 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol { setTitleColor(enabledColor, for: .normal) setTitleColor(disabledColor, for: .disabled) - + if let rightCaretView = rightView as? CaretView { rightCaretView.enabledColor = enabledColor rightCaretView.disabledColor = disabledColor @@ -123,7 +122,7 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol { bottomAnchor.constraint(greaterThanOrEqualTo: caretView.bottomAnchor).isActive = true contentHorizontalAlignment = .left - //set correct color after layout + // Set correct color after layout changeCaretColor() } @@ -135,6 +134,7 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol { //------------------------------------------------------ // MARK: - Atomization //------------------------------------------------------ + public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { guard let model = model as? CaretLinkModel else { return } @@ -143,7 +143,8 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol { backgroundColor = color.uiColor } - enabledColor = model.enabledColor.uiColor + enabledColor = (model.inverted ? model.enabled_inverted : model.enabledColor).uiColor + if let color = model.disabledColor { disabledColor = color.uiColor } diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/CaretLinkModel.swift b/MVMCoreUI/Atomic/Atoms/Buttons/CaretLinkModel.swift index 8f3ee74d..5b48deea 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/CaretLinkModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/CaretLinkModel.swift @@ -9,46 +9,80 @@ import Foundation import MVMCore + public class CaretLinkModel: ButtonModelProtocol, MoleculeModelProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public static var identifier: String = "caretLink" public var backgroundColor: Color? public var title: String public var action: ActionModelProtocol - public var enabledColor: Color = Color(uiColor: .black) + public var enabledColor: Color = Color(uiColor: .mvmBlack) public var disabledColor: Color? = Color(uiColor: .mvmCoolGray6) + public var enabled_inverted: Color = Color(uiColor: .mvmWhite) public var enabled = true - + public var inverted = false + + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- + public init(title: String, action: ActionModelProtocol) { self.title = title self.action = action } + //-------------------------------------------------- + // MARK: - Keys + //-------------------------------------------------- + private enum CodingKeys: String, CodingKey { case backgroundColor case title case action + case enabled_inverted case enabledColor case disabledColor case enabled + case inverted case moleculeName } - + + //-------------------------------------------------- + // MARK: - Codec + //-------------------------------------------------- + required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) title = try typeContainer.decode(String.self, forKey: .title) + + if let enabled_inverted = try typeContainer.decodeIfPresent(Color.self, forKey: .enabled_inverted) { + self.enabled_inverted = enabled_inverted + } + if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor) { enabledColor = color } + if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor) { disabledColor = color } + if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) { self.enabled = enabled } + + if let inverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) { + self.inverted = inverted + } + action = try typeContainer.decodeModel(codingKey: .action) } - + public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) @@ -58,5 +92,7 @@ public class CaretLinkModel: ButtonModelProtocol, MoleculeModelProtocol { try container.encode(enabled, forKey: .enabledColor) try container.encodeIfPresent(disabledColor, forKey: .disabledColor) try container.encode(enabled, forKey: .enabled) + try container.encode(enabled_inverted, forKey: .enabled_inverted) + try container.encode(inverted, forKey: .inverted) } } diff --git a/MVMCoreUI/Atomic/Atoms/Views/LineModel.swift b/MVMCoreUI/Atomic/Atoms/Views/LineModel.swift index 7412230d..dbd1727e 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/LineModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/LineModel.swift @@ -9,13 +9,16 @@ 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 @@ -24,13 +27,13 @@ import UIKit case between } - /* - 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 @@ -40,23 +43,35 @@ import UIKit case none } + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + 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 color: Color? public var backgroundColor: Color? // Use this to show vertical line // Default is false public var useVerticalLine: Bool? + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- + public init(type: Style) { self.type = type self.useVerticalLine = false } + //-------------------------------------------------- + // MARK: - Keys + //-------------------------------------------------- + private enum CodingKeys: String, CodingKey { case moleculeName case type @@ -66,14 +81,21 @@ import UIKit case useVerticalLine } + //-------------------------------------------------- + // MARK: - Codec + //-------------------------------------------------- + required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + if let type = try typeContainer.decodeIfPresent(Style.self, forKey: .type) { self.type = type } + if let frequency = try typeContainer.decodeIfPresent(Frequency.self, forKey: .frequency) { self.frequency = frequency } + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) useVerticalLine = try typeContainer.decodeIfPresent(Bool.self, forKey: .useVerticalLine) }