Digital ACT191 story ONEAPP-6682 added preset default height property.
This commit is contained in:
parent
f527ec5483
commit
4f41d9cc93
@ -69,11 +69,44 @@ open class TextArea: EntryFieldBase {
|
||||
$0.numberOfLines = 1
|
||||
}
|
||||
|
||||
private var _minHeight: Height = .twoX
|
||||
|
||||
open var minHeight: Height? {
|
||||
get { return _minHeight }
|
||||
set {
|
||||
if let newValue {
|
||||
_minHeight = newValue
|
||||
} else {
|
||||
_minHeight = .twoX
|
||||
}
|
||||
textViewHeightConstraint?.constant = _minHeight.value
|
||||
setNeedsUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Public Properties
|
||||
//--------------------------------------------------
|
||||
override var containerSize: CGSize { CGSize(width: 182, height: 88) }
|
||||
|
||||
|
||||
/// Enum used to describe the the height of TextArea.
|
||||
public enum Height: String, CaseIterable {
|
||||
case twoX = "2X"
|
||||
case fourX = "4X"
|
||||
case eightX = "8X"
|
||||
|
||||
var value: CGFloat {
|
||||
switch self {
|
||||
case .twoX:
|
||||
88
|
||||
case .fourX:
|
||||
176
|
||||
case .eightX:
|
||||
352
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// UITextView shown in the TextArea.
|
||||
open var textView = UITextView().with {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
@ -139,6 +172,8 @@ open class TextArea: EntryFieldBase {
|
||||
textView.text = ""
|
||||
characterCounterLabel.reset()
|
||||
characterCounterLabel.textStyle = .bodySmall
|
||||
minHeight = .twoX
|
||||
setNeedsUpdate()
|
||||
}
|
||||
|
||||
/// Container for the area in which the user interacts.
|
||||
@ -230,7 +265,7 @@ open class TextArea: EntryFieldBase {
|
||||
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
|
||||
textView.attributedText = text
|
||||
}
|
||||
}
|
||||
|
||||
@ -244,15 +279,15 @@ extension TextArea: UITextViewDelegate {
|
||||
//if you want it to work "as-is" delete this code
|
||||
//since it will autogrow with the current settings
|
||||
if let textViewHeightConstraint, textView.isEditable {
|
||||
let height = textView.contentSize.height
|
||||
if height > 88 && height < 176 {
|
||||
textViewHeightConstraint.constant = 176
|
||||
} else if height > 176 {
|
||||
textViewHeightConstraint.constant = 352
|
||||
var height = textView.contentSize.height
|
||||
height = max(height, _minHeight.value)
|
||||
if height > Height.twoX.value && height < Height.fourX.value {
|
||||
textViewHeightConstraint.constant = Height.fourX.value
|
||||
} else if height > Height.fourX.value {
|
||||
textViewHeightConstraint.constant = Height.eightX.value
|
||||
} else {
|
||||
textViewHeightConstraint.constant = 88
|
||||
textViewHeightConstraint.constant = Height.twoX.value
|
||||
}
|
||||
textViewHeightConstraint.isActive = true
|
||||
}
|
||||
|
||||
//The exceeding characters will be highlighted to help users correct their entry.
|
||||
@ -261,7 +296,6 @@ extension TextArea: UITextViewDelegate {
|
||||
//setting the value and firing control event
|
||||
value = textView.text
|
||||
sendActions(for: .valueChanged)
|
||||
|
||||
if (textView.text.count > (maxLength ?? 0)) {
|
||||
highlightCharacterOverflow()
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user