CR: Faster animation from loading -> picker

// FREEBIE
pull/1/head
Michael Kirk 7 years ago
parent 813f4e474e
commit 03220ffa79

@ -18,9 +18,10 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE
private var progressPoller: ProgressPoller? private var progressPoller: ProgressPoller?
var loadViewController: SAELoadViewController? var loadViewController: SAELoadViewController?
let shareViewNavigationController: UINavigationController = UINavigationController()
override open func loadView() { override open func loadView() {
super.loadView() super.loadView()
Logger.debug("\(self.logTag) \(#function)") Logger.debug("\(self.logTag) \(#function)")
// This should be the first thing we do. // This should be the first thing we do.
@ -56,7 +57,7 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE
// most of the singletons, etc.). We just want to show an error view and // most of the singletons, etc.). We just want to show an error view and
// abort. // abort.
isReadyForAppExtensions = OWSPreferences.isReadyForAppExtensions() isReadyForAppExtensions = OWSPreferences.isReadyForAppExtensions()
if !isReadyForAppExtensions { guard isReadyForAppExtensions else {
// If we don't have TSSStorageManager, we can't consult TSAccountManager // If we don't have TSSStorageManager, we can't consult TSAccountManager
// for isRegistered, so we use OWSPreferences which is usually-accurate // for isRegistered, so we use OWSPreferences which is usually-accurate
// copy of that state. // copy of that state.
@ -79,9 +80,7 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE
} }
Logger.debug("\(self.logTag) setup is slow - showing loading screen") Logger.debug("\(self.logTag) setup is slow - showing loading screen")
self.showPrimaryViewController(loadViewController)
let navigationController = UINavigationController(rootViewController: loadViewController)
self.present(navigationController, animated: true)
}.retainUntilComplete() }.retainUntilComplete()
// We shouldn't set up our environment until after we've consulted isReadyForAppExtensions. // We shouldn't set up our environment until after we've consulted isReadyForAppExtensions.
@ -117,6 +116,7 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE
} }
deinit { deinit {
Logger.info("\(self.logTag) dealloc")
NotificationCenter.default.removeObserver(self) NotificationCenter.default.removeObserver(self)
} }
@ -298,7 +298,7 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE
private func showErrorView(title: String, message: String) { private func showErrorView(title: String, message: String) {
let viewController = SAEFailedViewController(delegate:self, title:title, message:message) let viewController = SAEFailedViewController(delegate:self, title:title, message:message)
self.setViewControllers([viewController], animated: false) self.showPrimaryViewController(viewController)
} }
// MARK: View Lifecycle // MARK: View Lifecycle
@ -363,22 +363,30 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE
// MARK: Helpers // MARK: Helpers
// This view controller is not visible to the user. It exists to intercept touches, set up the
// extensions dependencies, and eventually present a visible view to the user.
// For speed of presentation, we only present a single modal, and if it's already been presented
// we swap out the contents.
// e.g. if loading is taking a while, the user will see the load screen presented with a modal
// animation. Next, when loading completes, the load view will be switched out for the contact
// picker view.
private func showPrimaryViewController(_ viewController: UIViewController) {
shareViewNavigationController.setViewControllers([viewController], animated: false)
if self.presentedViewController == nil {
Logger.debug("\(self.logTag) presenting modally: \(viewController)")
self.present(shareViewNavigationController, animated: true)
} else {
Logger.debug("\(self.logTag) modal already presented. swapping modal content for: \(viewController)")
assert(self.presentedViewController == shareViewNavigationController)
}
}
private func presentConversationPicker() { private func presentConversationPicker() {
self.buildAttachment().then { attachment -> Void in self.buildAttachment().then { attachment -> Void in
let conversationPicker = SharingThreadPickerViewController(shareViewDelegate: self) let conversationPicker = SharingThreadPickerViewController(shareViewDelegate: self)
let navigationController = UINavigationController(rootViewController: conversationPicker)
navigationController.isNavigationBarHidden = true
conversationPicker.attachment = attachment conversationPicker.attachment = attachment
if let presentedViewController = self.presentedViewController { self.shareViewNavigationController.isNavigationBarHidden = true
Logger.debug("\(self.logTag) dismissing \(presentedViewController) before presenting conversation picker") self.showPrimaryViewController(conversationPicker)
self.dismiss(animated: true) {
self.present(navigationController, animated: true)
}
} else {
Logger.debug("\(self.logTag) no other modal, presenting conversation picker immediately")
self.present(navigationController, animated: true)
}
Logger.info("showing picker with attachment: \(attachment)") Logger.info("showing picker with attachment: \(attachment)")
}.catch { error in }.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.") 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.")

Loading…
Cancel
Save