From f28abbc2a1dd8cb19b12f5c5a196b310df3571a7 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 19 Oct 2017 07:10:05 -0700 Subject: [PATCH] Revert from numeric to default keyboard after message send. // FREEBIE --- .../ConversationInputToolbar.h | 2 ++ .../ConversationInputToolbar.m | 5 +++++ .../ConversationViewController.m | 21 +++++++++---------- .../src/ViewControllers/OWSViewController.h | 2 ++ .../src/ViewControllers/OWSViewController.m | 5 +++++ 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.h b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.h index 5688f98d5..62d2ada52 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.h +++ b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.h @@ -47,6 +47,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)setMessageText:(NSString *_Nullable)value; - (void)clearTextMessage; +- (nullable NSString *)textInputPrimaryLanguage; + #pragma mark - Voice Memo - (void)showVoiceMemoUI; diff --git a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m index 0edb477c7..4fcd80c98 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m @@ -762,6 +762,11 @@ static void *kConversationInputTextViewObservingContext = &kConversationInputTex [self.attachmentView viewWillDisappear:animated]; } +- (nullable NSString *)textInputPrimaryLanguage +{ + return self.inputTextView.textInputMode.primaryLanguage; +} + #pragma mark - Logging + (NSString *)logTag diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index d123a1ead..dad3f90f1 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -1353,19 +1353,18 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { #pragma mark - JSQMessagesViewController method overrides -// TODO: We need to audit all usage of this method. - (void)toggleDefaultKeyboard { - // // Primary language is nil for the emoji keyboard & we want to stay on it after sending - // if (![self.inputToolbar.inputTextView.textInputMode primaryLanguage]) { - // return; - // } - // - // // The JSQ event listeners cause a bounce animation, so we temporarily disable them. - // [self.keyboardController endListeningForKeyboard]; - // [self dismissKeyBoard]; - // [self popKeyBoard]; - // [self.keyboardController beginListeningForKeyboard]; + // Primary language is nil for the emoji keyboard & we want to stay on it after sending + if (!self.inputToolbar.textInputPrimaryLanguage) { + return; + } + + // The JSQ event listeners cause a bounce animation, so we temporarily disable them. + [self setShouldIgnoreKeyboardChanges:YES]; + [self dismissKeyBoard]; + [self popKeyBoard]; + [self setShouldIgnoreKeyboardChanges:NO]; } #pragma mark - Dynamic Text diff --git a/Signal/src/ViewControllers/OWSViewController.h b/Signal/src/ViewControllers/OWSViewController.h index f27b04d63..f724660f2 100644 --- a/Signal/src/ViewControllers/OWSViewController.h +++ b/Signal/src/ViewControllers/OWSViewController.h @@ -15,6 +15,8 @@ NS_ASSUME_NONNULL_BEGIN // Use this method in lieu of autoPinToBottomLayoutGuideOfViewController: - (void)autoPinViewToBottomGuideOrKeyboard:(UIView *)view; +- (void)setShouldIgnoreKeyboardChanges:(BOOL)value; + @end NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/OWSViewController.m b/Signal/src/ViewControllers/OWSViewController.m index 3a0e22703..155db72f7 100644 --- a/Signal/src/ViewControllers/OWSViewController.m +++ b/Signal/src/ViewControllers/OWSViewController.m @@ -11,6 +11,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, weak) UIView *bottomLayoutView; @property (nonatomic) NSLayoutConstraint *bottomLayoutConstraint; +@property (nonatomic) BOOL shouldIgnoreKeyboardChanges; @end @@ -94,6 +95,10 @@ NS_ASSUME_NONNULL_BEGIN { OWSAssert([NSThread isMainThread]); + if (self.shouldIgnoreKeyboardChanges) { + return; + } + NSDictionary *userInfo = [notification userInfo]; NSValue *_Nullable keyboardEndFrameValue = userInfo[UIKeyboardFrameEndUserInfoKey];