From 783143717c71d219d725deeef868ea40312a03fd Mon Sep 17 00:00:00 2001 From: vasavk Date: Fri, 23 Feb 2024 12:47:47 +0530 Subject: [PATCH] Digital ACT191 story ONEAPP-6682 adding character count limit to container --- .../TextFields/EntryFieldBase.swift | 35 ++++++++++++++++-- .../TextFields/TextArea/TextArea.swift | 37 ++++++++++++++++++- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/VDS/Components/TextFields/EntryFieldBase.swift b/VDS/Components/TextFields/EntryFieldBase.swift index aaf03256..31529f61 100644 --- a/VDS/Components/TextFields/EntryFieldBase.swift +++ b/VDS/Components/TextFields/EntryFieldBase.swift @@ -70,6 +70,20 @@ open class EntryFieldBase: Control, Changeable { } }() + internal var bottomContainerView: UIView = { + return UIView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + } + }() + + internal var bottomContainerStackView: UIStackView = { + return UIStackView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.axis = .vertical + $0.distribution = .fill + } + }() + //-------------------------------------------------- // MARK: - Configuration Properties //-------------------------------------------------- @@ -204,14 +218,24 @@ open class EntryFieldBase: Control, Changeable { containerStackView.addArrangedSubview(controlContainerView) containerStackView.addArrangedSubview(icon) + //get the container this is what show helper text, error text + //can include other for character count, max length + let bottomContainer = getBottomContainer() + + //add bottomContainerStackView + //this is the vertical stack that contains error text, helper text + bottomContainer.addSubview(bottomContainerStackView) + bottomContainerStackView.pinToSuperView() + bottomContainerStackView.addArrangedSubview(errorLabel) + bottomContainerStackView.addArrangedSubview(helperLabel) + stackView.addArrangedSubview(titleLabel) stackView.addArrangedSubview(container) - stackView.addArrangedSubview(errorLabel) - stackView.addArrangedSubview(helperLabel) + stackView.addArrangedSubview(bottomContainer) stackView.setCustomSpacing(4, after: titleLabel) stackView.setCustomSpacing(8, after: container) - stackView.setCustomSpacing(8, after: errorLabel) + stackView.setCustomSpacing(8, after: bottomContainer) stackView .pinTop() @@ -273,6 +297,11 @@ open class EntryFieldBase: Control, Changeable { open func getContainer() -> UIView { return containerView } + + /// Container for the area in which helper or error text presents. + open func getBottomContainer() -> UIView { + return bottomContainerView + } open func updateTitleLabel() { diff --git a/VDS/Components/TextFields/TextArea/TextArea.swift b/VDS/Components/TextFields/TextArea/TextArea.swift index 4494f1b7..7cca53da 100644 --- a/VDS/Components/TextFields/TextArea/TextArea.swift +++ b/VDS/Components/TextFields/TextArea/TextArea.swift @@ -45,6 +45,30 @@ open class TextArea: EntryFieldBase { } }() + internal var bottomView: UIView = { + return UIView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + } + }() + + internal var bottomStackView: UIStackView = { + return UIStackView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.axis = .horizontal + $0.distribution = .fill + $0.alignment = .top + } + }() + + open var characterCountLabel = Label().with { + $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.textStyle = .bodySmall + } + open var maxLengthLabel = Label().with { + $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.textStyle = .bodySmall + } + //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- @@ -70,9 +94,10 @@ open class TextArea: 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() - minWidthConstraint = containerView.widthAnchor.constraint(greaterThanOrEqualToConstant: containerSize.width) minWidthConstraint?.isActive = true + characterCountLabel.text = "0" + maxLengthLabel.text = "/200" controlContainerView.addSubview(textView) textView @@ -119,6 +144,16 @@ open class TextArea: EntryFieldBase { minWidthConstraint?.isActive = true } } + + /// Container for the area which shows helper text, error text, character count, max length value. + open override func getBottomContainer() -> UIView { + bottomView.addSubview(bottomStackView) + bottomStackView.pinToSuperView() + bottomStackView.addArrangedSubview(bottomContainerView) + bottomStackView.addArrangedSubview(characterCountLabel) + bottomStackView.addArrangedSubview(maxLengthLabel) + return bottomView + } } extension TextArea: UITextViewDelegate {