Skip to content
This repository was archived by the owner on Oct 30, 2018. It is now read-only.

Increase SLKTextView's influence over calculating its height. #653

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
21 changes: 4 additions & 17 deletions Source/SLKTextInputbar.m
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,10 @@ - (CGFloat)appropriateHeight

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];
} else {
height = self.textView.appropriateHeight;
height += self.contentInset.top;
height += self.slk_bottomMargin;
}

if (height < minimumHeight) {
Expand All @@ -344,17 +342,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;
Expand Down
3 changes: 3 additions & 0 deletions Source/SLKTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions Source/SLKTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down