diff --git a/VDS/Components/TextFields/EntryFieldBase.swift b/VDS/Components/TextFields/EntryFieldBase.swift index 02767152..2c2435be 100644 --- a/VDS/Components/TextFields/EntryFieldBase.swift +++ b/VDS/Components/TextFields/EntryFieldBase.swift @@ -101,6 +101,13 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { /// This is set by a local method. internal var bottomContainerView: UIView! + //-------------------------------------------------- + // MARK: - Constraints + //-------------------------------------------------- + internal var widthConstraint: NSLayoutConstraint? + internal var trailingEqualsConstraint: NSLayoutConstraint? + internal var trailingLessThanEqualsConstraint: NSLayoutConstraint? + //-------------------------------------------------- // MARK: - Configuration Properties //-------------------------------------------------- @@ -228,11 +235,27 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { open override func setup() { super.setup() + let layoutGuide = UILayoutGuide() + addLayoutGuide(layoutGuide) + layoutGuide + .pinTop() + .pinLeading() + .pinBottom() + + trailingEqualsConstraint = layoutGuide.pinTrailing(anchor: trailingAnchor) + + // width constraints + trailingLessThanEqualsConstraint = layoutGuide.pinTrailingLessThanOrEqualTo(anchor: trailingAnchor)?.deactivate() + widthConstraint = layoutGuide.widthAnchor.constraint(equalToConstant: 0).deactivate() + // Add mainStackView to the view addSubview(mainStackView) - - mainStackView.pinToSuperView() - + + mainStackView.pinTop(anchor: layoutGuide.topAnchor) + mainStackView.pinLeading(anchor: layoutGuide.leadingAnchor) + mainStackView.pinBottom(anchor: layoutGuide.bottomAnchor) + mainStackView.pinTrailing(anchor: layoutGuide.trailingAnchor) + //add ContainerStackView //this is the horizontal stack that contains //InputContainer, Icons, Buttons @@ -265,12 +288,18 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { // Initial position of the helper label updateHelperTextPosition() + + // colorconfigs + titleLabel.textColorConfiguration = primaryColorConfiguration.eraseToAnyColorable() + errorLabel.textColorConfiguration = primaryColorConfiguration.eraseToAnyColorable() + helperLabel.textColorConfiguration = secondaryColorConfiguration.eraseToAnyColorable() } /// Updates the UI open override func updateView() { super.updateView() updateContainerView() + updateContainerWidth() updateTitleLabel() updateErrorLabel() updateHelperLabel() @@ -411,7 +440,21 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { 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() + } + } + internal func updateHelperTextPosition() { titleLabel.removeFromSuperview()