diff --git a/VDS/Components/DatePicker/DatePicker.swift b/VDS/Components/DatePicker/DatePicker.swift index 9d049613..a7dc3e29 100644 --- a/VDS/Components/DatePicker/DatePicker.swift +++ b/VDS/Components/DatePicker/DatePicker.swift @@ -147,15 +147,6 @@ open class DatePicker: EntryFieldBase { selectedDateLabel.surface = surface selectedDateLabel.isEnabled = isEnabled calendarIcon.color = iconColorConfiguration.getColor(self) - - //set the width constraints - let minWidth = containerSize.width - let maxwidth = frame.size.width - if let width, width > minWidth && width < maxwidth { - widthConstraint?.constant = width - } else { - widthConstraint?.constant = maxwidth >= minWidth ? maxwidth : minWidth - } } /// Resets to default settings. diff --git a/VDS/Components/DropdownSelect/DropdownSelect.swift b/VDS/Components/DropdownSelect/DropdownSelect.swift index 411f8327..9c30ea03 100644 --- a/VDS/Components/DropdownSelect/DropdownSelect.swift +++ b/VDS/Components/DropdownSelect/DropdownSelect.swift @@ -71,7 +71,11 @@ open class DropdownSelect: EntryFieldBase { //-------------------------------------------------- internal var minWidthDefault = 66.0 internal var minWidthInlineLabel = 102.0 - internal var minWidth: CGFloat { showInlineLabel ? minWidthInlineLabel : minWidthDefault } + internal override var minWidth: CGFloat { showInlineLabel ? minWidthInlineLabel : minWidthDefault } + internal override var maxWidth: CGFloat { + let frameWidth = frame.size.width + return helperTextPlacement == .right ? (frameWidth - horizontalStackView.spacing) / 2 : frameWidth + } /// The is used for the for adding the helperLabel to the right of the containerView. internal var horizontalStackView: UIStackView = { @@ -133,7 +137,8 @@ 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() - + widthConstraint?.activate() + titleLabel.setContentCompressionResistancePriority(.required, for: .horizontal) titleLabel.setContentHuggingPriority(.required, for: .horizontal) titleLabelWidthConstraint = titleLabel.width(constant: 0) @@ -302,17 +307,8 @@ open class DropdownSelect: EntryFieldBase { } else { primaryStackView.addArrangedSubview(secondaryStackView) } - - //set the width constraints - let frameWidth = frame.size.width - let maxwidth = helperTextPlacement == .right ? (frameWidth - horizontalStackView.spacing) / 2 : frameWidth - if let width, width > minWidth && width < maxwidth { - widthConstraint?.constant = width - } else { - widthConstraint?.constant = maxwidth >= minWidth ? maxwidth : minWidth - } } - + open override func updateAccessibility() { super.updateAccessibility() let selectedOption = selectedOptionLabel.text ?? "" diff --git a/VDS/Components/TextFields/EntryFieldBase.swift b/VDS/Components/TextFields/EntryFieldBase.swift index 86cc6a48..c7cd766c 100644 --- a/VDS/Components/TextFields/EntryFieldBase.swift +++ b/VDS/Components/TextFields/EntryFieldBase.swift @@ -93,7 +93,9 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { // MARK: - Configuration Properties //-------------------------------------------------- // Sizes are from InVision design specs. - internal var containerSize: CGSize { CGSize(width: 45, height: 44) } + internal var maxWidth: CGFloat { frame.size.width } + internal var minWidth: CGFloat { containerSize.width } + internal var containerSize: CGSize { CGSize(width: minWidth, height: 44) } internal let primaryColorConfiguration = ViewColorConfiguration().with { $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forDisabled: true) @@ -216,7 +218,7 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { //create the wrapping view heightConstraint = containerView.heightGreaterThanEqualTo(constant: containerSize.height) - widthConstraint = containerView.width(constant: 0) + widthConstraint = containerView.width(constant: frame.size.width) secondaryStackView.addArrangedSubview(containerView) secondaryStackView.setCustomSpacing(8, after: containerView) @@ -292,6 +294,7 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { updateTitleLabel() updateErrorLabel() updateHelperLabel() + updateContainerWidth() } open func validate(){ @@ -314,6 +317,15 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { //-------------------------------------------------- // MARK: - Public Methods //-------------------------------------------------- + open func updateContainerWidth() { + if let width, width > minWidth && width < maxWidth { + widthConstraint?.constant = width + } else { + widthConstraint?.constant = maxWidth >= minWidth ? maxWidth : minWidth + } + widthConstraint?.activate() + } + /// Container for the area in which the user interacts. open func getFieldContainer() -> UIView { fatalError("Subclass must return the view that contains the field/view the user will interact with.") diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index 08af1134..1886a9ab 100644 --- a/VDS/Components/TextFields/InputField/InputField.swift +++ b/VDS/Components/TextFields/InputField/InputField.swift @@ -35,6 +35,11 @@ open class InputField: EntryFieldBase { // MARK: - Private Properties //-------------------------------------------------- internal var titleLabelWidthConstraint: NSLayoutConstraint? + internal override var minWidth: CGFloat { fieldType.handler().minWidth } + internal override var maxWidth: CGFloat { + let frameWidth = frame.size.width + return helperTextPlacement == .right ? (frameWidth - horizontalStackView.spacing) / 2 : frameWidth + } /// The is used for the for adding the helperLabel to the right of the containerView. internal var horizontalStackView: UIStackView = { @@ -277,16 +282,6 @@ open class InputField: EntryFieldBase { } else { primaryStackView.addArrangedSubview(secondaryStackView) } - - //set the width constraints - let minWidth = fieldType.handler().minWidth - let frameWidth = frame.size.width - let maxwidth = helperTextPlacement == .right ? (frameWidth - horizontalStackView.spacing) / 2 : frameWidth - if let width, width > minWidth && width < maxwidth { - widthConstraint?.constant = width - } else { - widthConstraint?.constant = maxwidth >= minWidth ? maxwidth : minWidth - } } override func updateRules() { diff --git a/VDS/Components/TextFields/TextArea/TextArea.swift b/VDS/Components/TextFields/TextArea/TextArea.swift index 3913f2e6..eccd228e 100644 --- a/VDS/Components/TextFields/TextArea/TextArea.swift +++ b/VDS/Components/TextFields/TextArea/TextArea.swift @@ -187,10 +187,6 @@ open class TextArea: EntryFieldBase { textView.isEnabled = isEnabled textView.surface = surface - //set the width constraints - let maxwidth = frame.size.width - let minWidth = containerSize.width - widthConstraint?.constant = maxwidth >= minWidth ? maxwidth : minWidth textViewHeightConstraint?.constant = minHeight.value characterCounterLabel.text = getCharacterCounterText()