From db410becb7f1eafab53465d177715bcdb2d75c16 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Sat, 13 Apr 2019 10:52:29 -0600 Subject: [PATCH] per design: "back" is retake for first photo --- .../SendMediaNavigationController.swift | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Signal/src/ViewControllers/Photos/SendMediaNavigationController.swift b/Signal/src/ViewControllers/Photos/SendMediaNavigationController.swift index 15b63dde9..e887f5034 100644 --- a/Signal/src/ViewControllers/Photos/SendMediaNavigationController.swift +++ b/Signal/src/ViewControllers/Photos/SendMediaNavigationController.swift @@ -259,6 +259,13 @@ extension SendMediaNavigationController: UINavigationControllerDelegate { owsFailDebug("unexpected navigationBar: \(navigationBar)") } } + + if viewController is PhotoCaptureViewController && !isInBatchSelectMode { + // We're either showing the captureView for the first time or the user is navigating "back" + // indicating they want to "retake". We should discard any current image. + discardCameraDraft() + } + self.updateButtons(topViewController: viewController) } @@ -305,6 +312,14 @@ extension SendMediaNavigationController: PhotoCaptureViewControllerDelegate { let dontAbandonText = NSLocalizedString("SEND_MEDIA_RETURN_TO_CAMERA", comment: "alert action when the user decides not to cancel the media flow after all.") didRequestExit(dontAbandonText: dontAbandonText) } + + func discardCameraDraft() { + assert(attachmentDraftCollection.cameraAttachments.count <= 1) + if let lastCameraAttachment = attachmentDraftCollection.cameraAttachments.last { + attachmentDraftCollection.remove(attachment: lastCameraAttachment) + } + assert(attachmentDraftCollection.cameraAttachments.count == 0) + } } extension SendMediaNavigationController: ImagePickerGridControllerDelegate { @@ -457,6 +472,17 @@ private struct AttachmentDraftCollection { } } + var cameraAttachments: [SignalAttachment] { + return attachmentDrafts.compactMap { attachmentDraft in + switch attachmentDraft.source { + case .picker: + return nil + case .camera(let cameraAttachment): + return cameraAttachment + } + } + } + mutating func append(_ element: AttachmentDraft) { attachmentDrafts.append(element) }