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
|
$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
|
// MARK: - Public Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
override var containerSize: CGSize { CGSize(width: 182, height: 88) }
|
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.
|
/// UITextView shown in the TextArea.
|
||||||
open var textView = UITextView().with {
|
open var textView = UITextView().with {
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
@ -139,6 +172,8 @@ open class TextArea: EntryFieldBase {
|
|||||||
textView.text = ""
|
textView.text = ""
|
||||||
characterCounterLabel.reset()
|
characterCounterLabel.reset()
|
||||||
characterCounterLabel.textStyle = .bodySmall
|
characterCounterLabel.textStyle = .bodySmall
|
||||||
|
minHeight = .twoX
|
||||||
|
setNeedsUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Container for the area in which the user interacts.
|
/// 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 }
|
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.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)))
|
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
|
//if you want it to work "as-is" delete this code
|
||||||
//since it will autogrow with the current settings
|
//since it will autogrow with the current settings
|
||||||
if let textViewHeightConstraint, textView.isEditable {
|
if let textViewHeightConstraint, textView.isEditable {
|
||||||
let height = textView.contentSize.height
|
var height = textView.contentSize.height
|
||||||
if height > 88 && height < 176 {
|
height = max(height, _minHeight.value)
|
||||||
textViewHeightConstraint.constant = 176
|
if height > Height.twoX.value && height < Height.fourX.value {
|
||||||
} else if height > 176 {
|
textViewHeightConstraint.constant = Height.fourX.value
|
||||||
textViewHeightConstraint.constant = 352
|
} else if height > Height.fourX.value {
|
||||||
|
textViewHeightConstraint.constant = Height.eightX.value
|
||||||
} else {
|
} else {
|
||||||
textViewHeightConstraint.constant = 88
|
textViewHeightConstraint.constant = Height.twoX.value
|
||||||
}
|
}
|
||||||
textViewHeightConstraint.isActive = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//The exceeding characters will be highlighted to help users correct their entry.
|
//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
|
//setting the value and firing control event
|
||||||
value = textView.text
|
value = textView.text
|
||||||
sendActions(for: .valueChanged)
|
sendActions(for: .valueChanged)
|
||||||
|
|
||||||
if (textView.text.count > (maxLength ?? 0)) {
|
if (textView.text.count > (maxLength ?? 0)) {
|
||||||
highlightCharacterOverflow()
|
highlightCharacterOverflow()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user