refactred getContainer() to getFieldContainer() to make more sense that the developer needs to only return the Item the User see to interact with.

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-05-10 09:10:35 -05:00
parent 501dc4a55f
commit c5262246f3
5 changed files with 58 additions and 80 deletions

View File

@ -103,26 +103,10 @@ open class DropdownSelect: EntryFieldBase {
open override func setup() { open override func setup() {
super.setup() super.setup()
// stackview for controls in EntryFieldBase.controlContainerView fieldStackView.isAccessibilityElement = true
let controlStackView = UIStackView().with { fieldStackView.accessibilityLabel = "Dropdown Select"
$0.translatesAutoresizingMaskIntoConstraints = false
$0.axis = .horizontal
$0.spacing = VDSFormControls.spaceInset
}
fieldContainerView.addSubview(controlStackView)
controlStackView.pinToSuperView()
controlStackView.addArrangedSubview(dropdownField)
controlStackView.addArrangedSubview(inlineDisplayLabel)
controlStackView.addArrangedSubview(selectedOptionLabel)
containerStackView.isAccessibilityElement = true
containerStackView.accessibilityLabel = "Dropdown Select"
inlineDisplayLabel.isAccessibilityElement = true inlineDisplayLabel.isAccessibilityElement = true
controlStackView.setCustomSpacing(0, after: dropdownField)
controlStackView.setCustomSpacing(VDSLayout.space1X, after: inlineDisplayLabel)
controlStackView.setCustomSpacing(VDSLayout.space3X, after: selectedOptionLabel)
dropdownField.width(0) dropdownField.width(0)
inlineWidthConstraint = inlineDisplayLabel.widthAnchor.constraint(greaterThanOrEqualToConstant: 0) inlineWidthConstraint = inlineDisplayLabel.widthAnchor.constraint(greaterThanOrEqualToConstant: 0)
inlineWidthConstraint?.isActive = true inlineWidthConstraint?.isActive = true
@ -150,7 +134,7 @@ open class DropdownSelect: EntryFieldBase {
}() }()
// tap gesture // tap gesture
containerStackView fieldStackView
.publisher(for: UITapGestureRecognizer()) .publisher(for: UITapGestureRecognizer())
.sink { [weak self] _ in .sink { [weak self] _ in
self?.launchPicker() self?.launchPicker()
@ -158,6 +142,21 @@ open class DropdownSelect: EntryFieldBase {
.store(in: &subscribers) .store(in: &subscribers)
} }
open override func getFieldContainer() -> UIView {
let controlStackView = UIStackView().with {
$0.translatesAutoresizingMaskIntoConstraints = false
$0.axis = .horizontal
$0.spacing = VDSFormControls.spaceInset
}
controlStackView.addArrangedSubview(dropdownField)
controlStackView.addArrangedSubview(inlineDisplayLabel)
controlStackView.addArrangedSubview(selectedOptionLabel)
controlStackView.setCustomSpacing(0, after: dropdownField)
controlStackView.setCustomSpacing(VDSLayout.space1X, after: inlineDisplayLabel)
controlStackView.setCustomSpacing(VDSLayout.space3X, after: selectedOptionLabel)
return controlStackView
}
/// Used to make changes to the View based off a change events or from local properties. /// Used to make changes to the View based off a change events or from local properties.
open override func updateView() { open override func updateView() {
super.updateView() super.updateView()
@ -250,14 +249,14 @@ open class DropdownSelect: EntryFieldBase {
open override func updateAccessibility() { open override func updateAccessibility() {
super.updateAccessibility() super.updateAccessibility()
let selectedOption = selectedOptionLabel.text ?? "" let selectedOption = selectedOptionLabel.text ?? ""
containerStackView.accessibilityLabel = "Dropdown Select, \(selectedOption) \(isReadOnly ? ", read only" : "")" fieldStackView.accessibilityLabel = "Dropdown Select, \(selectedOption) \(isReadOnly ? ", read only" : "")"
containerStackView.accessibilityHint = isReadOnly || !isEnabled ? "" : "Double tap to open." fieldStackView.accessibilityHint = isReadOnly || !isEnabled ? "" : "Double tap to open."
} }
open override var accessibilityElements: [Any]? { open override var accessibilityElements: [Any]? {
get { get {
var elements = [Any]() var elements = [Any]()
elements.append(contentsOf: [titleLabel, containerStackView]) elements.append(contentsOf: [titleLabel, fieldStackView])
if showError { if showError {
elements.append(statusIcon) elements.append(statusIcon)
@ -281,7 +280,7 @@ open class DropdownSelect: EntryFieldBase {
optionsPicker.isHidden = true optionsPicker.isHidden = true
dropdownField.resignFirstResponder() dropdownField.resignFirstResponder()
setNeedsUpdate() setNeedsUpdate()
UIAccessibility.post(notification: .layoutChanged, argument: containerStackView) UIAccessibility.post(notification: .layoutChanged, argument: fieldStackView)
} }
} }

View File

@ -67,7 +67,7 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
} }
}() }()
internal var containerStackView: UIStackView = { internal var fieldStackView: UIStackView = {
return UIStackView().with { return UIStackView().with {
$0.translatesAutoresizingMaskIntoConstraints = false $0.translatesAutoresizingMaskIntoConstraints = false
$0.axis = .horizontal $0.axis = .horizontal
@ -76,12 +76,6 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
} }
}() }()
internal var fieldContainerView: UIView = {
return UIView().with {
$0.translatesAutoresizingMaskIntoConstraints = false
}
}()
internal var bottomContainerStackView: UIStackView = { internal var bottomContainerStackView: UIStackView = {
return UIStackView().with { return UIStackView().with {
$0.translatesAutoresizingMaskIntoConstraints = false $0.translatesAutoresizingMaskIntoConstraints = false
@ -224,21 +218,20 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
widthConstraint = containerView.widthAnchor.constraint(equalToConstant: 0) widthConstraint = containerView.widthAnchor.constraint(equalToConstant: 0)
widthConstraint?.priority = .defaultHigh widthConstraint?.priority = .defaultHigh
//get the container this is what is color
//border, internal, etc...
let container = getContainer()
//add ContainerStackView //add ContainerStackView
//this is the horizontal stack that contains //this is the horizontal stack that contains
//the left, InputContainer, Icons, Buttons //the left, InputContainer, Icons, Buttons
container.addSubview(containerStackView) containerView.addSubview(fieldStackView)
containerStackView.pinToSuperView(.uniform(VDSLayout.space3X)) fieldStackView.pinToSuperView(.uniform(VDSLayout.space3X))
let fieldContainerView = getFieldContainer()
fieldContainerView.translatesAutoresizingMaskIntoConstraints = false
//add the view to add input fields //add the view to add input fields
containerStackView.addArrangedSubview(fieldContainerView) fieldStackView.addArrangedSubview(fieldContainerView)
containerStackView.addArrangedSubview(statusIcon) fieldStackView.addArrangedSubview(statusIcon)
containerStackView.setCustomSpacing(VDSLayout.space3X, after: fieldContainerView) fieldStackView.setCustomSpacing(VDSLayout.space3X, after: fieldContainerView)
//get the container this is what show helper text, error text //get the container this is what show helper text, error text
//can include other for character count, max length //can include other for character count, max length
@ -249,11 +242,11 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
bottomContainerStackView.addArrangedSubview(helperLabel) bottomContainerStackView.addArrangedSubview(helperLabel)
stackView.addArrangedSubview(titleLabel) stackView.addArrangedSubview(titleLabel)
stackView.addArrangedSubview(container) stackView.addArrangedSubview(containerView)
stackView.addArrangedSubview(bottomContainer) stackView.addArrangedSubview(bottomContainer)
stackView.setCustomSpacing(4, after: titleLabel) stackView.setCustomSpacing(4, after: titleLabel)
stackView.setCustomSpacing(8, after: container) stackView.setCustomSpacing(8, after: containerView)
stackView.setCustomSpacing(8, after: bottomContainer) stackView.setCustomSpacing(8, after: bottomContainer)
stackView stackView
@ -322,8 +315,8 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
// MARK: - Public Methods // MARK: - Public Methods
//-------------------------------------------------- //--------------------------------------------------
/// Container for the area in which the user interacts. /// Container for the area in which the user interacts.
open func getContainer() -> UIView { open func getFieldContainer() -> UIView {
return containerView fatalError("Subclass must return the view that contains the field/view the user will interact with.")
} }
/// Container for the area in which helper or error text presents. /// Container for the area in which helper or error text presents.

View File

@ -72,10 +72,10 @@ extension InputField {
actionModel.onClick(inputField) actionModel.onClick(inputField)
} }
inputField.actionTextLink.isHidden = false inputField.actionTextLink.isHidden = false
inputField.containerStackView.setCustomSpacing(VDSLayout.space2X, after: inputField.statusIcon) inputField.fieldStackView.setCustomSpacing(VDSLayout.space2X, after: inputField.statusIcon)
} else { } else {
inputField.actionTextLink.isHidden = true inputField.actionTextLink.isHidden = true
inputField.containerStackView.setCustomSpacing(0, after: inputField.statusIcon) inputField.fieldStackView.setCustomSpacing(0, after: inputField.statusIcon)
} }
//set the width constraints //set the width constraints

View File

@ -178,19 +178,7 @@ open class InputField: EntryFieldBase {
minWidthConstraint = containerView.widthAnchor.constraint(greaterThanOrEqualToConstant: 0) minWidthConstraint = containerView.widthAnchor.constraint(greaterThanOrEqualToConstant: 0)
minWidthConstraint?.isActive = true minWidthConstraint?.isActive = true
// stackview for controls in EntryFieldBase.controlContainerView
let controlStackView = UIStackView().with {
$0.translatesAutoresizingMaskIntoConstraints = false
$0.axis = .horizontal
$0.spacing = VDSLayout.space3X
}
fieldContainerView.addSubview(controlStackView)
controlStackView.pinToSuperView()
controlStackView.addArrangedSubview(leftImageView)
controlStackView.addArrangedSubview(textField)
textField.heightAnchor.constraint(equalToConstant: 20).isActive = true textField.heightAnchor.constraint(equalToConstant: 20).isActive = true
textField.delegate = self textField.delegate = self
textField textField
@ -207,7 +195,7 @@ open class InputField: EntryFieldBase {
stackView.addArrangedSubview(successLabel) stackView.addArrangedSubview(successLabel)
stackView.setCustomSpacing(8, after: successLabel) stackView.setCustomSpacing(8, after: successLabel)
containerStackView.addArrangedSubview(actionTextLink) fieldStackView.addArrangedSubview(actionTextLink)
successLabel.textColorConfiguration = primaryColorConfiguration.eraseToAnyColorable() successLabel.textColorConfiguration = primaryColorConfiguration.eraseToAnyColorable()
@ -217,6 +205,18 @@ open class InputField: EntryFieldBase {
} }
open override func getFieldContainer() -> UIView {
// stackview for controls in EntryFieldBase.controlContainerView
let stackView = UIStackView().with {
$0.translatesAutoresizingMaskIntoConstraints = false
$0.axis = .horizontal
$0.spacing = VDSLayout.space3X
}
stackView.addArrangedSubview(leftImageView)
stackView.addArrangedSubview(textField)
return stackView
}
/// Resets to default settings. /// Resets to default settings.
open override func reset() { open override func reset() {
super.reset() super.reset()
@ -230,12 +230,6 @@ open class InputField: EntryFieldBase {
successText = nil successText = nil
helperTextPlacement = .bottom helperTextPlacement = .bottom
} }
/// Container for the area in which the user interacts.
open override func getContainer() -> UIView {
inputFieldStackView.addArrangedSubview(containerView)
return inputFieldStackView
}
/// Used to make changes to the View based off a change events or from local properties. /// Used to make changes to the View based off a change events or from local properties.
open override func updateView() { open override func updateView() {

View File

@ -151,15 +151,9 @@ open class TextArea: 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()
containerStackView.pinToSuperView(.uniform(VDSFormControls.spaceInset)) fieldStackView.pinToSuperView(.uniform(VDSFormControls.spaceInset))
minWidthConstraint = containerView.widthAnchor.constraint(greaterThanOrEqualToConstant: containerSize.width) minWidthConstraint = containerView.widthAnchor.constraint(greaterThanOrEqualToConstant: containerSize.width)
minWidthConstraint?.isActive = true minWidthConstraint?.isActive = true
fieldContainerView.addSubview(textView)
textView
.pinTop()
.pinLeading()
.pinTrailingLessThanOrEqualTo(nil, 0, .defaultHigh)
.pinBottom(0, .defaultHigh)
textView.isScrollEnabled = true textView.isScrollEnabled = true
textView.autocorrectionType = .no textView.autocorrectionType = .no
@ -200,13 +194,7 @@ open class TextArea: EntryFieldBase {
characterCounterLabel.textStyle = .bodySmall characterCounterLabel.textStyle = .bodySmall
setNeedsUpdate() setNeedsUpdate()
} }
/// Container for the area in which the user interacts.
open override func getContainer() -> UIView {
inputFieldStackView.addArrangedSubview(containerView)
return inputFieldStackView
}
/// Used to make changes to the View based off a change events or from local properties. /// Used to make changes to the View based off a change events or from local properties.
open override func updateView() { open override func updateView() {
super.updateView() super.updateView()
@ -242,6 +230,10 @@ open class TextArea: EntryFieldBase {
rules.append(.init(countRule)) rules.append(.init(countRule))
} }
open override func getFieldContainer() -> UIView {
textView
}
/// Container for the area showing helper text, error text, character count, maximum length value. /// Container for the area showing helper text, error text, character count, maximum length value.
open override func getBottomContainer() -> UIView { open override func getBottomContainer() -> UIView {
let stackView = UIStackView().with { let stackView = UIStackView().with {