From 74019b2ae49118bd9ab93c5d5d13783fbb9c8562 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Mon, 8 Jan 2018 17:48:26 -0500 Subject: [PATCH] Fix keyboard animation glitch after sending // FREEBIE --- .../ConversationInputToolbar.h | 5 ++-- .../ConversationInputToolbar.m | 25 +++++++++++++++---- .../ConversationViewController.m | 15 ++--------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.h b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.h index 802d31d02..3f7ee27b8 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.h +++ b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // NS_ASSUME_NONNULL_BEGIN @@ -48,8 +48,7 @@ NS_ASSUME_NONNULL_BEGIN - (NSString *)messageText; - (void)setMessageText:(NSString *_Nullable)value; - (void)clearTextMessage; - -- (nullable NSString *)textInputPrimaryLanguage; +- (void)toggleDefaultKeyboard; - (void)updateFontSizes; diff --git a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m index c5ddb7be1..baa9d95c8 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m @@ -199,6 +199,26 @@ static const CGFloat ConversationInputToolbarBorderViewHeight = 0.5; [self.inputTextView.undoManager removeAllActions]; } +- (void)toggleDefaultKeyboard +{ + // Primary language is nil for the emoji keyboard. + if (!self.inputTextView.textInputMode.primaryLanguage) { + // Stay on emoji keyboard after sending + return; + } + + // Otherwise, we want to toggle back to default keyboard if the user had the numeric keyboard present. + + // Momentarily switch to a non-default keyboard, else reloadInputViews + // will not affect the displayed keyboard. In practice this isn't perceptable to the user. + // The alternative would be to dismiss-and-pop the keyboard, but that can cause a more pronounced animation. + self.inputTextView.keyboardType = UIKeyboardTypeNumbersAndPunctuation; + [self.inputTextView reloadInputViews]; + + self.inputTextView.keyboardType = UIKeyboardTypeDefault; + [self.inputTextView reloadInputViews]; +} + - (void)setShouldShowVoiceMemoButton:(BOOL)shouldShowVoiceMemoButton { if (_shouldShowVoiceMemoButton == shouldShowVoiceMemoButton) { @@ -827,11 +847,6 @@ static const CGFloat ConversationInputToolbarBorderViewHeight = 0.5; [self.attachmentView viewWillDisappear:animated]; } -- (nullable NSString *)textInputPrimaryLanguage -{ - return self.inputTextView.textInputMode.primaryLanguage; -} - @end NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index a7d1a071f..4e9aa5d53 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -1394,17 +1394,6 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { #pragma mark - JSQMessagesViewController method overrides -- (void)toggleDefaultKeyboard -{ - // Primary language is nil for the emoji keyboard & we want to stay on it after sending - if (!self.inputToolbar.textInputPrimaryLanguage) { - return; - } - - [self dismissKeyBoard]; - [self popKeyBoard]; -} - #pragma mark - Dynamic Text /** @@ -3902,10 +3891,10 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { [self messageWasSent:message]; if (updateKeyboardState) { - [self toggleDefaultKeyboard]; + [self.inputToolbar toggleDefaultKeyboard]; } - [self clearDraft]; [self.inputToolbar clearTextMessage]; + [self clearDraft]; if (didAddToProfileWhitelist) { [self ensureDynamicInteractions]; }