diff --git a/VDS/Components/Line/Line.swift b/VDS/Components/Line/Line.swift index c9c33aba..ffef28b5 100644 --- a/VDS/Components/Line/Line.swift +++ b/VDS/Components/Line/Line.swift @@ -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) } }