Skip to content

Commit

Permalink
Bump to v2.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
stleamist committed Jan 19, 2021
2 parents 1d0d8d8 + 0d15ad1 commit 561919b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"])
Expand Down
25 changes: 18 additions & 7 deletions Sources/BetterSafariView/SafariView/SafariViewPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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
Expand Down

0 comments on commit 561919b

Please sign in to comment.