Digital ACT191 story ONEAPP-6682 minor changes

This commit is contained in:
vasavk 2024-02-26 18:02:37 +05:30
parent 72ef366eed
commit f527ec5483

View File

@ -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
}
}