Merge branch 'feature/useVerticalLine' into 'develop'

vertical line support for Line atom.

See merge request BPHV_MIPS/mvm_core_ui!412
This commit is contained in:
Pfeil, Scott Robert 2020-04-29 11:18:25 -04:00
commit ba8e2479a3
2 changed files with 33 additions and 10 deletions

View File

@ -14,23 +14,36 @@ import UIKit
}
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
backgroundColor = .mfSilver()
updateLineConstraints(constant: 1)
backgroundColor = lineModel?.backgroundColor?.uiColor ?? .mfSilver()
case .thin:
heightConstraint?.constant = 1
backgroundColor = .black
updateLineConstraints(constant: 1)
backgroundColor = lineModel?.backgroundColor?.uiColor ?? .black
case .medium:
heightConstraint?.constant = 2
backgroundColor = .black
updateLineConstraints(constant: 2)
backgroundColor = lineModel?.backgroundColor?.uiColor ?? .black
case .heavy:
heightConstraint?.constant = 4
backgroundColor = .black
updateLineConstraints(constant: 4)
backgroundColor = lineModel?.backgroundColor?.uiColor ?? .black
case .none:
heightConstraint?.constant = 0
updateLineConstraints(constant: 0)
}
}
@ -51,15 +64,17 @@ 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 {
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)
}
}