Skip to content

Commit

Permalink
Merge pull request #79 from csv8674xn/remove_unnecessary_resign_first…
Browse files Browse the repository at this point in the history
…_responder

Remove unnecessary call for resignFisrtResponder
  • Loading branch information
jmkk authored Oct 10, 2018
2 parents fad59c8 + d6a95a6 commit 85e5c6d
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions Hakawai/Core/HKWTextView+Plugins.m
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ - (void)setTopLevelViewForAccessoryViewPositioning:(UIView *)view {

- (void)dismissAutocorrectSuggestion {
[self cycleFirstResponderStatusWithMode:HKWCycleFirstResponderModeNone
cancelAnimation:YES];
cancelAnimation:YES
disableResignFirstResponder:NO];
}

- (void)overrideAutocapitalizationWith:(UITextAutocapitalizationType)override {
Expand All @@ -296,7 +297,8 @@ - (void)overrideAutocapitalizationWith:(UITextAutocapitalizationType)override {
self.overridingAutocapitalization = YES;
self.originalAutocapitalization = self.autocapitalizationType;
[self cycleFirstResponderStatusWithMode:[HKWTextView modeForAutocapitalization:override]
cancelAnimation:YES];
cancelAnimation:YES
disableResignFirstResponder:NO];
}

- (void)restoreOriginalAutocapitalization:(BOOL)shouldCycle {
Expand All @@ -305,7 +307,8 @@ - (void)restoreOriginalAutocapitalization:(BOOL)shouldCycle {
}
if (shouldCycle) {
[self cycleFirstResponderStatusWithMode:[HKWTextView modeForAutocapitalization:self.originalAutocapitalization]
cancelAnimation:YES];
cancelAnimation:YES
disableResignFirstResponder:NO];
}
else {
self.autocapitalizationType = self.originalAutocapitalization;
Expand All @@ -320,7 +323,8 @@ - (void)overrideAutocorrectionWith:(UITextAutocorrectionType)override {
self.overridingAutocorrection = YES;
self.originalAutocorrection = self.autocorrectionType;
[self cycleFirstResponderStatusWithMode:[HKWTextView modeForAutocorrection:override]
cancelAnimation:YES];
cancelAnimation:YES
disableResignFirstResponder:YES];
}

- (void)restoreOriginalAutocorrection:(BOOL)shouldCycle {
Expand All @@ -329,7 +333,8 @@ - (void)restoreOriginalAutocorrection:(BOOL)shouldCycle {
}
if (shouldCycle) {
[self cycleFirstResponderStatusWithMode:[HKWTextView modeForAutocorrection:self.originalAutocorrection]
cancelAnimation:YES];
cancelAnimation:YES
disableResignFirstResponder:YES];
}
else {
self.autocorrectionType = self.originalAutocorrection;
Expand All @@ -344,7 +349,8 @@ - (void)overrideSpellCheckingWith:(UITextSpellCheckingType)override {
self.overridingSpellChecking = YES;
self.originalSpellChecking = self.spellCheckingType;
[self cycleFirstResponderStatusWithMode:[HKWTextView modeForSpellChecking:override]
cancelAnimation:YES];
cancelAnimation:YES
disableResignFirstResponder:NO];
}

- (void)restoreOriginalSpellChecking:(BOOL)shouldCycle {
Expand All @@ -353,21 +359,28 @@ - (void)restoreOriginalSpellChecking:(BOOL)shouldCycle {
}
if (shouldCycle) {
[self cycleFirstResponderStatusWithMode:[HKWTextView modeForSpellChecking:self.originalSpellChecking]
cancelAnimation:YES];
cancelAnimation:YES
disableResignFirstResponder:NO];
}
else {
self.spellCheckingType = self.originalSpellChecking;
}
self.overridingSpellChecking = NO;
}

- (void)cycleFirstResponderStatusWithMode:(HKWCycleFirstResponderMode)mode cancelAnimation:(BOOL)cancelAnimation {
/*
disableResignFirstResponder is set to skip calling resignFirstResponder, which will result in crash with 3D touch. Not calling resignFirstResponder in general does not seem to have negative impact.
However, to limit the scope of the change and the potential impact, we will skill the call only in the code path of 3D touch crashes, which are restoreOriginalAutocorrection and overrideAutocorrectionWith.
TODO: remove disableResignFirstResponder once we have more data about its impact.
*/
- (void)cycleFirstResponderStatusWithMode:(HKWCycleFirstResponderMode)mode cancelAnimation:(BOOL)cancelAnimation disableResignFirstResponder:(BOOL)disableResignFirstResponder{
BOOL usingAbstraction = self.abstractionLayerEnabled;
if (usingAbstraction) {
[self.abstractionLayer pushIgnore];
}
self.firstResponderIsCycling = YES;
[self resignFirstResponder];
if (!disableResignFirstResponder) {
[self resignFirstResponder];
}

switch (mode) {
case HKWCycleFirstResponderModeAutocapitalizationNone:
Expand Down

0 comments on commit 85e5c6d

Please sign in to comment.