refactored calculating width

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-05-13 12:32:46 -05:00
parent 4b5bbd1ace
commit e667054eb6
5 changed files with 27 additions and 37 deletions

View File

@ -147,15 +147,6 @@ open class DatePicker: EntryFieldBase {
selectedDateLabel.surface = surface selectedDateLabel.surface = surface
selectedDateLabel.isEnabled = isEnabled selectedDateLabel.isEnabled = isEnabled
calendarIcon.color = iconColorConfiguration.getColor(self) 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. /// Resets to default settings.

View File

@ -71,7 +71,11 @@ open class DropdownSelect: EntryFieldBase {
//-------------------------------------------------- //--------------------------------------------------
internal var minWidthDefault = 66.0 internal var minWidthDefault = 66.0
internal var minWidthInlineLabel = 102.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. /// The is used for the for adding the helperLabel to the right of the containerView.
internal var horizontalStackView: UIStackView = { 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. /// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations.
open override func setup() { open override func setup() {
super.setup() super.setup()
widthConstraint?.activate()
titleLabel.setContentCompressionResistancePriority(.required, for: .horizontal) titleLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
titleLabel.setContentHuggingPriority(.required, for: .horizontal) titleLabel.setContentHuggingPriority(.required, for: .horizontal)
titleLabelWidthConstraint = titleLabel.width(constant: 0) titleLabelWidthConstraint = titleLabel.width(constant: 0)
@ -302,17 +307,8 @@ open class DropdownSelect: EntryFieldBase {
} else { } else {
primaryStackView.addArrangedSubview(secondaryStackView) 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() { open override func updateAccessibility() {
super.updateAccessibility() super.updateAccessibility()
let selectedOption = selectedOptionLabel.text ?? "" let selectedOption = selectedOptionLabel.text ?? ""

View File

@ -93,7 +93,9 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
// MARK: - Configuration Properties // MARK: - Configuration Properties
//-------------------------------------------------- //--------------------------------------------------
// Sizes are from InVision design specs. // 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 { internal let primaryColorConfiguration = ViewColorConfiguration().with {
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forDisabled: true) $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forDisabled: true)
@ -216,7 +218,7 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
//create the wrapping view //create the wrapping view
heightConstraint = containerView.heightGreaterThanEqualTo(constant: containerSize.height) heightConstraint = containerView.heightGreaterThanEqualTo(constant: containerSize.height)
widthConstraint = containerView.width(constant: 0) widthConstraint = containerView.width(constant: frame.size.width)
secondaryStackView.addArrangedSubview(containerView) secondaryStackView.addArrangedSubview(containerView)
secondaryStackView.setCustomSpacing(8, after: containerView) secondaryStackView.setCustomSpacing(8, after: containerView)
@ -292,6 +294,7 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
updateTitleLabel() updateTitleLabel()
updateErrorLabel() updateErrorLabel()
updateHelperLabel() updateHelperLabel()
updateContainerWidth()
} }
open func validate(){ open func validate(){
@ -314,6 +317,15 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Public Methods // 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. /// Container for the area in which the user interacts.
open func getFieldContainer() -> UIView { open func getFieldContainer() -> UIView {
fatalError("Subclass must return the view that contains the field/view the user will interact with.") fatalError("Subclass must return the view that contains the field/view the user will interact with.")

View File

@ -35,6 +35,11 @@ open class InputField: EntryFieldBase {
// MARK: - Private Properties // MARK: - Private Properties
//-------------------------------------------------- //--------------------------------------------------
internal var titleLabelWidthConstraint: NSLayoutConstraint? 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. /// The is used for the for adding the helperLabel to the right of the containerView.
internal var horizontalStackView: UIStackView = { internal var horizontalStackView: UIStackView = {
@ -277,16 +282,6 @@ open class InputField: EntryFieldBase {
} else { } else {
primaryStackView.addArrangedSubview(secondaryStackView) 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() { override func updateRules() {

View File

@ -187,10 +187,6 @@ open class TextArea: EntryFieldBase {
textView.isEnabled = isEnabled textView.isEnabled = isEnabled
textView.surface = surface 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 textViewHeightConstraint?.constant = minHeight.value
characterCounterLabel.text = getCharacterCounterText() characterCounterLabel.text = getCharacterCounterText()