updated tab to fix issue with resized

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>

# Conflicts:
#	VDS/Components/Tabs/Tab.swift
This commit is contained in:
Matt Bruce 2023-08-10 15:15:48 -05:00
parent 4c60e4907c
commit a2c3c22da8

View File

@ -20,7 +20,11 @@ extension Tabs {
open var index: Int = 0 open var index: Int = 0
///label to write out the text ///label to write out the text
open var label: Label = Label().with { $0.isUserInteractionEnabled = false } open var label: Label = Label().with {
$0.isUserInteractionEnabled = false
$0.setContentCompressionResistancePriority(.required, for: .horizontal)
$0.setContentHuggingPriority(.required, for: .horizontal)
}
///orientation of the tabs ///orientation of the tabs
open var orientation: Tabs.Orientation = .horizontal { didSet { setNeedsUpdate() } } open var orientation: Tabs.Orientation = .horizontal { didSet { setNeedsUpdate() } }
@ -38,7 +42,7 @@ extension Tabs {
open var width: CGFloat? { didSet { setNeedsUpdate() } } open var width: CGFloat? { didSet { setNeedsUpdate() } }
///The text label of the tab. ///The text label of the tab.
open var text: String = "" { didSet { setNeedsUpdate() } } open var text: String = "Tab" { didSet { setNeedsUpdate() } }
///Minimum width for the tab ///Minimum width for the tab
open var minWidth: CGFloat = 44.0 { didSet { setNeedsUpdate() } } open var minWidth: CGFloat = 44.0 { didSet { setNeedsUpdate() } }
@ -88,12 +92,14 @@ extension Tabs {
return VDSLayout.Spacing.space2X.value return VDSLayout.Spacing.space2X.value
} }
} }
private let layoutGuide = UILayoutGuide()
private var widthConstraint: NSLayoutConstraint { private var widthConstraint: NSLayoutConstraint? {
if let width, orientation == .vertical { if let width, orientation == .vertical {
return label.widthAnchor.constraint(equalToConstant: width) return layoutGuide.widthAnchor.constraint(equalToConstant: width)
} else { } else {
return label.widthAnchor.constraint(greaterThanOrEqualToConstant: minWidth) return layoutGuide.widthAnchor.constraint(greaterThanOrEqualToConstant: minWidth)
} }
} }
@ -115,35 +121,30 @@ extension Tabs {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Overrides // MARK: - Overrides
//-------------------------------------------------- //--------------------------------------------------
open override func setup() { open override func setup() {
super.setup() super.setup()
addLayoutGuide(layoutGuide)
addSubview(label) addSubview(label)
accessibilityTraits = .button accessibilityTraits = .button
isAccessibilityElement = true isAccessibilityElement = true
label.translatesAutoresizingMaskIntoConstraints = false
label.pinTrailing()
labelTopConstraint = label.topAnchor.constraint(equalTo: topAnchor)
labelTopConstraint?.isActive = true
labelBottomConstraint = label.bottomAnchor.constraint(equalTo: bottomAnchor)
labelBottomConstraint?.isActive = true
labelLeadingConstraint = label.leadingAnchor.constraint(equalTo: leadingAnchor)
labelLeadingConstraint?.isActive = true
let layoutGuide = UILayoutGuide()
addLayoutGuide(layoutGuide)
labelWidthConstraint = layoutGuide.widthAnchor.constraint(greaterThanOrEqualToConstant: minWidth)
labelWidthConstraint?.isActive = true
//activate the constraints //activate the constraints
NSLayoutConstraint.activate([layoutGuide.topAnchor.constraint(equalTo: topAnchor), NSLayoutConstraint.activate([layoutGuide.topAnchor.constraint(equalTo: topAnchor),
layoutGuide.bottomAnchor.constraint(equalTo: bottomAnchor), layoutGuide.bottomAnchor.constraint(equalTo: bottomAnchor),
layoutGuide.leadingAnchor.constraint(equalTo: leadingAnchor), layoutGuide.leadingAnchor.constraint(equalTo: leadingAnchor),
layoutGuide.trailingAnchor.constraint(equalTo: trailingAnchor)]) layoutGuide.trailingAnchor.constraint(equalTo: trailingAnchor)])
label.pinTrailing(layoutGuide.trailingAnchor)
labelTopConstraint = label.topAnchor.constraint(equalTo: layoutGuide.topAnchor)
labelTopConstraint?.isActive = true
labelBottomConstraint = label.bottomAnchor.constraint(equalTo: layoutGuide.bottomAnchor)
labelBottomConstraint?.isActive = true
labelLeadingConstraint = label.leadingAnchor.constraint(equalTo: layoutGuide.leadingAnchor)
labelLeadingConstraint?.isActive = true
} }
/// Function used to make changes to the View based off a change events or from local properties. /// Function used to make changes to the View based off a change events or from local properties.
@ -151,13 +152,8 @@ extension Tabs {
super.updateView() super.updateView()
guard !text.isEmpty else { return } guard !text.isEmpty else { return }
//label properties accessibilityIdentifier = "VDSTab:\(text)"
label.text = text
label.surface = surface
label.textStyle = textStyle
label.textPosition = textPosition
label.textColorConfiguration = textColorConfiguration.eraseToAnyColorable()
//constaints //constaints
labelWidthConstraint?.isActive = false labelWidthConstraint?.isActive = false
@ -166,8 +162,17 @@ extension Tabs {
labelLeadingConstraint?.constant = leadingSpace labelLeadingConstraint?.constant = leadingSpace
labelTopConstraint?.constant = otherSpace labelTopConstraint?.constant = otherSpace
labelBottomConstraint?.constant = -otherSpace labelBottomConstraint?.constant = -otherSpace
//label properties
label.text = text
label.surface = surface
label.textStyle = textStyle
label.textPosition = textPosition
label.textColorConfiguration = textColorConfiguration.eraseToAnyColorable()
setNeedsLayout() setNeedsLayout()
layoutIfNeeded()
} }
open override func updateAccessibility() { open override func updateAccessibility() {
@ -177,7 +182,7 @@ extension Tabs {
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
removeBorders() removeBorders()
if isSelected { if isSelected {
@ -186,5 +191,3 @@ extension Tabs {
} }
} }
} }