Skip to content

Commit 10dc921

Browse files
author
dzenbot
committed
Stops auto-completion view from being hidden while rotating the device.
1 parent 10965c8 commit 10dc921

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

Source/Classes/SLKTextViewController.m

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -931,9 +931,7 @@ - (void)dismissTextInputbarIfNeeded
931931
self.keyboardHC.constant = 0.0;
932932
self.scrollViewHC.constant = [self appropriateScrollViewHeight];
933933

934-
if (self.isAutoCompleting) {
935-
[self hideAutoCompletionView];
936-
}
934+
[self hideAutoCompletionViewIfNeeded];
937935

938936
// Forces the keyboard status change
939937
[self updateKeyboardStatus:SLKKeyboardStatusDidHide];
@@ -1086,9 +1084,9 @@ - (void)willShowOrHideKeyboard:(NSNotification *)notification
10861084
self.keyboardHC.constant = [self appropriateKeyboardHeight:notification];
10871085
self.scrollViewHC.constant = [self appropriateScrollViewHeight];
10881086

1089-
// Hides autocompletion mode if the keyboard is being dismissed
1090-
if ((![self.textView isFirstResponder] || status == SLKKeyboardStatusWillHide) && self.isAutoCompleting) {
1091-
[self hideAutoCompletionView];
1087+
// Hides the autocompletion view if the keyboard is being dismissed
1088+
if (![self.textView isFirstResponder] || status == SLKKeyboardStatusWillHide) {
1089+
[self hideAutoCompletionViewIfNeeded];
10921090
}
10931091

10941092
// Only for this animation, we set bo to bounce since we want to give the impression that the text input is glued to the keyboard.
@@ -1300,6 +1298,10 @@ - (void)registerPrefixesForAutoCompletion:(NSArray *)prefixes
13001298

13011299
- (void)processTextForAutoCompletion
13021300
{
1301+
if (self.isRotating) {
1302+
return;
1303+
}
1304+
13031305
// Avoids text processing for autocompletion if the registered prefix list is empty.
13041306
if (self.registeredPrefixes.count == 0) {
13051307
return;
@@ -1385,9 +1387,7 @@ - (void)cancelAutoCompletion
13851387

13861388
[self.autoCompletionView setContentOffset:CGPointZero];
13871389

1388-
if (self.isAutoCompleting) {
1389-
[self showAutoCompletionView:NO];
1390-
}
1390+
[self hideAutoCompletionViewIfNeeded];
13911391
}
13921392

13931393
- (void)acceptAutoCompletionWithString:(NSString *)string
@@ -1408,13 +1408,20 @@ - (void)acceptAutoCompletionWithString:(NSString *)string
14081408
[textView slk_scrollToCaretPositonAnimated:NO];
14091409
}
14101410

1411-
- (void)hideAutoCompletionView
1411+
- (void)hideAutoCompletionViewIfNeeded
14121412
{
1413-
[self showAutoCompletionView:NO];
1413+
if (self.isAutoCompleting) {
1414+
[self showAutoCompletionView:NO];
1415+
}
14141416
}
14151417

14161418
- (void)showAutoCompletionView:(BOOL)show
14171419
{
1420+
// Skips if rotating
1421+
if (self.isRotating) {
1422+
return;
1423+
}
1424+
14181425
CGFloat viewHeight = show ? [self heightForAutoCompletionView] : 0.0;
14191426

14201427
if (self.autoCompletionViewHC.constant == viewHeight) {
@@ -1806,7 +1813,10 @@ - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrie
18061813

18071814
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
18081815
{
1809-
self.rotating = NO;
1816+
// Delays the rotation flag
1817+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
1818+
self.rotating = NO;
1819+
});
18101820
}
18111821

18121822
- (NSUInteger)supportedInterfaceOrientations

0 commit comments

Comments
 (0)