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. 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"]) diff --git a/Sources/BetterSafariView/SafariView/SafariViewPresenter.swift b/Sources/BetterSafariView/SafariView/SafariViewPresenter.swift index c024dfc..8de0043 100644 --- a/Sources/BetterSafariView/SafariView/SafariViewPresenter.swift +++ b/Sources/BetterSafariView/SafariView/SafariViewPresenter.swift @@ -75,6 +75,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 @@ -83,8 +87,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) { @@ -96,16 +101,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 { + guard let safariViewController = uiViewController.presentedViewController as? SFSafariViewController else { return } - uiViewController.dismiss(animated: true) { - self.handleDismissalWithoutResettingItemBinding() - completion?() - } + safariViewController.dismiss(animated: true, completion: dismissCompletion) } // MARK: Dismissal Handlers