From d09524c3f8055d998672567b554d402c219b99a7 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 23 Dec 2020 15:20:12 -0300 Subject: [PATCH 1/2] Update CVC contentInset after keyboard presentation/dismissal. --- .../ConversationViewController+BottomBar.swift | 13 +++++++++++-- .../AttachmentApprovalViewController.swift | 8 ++++++++ .../TextApprovalViewController.swift | 8 ++++++++ .../Views/InputAccessoryViewPlaceholder.swift | 12 +++++++++--- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController+BottomBar.swift b/Signal/src/ViewControllers/ConversationView/ConversationViewController+BottomBar.swift index 3121020951..35cb8b409d 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController+BottomBar.swift +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController+BottomBar.swift @@ -187,11 +187,20 @@ public extension ConversationViewController { } } - bottomBarBottomConstraint?.constant = -inputAccessoryPlaceholder.keyboardOverlap + guard let bottomBarBottomConstraint = bottomBarBottomConstraint, + let bottomBarSuperview = bottomBar.superview else { + return + } + let bottomBarPosition = -inputAccessoryPlaceholder.keyboardOverlap + let didChange = bottomBarBottomConstraint.constant != bottomBarPosition + guard didChange else { + return + } + bottomBarBottomConstraint.constant = bottomBarPosition // We always want to apply the new bottom bar position immediately, // as this only happens during animations (interactive or otherwise) - bottomBar.superview?.layoutIfNeeded() + bottomBarSuperview.layoutIfNeeded() } @objc diff --git a/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalViewController.swift b/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalViewController.swift index de92b1ff78..c6a7f47702 100644 --- a/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalViewController.swift +++ b/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalViewController.swift @@ -1033,10 +1033,18 @@ extension AttachmentApprovalViewController: InputAccessoryViewPlaceholderDelegat handleKeyboardStateChange(animationDuration: animationDuration, animationCurve: animationCurve) } + func inputAccessoryPlaceholderKeyboardDidPresent() { + updateBottomToolViewPosition() + } + func inputAccessoryPlaceholderKeyboardIsDismissing(animationDuration: TimeInterval, animationCurve: UIView.AnimationCurve) { handleKeyboardStateChange(animationDuration: animationDuration, animationCurve: animationCurve) } + func inputAccessoryPlaceholderKeyboardDidDismiss() { + updateBottomToolViewPosition() + } + func inputAccessoryPlaceholderKeyboardIsDismissingInteractively() { updateBottomToolViewPosition() } diff --git a/SignalMessaging/ViewControllers/TextApprovalViewController.swift b/SignalMessaging/ViewControllers/TextApprovalViewController.swift index 760a3064ab..6204e53ecb 100644 --- a/SignalMessaging/ViewControllers/TextApprovalViewController.swift +++ b/SignalMessaging/ViewControllers/TextApprovalViewController.swift @@ -239,10 +239,18 @@ extension TextApprovalViewController: InputAccessoryViewPlaceholderDelegate { handleKeyboardStateChange(animationDuration: animationDuration, animationCurve: animationCurve) } + func inputAccessoryPlaceholderKeyboardDidPresent() { + updateFooterViewPosition() + } + func inputAccessoryPlaceholderKeyboardIsDismissing(animationDuration: TimeInterval, animationCurve: UIView.AnimationCurve) { handleKeyboardStateChange(animationDuration: animationDuration, animationCurve: animationCurve) } + func inputAccessoryPlaceholderKeyboardDidDismiss() { + updateFooterViewPosition() + } + func inputAccessoryPlaceholderKeyboardIsDismissingInteractively() { updateFooterViewPosition() } diff --git a/SignalMessaging/Views/InputAccessoryViewPlaceholder.swift b/SignalMessaging/Views/InputAccessoryViewPlaceholder.swift index d220fa25b9..9dd6e12458 100644 --- a/SignalMessaging/Views/InputAccessoryViewPlaceholder.swift +++ b/SignalMessaging/Views/InputAccessoryViewPlaceholder.swift @@ -7,7 +7,9 @@ import Foundation @objc protocol InputAccessoryViewPlaceholderDelegate: class { func inputAccessoryPlaceholderKeyboardIsPresenting(animationDuration: TimeInterval, animationCurve: UIView.AnimationCurve) + func inputAccessoryPlaceholderKeyboardDidPresent() func inputAccessoryPlaceholderKeyboardIsDismissing(animationDuration: TimeInterval, animationCurve: UIView.AnimationCurve) + func inputAccessoryPlaceholderKeyboardDidDismiss() func inputAccessoryPlaceholderKeyboardIsDismissingInteractively() } @@ -75,9 +77,11 @@ public class InputAccessoryViewPlaceholder: UIView { set { guard newValue != desiredHeight else { return } heightConstraint.constant = newValue - heightConstraintView.layoutIfNeeded() - self.layoutIfNeeded() - superview?.layoutIfNeeded() + UIView.performWithoutAnimation { + heightConstraintView.layoutIfNeeded() + self.layoutIfNeeded() + superview?.layoutIfNeeded() + } } get { return heightConstraint.constant @@ -215,6 +219,7 @@ public class InputAccessoryViewPlaceholder: UIView { @objc private func keyboardDidPresent(_ notification: Notification) { keyboardState = .presented + delegate?.inputAccessoryPlaceholderKeyboardDidPresent() } @objc @@ -234,5 +239,6 @@ public class InputAccessoryViewPlaceholder: UIView { @objc private func keyboardDidDismiss(_ notification: Notification) { keyboardState = .dismissed + delegate?.inputAccessoryPlaceholderKeyboardDidDismiss() } } From 460f7dc2012a8738f6ec1457ea05813884a8d138 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 23 Dec 2020 15:49:05 -0300 Subject: [PATCH 2/2] Update CVC contentInset after keyboard presentation/dismissal. --- .../ConversationView/ConversationViewController.m | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index b85a5dd8af..9ff0c978fe 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -3934,12 +3934,24 @@ typedef enum : NSUInteger { [self handleKeyboardStateChange:animationDuration animationCurve:animationCurve]; } +- (void)inputAccessoryPlaceholderKeyboardDidDismiss +{ + [self updateBottomBarPosition]; + [self updateContentInsetsAnimated:NO]; +} + - (void)inputAccessoryPlaceholderKeyboardIsPresentingWithAnimationDuration:(NSTimeInterval)animationDuration animationCurve:(UIViewAnimationCurve)animationCurve { [self handleKeyboardStateChange:animationDuration animationCurve:animationCurve]; } +- (void)inputAccessoryPlaceholderKeyboardDidPresent +{ + [self updateBottomBarPosition]; + [self updateContentInsetsAnimated:NO]; +} + - (void)handleKeyboardStateChange:(NSTimeInterval)animationDuration animationCurve:(UIViewAnimationCurve)animationCurve { if (self.shouldAnimateKeyboardChanges && animationDuration > 0) {