Skip to content

Commit 919e57b

Browse files
author
Ignacio Romero Zurbuchen
committed
Merge pull request slackhq#390 from slackhq/textbar-dismissal-public
Make dismissTextInputBar method public
2 parents eff7d4a + b75e113 commit 919e57b

File tree

2 files changed

+37
-15
lines changed

2 files changed

+37
-15
lines changed

Source/SLKTextViewController.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,16 @@ NS_CLASS_AVAILABLE_IOS(7_0) @interface SLKTextViewController : UIViewController
208208
*/
209209
- (void)dismissKeyboard:(BOOL)animated;
210210

211+
/**
212+
Dismisses the text input bar, if not already
213+
214+
The recommended method to use is forceTextInputbarAdjustmentForResponder:
215+
Only if that doesn't dismiss the textInputBar should this be used.
216+
217+
@param animated YES if the textInputBar should be dismissed using an animation.
218+
*/
219+
- (void)dismissTextInputbar:(BOOL)animated;
220+
211221
/**
212222
Verifies if the text input bar should still move up/down even if it is not first responder. Default is NO.
213223
You can override this method to perform additional tasks associated with presenting the view.

Source/SLKTextViewController.m

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,32 @@ - (void)setTextInputbarHidden:(BOOL)hidden animated:(BOOL)animated
892892
}
893893
}
894894

895+
- (void)dismissTextInputbar:(BOOL)animated
896+
{
897+
if (self.keyboardHC.constant == 0) {
898+
return;
899+
}
900+
901+
__weak typeof(self) weakSelf = self;
902+
903+
[self slk_hideAutoCompletionViewIfNeeded];
904+
905+
void (^animations)() = ^void(){
906+
907+
weakSelf.keyboardHC.constant = 0.0;
908+
weakSelf.scrollViewHC.constant = [weakSelf slk_appropriateScrollViewHeight];
909+
910+
[weakSelf.view layoutIfNeeded];
911+
};
912+
913+
if (animated) {
914+
[UIView animateWithDuration:0.25 animations:animations completion:nil];
915+
}
916+
else {
917+
animations();
918+
}
919+
}
920+
895921

896922
#pragma mark - Private Methods
897923

@@ -1160,20 +1186,6 @@ - (void)slk_enableTypingSuggestionIfNeeded
11601186
[self.textView setTypingSuggestionEnabled:enable];
11611187
}
11621188

1163-
- (void)slk_dismissTextInputbarIfNeeded
1164-
{
1165-
if (self.keyboardHC.constant == 0) {
1166-
return;
1167-
}
1168-
1169-
self.keyboardHC.constant = 0.0;
1170-
self.scrollViewHC.constant = [self slk_appropriateScrollViewHeight];
1171-
1172-
[self slk_hideAutoCompletionViewIfNeeded];
1173-
1174-
[self.view layoutIfNeeded];
1175-
}
1176-
11771189
- (void)slk_detectKeyboardStatesInNotification:(NSNotification *)notification
11781190
{
11791191
// Tear down
@@ -1343,7 +1355,7 @@ - (void)slk_willShowOrHideKeyboard:(NSNotification *)notification
13431355
return;
13441356
}
13451357
else if (![self forceTextInputbarAdjustmentForResponder:currentResponder]) {
1346-
return [self slk_dismissTextInputbarIfNeeded];
1358+
return [self dismissTextInputbar:NO];
13471359
}
13481360
}
13491361

0 commit comments

Comments
 (0)