92 lines
2.8 KiB
Swift
92 lines
2.8 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: - Initializers
|
|
//--------------------------------------------------
|
|
required public init() {
|
|
super.init(frame: .zero)
|
|
}
|
|
|
|
public override init(frame: CGRect) {
|
|
super.init(frame: .zero)
|
|
}
|
|
|
|
public required init?(coder: NSCoder) {
|
|
super.init(coder: coder)
|
|
}
|
|
|
|
//--------------------------------------------------
|
|
// 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: - 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: - Overrides
|
|
//--------------------------------------------------
|
|
|
|
/// The natural size for the receiving view, considering only properties of the view itself.
|
|
open override var intrinsicContentSize: CGSize {
|
|
if orientation == .vertical {
|
|
return .init(width: 1, height: bounds.height)
|
|
} else {
|
|
return .init(width: bounds.width, height: 1)
|
|
}
|
|
}
|
|
|
|
/// Resets to default settings.
|
|
open override func reset() {
|
|
super.reset()
|
|
style = .primary
|
|
orientation = .horizontal
|
|
}
|
|
|
|
/// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations.
|
|
open override func setup() {
|
|
super.setup()
|
|
}
|
|
|
|
/// Used to make changes to the View based off a change events or from local properties.
|
|
open override func updateView() {
|
|
super.updateView()
|
|
|
|
backgroundColor = lineViewColorConfiguration.getColor(self)
|
|
|
|
invalidateIntrinsicContentSize()
|
|
}
|
|
|
|
}
|