diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index 33428b8d..b0224473 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -52,17 +52,13 @@ open class Badge: View { //-------------------------------------------------- // MARK: - Constraints //-------------------------------------------------- - private var labelWidthConstraint: NSLayoutConstraint? + private var maxWidthConstraint: NSLayoutConstraint? - private var widthConstraint: NSLayoutConstraint { - // Determine which constraint to activate based on the maxWidth and minWidth properties - if let maxWidth = maxWidth, maxWidth > minWidth { - // Apply maximum width constraint if set and greater than minWidth - return label.widthAnchor.constraint(lessThanOrEqualToConstant: maxWidth) - } else { - // Apply minimum width constraint - return label.widthAnchor.constraint(greaterThanOrEqualToConstant: minWidth) - } + private func updateMaxWidth() { + maxWidthConstraint?.isActive = false + guard let maxWidth else { return } + maxWidthConstraint?.constant = maxWidth + maxWidthConstraint?.isActive = true } //-------------------------------------------------- @@ -121,8 +117,15 @@ open class Badge: View { layer.cornerRadius = 2 addSubview(label) - label.pinToSuperView(labelInset) + label + .pinTop(labelInset.top) + .pinLeading(labelInset.left) + .pinTrailing(labelInset.right) + .pinBottom(labelInset.bottom, .defaultHigh) + + label.widthGreaterThanEqualTo(constant: minWidth) + maxWidthConstraint = label.widthLessThanEqualTo(constant: 0).with { $0.isActive = false } } /// Resets to default settings. @@ -146,18 +149,14 @@ open class Badge: View { super.updateView() updateTextColorConfig() - + updateMaxWidth() + backgroundColor = backgroundColorConfiguration.getColor(self) - labelWidthConstraint?.isActive = false - labelWidthConstraint = widthConstraint - labelWidthConstraint?.isActive = true - label.textColorConfiguration = textColorConfiguration.eraseToAnyColorable() label.numberOfLines = numberOfLines label.text = text label.surface = surface label.disabled = disabled - } } diff --git a/VDS/Components/Tabs/Tab.swift b/VDS/Components/Tabs/Tab.swift index 7369202f..b688e8d4 100644 --- a/VDS/Components/Tabs/Tab.swift +++ b/VDS/Components/Tabs/Tab.swift @@ -95,12 +95,11 @@ extension Tabs { private let layoutGuide = UILayoutGuide() - private var widthConstraint: NSLayoutConstraint? { - if let width, orientation == .vertical { - return layoutGuide.widthAnchor.constraint(equalToConstant: width) - } else { - return layoutGuide.widthAnchor.constraint(greaterThanOrEqualToConstant: minWidth) - } + private func updateWidth() { + labelWidthConstraint?.isActive = false + guard let width else { return } + labelWidthConstraint?.constant = width + labelWidthConstraint?.isActive = true } //-------------------------------------------------- @@ -138,16 +137,14 @@ extension Tabs { layoutGuide.leadingAnchor.constraint(equalTo: leadingAnchor), layoutGuide.trailingAnchor.constraint(equalTo: trailingAnchor)]) + //pin trailing 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 + + //setup constraints + labelWidthConstraint = label.width(constant: 0).with { $0.isActive = false } + labelTopConstraint = label.pinTop(anchor: layoutGuide.topAnchor) + labelLeadingConstraint = label.pinLeading(anchor: layoutGuide.leadingAnchor) + labelBottomConstraint = label.pinBottom(anchor: layoutGuide.bottomAnchor, priority: .defaultHigh) } /// Function used to make changes to the View based off a change events or from local properties. @@ -159,9 +156,7 @@ extension Tabs { accessibilityIdentifier = "VDSTab:\(text)" //constaints - labelWidthConstraint?.isActive = false - labelWidthConstraint = widthConstraint - labelWidthConstraint?.isActive = true + updateWidth() labelLeadingConstraint?.constant = leadingSpace labelTopConstraint?.constant = otherSpace labelBottomConstraint?.constant = -otherSpace diff --git a/VDS/Components/TitleLockup/TitleLockup.swift b/VDS/Components/TitleLockup/TitleLockup.swift index 354644ee..2b1dd4db 100644 --- a/VDS/Components/TitleLockup/TitleLockup.swift +++ b/VDS/Components/TitleLockup/TitleLockup.swift @@ -269,8 +269,11 @@ open class TitleLockup: View { stackView.addArrangedSubview(subTitleLabel) //pin stackview to edges - stackView.pinToSuperView() - + stackView + .pinTop() + .pinLeading() + .pinTrailing() + .pinBottom(0, .defaultHigh) } /// Resets to default settings.