From cfebdb39353797b99e0cedebbc5b097bd7feb091 Mon Sep 17 00:00:00 2001 From: Bohdan Hernandez Navia Date: Fri, 4 Dec 2020 21:23:28 +0000 Subject: [PATCH 1/6] Considers the case when uiViewController is not presenting any view controller. --- .../SafariView/SafariViewPresenter.swift | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Sources/BetterSafariView/SafariView/SafariViewPresenter.swift b/Sources/BetterSafariView/SafariView/SafariViewPresenter.swift index 48e91cb..7f88c3c 100644 --- a/Sources/BetterSafariView/SafariView/SafariViewPresenter.swift +++ b/Sources/BetterSafariView/SafariView/SafariViewPresenter.swift @@ -94,16 +94,22 @@ extension SafariViewPresenter { } private func dismissSafariViewController(completion: (() -> Void)? = nil) { + let dismissCompletion: () -> Void = { + self.handleDismissalWithoutResettingItemBinding() + completion?() + } + + guard uiViewController.presentedViewController != nil else { + dismissCompletion() + return + } // Check if the `uiViewController` is a instance of the `SFSafariViewController` // to prevent other controllers presented by the container view from being dismissed unintentionally. guard uiViewController.presentedViewController is SFSafariViewController else { return } - uiViewController.dismiss(animated: true) { - self.handleDismissalWithoutResettingItemBinding() - completion?() - } + uiViewController.dismiss(animated: true, completion: dismissCompletion) } // MARK: Dismissal Handlers From 1d2c3f61f1791494e5b889d1c80c5cfa7e5d6d79 Mon Sep 17 00:00:00 2001 From: Bohdan Hernandez Navia Date: Sat, 5 Dec 2020 20:44:35 +0000 Subject: [PATCH 2/6] Allows presenting SFSafariViewController when the rootViewController is already presenting another view controller. --- .../SafariView/SafariViewPresenter.swift | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Sources/BetterSafariView/SafariView/SafariViewPresenter.swift b/Sources/BetterSafariView/SafariView/SafariViewPresenter.swift index 7f88c3c..fd4fa21 100644 --- a/Sources/BetterSafariView/SafariView/SafariViewPresenter.swift +++ b/Sources/BetterSafariView/SafariView/SafariViewPresenter.swift @@ -73,6 +73,10 @@ extension SafariViewPresenter { // MARK: Presentation Handlers private func presentSafariViewController(with item: Item) { + guard uiViewController.presentedViewController == nil else { + return + } + let representation = parent.representationBuilder(item) let safariViewController = SFSafariViewController(url: representation.url, configuration: representation.configuration) safariViewController.delegate = self @@ -81,8 +85,9 @@ extension SafariViewPresenter { // There is a problem that page loading and parallel push animation are not working when a modifier is attached to the view in a `List`. // As a workaround, use a `rootViewController` of the `window` for presenting. // (Unlike the other view controllers, a view controller hosted by a cell doesn't have a parent, but has the same window.) - let presentingViewController = uiViewController.view.window?.rootViewController ?? uiViewController - presentingViewController.present(safariViewController, animated: true) + var presentingViewController = uiViewController.view.window?.rootViewController + presentingViewController = presentingViewController?.presentedViewController ?? presentingViewController ?? uiViewController + presentingViewController?.present(safariViewController, animated: true) } private func updateSafariViewController(with item: Item) { From 04e067b9a29fc634138e761d36028d22eb5bb41c Mon Sep 17 00:00:00 2001 From: Bohdan Hernandez Navia Date: Tue, 8 Dec 2020 17:13:28 +0000 Subject: [PATCH 3/6] Makes sure SFSafariViewController is the one dismissed. --- Sources/BetterSafariView/SafariView/SafariViewPresenter.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/BetterSafariView/SafariView/SafariViewPresenter.swift b/Sources/BetterSafariView/SafariView/SafariViewPresenter.swift index fd4fa21..346afd4 100644 --- a/Sources/BetterSafariView/SafariView/SafariViewPresenter.swift +++ b/Sources/BetterSafariView/SafariView/SafariViewPresenter.swift @@ -111,10 +111,10 @@ extension SafariViewPresenter { // Check if the `uiViewController` is a instance of the `SFSafariViewController` // to prevent other controllers presented by the container view from being dismissed unintentionally. - guard uiViewController.presentedViewController is SFSafariViewController else { + guard let safariViewController = uiViewController.presentedViewController as? SFSafariViewController else { return } - uiViewController.dismiss(animated: true, completion: dismissCompletion) + safariViewController.dismiss(animated: true, completion: dismissCompletion) } // MARK: Dismissal Handlers From 9be5e5fc30e7222608b12a81b36313c4b9eb009b Mon Sep 17 00:00:00 2001 From: Dongkyu Kim Date: Tue, 19 Jan 2021 20:57:37 +0900 Subject: [PATCH 4/6] Convert tabs to spaces --- .../SafariView/SafariViewPresenter.swift | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Sources/BetterSafariView/SafariView/SafariViewPresenter.swift b/Sources/BetterSafariView/SafariView/SafariViewPresenter.swift index 346afd4..fdeb7fa 100644 --- a/Sources/BetterSafariView/SafariView/SafariViewPresenter.swift +++ b/Sources/BetterSafariView/SafariView/SafariViewPresenter.swift @@ -73,10 +73,10 @@ extension SafariViewPresenter { // MARK: Presentation Handlers private func presentSafariViewController(with item: Item) { - guard uiViewController.presentedViewController == nil else { - return - } - + guard uiViewController.presentedViewController == nil else { + return + } + let representation = parent.representationBuilder(item) let safariViewController = SFSafariViewController(url: representation.url, configuration: representation.configuration) safariViewController.delegate = self @@ -85,8 +85,8 @@ extension SafariViewPresenter { // There is a problem that page loading and parallel push animation are not working when a modifier is attached to the view in a `List`. // As a workaround, use a `rootViewController` of the `window` for presenting. // (Unlike the other view controllers, a view controller hosted by a cell doesn't have a parent, but has the same window.) - var presentingViewController = uiViewController.view.window?.rootViewController - presentingViewController = presentingViewController?.presentedViewController ?? presentingViewController ?? uiViewController + var presentingViewController = uiViewController.view.window?.rootViewController + presentingViewController = presentingViewController?.presentedViewController ?? presentingViewController ?? uiViewController presentingViewController?.present(safariViewController, animated: true) } @@ -99,22 +99,22 @@ extension SafariViewPresenter { } private func dismissSafariViewController(completion: (() -> Void)? = nil) { - let dismissCompletion: () -> Void = { - self.handleDismissalWithoutResettingItemBinding() - completion?() - } - - guard uiViewController.presentedViewController != nil else { - dismissCompletion() - return - } + let dismissCompletion: () -> Void = { + self.handleDismissalWithoutResettingItemBinding() + completion?() + } + + guard uiViewController.presentedViewController != nil else { + dismissCompletion() + return + } // Check if the `uiViewController` is a instance of the `SFSafariViewController` // to prevent other controllers presented by the container view from being dismissed unintentionally. - guard let safariViewController = uiViewController.presentedViewController as? SFSafariViewController else { + guard let safariViewController = uiViewController.presentedViewController as? SFSafariViewController else { return } - safariViewController.dismiss(animated: true, completion: dismissCompletion) + safariViewController.dismiss(animated: true, completion: dismissCompletion) } // MARK: Dismissal Handlers From 744c1d469f9b17788ae4c1d9b21bad5592fa4973 Mon Sep 17 00:00:00 2001 From: Dongkyu Kim Date: Wed, 20 Jan 2021 00:45:53 +0900 Subject: [PATCH 5/6] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb86e29..09908f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [v2.3.1](https://github.com/stleamist/BetterSafariView/releases/tag/v2.3.1) (2020-01-20) +### Fixed +- Fixed an issue where the `SafariView` is not presented on the modal sheets (#9). Thanks @boherna! + ## [v2.3.0](https://github.com/stleamist/BetterSafariView/releases/tag/v2.3.0) (2021-01-19) ### Added - Added `WebAuthenticationSession` support for macOS and watchOS. From 0d15ad11245a09bd77eacd22be59ce8ef4625a31 Mon Sep 17 00:00:00 2001 From: Dongkyu Kim Date: Wed, 20 Jan 2021 00:45:59 +0900 Subject: [PATCH 6/6] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9a70950..6566cec 100644 --- a/README.md +++ b/README.md @@ -282,7 +282,7 @@ func prefersEphemeralWebBrowserSession(_ prefersEphemeralWebBrowserSession: Bool Add the following line to the `dependencies` in your [`Package.swift`](https://developer.apple.com/documentation/swift_packages/package) file: ```swift -.package(url: "https://github.com/stleamist/BetterSafariView.git", .upToNextMajor(from: "2.3.0")) +.package(url: "https://github.com/stleamist/BetterSafariView.git", .upToNextMajor(from: "2.3.1")) ``` Next, add `BetterSafariView` as a dependency for your targets: @@ -301,7 +301,7 @@ import PackageDescription let package = Package( name: "MyPackage", dependencies: [ - .package(url: "https://github.com/stleamist/BetterSafariView.git", .upToNextMajor(from: "2.3.0")) + .package(url: "https://github.com/stleamist/BetterSafariView.git", .upToNextMajor(from: "2.3.1")) ], targets: [ .target(name: "MyTarget", dependencies: ["BetterSafariView"])