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
@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() {

View File

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