Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 47aba94

Browse files
author
dzenbot
committed
Refactors the QuickType bar detection and implementation for disabling it on auto-completion.
1 parent c19236b commit 47aba94

3 files changed

Lines changed: 22 additions & 116 deletions

File tree

Source/Additions/SLKUIConstants.h

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@
2626
#define SLK_INPUT_ACCESSORY_DEBUG 0 // Renders a translucent red area representing the keyboard accessory view
2727
#define SLK_KEYBOARD_NOTIFICATION_DEBUG 0 // Logs every keyboard notification being sent
2828

29-
typedef NS_ENUM(NSUInteger, SLKQuicktypeBarMode) {
30-
SLKQuicktypeBarModeHidden,
31-
SLKQuicktypeBarModeCollapsed,
32-
SLKQuicktypeBarModeExpanded,
33-
};
34-
3529
inline static CGFloat minimumKeyboardHeight()
3630
{
3731
if (UI_IS_IPAD) {
@@ -48,61 +42,6 @@ inline static CGFloat minimumKeyboardHeight()
4842
}
4943
}
5044

51-
inline static CGFloat SLKQuicktypeBarHeightForMode(SLKQuicktypeBarMode mode)
52-
{
53-
if (UI_IS_IPAD) {
54-
switch (mode) {
55-
case SLKQuicktypeBarModeHidden:
56-
return 0.f;
57-
58-
case SLKQuicktypeBarModeCollapsed:
59-
return 10.f;
60-
61-
case SLKQuicktypeBarModeExpanded :
62-
return 39.f;
63-
}
64-
}
65-
if (UI_IS_IPHONE6PLUS) {
66-
switch (mode) {
67-
case SLKQuicktypeBarModeHidden:
68-
return 0.f;
69-
70-
case SLKQuicktypeBarModeCollapsed:
71-
return 9.f;
72-
73-
case SLKQuicktypeBarModeExpanded :
74-
if (UI_IS_LANDSCAPE) return 32.f;
75-
else return 45.f;
76-
}
77-
}
78-
else {
79-
switch (mode) {
80-
case SLKQuicktypeBarModeHidden:
81-
return 0.f;
82-
83-
case SLKQuicktypeBarModeCollapsed:
84-
return 8.f;
85-
86-
case SLKQuicktypeBarModeExpanded :
87-
if (UI_IS_LANDSCAPE) return 31.f;
88-
else return 37.f;
89-
}
90-
}
91-
}
92-
93-
inline static SLKQuicktypeBarMode SLKQuicktypeBarModeForHeight(CGFloat height)
94-
{
95-
if (height > 0.f && height <= 10.f) {
96-
return SLKQuicktypeBarModeCollapsed;
97-
}
98-
99-
if (height > 10.f && height <= 45.f) {
100-
return SLKQuicktypeBarModeExpanded ;
101-
}
102-
103-
return SLKQuicktypeBarModeHidden;
104-
}
105-
10645
inline static CGRect SLKRectInvert(CGRect rect)
10746
{
10847
CGRect invert = CGRectZero;

Source/Classes/SLKTextViewController.m

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,16 @@ - (BOOL)isPresentedInPopover
309309
return _presentedInPopover && UI_IS_IPAD;
310310
}
311311

312+
- (BOOL)isQuickTypeBarVisible
313+
{
314+
CGFloat quickTypeBarHeight = self.keyboardHC.constant-minimumKeyboardHeight();
315+
316+
if (UI_IS_IOS8_AND_HIGHER && quickTypeBarHeight > 0.0 && self.textView.autocorrectionType != UITextAutocorrectionTypeNo) {
317+
return YES;
318+
}
319+
return NO;
320+
}
321+
312322
- (SLKTextView *)textView
313323
{
314324
return self.textInputbar.textView;
@@ -532,14 +542,6 @@ - (void)setAutoCompleting:(BOOL)autoCompleting
532542
_autoCompleting = autoCompleting;
533543

534544
self.scrollViewProxy.scrollEnabled = !autoCompleting;
535-
536-
if (UI_IS_IOS8_AND_HIGHER) {
537-
// Updates the iOS8 QuickType bar mode based on the keyboard height constant
538-
CGFloat quicktypeBarHeight = self.keyboardHC.constant-minimumKeyboardHeight();
539-
540-
// Updates the QuickType bar mode based on the keyboard height constant
541-
self.quicktypeBarMode = SLKQuicktypeBarModeForHeight(quicktypeBarHeight);
542-
}
543545
}
544546

545547
- (void)setInverted:(BOOL)inverted
@@ -636,6 +638,11 @@ - (void)textWillUpdate
636638

637639
- (void)textDidUpdate:(BOOL)animated
638640
{
641+
// Disables animation if not first responder
642+
if (![self.textView isFirstResponder]) {
643+
animated = NO;
644+
}
645+
639646
self.textInputbar.rightButton.enabled = [self canPressRightButton];
640647
self.textInputbar.editortRightButton.enabled = [self canPressRightButton];
641648

@@ -872,8 +879,7 @@ - (void)scrollToBottomIfNeeded
872879

873880
- (void)enableTypingSuggestionIfNeeded
874881
{
875-
// Skips if the QuickType Bar is minimised
876-
if (self.quicktypeBarMode == SLKQuicktypeBarModeCollapsed) {
882+
if (![self.textView isFirstResponder]) {
877883
return;
878884
}
879885

@@ -883,8 +889,12 @@ - (void)enableTypingSuggestionIfNeeded
883889
enable = NO;
884890
}
885891

886-
// On iOS8, when the predictive mode is enabled, the QuicktypeBar is hidden
887-
// On iOS7, it should always disable auto-correction and spell checking if autocompletion is enabled.
892+
// Skips if the QuickType Bar isn't visible and it's trying to disable it. And the inverted logic.
893+
if (UI_IS_IOS8_AND_HIGHER && ((enable == NO && !self.isQuickTypeBarVisible) || (enable == YES && self.isQuickTypeBarVisible))) {
894+
return;
895+
}
896+
897+
// During text autocompletion, the iOS 8 QuickType bar is hidden and auto-correction and spell checking are disabled.
888898
[self.textView setTypingSuggestionEnabled:enable];
889899
}
890900

Source/Docs/UIKeyboard_constants.txt

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)