80 lines
2.6 KiB
Swift
80 lines
2.6 KiB
Swift
//
|
|
// Line.swift
|
|
// VDS
|
|
//
|
|
// Created by Nadigadda, Sumanth on 24/03/23.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
import VDSColorTokens
|
|
|
|
@objc(VDSLine)
|
|
open class Line: View {
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Enums
|
|
//--------------------------------------------------
|
|
public enum Style: String, CaseIterable {
|
|
case primary, secondary
|
|
}
|
|
|
|
public enum Orientation: String, CaseIterable {
|
|
case horizontal, vertical
|
|
}
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Public Properties
|
|
//--------------------------------------------------
|
|
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
|
|
//--------------------------------------------------
|
|
open var lineViewColorConfiguration: AnyColorable = {
|
|
let config = KeyedColorConfiguration<Line, Style>(keyPath: \.style)
|
|
config.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forKey: .primary)
|
|
config.setSurfaceColors(VDSColor.elementsLowcontrastOnlight, VDSColor.elementsLowcontrastOndark, forKey: .secondary)
|
|
return config.eraseToAnyColorable()
|
|
}()
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Lifecycle
|
|
//--------------------------------------------------
|
|
/// 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()
|
|
|
|
if orientation == .vertical {
|
|
heightConstraint?.isActive = false
|
|
widthConstraint?.isActive = true
|
|
} else {
|
|
widthConstraint?.isActive = false
|
|
heightConstraint?.isActive = true
|
|
}
|
|
|
|
backgroundColor = lineViewColorConfiguration.getColor(self)
|
|
}
|
|
}
|