used intrinsicSize for line

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-08-18 16:33:14 -05:00
parent efc15eabdf
commit 28db6509cc

View File

@ -29,12 +29,6 @@ open class Line: View {
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
//--------------------------------------------------
@ -44,10 +38,19 @@ open class Line: View {
config.setSurfaceColors(VDSColor.elementsLowcontrastOnlight, VDSColor.elementsLowcontrastOndark, forKey: .secondary)
return config.eraseToAnyColorable()
}()
//--------------------------------------------------
// MARK: - Lifecycle
// MARK: - Overrides
//--------------------------------------------------
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()
@ -57,23 +60,15 @@ open class Line: View {
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)
invalidateIntrinsicContentSize()
}
}