diff --git a/iOS/AppDelegate.swift b/iOS/AppDelegate.swift index 659b7f9b0..02d0bf1ad 100644 --- a/iOS/AppDelegate.swift +++ b/iOS/AppDelegate.swift @@ -210,6 +210,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD default: if let sceneDelegate = response.targetScene?.delegate as? SceneDelegate { sceneDelegate.handle(response) + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { + sceneDelegate.coordinator.dismissIfLaunchingFromExternalAction() + }) } } diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index 7a4711d76..f988830a9 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -687,6 +687,7 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { present(vc, animated: true) } } + } // MARK: UIContextMenuInteractionDelegate diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index c03018039..1c6a526b9 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -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 diff --git a/iOS/SceneDelegate.swift b/iOS/SceneDelegate.swift index 3da542328..523446eed 100644 --- a/iOS/SceneDelegate.swift +++ b/iOS/SceneDelegate.swift @@ -105,6 +105,11 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { guard let context = urlContexts.first else { return } DispatchQueue.main.async { + + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { + self.coordinator.dismissIfLaunchingFromExternalAction() + } + let urlString = context.url.absoluteString // Handle the feed: and feeds: schemes @@ -202,6 +207,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { return } + } } }