From 3bb772f135d4a3600c00903dfdadd98a8cff4bce Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Thu, 7 Dec 2017 12:50:16 -0500 Subject: [PATCH] Modal conversation picker, hide loading screen when possible The first usable screen in the conversation picker, that's the first thing we want to show the user, and the modal presentation feels like the right way to introduce this new context. Long load times should be the exception, not the normal flow, so we delay it's presentation in hopes that it will generally never be seen. // FREEBIE --- .../ShareViewController.swift | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/SignalShareExtension/ShareViewController.swift b/SignalShareExtension/ShareViewController.swift index 3e5a37236..03efa5e84 100644 --- a/SignalShareExtension/ShareViewController.swift +++ b/SignalShareExtension/ShareViewController.swift @@ -20,6 +20,12 @@ public class ShareViewController: UINavigationController, SAELoadViewDelegate, S Logger.debug("\(self.logTag) \(#function)") + // We can't show the conversation picker until the DB is set up. + // Normally this will only take a moment, so rather than flickering and then hiding the loading screen + // We start with as invisible, and only fade it in if it's going to take a while + self.view.isHidden = true + self.view.alpha = 0 + // This should be the first thing we do. let appContext = ShareAppExtensionContext(rootViewController:self) SetCurrentAppContext(appContext) @@ -78,7 +84,7 @@ public class ShareViewController: UINavigationController, SAELoadViewDelegate, S let loadViewController = SAELoadViewController(delegate:self) self.pushViewController(loadViewController, animated: false) - self.isNavigationBarHidden = false + self.isNavigationBarHidden = true // We don't need to use "screen protection" in the SAE. @@ -225,7 +231,7 @@ public class ShareViewController: UINavigationController, SAELoadViewDelegate, S Logger.info("Presenting initial root view controller") if TSAccountManager.isRegistered() { - showConversationPicker() + presentConversationPicker() } else { showNotRegisteredView() } @@ -278,7 +284,6 @@ public class ShareViewController: UINavigationController, SAELoadViewDelegate, S private func showErrorView(title: String, message: String) { let viewController = SAEFailedViewController(delegate:self, title:title, message:message) self.setViewControllers([viewController], animated: false) - self.isNavigationBarHidden = false } // MARK: View Lifecycle @@ -303,6 +308,14 @@ public class ShareViewController: UINavigationController, SAELoadViewDelegate, S Logger.debug("\(self.logTag) \(#function)") super.viewDidAppear(animated) + + // We can't show the conversation picker until the DB is set up. + // Normally this will only take a moment, so rather than flickering and then hiding the loading screen + // We start with as invisible, and only fade it in if it's going to take a while + self.view.isHidden = false + UIView.animate(withDuration: 0.1, delay: 0.5, options: [.curveEaseInOut], animations: { + self.view.alpha = 1 + }, completion: nil) } override open func viewWillDisappear(_ animated: Bool) { @@ -329,11 +342,13 @@ public class ShareViewController: UINavigationController, SAELoadViewDelegate, S // MARK: Helpers - private func showConversationPicker() { - let conversationPicker = SendExternalFileViewController() - buildAttachment().then { attachment -> Void in + private func presentConversationPicker() { + self.buildAttachment().then { attachment -> Void in + let conversationPicker = SendExternalFileViewController() + let navigationController = UINavigationController(rootViewController: conversationPicker) + navigationController.isNavigationBarHidden = true conversationPicker.attachment = attachment - self.setViewControllers([conversationPicker], animated: true) + self.present(navigationController, animated: true, completion: nil) Logger.info("showing picker with attachment: \(attachment)") }.catch { error in let alertTitle = NSLocalizedString("SHARE_EXTENSION_UNABLE_TO_BUILD_ATTACHMENT_ALERT_TITLE", comment: "Shown when trying to share content to a Signal user for the share extension. Followed by failure details.")