vertical line support for Line atom.

This commit is contained in:
Khan, Arshad 2020-04-28 16:39:04 +05:30
parent 0b29538d7c
commit 436f13ce8a
2 changed files with 31 additions and 9 deletions

View File

@ -9,28 +9,39 @@
import UIKit import UIKit
@objcMembers open class Line: View { @objcMembers open class Line: View {
var lineModel: LineModel? { var lineModel: LineModel?
get { return model as? LineModel }
}
public var heightConstraint: NSLayoutConstraint? 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) { open func setStyle(_ style: LineModel.Style) {
switch style { switch style {
case .standard: case .standard:
heightConstraint?.constant = 1 updateLineConstraints(constant: 1)
backgroundColor = .mfSilver() backgroundColor = .mfSilver()
case .thin: case .thin:
heightConstraint?.constant = 1 updateLineConstraints(constant: 1)
backgroundColor = .black backgroundColor = .black
case .medium: case .medium:
heightConstraint?.constant = 2 updateLineConstraints(constant: 2)
backgroundColor = .black backgroundColor = .black
case .heavy: case .heavy:
heightConstraint?.constant = 4 updateLineConstraints(constant: 4)
backgroundColor = .black backgroundColor = .black
case .none: case .none:
heightConstraint?.constant = 0 updateLineConstraints(constant: 0)
} }
} }
@ -51,15 +62,18 @@ import UIKit
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?.isActive = false
setStyle(.standard) setStyle(.standard)
} }
// MARK: - MoleculeViewProtocol // 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)
if let lineModel = model as? LineModel { if let lineModel = model as? LineModel {
self.lineModel = lineModel
setStyle(lineModel.type) setStyle(lineModel.type)
} }
super.set(with: model, delegateObject, additionalData)
} }
open override func reset() { open override func reset() {

View File

@ -48,8 +48,13 @@ import UIKit
// public var color: Color? // public var color: Color?
public var backgroundColor: Color? public var backgroundColor: Color?
// Use this to show vertical line
// Default is false
public var useVerticalLine: Bool?
public init(type: Style) { public init(type: Style) {
self.type = type self.type = type
self.useVerticalLine = false
} }
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
@ -58,6 +63,7 @@ import UIKit
case backgroundColor case backgroundColor
case color case color
case frequency case frequency
case useVerticalLine
} }
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
@ -69,6 +75,7 @@ import UIKit
self.frequency = frequency self.frequency = frequency
} }
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
useVerticalLine = try typeContainer.decodeIfPresent(Bool.self, forKey: .useVerticalLine)
} }
public func encode(to encoder: Encoder) throws { public func encode(to encoder: Encoder) throws {
@ -77,5 +84,6 @@ import UIKit
try container.encode(type, forKey: .type) try container.encode(type, forKey: .type)
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)
} }
} }