From 61758dcf051c7a9ef0244271e62e1cd27e90607a Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 27 Nov 2018 14:55:46 -0700 Subject: [PATCH] Only show caption for multiple images --- .../AttachmentApprovalViewController.swift | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/SignalMessaging/ViewControllers/AttachmentApprovalViewController.swift b/SignalMessaging/ViewControllers/AttachmentApprovalViewController.swift index ad65eacce..c4da32637 100644 --- a/SignalMessaging/ViewControllers/AttachmentApprovalViewController.swift +++ b/SignalMessaging/ViewControllers/AttachmentApprovalViewController.swift @@ -254,6 +254,8 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC return } navigationBar.overrideTheme(type: .clear) + + updateCaptionVisibility() } override public func viewDidAppear(_ animated: Bool) { @@ -405,6 +407,12 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC return pagerScrollView }() + func updateCaptionVisibility() { + for pageViewController in pageViewControllers { + pageViewController.updateCaptionVisibility(attachmentCount: attachments.count) + } + } + // MARK: - UIPageViewControllerDelegate public func pageViewController(_ pageViewController: UIPageViewController, willTransitionTo pendingViewControllers: [UIViewController]) { @@ -511,6 +519,7 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC Logger.debug("cache miss.") let viewController = AttachmentPrepViewController(attachmentItem: item) viewController.prepDelegate = self + viewController.updateCaptionVisibility(attachmentCount: attachments.count) cachedPages[item] = viewController return viewController @@ -780,6 +789,22 @@ public class AttachmentPrepViewController: OWSViewController, PlayerProgressBarD fatalError("init(coder:) has not been implemented") } + func updateCaptionVisibility(attachmentCount: Int) { + if attachmentCount > 1 { + captionView.isHidden = false + } + + // If we previously had multiple attachments, we'd have shown the caption fields. + // + // Subsequently, if the user had added caption text, then removed the other attachments + // we will continue to show this caption field, so as not to hide any already-entered text. + if let captionText = captionView.captionText, captionText.count > 0 { + captionView.isHidden = false + } + + captionView.isHidden = true + } + // MARK: - Subviews lazy var captionView: CaptionView = {