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
|
/// Label used to render text
|
||||||
open var label = Label().with {
|
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.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.textPosition = .left
|
||||||
$0.textStyle = .boldBodySmall
|
$0.textStyle = .boldBodySmall
|
||||||
}
|
}
|
||||||
@ -53,8 +52,18 @@ open class Badge: View {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Constraints
|
// MARK: - Constraints
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
private var maxWidthConstraint: NSLayoutConstraint?
|
private var labelWidthConstraint: NSLayoutConstraint?
|
||||||
private var minWidthConstraint: 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
|
// MARK: - Configuration
|
||||||
@ -114,10 +123,6 @@ open class Badge: View {
|
|||||||
addSubview(label)
|
addSubview(label)
|
||||||
label.pinToSuperView(labelInset)
|
label.pinToSuperView(labelInset)
|
||||||
|
|
||||||
maxWidthConstraint = label.widthAnchor.constraint(lessThanOrEqualToConstant: 0)
|
|
||||||
minWidthConstraint = label.widthAnchor.constraint(greaterThanOrEqualToConstant: minWidth)
|
|
||||||
minWidthConstraint?.isActive = true
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resets to default settings.
|
/// Resets to default settings.
|
||||||
@ -144,19 +149,15 @@ open class Badge: View {
|
|||||||
|
|
||||||
backgroundColor = backgroundColorConfiguration.getColor(self)
|
backgroundColor = backgroundColorConfiguration.getColor(self)
|
||||||
|
|
||||||
if let maxWidth = maxWidth, maxWidth > minWidth {
|
labelWidthConstraint?.isActive = false
|
||||||
maxWidthConstraint?.constant = maxWidth
|
labelWidthConstraint = widthConstraint
|
||||||
maxWidthConstraint?.isActive = true
|
labelWidthConstraint?.isActive = true
|
||||||
minWidthConstraint?.isActive = false
|
|
||||||
} else {
|
|
||||||
maxWidthConstraint?.isActive = false
|
|
||||||
minWidthConstraint?.isActive = true
|
|
||||||
}
|
|
||||||
|
|
||||||
label.textColorConfiguration = textColorConfiguration.eraseToAnyColorable()
|
label.textColorConfiguration = textColorConfiguration.eraseToAnyColorable()
|
||||||
label.numberOfLines = numberOfLines
|
label.numberOfLines = numberOfLines
|
||||||
label.text = text
|
label.text = text
|
||||||
label.surface = surface
|
label.surface = surface
|
||||||
label.disabled = disabled
|
label.disabled = disabled
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user