From 5ea18aa807c00ea6b2e962a7f0c844e48bb7fa53 Mon Sep 17 00:00:00 2001 From: porohov Date: Mon, 21 Mar 2022 14:16:34 +0400 Subject: [PATCH 1/3] Added preferred height --- .../TextFields/UnderlinedTextView/UnderlinedTextView.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/TextFieldsCatalog/TextFields/UnderlinedTextView/UnderlinedTextView.swift b/TextFieldsCatalog/TextFields/UnderlinedTextView/UnderlinedTextView.swift index 18b5852..cb1da9b 100644 --- a/TextFieldsCatalog/TextFields/UnderlinedTextView/UnderlinedTextView.swift +++ b/TextFieldsCatalog/TextFields/UnderlinedTextView/UnderlinedTextView.swift @@ -71,6 +71,8 @@ open class UnderlinedTextView: InnerDesignableView, ResetableField, RespondableF // MARK: - Public Properties + public var preferredHeight: CGFloat? + public var field: InnerTextView { return textView } @@ -614,7 +616,7 @@ private extension UnderlinedTextView { textView.isScrollEnabled = false } - textViewHeightConstraint.constant = textHeight + textViewHeightConstraint.constant = preferredHeight ?? textHeight view.layoutIfNeeded() lastViewHeight = viewHeight } From 7fc945aadd10a9ea7a0eebe5da3b1cbc4ad77f77 Mon Sep 17 00:00:00 2001 From: porohov Date: Mon, 21 Mar 2022 21:26:16 +0400 Subject: [PATCH 2/3] Added comment --- .../UnderlinedTextView/UnderlinedTextView.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/TextFieldsCatalog/TextFields/UnderlinedTextView/UnderlinedTextView.swift b/TextFieldsCatalog/TextFields/UnderlinedTextView/UnderlinedTextView.swift index cb1da9b..4040832 100644 --- a/TextFieldsCatalog/TextFields/UnderlinedTextView/UnderlinedTextView.swift +++ b/TextFieldsCatalog/TextFields/UnderlinedTextView/UnderlinedTextView.swift @@ -71,7 +71,10 @@ open class UnderlinedTextView: InnerDesignableView, ResetableField, RespondableF // MARK: - Public Properties - public var preferredHeight: CGFloat? + /// This property sets a fixed initial height for the text field. + /// Affects auto expandability: if not null, then the text field will not auto expand. + /// Property **maxTextContainerHeight** will be ignored + public var fixedTextHeight: CGFloat? public var field: InnerTextView { return textView @@ -601,7 +604,8 @@ private extension UnderlinedTextView { func updateViewHeight() { let hintHeight = hintService.hintHeight(containerState: containerState) - let textHeight = min(textViewHeight(), maxTextContainerHeight ?? CGFloat.greatestFiniteMagnitude) + let textHeight = fixedTextHeight ?? min(textViewHeight(), + maxTextContainerHeight ?? CGFloat.greatestFiniteMagnitude) let freeSpace = freeVerticalSpace(isEmptyHint: hintHeight == 0) let actualViewHeight = textHeight + hintHeight + freeSpace let viewHeight = max(flexibleHeightPolicy.minHeight, actualViewHeight) @@ -616,7 +620,7 @@ private extension UnderlinedTextView { textView.isScrollEnabled = false } - textViewHeightConstraint.constant = preferredHeight ?? textHeight + textViewHeightConstraint.constant = textHeight view.layoutIfNeeded() lastViewHeight = viewHeight } From a8b22ffdafc886631e9fd2facf8cefb84240d7d0 Mon Sep 17 00:00:00 2001 From: porohov Date: Mon, 21 Mar 2022 22:42:01 +0400 Subject: [PATCH 3/3] renamed fixedTextContainerHeight --- .../UnderlinedTextView/UnderlinedTextView.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/TextFieldsCatalog/TextFields/UnderlinedTextView/UnderlinedTextView.swift b/TextFieldsCatalog/TextFields/UnderlinedTextView/UnderlinedTextView.swift index 4040832..8c22904 100644 --- a/TextFieldsCatalog/TextFields/UnderlinedTextView/UnderlinedTextView.swift +++ b/TextFieldsCatalog/TextFields/UnderlinedTextView/UnderlinedTextView.swift @@ -73,8 +73,8 @@ open class UnderlinedTextView: InnerDesignableView, ResetableField, RespondableF /// This property sets a fixed initial height for the text field. /// Affects auto expandability: if not null, then the text field will not auto expand. - /// Property **maxTextContainerHeight** will be ignored - public var fixedTextHeight: CGFloat? + /// Property **maxTextContainerHeight** will be ignored, must be set with the same height + public var fixedTextContainerHeight: CGFloat? public var field: InnerTextView { return textView @@ -604,8 +604,8 @@ private extension UnderlinedTextView { func updateViewHeight() { let hintHeight = hintService.hintHeight(containerState: containerState) - let textHeight = fixedTextHeight ?? min(textViewHeight(), - maxTextContainerHeight ?? CGFloat.greatestFiniteMagnitude) + let textHeight = fixedTextContainerHeight ?? min(textViewHeight(), + maxTextContainerHeight ?? CGFloat.greatestFiniteMagnitude) let freeSpace = freeVerticalSpace(isEmptyHint: hintHeight == 0) let actualViewHeight = textHeight + hintHeight + freeSpace let viewHeight = max(flexibleHeightPolicy.minHeight, actualViewHeight)