From a3efb58d15f2dd6cadf1a901a1dc1b0068a6dd37 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 28 Mar 2019 18:29:19 -0400 Subject: [PATCH] Respond to CR. --- .../AttachmentApprovalInputAccessoryView.swift | 18 +++++++++++++++--- .../AttachmentApprovalViewController.swift | 6 ++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalInputAccessoryView.swift b/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalInputAccessoryView.swift index 3f9907d86..eadc0afda 100644 --- a/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalInputAccessoryView.swift +++ b/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalInputAccessoryView.swift @@ -120,6 +120,12 @@ class AttachmentApprovalInputAccessoryView: UIView { currentCaptionWrapper.isHidden = isEditingCaptions || !hasCurrentCaption attachmentTextToolbar.isHidden = isEditingCaptions + updateFirstResponder() + + layoutSubviews() + } + + private func updateFirstResponder() { if (shouldHideControls) { if attachmentCaptionToolbar.textView.isFirstResponder { attachmentCaptionToolbar.textView.resignFirstResponder() @@ -138,8 +144,6 @@ class AttachmentApprovalInputAccessoryView: UIView { } // NOTE: We don't automatically make attachmentTextToolbar.textView // first responder; - - layoutSubviews() } public func update(isEditingCaptions: Bool, @@ -149,7 +153,9 @@ class AttachmentApprovalInputAccessoryView: UIView { guard self.isEditingCaptions != isEditingCaptions || self.currentAttachmentItem != currentAttachmentItem || self.shouldHideControls != shouldHideControls else { - return + + updateFirstResponder() + return } self.isEditingCaptions = isEditingCaptions @@ -168,6 +174,12 @@ class AttachmentApprovalInputAccessoryView: UIView { return CGSize.zero } } + + public var hasFirstResponder: Bool { + return (isFirstResponder || + attachmentCaptionToolbar.textView.isFirstResponder || + attachmentTextToolbar.textView.isFirstResponder) + } } // MARK: - diff --git a/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalViewController.swift b/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalViewController.swift index 569ca847a..dc837b294 100644 --- a/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalViewController.swift +++ b/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalViewController.swift @@ -206,6 +206,12 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC } let currentAttachmentItem: SignalAttachmentItem? = currentPageViewController?.attachmentItem + let hasPresentedView = self.presentedViewController != nil + let isToolbarFirstResponder = bottomToolView.hasFirstResponder + if !shouldHideControls, !isFirstResponder, !hasPresentedView, !isToolbarFirstResponder { + becomeFirstResponder() + } + bottomToolView.update(isEditingCaptions: isEditingCaptions, currentAttachmentItem: currentAttachmentItem, shouldHideControls: shouldHideControls)