diff --git a/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalInputAccessoryView.swift b/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalInputAccessoryView.swift index b983274e2..3f9907d86 100644 --- a/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalInputAccessoryView.swift +++ b/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalInputAccessoryView.swift @@ -101,11 +101,7 @@ class AttachmentApprovalInputAccessoryView: UIView { // MARK: - public var shouldHideControls = false { - didSet { - updateContents() - } - } + private var shouldHideControls = false private func updateContents() { var hasCurrentCaption = false @@ -135,6 +131,10 @@ class AttachmentApprovalInputAccessoryView: UIView { if !attachmentCaptionToolbar.textView.isFirstResponder { attachmentCaptionToolbar.textView.becomeFirstResponder() } + } else { + if attachmentCaptionToolbar.textView.isFirstResponder { + attachmentCaptionToolbar.textView.resignFirstResponder() + } } // NOTE: We don't automatically make attachmentTextToolbar.textView // first responder; @@ -143,9 +143,18 @@ class AttachmentApprovalInputAccessoryView: UIView { } public func update(isEditingCaptions: Bool, - currentAttachmentItem: SignalAttachmentItem?) { + currentAttachmentItem: SignalAttachmentItem?, + shouldHideControls: Bool) { + // De-bounce + guard self.isEditingCaptions != isEditingCaptions || + self.currentAttachmentItem != currentAttachmentItem || + self.shouldHideControls != shouldHideControls else { + return + } + self.isEditingCaptions = isEditingCaptions self.currentAttachmentItem = currentAttachmentItem + self.shouldHideControls = shouldHideControls updateContents() } diff --git a/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalViewController.swift b/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalViewController.swift index cba9ceffa..569ca847a 100644 --- a/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalViewController.swift +++ b/SignalMessaging/ViewControllers/AttachmentApproval/AttachmentApprovalViewController.swift @@ -184,7 +184,6 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC private func updateContents() { updateNavigationBar() updateInputAccessory() - updateControlVisibility() touchInterceptorView.isHidden = !isEditingCaptions } @@ -206,7 +205,10 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC currentPageViewController = pageViewControllers.first } let currentAttachmentItem: SignalAttachmentItem? = currentPageViewController?.attachmentItem - bottomToolView.update(isEditingCaptions: isEditingCaptions, currentAttachmentItem: currentAttachmentItem) + + bottomToolView.update(isEditingCaptions: isEditingCaptions, + currentAttachmentItem: currentAttachmentItem, + shouldHideControls: shouldHideControls) } // MARK: - Navigation Bar @@ -327,15 +329,6 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC return pageViewController.shouldHideControls } - private func updateControlVisibility() { - let hasPresentedView = self.presentedViewController != nil - - if !shouldHideControls, !isFirstResponder, !hasPresentedView { - becomeFirstResponder() - } - bottomToolView.shouldHideControls = shouldHideControls - } - // MARK: - View Helpers func remove(attachmentItem: SignalAttachmentItem) { @@ -411,8 +404,6 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC updateMediaRail() } } - - updateContents() } // MARK: - UIPageViewControllerDataSource @@ -463,6 +454,18 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC return super.viewControllers!.map { $0 as! AttachmentPrepViewController } } + @objc + public override func setViewControllers(_ viewControllers: [UIViewController]?, direction: UIPageViewController.NavigationDirection, animated: Bool, completion: ((Bool) -> Void)? = nil) { + super.setViewControllers(viewControllers, + direction: direction, + animated: animated) { [weak self] (finished) in + if let completion = completion { + completion(finished) + } + self?.updateContents() + } + } + var currentItem: SignalAttachmentItem! { get { return currentPageViewController.attachmentItem @@ -682,7 +685,7 @@ extension AttachmentApprovalViewController: AttachmentPrepViewControllerDelegate } func prepViewControllerUpdateControls() { - updateControlVisibility() + updateInputAccessory() } }