From 81eb342e42d73fd65b43a107a2b42884c0276b3a Mon Sep 17 00:00:00 2001 From: Lukasz Kasperek Date: Thu, 16 Nov 2017 15:35:08 +0100 Subject: [PATCH 1/3] move text view calculations to SLKTextView --- Source/SLKTextInputbar.m | 24 +++--------------------- Source/SLKTextView.h | 3 +++ Source/SLKTextView.m | 10 ++++++++++ 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Source/SLKTextInputbar.m b/Source/SLKTextInputbar.m index ca970691..02f3deb1 100644 --- a/Source/SLKTextInputbar.m +++ b/Source/SLKTextInputbar.m @@ -310,18 +310,11 @@ - (CGFloat)minimumInputbarHeight - (CGFloat)appropriateHeight { - CGFloat height = 0.0; + CGFloat height = self.textView.appropriateHeight; CGFloat minimumHeight = [self minimumInputbarHeight]; - if (self.textView.numberOfLines == 1) { - height = minimumHeight; - } - else if (self.textView.numberOfLines < self.textView.maxNumberOfLines) { - height = [self slk_inputBarHeightForLines:self.textView.numberOfLines]; - } - else { - height = [self slk_inputBarHeightForLines:self.textView.maxNumberOfLines]; - } + height += self.contentInset.top; + height += self.slk_bottomMargin; if (height < minimumHeight) { height = minimumHeight; @@ -344,17 +337,6 @@ - (BOOL)limitExceeded return NO; } -- (CGFloat)slk_inputBarHeightForLines:(NSUInteger)numberOfLines -{ - CGFloat height = self.textView.intrinsicContentSize.height; - height -= self.textView.font.lineHeight; - height += roundf(self.textView.font.lineHeight*numberOfLines); - height += self.contentInset.top; - height += self.slk_bottomMargin; - - return height; -} - - (CGFloat)slk_bottomMargin { CGFloat margin = self.contentInset.bottom; diff --git a/Source/SLKTextView.h b/Source/SLKTextView.h index 05850cb5..8d2f1efd 100644 --- a/Source/SLKTextView.h +++ b/Source/SLKTextView.h @@ -53,6 +53,9 @@ UIKIT_EXTERN NSString * const SLKTextViewPastedItemData; /** The placeholder's font. Default is the textView's font. */ @property (nonatomic, copy, null_resettable) UIFont *placeholderFont; +/** Height being multiplication of number of lines and font's line height. */ +@property(nonatomic, readonly) CGFloat appropriateHeight; + /** The maximum number of lines before enabling scrolling. Default is 0 wich means limitless. If dynamic type is enabled, the maximum number of lines will be calculated proportionally to the user preferred font size. */ @property (nonatomic, readwrite) NSUInteger maxNumberOfLines; diff --git a/Source/SLKTextView.m b/Source/SLKTextView.m index 08a43081..ef4b636e 100644 --- a/Source/SLKTextView.m +++ b/Source/SLKTextView.m @@ -165,6 +165,16 @@ - (UIFont *)placeholderFont return self.placeholderLabel.font; } +- (CGFloat)appropriateHeight +{ + NSUInteger numberOfLines = self.numberOfLines > self.maxNumberOfLines ? self.maxNumberOfLines : self.numberOfLines; + CGFloat height = [self intrinsicContentSize].height; + height -= self.font.lineHeight; + height += roundf(self.font.lineHeight*numberOfLines); + + return height; +} + - (NSUInteger)numberOfLines { CGSize contentSize = self.contentSize; From 05e736bdc30a7912806c2260706689ac7d8a9b21 Mon Sep 17 00:00:00 2001 From: Lukasz Kasperek Date: Thu, 16 Nov 2017 16:12:28 +0100 Subject: [PATCH 2/3] make code outcomie to be exactly the same as before changes --- Source/SLKTextInputbar.m | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Source/SLKTextInputbar.m b/Source/SLKTextInputbar.m index 02f3deb1..fd03d56b 100644 --- a/Source/SLKTextInputbar.m +++ b/Source/SLKTextInputbar.m @@ -310,11 +310,16 @@ - (CGFloat)minimumInputbarHeight - (CGFloat)appropriateHeight { - CGFloat height = self.textView.appropriateHeight; + CGFloat height = 0.0; CGFloat minimumHeight = [self minimumInputbarHeight]; - height += self.contentInset.top; - height += self.slk_bottomMargin; + if (self.textView.numberOfLines == 1) { + height = minimumHeight; + } else { + height = self.textView.appropriateHeight; + height += self.contentInset.top; + height += self.slk_bottomMargin; + } if (height < minimumHeight) { height = minimumHeight; From 145c9ed2be9d7fd01dbb8449cbd06fef69223361 Mon Sep 17 00:00:00 2001 From: Lukasz Kasperek Date: Thu, 16 Nov 2017 16:44:46 +0100 Subject: [PATCH 3/3] update changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2592d34..1c0a6caa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## [Version 1.9.7](https://github.com/slackhq/SlackTextViewController/releases/tag/v1.9.7) + +##### Hot Fixes & Enhancements: +- Increased SLKTextView's (and therefore its subclasses') influence on its own height By @lukkas + ## [Version 1.9.6](https://github.com/slackhq/SlackTextViewController/releases/tag/v1.9.6) This release includes many iOS 11 and iPhone X hot fixes.