updated badge
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
c9f6caa680
commit
5502cdaf46
@ -27,12 +27,11 @@ open class Badge: View {
|
||||
|
||||
/// Label used to render text
|
||||
open var label = Label().with {
|
||||
$0.setContentHuggingPriority(.required, for: .vertical)
|
||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||
$0.setContentHuggingPriority(.required, for: .horizontal)
|
||||
$0.setContentCompressionResistancePriority(.required, for: .horizontal)
|
||||
$0.adjustsFontSizeToFitWidth = false
|
||||
$0.lineBreakMode = .byTruncatingTail
|
||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||
$0.setContentHuggingPriority(.defaultHigh, for: .vertical)
|
||||
$0.setContentCompressionResistancePriority(.required, for: .horizontal)
|
||||
$0.setContentHuggingPriority(.defaultHigh, for: .horizontal)
|
||||
$0.textPosition = .left
|
||||
$0.textStyle = .boldBodySmall
|
||||
}
|
||||
@ -53,8 +52,18 @@ open class Badge: View {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Constraints
|
||||
//--------------------------------------------------
|
||||
private var maxWidthConstraint: NSLayoutConstraint?
|
||||
private var minWidthConstraint: NSLayoutConstraint?
|
||||
private var labelWidthConstraint: 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)
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Configuration
|
||||
@ -114,10 +123,6 @@ open class Badge: View {
|
||||
addSubview(label)
|
||||
label.pinToSuperView(labelInset)
|
||||
|
||||
maxWidthConstraint = label.widthAnchor.constraint(lessThanOrEqualToConstant: 0)
|
||||
minWidthConstraint = label.widthAnchor.constraint(greaterThanOrEqualToConstant: minWidth)
|
||||
minWidthConstraint?.isActive = true
|
||||
|
||||
}
|
||||
|
||||
/// Resets to default settings.
|
||||
@ -144,19 +149,15 @@ open class Badge: View {
|
||||
|
||||
backgroundColor = backgroundColorConfiguration.getColor(self)
|
||||
|
||||
if let maxWidth = maxWidth, maxWidth > minWidth {
|
||||
maxWidthConstraint?.constant = maxWidth
|
||||
maxWidthConstraint?.isActive = true
|
||||
minWidthConstraint?.isActive = false
|
||||
} else {
|
||||
maxWidthConstraint?.isActive = false
|
||||
minWidthConstraint?.isActive = true
|
||||
}
|
||||
labelWidthConstraint?.isActive = false
|
||||
labelWidthConstraint = widthConstraint
|
||||
labelWidthConstraint?.isActive = true
|
||||
|
||||
label.textColorConfiguration = textColorConfiguration.eraseToAnyColorable()
|
||||
label.numberOfLines = numberOfLines
|
||||
label.text = text
|
||||
label.surface = surface
|
||||
label.disabled = disabled
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user