Uses SceneCoordinator

Adds a `func` to SceneCoordinator to handle dismisses vis-a-vis using notifications.
This commit is contained in:
Stuart Breckenridge 2021-11-08 09:52:12 +08:00
parent 0469d81c62
commit 8b39dc4abb
5 changed files with 20 additions and 20 deletions

View File

@ -211,9 +211,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
if let sceneDelegate = response.targetScene?.delegate as? SceneDelegate {
sceneDelegate.handle(response)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
NotificationCenter.default.post(name: .DidLaunchFromExternalAction, object: nil)
sceneDelegate.coordinator.dismissIfLaunchingFromExternalAction()
})
}
}

View File

@ -75,7 +75,6 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
NotificationCenter.default.addObserver(self, selector: #selector(contentSizeCategoryDidChange), name: UIContentSizeCategory.didChangeNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(willEnterForeground(_:)), name: UIApplication.willEnterForegroundNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(configureContextMenu(_:)), name: .ActiveExtensionPointsDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(didLaunchFromExternalAction), name: .DidLaunchFromExternalAction, object: nil)
refreshControl = UIRefreshControl()
refreshControl!.addTarget(self, action: #selector(refreshAccounts(_:)), for: .valueChanged)
@ -688,13 +687,7 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
present(vc, animated: true)
}
}
@objc func didLaunchFromExternalAction() {
guard let presentedController = presentedViewController as? SFSafariViewController else {
return
}
presentedController.dismiss(animated: true, completion: nil)
}
}
// MARK: UIContextMenuInteractionDelegate

View File

@ -1327,6 +1327,23 @@ class SceneCoordinator: NSObject, UndoableCommandRunner {
}
/// This will dismiss the foremost view controller if the user
/// has launched from an external action (i.e., a widget tap, or
/// selecting an artice via a notification).
///
/// The dismiss is only applicable if the view controller is a
/// `SFSafariViewController` or `SettingsViewController`,
/// otherwise, this function does nothing.
func dismissIfLaunchingFromExternalAction() {
guard let presentedController = masterFeedViewController.presentedViewController else { return }
if presentedController.isKind(of: SFSafariViewController.self) {
presentedController.dismiss(animated: true, completion: nil)
}
guard let settings = presentedController.children.first as? SettingsViewController else { return }
settings.dismiss(animated: true, completion: nil)
}
}
// MARK: UISplitViewControllerDelegate

View File

@ -11,10 +11,6 @@ import UserNotifications
import Account
import Zip
public extension Notification.Name {
static let DidLaunchFromExternalAction = Notification.Name("DidLaunchFromExternalAction")
}
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
@ -111,7 +107,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
DispatchQueue.main.async {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
NotificationCenter.default.post(name: .DidLaunchFromExternalAction, object: nil)
self.coordinator.dismissIfLaunchingFromExternalAction()
}
let urlString = context.url.absoluteString

View File

@ -38,7 +38,6 @@ class SettingsViewController: UITableViewController {
NotificationCenter.default.addObserver(self, selector: #selector(accountsDidChange), name: .UserDidDeleteAccount, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange), name: .DisplayNameDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(activeExtensionPointsDidChange), name: .ActiveExtensionPointsDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(didLaunchFromExternalAction), name: .DidLaunchFromExternalAction, object: nil)
tableView.register(UINib(nibName: "SettingsComboTableViewCell", bundle: nil), forCellReuseIdentifier: "SettingsComboTableViewCell")
@ -390,10 +389,6 @@ class SettingsViewController: UITableViewController {
tableView.reloadData()
}
@objc func didLaunchFromExternalAction() {
dismiss(animated: true, completion: nil)
}
}
// MARK: OPML Document Picker