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) } }