diff --git a/VDS/Components/DropdownSelect/DropdownSelect.swift b/VDS/Components/DropdownSelect/DropdownSelect.swift index 98a5a61f..f8a74aea 100644 --- a/VDS/Components/DropdownSelect/DropdownSelect.swift +++ b/VDS/Components/DropdownSelect/DropdownSelect.swift @@ -61,8 +61,9 @@ open class DropdownSelect: EntryFieldBase { internal var minWidthInlineLabel = 102.0 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 + let frameWidth = constrainedWidth + let halfWidth = (frameWidth - horizontalStackView.spacing) / 2 + return helperTextPlacement == .right && halfWidth > minWidth * 2 ? halfWidth : frameWidth } /// The is used for the for adding the helperLabel to the right of the containerView. diff --git a/VDS/Components/Footnote/FootnoteGroup.swift b/VDS/Components/Footnote/FootnoteGroup.swift index 5d325d8b..4a2a00c7 100644 --- a/VDS/Components/Footnote/FootnoteGroup.swift +++ b/VDS/Components/Footnote/FootnoteGroup.swift @@ -83,7 +83,7 @@ open class FootnoteGroup: View { //-------------------------------------------------- // MARK: - Configuration Properties //-------------------------------------------------- - internal var maxWidth: CGFloat { horizontalPinnedWidth() ?? (superview?.frame.size.width ?? frame.size.width) } + internal var maxWidth: CGFloat { constrainedWidth } internal var minWidth: CGFloat { containerSize.width } internal var containerSize: CGSize { CGSize(width: 55, height: 44) } diff --git a/VDS/Components/Footnote/FootnoteItem.swift b/VDS/Components/Footnote/FootnoteItem.swift index 489c05be..1bbf7b26 100644 --- a/VDS/Components/Footnote/FootnoteItem.swift +++ b/VDS/Components/Footnote/FootnoteItem.swift @@ -152,7 +152,7 @@ open class FootnoteItem: View { //-------------------------------------------------- // MARK: - Configuration Properties //-------------------------------------------------- - internal var maxWidth: CGFloat { horizontalPinnedWidth() ?? (superview?.frame.size.width ?? frame.size.width) } + internal var maxWidth: CGFloat { constrainedWidth } internal var minWidth: CGFloat { containerSize.width } internal var containerSize: CGSize { CGSize(width: 45, height: 44) } diff --git a/VDS/Components/InputStepper/InputStepper.swift b/VDS/Components/InputStepper/InputStepper.swift index 1323bd25..8d954c06 100644 --- a/VDS/Components/InputStepper/InputStepper.swift +++ b/VDS/Components/InputStepper/InputStepper.swift @@ -331,9 +331,7 @@ open class InputStepper: EntryFieldBase { stepperWidthConstraint?.deactivate() widthConstraint?.deactivate() - trailingLessThanEqualsConstraint?.deactivate() - trailingEqualsConstraint?.deactivate() - + var widthConstraintConstant: CGFloat? if let widthPercentage, let superWidth = horizontalPinnedWidth() { @@ -350,9 +348,6 @@ open class InputStepper: EntryFieldBase { if let widthConstraintConstant { widthConstraint?.constant = widthConstraintConstant widthConstraint?.activate() - trailingLessThanEqualsConstraint?.activate() - } else { - trailingEqualsConstraint?.activate() } // Update Edge insets if size changes applied. diff --git a/VDS/Components/TextFields/EntryFieldBase.swift b/VDS/Components/TextFields/EntryFieldBase.swift index 8d4aeadc..72d36dc1 100644 --- a/VDS/Components/TextFields/EntryFieldBase.swift +++ b/VDS/Components/TextFields/EntryFieldBase.swift @@ -105,14 +105,12 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalVali // MARK: - Constraints //-------------------------------------------------- internal var widthConstraint: NSLayoutConstraint? - internal var trailingEqualsConstraint: NSLayoutConstraint? - internal var trailingLessThanEqualsConstraint: NSLayoutConstraint? - + //-------------------------------------------------- // MARK: - Configuration Properties //-------------------------------------------------- // Sizes are from InVision design specs. - internal var maxWidth: CGFloat { frame.size.width } + internal var maxWidth: CGFloat { constrainedWidth } internal var minWidth: CGFloat { containerSize.width } internal var containerSize: CGSize { CGSize(width: minWidth, height: 44) } @@ -258,15 +256,9 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalVali let layoutGuide = UILayoutGuide() addLayoutGuide(layoutGuide) - layoutGuide - .pinTop() - .pinLeading() - .pinBottom() - - trailingEqualsConstraint = layoutGuide.pinTrailing(anchor: trailingAnchor) + layoutGuide.pinToSuperView() // width constraints - trailingLessThanEqualsConstraint = layoutGuide.pinTrailingLessThanOrEqualTo(anchor: trailingAnchor)?.deactivate() widthConstraint = layoutGuide.widthAnchor.constraint(equalToConstant: 0).deactivate() // Add mainStackView to the view @@ -549,18 +541,13 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalVali containerView.layer.borderWidth = VDSFormControls.borderWidth containerView.layer.cornerRadius = VDSFormControls.borderRadius } - + internal func updateContainerWidth() { widthConstraint?.deactivate() - trailingLessThanEqualsConstraint?.deactivate() - trailingEqualsConstraint?.deactivate() - + if let width, width >= minWidth, width <= maxWidth { widthConstraint?.constant = width widthConstraint?.activate() - trailingLessThanEqualsConstraint?.activate() - } else { - trailingEqualsConstraint?.activate() } } diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index 165d4dc5..227d515d 100644 --- a/VDS/Components/TextFields/InputField/InputField.swift +++ b/VDS/Components/TextFields/InputField/InputField.swift @@ -47,8 +47,9 @@ open class InputField: EntryFieldBase { 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 + let frameWidth = constrainedWidth + let halfWidth = (frameWidth - horizontalStackView.spacing) / 2 + return helperTextPlacement == .right && halfWidth > minWidth * 2 ? halfWidth : frameWidth } /// The is used for the for adding the helperLabel to the right of the containerView. @@ -320,15 +321,12 @@ open class InputField: EntryFieldBase { internal override func updateContainerWidth() { widthConstraint?.deactivate() - trailingLessThanEqualsConstraint?.deactivate() - trailingEqualsConstraint?.deactivate() //see if there is a widthPercentage and follow the same pattern as done for "width" let currentWidth = (horizontalPinnedWidth() ?? 0) * (widthPercentage ?? 0) if currentWidth >= minWidth, currentWidth <= maxWidth { widthConstraint?.constant = currentWidth widthConstraint?.activate() - trailingLessThanEqualsConstraint?.activate() } else { super.updateContainerWidth() } diff --git a/VDS/Protocols/LayoutConstraintable.swift b/VDS/Protocols/LayoutConstraintable.swift index bee145ad..daf65f3f 100644 --- a/VDS/Protocols/LayoutConstraintable.swift +++ b/VDS/Protocols/LayoutConstraintable.swift @@ -647,7 +647,14 @@ public enum LayoutDistribution: String, CaseIterable { case fillProportionally } +extension LayoutConstraintable where Self: UIView { + public var constrainedWidth: CGFloat { + horizontalPinnedWidth() ?? (superview?.frame.size.width ?? frame.size.width) + } +} + extension LayoutConstraintable { + public func removeConstraints() { guard let view = self as? UIView, let superview = view.superview else { return }