Commit 9fae5e1f by Orkhan Alikhanov Committed by OrkhanAlikhanov

Added preferredMaxLayoutHeight to TextView

parent 9cd30b33
......@@ -263,6 +263,12 @@ open class TextView: UITextView {
layoutShape()
layoutShadowPath()
layoutPlaceholderLabel()
guard isGrowEnabled else {
return
}
invalidateIntrinsicContentSize()
}
/**
......@@ -283,18 +289,43 @@ open class TextView: UITextView {
prepareRegularExpression()
preparePlaceholderLabel()
}
open override func insertText(_ text: String) {
fixTypingFont()
super.insertText(text)
fixTypingFont()
/// Maximum preffered layout height before scrolling.
open var preferredMaxLayoutHeight: CGFloat = 0 {
didSet {
invalidateIntrinsicContentSize()
}
open override func paste(_ sender: Any?) {
fixTypingFont()
super.paste(sender)
fixTypingFont()
}
/// A property indicating if textView allowed to grow.
private var isGrowEnabled: Bool {
return preferredMaxLayoutHeight > 0 && isScrollEnabled
}
open override var intrinsicContentSize: CGSize {
guard isGrowEnabled else {
return super.intrinsicContentSize
}
let insets = textContainerInsets
let w = bounds.width - insets.left - insets.right - 2 * textContainer.lineFragmentPadding
let placeholderH = placeholderLabel.sizeThatFits(CGSize(width: w, height: .greatestFiniteMagnitude)).height
let h = max(contentSize.height, placeholderH + insets.top + insets.bottom)
return CGSize(width: UIView.noIntrinsicMetric, height: min(h, preferredMaxLayoutHeight))
}
open override func insertText(_ text: String) {
fixTypingFont()
super.insertText(text)
fixTypingFont()
}
open override func paste(_ sender: Any?) {
fixTypingFont()
super.paste(sender)
fixTypingFont()
}
}
fileprivate extension TextView {
......
......@@ -129,6 +129,7 @@ open class Toolbar: Bar {
prepareDetailLabel()
}
/// A reference to titleLabel.textAlignment observation.
private var titleLabelTextAlignmentObserver: NSKeyValueObservation!
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment