diff --git a/Signal/ConversationView/ConversationViewController+ConversationInputToolbarDelegate.swift b/Signal/ConversationView/ConversationViewController+ConversationInputToolbarDelegate.swift index 41a7c84cec..ff4dd40450 100644 --- a/Signal/ConversationView/ConversationViewController+ConversationInputToolbarDelegate.swift +++ b/Signal/ConversationView/ConversationViewController+ConversationInputToolbarDelegate.swift @@ -474,6 +474,7 @@ extension ConversationViewController: ConversationInputToolbarDelegate { let locationPicker = LocationPicker() locationPicker.delegate = self let navigationController = OWSNavigationController(rootViewController: locationPicker) + navigationController.presentationController?.delegate = self dismissKeyBoard() presentFormSheet(navigationController, animated: true) } @@ -600,7 +601,9 @@ fileprivate extension ConversationViewController { "CONTACT_PICKER_TITLE", comment: "navbar title for contact picker when sharing a contact" ) - self.presentFormSheet(OWSNavigationController(rootViewController: contactsPicker), animated: true) + let sheet = OWSNavigationController(rootViewController: contactsPicker) + sheet.presentationController?.delegate = self + self.presentFormSheet(sheet, animated: true) }, presentErrorFrom: self ) @@ -616,6 +619,7 @@ fileprivate extension ConversationViewController { let pickerController = UIDocumentPickerViewController(forOpeningContentTypes: [.item], asCopy: true) pickerController.delegate = self + pickerController.presentationController?.delegate = self dismissKeyBoard() presentFormSheet(pickerController, animated: true) @@ -681,6 +685,7 @@ public extension ConversationViewController { let gifModal = GifPickerNavigationViewController(initialMessageBody: inputToolbar?.messageBodyForSending) gifModal.approvalDelegate = self gifModal.approvalDataSource = self + gifModal.presentationController?.delegate = self dismissKeyBoard() present(gifModal, animated: true) } @@ -725,11 +730,19 @@ extension ConversationViewController: LocationPickerDelegate { NotificationCenter.default.post(name: ChatListViewController.clearSearch, object: nil) } } + + public func locationPickerDidCancel() { + self.dismiss(animated: true) + self.openAttachmentKeyboard() + } } // MARK: - extension ConversationViewController: UIDocumentPickerDelegate { + public func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) { + self.openAttachmentKeyboard() + } public func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) { Logger.debug("Picked document at url: \(url)") @@ -862,15 +875,9 @@ extension ConversationViewController: UIDocumentPickerDelegate { // MARK: - extension ConversationViewController: SendMediaNavDelegate { - func sendMediaNavDidCancel(_ sendMediaNavigationController: SendMediaNavigationController) { - // Restore status bar visibility (if current VC hides it) so that - // there's no visible UI updates in the presenter. - if sendMediaNavigationController.topViewController?.prefersStatusBarHidden ?? false { - sendMediaNavigationController.modalPresentationCapturesStatusBarAppearance = false - sendMediaNavigationController.setNeedsStatusBarAppearanceUpdate() - } self.dismiss(animated: true, completion: nil) + self.openAttachmentKeyboard() } func sendMediaNav(_ sendMediaNavigationController: SendMediaNavigationController, diff --git a/Signal/ConversationView/ConversationViewController+Delegates.swift b/Signal/ConversationView/ConversationViewController+Delegates.swift index 0350d0be10..6556eaa875 100644 --- a/Signal/ConversationView/ConversationViewController+Delegates.swift +++ b/Signal/ConversationView/ConversationViewController+Delegates.swift @@ -32,8 +32,9 @@ extension ConversationViewController: AttachmentApprovalViewControllerDelegate { scrollToBottomOfConversation(animated: false) } - public func attachmentApprovalDidCancel(_ attachmentApproval: AttachmentApprovalViewController) { + public func attachmentApprovalDidCancel() { dismiss(animated: true, completion: nil) + self.openAttachmentKeyboard() } public func attachmentApproval(_ attachmentApproval: AttachmentApprovalViewController, @@ -76,12 +77,31 @@ extension ConversationViewController: AttachmentApprovalViewControllerDataSource } } +extension ConversationViewController: UIAdaptivePresentationControllerDelegate { + public func presentationControllerDidDismiss(_ presentationController: UIPresentationController) { + switch presentationController.presentedViewController { + case is GifPickerNavigationViewController, is UIDocumentPickerViewController: + self.openAttachmentKeyboard() + case let navigationController as OWSNavigationController: + switch navigationController.viewControllers.first { + case is ContactPickerViewController, is LocationPicker: + self.openAttachmentKeyboard() + default: + break + } + default: + break + } + } +} + // MARK: - extension ConversationViewController: ContactPickerDelegate { public func contactPickerDidCancel(_: ContactPickerViewController) { dismiss(animated: true, completion: nil) + self.openAttachmentKeyboard() } public func contactPicker(_ contactPicker: ContactPickerViewController, didSelect systemContact: SystemContact) { diff --git a/Signal/src/ViewControllers/CameraFirstCaptureSendFlow.swift b/Signal/src/ViewControllers/CameraFirstCaptureSendFlow.swift index e2828802a1..dea4eb1beb 100644 --- a/Signal/src/ViewControllers/CameraFirstCaptureSendFlow.swift +++ b/Signal/src/ViewControllers/CameraFirstCaptureSendFlow.swift @@ -55,14 +55,7 @@ class CameraFirstCaptureSendFlow { } extension CameraFirstCaptureSendFlow: SendMediaNavDelegate { - func sendMediaNavDidCancel(_ sendMediaNavigationController: SendMediaNavigationController) { - // Restore status bar visibility (if current VC hides it) so that - // there's no visible UI updates in the presenter. - if sendMediaNavigationController.topViewController?.prefersStatusBarHidden ?? false { - sendMediaNavigationController.modalPresentationCapturesStatusBarAppearance = false - sendMediaNavigationController.setNeedsStatusBarAppearanceUpdate() - } delegate?.cameraFirstCaptureSendFlowDidCancel(self) } diff --git a/Signal/src/ViewControllers/GifPicker/GifPickerViewController.swift b/Signal/src/ViewControllers/GifPicker/GifPickerViewController.swift index 6876b16af1..454aa0765a 100644 --- a/Signal/src/ViewControllers/GifPicker/GifPickerViewController.swift +++ b/Signal/src/ViewControllers/GifPicker/GifPickerViewController.swift @@ -42,7 +42,7 @@ extension GifPickerNavigationViewController: GifPickerViewControllerDelegate { } func gifPickerDidCancel() { - dismiss(animated: true) + approvalDelegate?.attachmentApprovalDidCancel() } } @@ -54,8 +54,8 @@ extension GifPickerNavigationViewController: AttachmentApprovalViewControllerDel approvalDelegate?.attachmentApproval(attachmentApproval, didApproveAttachments: attachments, messageBody: messageBody) } - public func attachmentApprovalDidCancel(_ attachmentApproval: AttachmentApprovalViewController) { - approvalDelegate?.attachmentApprovalDidCancel(attachmentApproval) + public func attachmentApprovalDidCancel() { + approvalDelegate?.attachmentApprovalDidCancel() } public func attachmentApproval(_ attachmentApproval: AttachmentApprovalViewController, diff --git a/Signal/src/ViewControllers/LocationPicker.swift b/Signal/src/ViewControllers/LocationPicker.swift index 4dce089183..f74c9036b4 100644 --- a/Signal/src/ViewControllers/LocationPicker.swift +++ b/Signal/src/ViewControllers/LocationPicker.swift @@ -18,6 +18,7 @@ import UniformTypeIdentifiers public protocol LocationPickerDelegate: AnyObject { func didPickLocation(_ locationPicker: LocationPicker, location: Location) + func locationPickerDidCancel() } public class LocationPicker: UIViewController { @@ -85,12 +86,12 @@ public class LocationPicker: UIViewController { title = OWSLocalizedString("LOCATION_PICKER_TITLE", comment: "The title for the location picker view") - navigationItem.leftBarButtonItem = UIBarButtonItem( - image: Theme.iconImage(.buttonX), - style: .plain, - target: self, - action: #selector(cancelButtonPressed) - ) + navigationItem.leftBarButtonItem = .button( + icon: .buttonX, + style: .done + ) { [weak delegate] in + delegate?.locationPickerDidCancel() + } locationManager.delegate = self mapView.delegate = self @@ -133,15 +134,6 @@ public class LocationPicker: UIViewController { navigationController?.navigationBar.isTranslucent = true } - @objc - private func cancelButtonPressed(_ sender: UIButton) { - if let navigation = navigationController, navigation.viewControllers.count > 1 { - navigation.popViewController(animated: true) - } else { - presentingViewController?.dismiss(animated: true, completion: nil) - } - } - @objc private func didPressCurrentLocation() { showCurrentLocation() diff --git a/Signal/src/ViewControllers/Photos/SendMediaNavigationController.swift b/Signal/src/ViewControllers/Photos/SendMediaNavigationController.swift index 41eedf5a17..1387504a69 100644 --- a/Signal/src/ViewControllers/Photos/SendMediaNavigationController.swift +++ b/Signal/src/ViewControllers/Photos/SendMediaNavigationController.swift @@ -481,9 +481,7 @@ extension SendMediaNavigationController: PHPickerViewControllerDelegate { if attachmentCount <= 0 { // The user tapped the cancel button or deselected everything self.view.layer.opacity = 0 - picker.dismiss(animated: true) { - self.dismiss(animated: false) - } + self.sendMediaNavDelegate?.sendMediaNavDidCancel(self) return } @@ -494,7 +492,7 @@ extension SendMediaNavigationController: PHPickerViewControllerDelegate { extension SendMediaNavigationController: UIAdaptivePresentationControllerDelegate { func presentationControllerDidDismiss(_ presentationController: UIPresentationController) { // The user swiped the photo picker down - self.dismiss(animated: false) + self.sendMediaNavDelegate?.sendMediaNavDidCancel(self) } } @@ -569,7 +567,7 @@ extension SendMediaNavigationController: AttachmentApprovalViewControllerDelegat sendMediaNavDelegate?.sendMediaNav(self, didApproveAttachments: attachments, messageBody: messageBody) } - func attachmentApprovalDidCancel(_ attachmentApproval: AttachmentApprovalViewController) { + func attachmentApprovalDidCancel() { sendMediaNavDelegate?.sendMediaNavDidCancel(self) } diff --git a/SignalShareExtension/SharingThreadPickerViewController.swift b/SignalShareExtension/SharingThreadPickerViewController.swift index bfa889c524..69773c7731 100644 --- a/SignalShareExtension/SharingThreadPickerViewController.swift +++ b/SignalShareExtension/SharingThreadPickerViewController.swift @@ -707,7 +707,7 @@ extension SharingThreadPickerViewController: AttachmentApprovalViewControllerDel send() } - func attachmentApprovalDidCancel(_ attachmentApproval: AttachmentApprovalViewController) { + func attachmentApprovalDidCancel() { shareViewDelegate?.shareViewWasCancelled() } diff --git a/SignalUI/AttachmentApproval/AttachmentApprovalViewController.swift b/SignalUI/AttachmentApproval/AttachmentApprovalViewController.swift index ddc5eb0245..acf473e2ab 100644 --- a/SignalUI/AttachmentApproval/AttachmentApprovalViewController.swift +++ b/SignalUI/AttachmentApproval/AttachmentApprovalViewController.swift @@ -15,7 +15,7 @@ public protocol AttachmentApprovalViewControllerDelegate: AnyObject { func attachmentApproval(_ attachmentApproval: AttachmentApprovalViewController, didApproveAttachments attachments: [SignalAttachment], messageBody: MessageBody?) - func attachmentApprovalDidCancel(_ attachmentApproval: AttachmentApprovalViewController) + func attachmentApprovalDidCancel() func attachmentApproval( _ attachmentApproval: AttachmentApprovalViewController, @@ -791,7 +791,7 @@ extension AttachmentApprovalViewController { @objc private func cancelPressed() { - self.approvalDelegate?.attachmentApprovalDidCancel(self) + self.approvalDelegate?.attachmentApprovalDidCancel() } @objc