updated with internal wrapper view so the object won't stretch and mess up alignments
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
8a85e67681
commit
0b63f5abea
@ -18,6 +18,11 @@ public enum BadgeFillColor: String, Codable, CaseIterable {
|
||||
@objc(VDSBadge)
|
||||
public class Badge: View, Accessable {
|
||||
|
||||
private var contentView = UIView().with {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
$0.layer.cornerRadius = 2
|
||||
}
|
||||
|
||||
private var label = Label().with {
|
||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||
$0.adjustsFontSizeToFitWidth = false
|
||||
@ -65,14 +70,18 @@ public class Badge: View, Accessable {
|
||||
|
||||
isAccessibilityElement = true
|
||||
accessibilityTraits = .staticText
|
||||
addSubview(label)
|
||||
|
||||
layer.cornerRadius = 2
|
||||
|
||||
label.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 4).isActive = true
|
||||
label.topAnchor.constraint(equalTo: topAnchor, constant: 2).isActive = true
|
||||
trailingAnchor.constraint(greaterThanOrEqualTo: label.trailingAnchor, constant: 4).isActive = true
|
||||
bottomAnchor.constraint(greaterThanOrEqualTo: label.bottomAnchor, constant: 2).isActive = true
|
||||
contentView.addSubview(label)
|
||||
addSubview(contentView)
|
||||
|
||||
contentView
|
||||
.pinTop()
|
||||
.pinBottom()
|
||||
.pinLeading()
|
||||
|
||||
contentView.trailingAnchor.constraint(lessThanOrEqualTo: trailingAnchor).isActive = true
|
||||
|
||||
label.pinToSuperView(.init(top: 2, left: 4, bottom: 2, right: 4))
|
||||
|
||||
maxWidthConstraint = label.widthAnchor.constraint(lessThanOrEqualToConstant: 100)
|
||||
minWidthConstraint = label.widthAnchor.constraint(greaterThanOrEqualToConstant: 23)
|
||||
@ -174,13 +183,12 @@ public class Badge: View, Accessable {
|
||||
}.eraseToAnyColorable()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - State
|
||||
//--------------------------------------------------
|
||||
open override func updateView() {
|
||||
backgroundColor = backgroundColor()
|
||||
contentView.backgroundColor = backgroundColor()
|
||||
|
||||
label.textColorConfiguration = textColorConfiguration()
|
||||
label.numberOfLines = numberOfLines
|
||||
|
||||
@ -62,6 +62,11 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Private Properties
|
||||
//--------------------------------------------------
|
||||
private var contentView = UIView().with {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
$0.layer.cornerRadius = 2
|
||||
}
|
||||
|
||||
private var stackView = UIStackView().with {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
$0.axis = .horizontal
|
||||
@ -252,8 +257,16 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable {
|
||||
|
||||
isAccessibilityElement = true
|
||||
accessibilityTraits = .button
|
||||
addSubview(stackView)
|
||||
addSubview(contentView)
|
||||
contentView.addSubview(stackView)
|
||||
|
||||
contentView
|
||||
.pinTop()
|
||||
.pinBottom()
|
||||
.pinLeading()
|
||||
|
||||
contentView.trailingAnchor.constraint(lessThanOrEqualTo: trailingAnchor).isActive = true
|
||||
|
||||
//set the h/w to container size, since the width "can" grow if text is there
|
||||
//allow this to be greaterThanEqualTo
|
||||
heightAnchor.constraint(equalToConstant: toggleContainerSize.height).isActive = true
|
||||
@ -286,10 +299,7 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable {
|
||||
knobView.topAnchor.constraint(greaterThanOrEqualTo: toggleView.topAnchor).isActive = true
|
||||
|
||||
//pin stackview to edges
|
||||
stackView.topAnchor.constraint(equalTo: topAnchor).isActive = true
|
||||
stackView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
|
||||
stackView.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
|
||||
stackView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
|
||||
stackView.pinToSuperView()
|
||||
}
|
||||
|
||||
public override func reset() {
|
||||
@ -329,6 +339,5 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable {
|
||||
setAccessibilityHint()
|
||||
setAccessibilityValue(isOn)
|
||||
setAccessibilityLabel(isOn)
|
||||
backgroundColor = surface.color
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user