refactored to for orientation

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-08-14 15:17:45 -05:00
parent 970ea12bc2
commit 3e3baac609

View File

@ -19,14 +19,21 @@ open class Line: View {
case primary, secondary
}
public enum Orientation: String, CaseIterable {
case horizontal, vertical
}
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
open var lineView = UIView().with {
$0.translatesAutoresizingMaskIntoConstraints = false
}
open var style: Style = .primary { didSet { setNeedsUpdate() } }
open var orientation: Orientation = .horizontal { didSet { setNeedsUpdate() } }
//--------------------------------------------------
// MARK: - Private Properties
//--------------------------------------------------
private var heightConstraint: NSLayoutConstraint?
private var widthConstraint: NSLayoutConstraint?
//--------------------------------------------------
// MARK: - Configuration
@ -41,25 +48,32 @@ open class Line: View {
//--------------------------------------------------
// MARK: - Lifecycle
//--------------------------------------------------
open override func setup() {
super.setup()
addSubview(lineView)
lineView.height(1)
lineView.pinToSuperView()
}
/// Resets to default settings.
open override func reset() {
super.reset()
style = .primary
orientation = .horizontal
}
open override func setup() {
super.setup()
heightConstraint = heightAnchor.constraint(equalToConstant: 1)
widthConstraint = widthAnchor.constraint(equalToConstant: 1)
}
/// Function used to make changes to the View based off a change events or from local properties.
open override func updateView() {
super.updateView()
lineView.backgroundColor = lineViewColorConfiguration.getColor(self)
if orientation == .vertical {
heightConstraint?.isActive = false
widthConstraint?.isActive = true
} else {
widthConstraint?.isActive = false
heightConstraint?.isActive = true
}
backgroundColor = lineViewColorConfiguration.getColor(self)
}
}