added width constraint check
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
c02ba88a76
commit
30b380fceb
@ -64,6 +64,8 @@ open class DropdownSelect: EntryFieldBase {
|
||||
// MARK: - Public Properties
|
||||
//--------------------------------------------------
|
||||
open var inlineDisplayLabel = Label().with {
|
||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||
$0.setContentCompressionResistancePriority(.required, for: .horizontal)
|
||||
$0.textAlignment = .left
|
||||
$0.textStyle = .boldBodyLarge
|
||||
$0.lineBreakMode = .byCharWrapping
|
||||
@ -72,6 +74,7 @@ open class DropdownSelect: EntryFieldBase {
|
||||
|
||||
open var selectedOptionLabel = Label().with {
|
||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||
$0.setContentCompressionResistancePriority(.required, for: .horizontal)
|
||||
$0.textAlignment = .left
|
||||
$0.textStyle = .bodyLarge
|
||||
$0.lineBreakMode = .byCharWrapping
|
||||
@ -91,13 +94,15 @@ open class DropdownSelect: EntryFieldBase {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Constraints
|
||||
//--------------------------------------------------
|
||||
internal var maxWidthConstraint: NSLayoutConstraint?
|
||||
internal var minWidthConstraint: NSLayoutConstraint?
|
||||
internal var inlineWidthConstraint: NSLayoutConstraint?
|
||||
internal var titleLabelWidthConstraint: NSLayoutConstraint?
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Configuration Properties
|
||||
//--------------------------------------------------
|
||||
internal override var containerSize: CGSize { CGSize(width: showInlineLabel ? minWidthInlineLabel : width ?? minWidthDefault, height: 44) }
|
||||
internal override var containerSize: CGSize { .init(width: minWidthDefault, height: 44) }
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Overrides
|
||||
@ -105,7 +110,9 @@ open class DropdownSelect: EntryFieldBase {
|
||||
|
||||
/// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations.
|
||||
open override func setup() {
|
||||
super.setup()
|
||||
super.setup()
|
||||
minWidthConstraint = containerView.widthGreaterThanEqualTo(constant: containerSize.width)
|
||||
maxWidthConstraint = containerView.width(constant: containerSize.width)
|
||||
|
||||
titleLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
|
||||
titleLabel.setContentHuggingPriority(.required, for: .horizontal)
|
||||
@ -154,6 +161,7 @@ open class DropdownSelect: EntryFieldBase {
|
||||
let controlStackView = UIStackView().with {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
$0.axis = .horizontal
|
||||
$0.distribution = .fill
|
||||
$0.spacing = VDSFormControls.spaceInset
|
||||
}
|
||||
controlStackView.addArrangedSubview(dropdownField)
|
||||
@ -174,6 +182,20 @@ open class DropdownSelect: EntryFieldBase {
|
||||
dropdownField.isUserInteractionEnabled = isReadOnly ? false : true
|
||||
selectedOptionLabel.surface = surface
|
||||
selectedOptionLabel.isEnabled = isEnabled
|
||||
|
||||
//set the width constraints
|
||||
if let width {
|
||||
widthConstraint?.constant = width
|
||||
widthConstraint?.isActive = true
|
||||
minWidthConstraint?.isActive = false
|
||||
maxWidthConstraint?.isActive = false
|
||||
} else {
|
||||
minWidthConstraint?.constant = showInlineLabel ? minWidthInlineLabel : minWidthDefault
|
||||
maxWidthConstraint?.constant = frame.width
|
||||
widthConstraint?.isActive = false
|
||||
minWidthConstraint?.isActive = true
|
||||
maxWidthConstraint?.isActive = true
|
||||
}
|
||||
}
|
||||
|
||||
/// Resets to default settings.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user