Skip to content

Commit 653fda7

Browse files
author
ignacio
committed
Moves implementation back to SLKTextInputbar
1 parent 6a604db commit 653fda7

File tree

3 files changed

+73
-68
lines changed

3 files changed

+73
-68
lines changed

Source/Classes/SLKTextInputbar.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ typedef NS_ENUM(NSUInteger, SLKCounterPosition) {
5757
/** The inner padding to use when laying out content in the view. Default is {5, 8, 5, 8}. */
5858
@property (nonatomic, assign) UIEdgeInsets contentInset;
5959

60+
/** The minimum height based on the intrinsic content size's. */
61+
@property (nonatomic, readonly) CGFloat minimumInputbarHeight;
62+
63+
/** The most appropriate height calculated based on the amount of lines of text and other factors. */
64+
@property (nonatomic, readonly) CGFloat appropriateHeight;
65+
6066

6167
#pragma mark - Initialization
6268
///------------------------------------------------

Source/Classes/SLKTextInputbar.m

Lines changed: 64 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -242,17 +242,66 @@ - (UILabel *)charCountLabel
242242
return _charCountLabel;
243243
}
244244

245-
- (NSUInteger)slk_defaultNumberOfLines
245+
- (BOOL)isViewVisible
246246
{
247-
if (SLK_IS_IPAD) {
248-
return 8;
247+
SEL selector = NSSelectorFromString(@"isViewVisible");
248+
249+
if ([self.controller respondsToSelector:selector]) {
250+
251+
#pragma clang diagnostic push
252+
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
253+
BOOL visible = (BOOL)[self.controller performSelector:selector];
254+
#pragma clang diagnostic pop
255+
256+
return visible;
249257
}
250-
if (SLK_IS_IPHONE4) {
251-
return 4;
258+
return NO;
259+
}
260+
261+
- (CGFloat)minimumInputbarHeight
262+
{
263+
return self.intrinsicContentSize.height;
264+
}
265+
266+
- (CGFloat)appropriateHeight
267+
{
268+
CGFloat height = 0.0;
269+
CGFloat minimumHeight = [self minimumInputbarHeight];
270+
271+
if (self.textView.numberOfLines == 1) {
272+
height = minimumHeight;
273+
}
274+
else if (self.textView.numberOfLines < self.textView.maxNumberOfLines) {
275+
height = [self slk_inputBarHeightForLines:self.textView.numberOfLines];
252276
}
253277
else {
254-
return 6;
278+
height = [self slk_inputBarHeightForLines:self.textView.maxNumberOfLines];
279+
}
280+
281+
if (height < minimumHeight) {
282+
height = minimumHeight;
283+
}
284+
285+
if (self.isEditing) {
286+
height += self.editorContentViewHeight;
255287
}
288+
289+
return roundf(height);
290+
}
291+
292+
- (CGFloat)slk_deltaInputbarHeight
293+
{
294+
return self.textView.intrinsicContentSize.height-self.textView.font.lineHeight;
295+
}
296+
297+
- (CGFloat)slk_inputBarHeightForLines:(NSUInteger)numberOfLines
298+
{
299+
CGFloat height = [self slk_deltaInputbarHeight];
300+
301+
height += roundf(self.textView.font.lineHeight*numberOfLines);
302+
height += self.contentInset.top+self.contentInset.bottom;
303+
304+
return height;
256305
}
257306

258307
- (BOOL)limitExceeded
@@ -285,24 +334,20 @@ - (CGFloat)slk_appropriateRightButtonMargin
285334
return 0.0;
286335
}
287336
}
288-
289337
return self.contentInset.right;
290338
}
291339

292-
- (BOOL)isViewVisible
340+
- (NSUInteger)slk_defaultNumberOfLines
293341
{
294-
SEL selector = NSSelectorFromString(@"isViewVisible");
295-
296-
if ([self.controller respondsToSelector:selector]) {
297-
298-
#pragma clang diagnostic push
299-
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
300-
BOOL visible = (BOOL)[self.controller performSelector:selector];
301-
#pragma clang diagnostic pop
302-
303-
return visible;
342+
if (SLK_IS_IPAD) {
343+
return 8;
344+
}
345+
if (SLK_IS_IPHONE4) {
346+
return 4;
347+
}
348+
else {
349+
return 6;
304350
}
305-
return NO;
306351
}
307352

308353

Source/Classes/SLKTextViewController.m

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -381,52 +381,6 @@ - (UIModalPresentationStyle)modalPresentationStyle
381381
return [super modalPresentationStyle];
382382
}
383383

384-
- (CGFloat)slk_deltaInputbarHeight
385-
{
386-
return self.textView.intrinsicContentSize.height-self.textView.font.lineHeight;
387-
}
388-
389-
- (CGFloat)slk_minimumInputbarHeight
390-
{
391-
return self.textInputbar.intrinsicContentSize.height;
392-
}
393-
394-
- (CGFloat)slk_inputBarHeightForLines:(NSUInteger)numberOfLines
395-
{
396-
CGFloat height = [self slk_deltaInputbarHeight];
397-
398-
height += roundf(self.textView.font.lineHeight*numberOfLines);
399-
height += self.textInputbar.contentInset.top+self.textInputbar.contentInset.bottom;
400-
401-
return height;
402-
}
403-
404-
- (CGFloat)slk_appropriateInputbarHeight
405-
{
406-
CGFloat height = 0.0;
407-
CGFloat minimumHeight = [self slk_minimumInputbarHeight];
408-
409-
if (self.textView.numberOfLines == 1) {
410-
height = minimumHeight;
411-
}
412-
else if (self.textView.numberOfLines < self.textView.maxNumberOfLines) {
413-
height = [self slk_inputBarHeightForLines:self.textView.numberOfLines];
414-
}
415-
else {
416-
height = [self slk_inputBarHeightForLines:self.textView.maxNumberOfLines];
417-
}
418-
419-
if (height < minimumHeight) {
420-
height = minimumHeight;
421-
}
422-
423-
if (self.textInputbar.isEditing) {
424-
height += self.textInputbar.editorContentViewHeight;
425-
}
426-
427-
return roundf(height);
428-
}
429-
430384
- (CGFloat)slk_appropriateKeyboardHeight:(NSNotification *)notification
431385
{
432386
CGFloat keyboardHeight = 0.0;
@@ -724,11 +678,11 @@ - (void)textWillUpdate
724678

725679
- (void)textDidUpdate:(BOOL)animated
726680
{
681+
CGFloat inputbarHeight = self.textInputbar.appropriateHeight;
682+
727683
self.textInputbar.rightButton.enabled = [self canPressRightButton];
728684
self.textInputbar.editortRightButton.enabled = [self canPressRightButton];
729685

730-
CGFloat inputbarHeight = [self slk_appropriateInputbarHeight];
731-
732686
if (inputbarHeight != self.textInputbarHC.constant)
733687
{
734688
self.textInputbarHC.constant = inputbarHeight;
@@ -1876,7 +1830,7 @@ - (void)slk_setupViewConstraints
18761830
self.textInputbarHC = [self.view slk_constraintForAttribute:NSLayoutAttributeHeight firstItem:self.textInputbar secondItem:nil];
18771831
self.keyboardHC = [self.view slk_constraintForAttribute:NSLayoutAttributeBottom firstItem:self.view secondItem:self.textInputbar];
18781832

1879-
self.textInputbarHC.constant = [self slk_minimumInputbarHeight];
1833+
self.textInputbarHC.constant = self.textInputbar.minimumInputbarHeight;
18801834
self.scrollViewHC.constant = [self slk_appropriateScrollViewHeight];
18811835

18821836
if (self.textInputbar.isEditing) {

0 commit comments

Comments
 (0)