From 436f13ce8a226cb0ae0c77d6ae6a5a674f8858be Mon Sep 17 00:00:00 2001 From: "Khan, Arshad" Date: Tue, 28 Apr 2020 16:39:04 +0530 Subject: [PATCH 1/4] vertical line support for Line atom. --- MVMCoreUI/Atomic/Atoms/Views/Line.swift | 32 ++++++++++++++------ MVMCoreUI/Atomic/Atoms/Views/LineModel.swift | 8 +++++ 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Line.swift b/MVMCoreUI/Atomic/Atoms/Views/Line.swift index 0429c1c6..c32a6bd8 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Line.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Line.swift @@ -9,28 +9,39 @@ import UIKit @objcMembers open class Line: View { - var lineModel: LineModel? { - get { return model as? LineModel } - } + var lineModel: LineModel? public var heightConstraint: NSLayoutConstraint? + public var widthConstraint: NSLayoutConstraint? + open func updateLineConstraints(constant: CGFloat) { + if let useVerticalLine = lineModel?.useVerticalLine, useVerticalLine { + heightConstraint?.isActive = false + widthConstraint?.isActive = true + widthConstraint?.constant = constant + } else { + widthConstraint?.isActive = false + heightConstraint?.isActive = true + heightConstraint?.constant = constant + } + } + open func setStyle(_ style: LineModel.Style) { switch style { case .standard: - heightConstraint?.constant = 1 + updateLineConstraints(constant: 1) backgroundColor = .mfSilver() case .thin: - heightConstraint?.constant = 1 + updateLineConstraints(constant: 1) backgroundColor = .black case .medium: - heightConstraint?.constant = 2 + updateLineConstraints(constant: 2) backgroundColor = .black case .heavy: - heightConstraint?.constant = 4 + updateLineConstraints(constant: 4) backgroundColor = .black case .none: - heightConstraint?.constant = 0 + updateLineConstraints(constant: 0) } } @@ -51,15 +62,18 @@ import UIKit super.setupView() heightConstraint = heightAnchor.constraint(equalToConstant: 1) heightConstraint?.isActive = true + widthConstraint = widthAnchor.constraint(equalToConstant: 1) + widthConstraint?.isActive = false 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 { + self.lineModel = lineModel setStyle(lineModel.type) } - super.set(with: model, delegateObject, additionalData) } open override func reset() { diff --git a/MVMCoreUI/Atomic/Atoms/Views/LineModel.swift b/MVMCoreUI/Atomic/Atoms/Views/LineModel.swift index 53bc1f4c..7412230d 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/LineModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/LineModel.swift @@ -48,8 +48,13 @@ import UIKit // public var color: Color? public var backgroundColor: Color? + // Use this to show vertical line + // Default is false + public var useVerticalLine: Bool? + public init(type: Style) { self.type = type + self.useVerticalLine = false } private enum CodingKeys: String, CodingKey { @@ -58,6 +63,7 @@ import UIKit case backgroundColor case color case frequency + case useVerticalLine } required public init(from decoder: Decoder) throws { @@ -69,6 +75,7 @@ import UIKit self.frequency = frequency } backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) + useVerticalLine = try typeContainer.decodeIfPresent(Bool.self, forKey: .useVerticalLine) } public func encode(to encoder: Encoder) throws { @@ -77,5 +84,6 @@ import UIKit try container.encode(type, forKey: .type) try container.encodeIfPresent(frequency, forKey: .frequency) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encodeIfPresent(useVerticalLine, forKey: .useVerticalLine) } } From cde1f5c4e66c13fa02322e7b8daf5d0edb2ef627 Mon Sep 17 00:00:00 2001 From: "Khan, Arshad" Date: Wed, 29 Apr 2020 13:06:22 +0530 Subject: [PATCH 2/4] reverting set method super call in Line. --- MVMCoreUI/Atomic/Atoms/Views/Line.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Line.swift b/MVMCoreUI/Atomic/Atoms/Views/Line.swift index c32a6bd8..92800e52 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Line.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Line.swift @@ -69,11 +69,11 @@ import UIKit // 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 { self.lineModel = lineModel setStyle(lineModel.type) } + super.set(with: model, delegateObject, additionalData) } open override func reset() { From e309c589d0267239ef40d734175eeccb2d5a4d06 Mon Sep 17 00:00:00 2001 From: "Khan, Arshad" Date: Wed, 29 Apr 2020 20:33:55 +0530 Subject: [PATCH 3/4] Implemented Scott feedback --- MVMCoreUI/Atomic/Atoms/Views/Line.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Line.swift b/MVMCoreUI/Atomic/Atoms/Views/Line.swift index 92800e52..c22aa11c 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Line.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Line.swift @@ -30,16 +30,16 @@ import UIKit switch style { case .standard: updateLineConstraints(constant: 1) - backgroundColor = .mfSilver() + backgroundColor = lineModel?.backgroundColor?.uiColor ?? .mfSilver() case .thin: updateLineConstraints(constant: 1) - backgroundColor = .black + backgroundColor = lineModel?.backgroundColor?.uiColor ?? .black case .medium: updateLineConstraints(constant: 2) - backgroundColor = .black + backgroundColor = lineModel?.backgroundColor?.uiColor ?? .black case .heavy: updateLineConstraints(constant: 4) - backgroundColor = .black + backgroundColor = lineModel?.backgroundColor?.uiColor ?? .black case .none: updateLineConstraints(constant: 0) } @@ -69,11 +69,11 @@ import UIKit // 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 { self.lineModel = lineModel setStyle(lineModel.type) } - super.set(with: model, delegateObject, additionalData) } open override func reset() { From 66718882d71a5abd872149864961c9a778db54f0 Mon Sep 17 00:00:00 2001 From: "Khan, Arshad" Date: Wed, 29 Apr 2020 20:43:47 +0530 Subject: [PATCH 4/4] removing Line model change. --- MVMCoreUI/Atomic/Atoms/Views/Line.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Line.swift b/MVMCoreUI/Atomic/Atoms/Views/Line.swift index c22aa11c..62550503 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Line.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Line.swift @@ -9,7 +9,9 @@ import UIKit @objcMembers open class Line: View { - var lineModel: LineModel? + var lineModel: LineModel? { + get { return model as? LineModel } + } public var heightConstraint: NSLayoutConstraint? public var widthConstraint: NSLayoutConstraint? @@ -71,7 +73,6 @@ import UIKit open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) if let lineModel = model as? LineModel { - self.lineModel = lineModel setStyle(lineModel.type) } }