From f527ec5483ea03bf8f7318f73c54913175098b01 Mon Sep 17 00:00:00 2001 From: vasavk Date: Mon, 26 Feb 2024 18:02:37 +0530 Subject: [PATCH] Digital ACT191 story ONEAPP-6682 minor changes --- .../TextFields/TextArea/TextArea.swift | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/VDS/Components/TextFields/TextArea/TextArea.swift b/VDS/Components/TextFields/TextArea/TextArea.swift index 01604134..135a2421 100644 --- a/VDS/Components/TextFields/TextArea/TextArea.swift +++ b/VDS/Components/TextFields/TextArea/TextArea.swift @@ -42,7 +42,7 @@ open class TextArea: EntryFieldBase { $0.translatesAutoresizingMaskIntoConstraints = false $0.axis = .horizontal $0.distribution = .fill - $0.spacing = 12 + $0.spacing = VDSLayout.Spacing.space3X.value } }() @@ -58,6 +58,7 @@ open class TextArea: EntryFieldBase { $0.axis = .horizontal $0.distribution = .fill $0.alignment = .top + $0.spacing = VDSLayout.Spacing.space2X.value } }() @@ -128,6 +129,8 @@ open class TextArea: EntryFieldBase { borderColorConfiguration.setSurfaceColors(VDSColor.feedbackSuccessOnlight, VDSColor.feedbackSuccessOndark, forState: .success) borderColorConfiguration.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .focused) textView.delegate = self + characterCounterLabel.textColorConfiguration = primaryColorConfiguration.eraseToAnyColorable() + bottomContainerStackView.spacing = VDSLayout.Spacing.space2X.value } /// Resets to default settings. @@ -161,10 +164,10 @@ open class TextArea: EntryFieldBase { minWidthConstraint?.isActive = true } - if ((maxLength ?? 0) > 0) { + if let maxLength, maxLength > 0 { // allow - 20% of character limit - let overflowLimit = Double(maxLength ?? 0) * 0.20 - allowCharCount = Int(overflowLimit) + (maxLength ?? 0) + let overflowLimit = Double(maxLength) * 0.20 + allowCharCount = Int(overflowLimit) + maxLength characterCounterLabel.text = getCharacterCounterText() } else { characterCounterLabel.text = "" @@ -175,8 +178,9 @@ open class TextArea: EntryFieldBase { containerView.layer.borderColor = readOnly ? readOnlyBorderColorConfiguration.getColor(self).cgColor : borderColorConfiguration.getColor(self).cgColor textView.isEditable = readOnly ? false : true textView.backgroundColor = backgroundColorConfiguration.getColor(self) - characterCounterLabel.textColorConfiguration = primaryColorConfiguration.eraseToAnyColorable() textView.tintColor = iconColorConfiguration.getColor(self) + characterCounterLabel.surface = surface + highlightCharacterOverflow() } /// Container for the area showing helper text, error text, character count, maximum length value. @@ -221,9 +225,11 @@ open class TextArea: EntryFieldBase { open func highlightCharacterOverflow() { let count = textView.text.count - guard let text = textView.attributedText?.mutableCopy() as? NSMutableAttributedString else { return } - text.addAttribute(NSAttributedString.Key.backgroundColor, value: highlightBackgroundColor.getColor(self), range: NSRange(location:(maxLength ?? 0 ), length: (count - (maxLength ?? 0)))) - text.addAttribute(NSAttributedString.Key.foregroundColor, value: highlightTextColor.getColor(self), range: NSRange(location:(maxLength ?? 0 ), length: (count - (maxLength ?? 0)))) + guard let maxLength, + count > maxLength, + let text = textView.attributedText?.mutableCopy() as? NSMutableAttributedString else { return } + text.addAttribute(NSAttributedString.Key.backgroundColor, value: highlightBackgroundColor.getColor(self), range: NSRange(location:maxLength, length: (count - maxLength))) + text.addAttribute(NSAttributedString.Key.foregroundColor, value: highlightTextColor.getColor(self), range: NSRange(location:maxLength, length: (count - maxLength))) textView.attributedText = text.copy() as? NSAttributedString } }