Skip to content

Commit

Permalink
Bump to v2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
stleamist committed Aug 26, 2020
2 parents 2efb01a + f5aaaa8 commit 72c58fe
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 8 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
# Changelog

## [v2.2.0](https://github.com/stleamist/BetterSafariView/releases/tag/v2.2.0) (2020-08-26)
### Added
- `SafariView` now conforms to `View` protocol, so it can be used even in the `.sheet()` or the `.fullScreenCover()` modifiers for the advanced usage.
- Added `accentColor(_:)` modifier to `SafariView` as a convenience method of `preferredControlAccentColor(_:)`.
- Added a new initializer of `WebAuthenticationSession` where the `onCompletion` closure receives a `Result` instance, which contains either a `URL` or an `Error`.

### Fixed
- Fixed typos on the markup.

## [v2.1.0](https://github.com/stleamist/BetterSafariView/releases/tag/v2.1.0) (2020-08-24)
### Changed
- Coordinators are now in charge of view controller presentations, following the structure of [VisualEffects](https://github.com/twostraws/VisualEffects).

## [v2.0.1](https://github.com/stleamist/BetterSafariView/releases/tag/v2.0.1) (2020-08-22)
### Fixed
- Fixed typos on markup
- Fixed typos on the markup.

## [v2.0.0](https://github.com/stleamist/BetterSafariView/releases/tag/v2.0.0) (2020-08-16)
### Added
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ struct ContentView: View {
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.1.0"))
.package(url: "https://github.com/stleamist/BetterSafariView.git", .upToNextMajor(from: "2.2.0"))
```

Next, add `BetterSafariView` as a dependency for your targets:
Expand All @@ -166,7 +166,7 @@ import PackageDescription
let package = Package(
name: "MyPackage",
dependencies: [
.package(url: "https://github.com/stleamist/BetterSafariView.git", .upToNextMajor(from: "2.1.0"))
.package(url: "https://github.com/stleamist/BetterSafariView.git", .upToNextMajor(from: "2.2.0"))
],
targets: [
.target(name: "MyTarget", dependencies: ["BetterSafariView"])
Expand Down
65 changes: 65 additions & 0 deletions Sources/BetterSafariView/SafariView/SafariView+View.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import SwiftUI
import SafariServices

// A `View` conformance for the advanced usage.
extension SafariView: View {

// To apply `ignoresSafeArea(_:edges:)` modifier to the `UIViewRepresentable`,
// define nested `Representable` struct and wrap it with `View`.
public var body: some View {
if #available(iOS 14.0, *) {
Representable(parent: self)
.ignoresSafeArea(.container, edges: .all)
} else {
Representable(parent: self)
.edgesIgnoringSafeArea(.all)
}
}

/// Sets the accent color for the control buttons on the navigation bar and the toolbar.
///
/// This color preference is ignored if the view controller is in Private Browsing mode or displaying an antiphishing warning.
/// After the view controller is presented, changes made are not reflected.
///
/// - Note:
/// This modifier is a convenience method of `preferredControlAccentColor(_:)`.
///
/// - Parameters:
/// - accentColor: The color to use as a control accent color. If `nil`, the accent color continues to be inherited.
///
@available(iOS 14.0, *)
public func accentColor(_ accentColor: Color?) -> Self {
return self.preferredControlAccentColor(accentColor)
}
}

extension SafariView {

struct Representable: UIViewControllerRepresentable {

// MARK: Parent Copying

private var parent: SafariView

init(parent: SafariView) {
self.parent = parent
}

// MARK: UIViewControllerRepresentable

func makeUIViewController(context: Context) -> SFSafariViewController {
let safariViewController = SFSafariViewController(
url: parent.url,
configuration: parent.configuration
)
// Disable interactive pop gesture recognizer
safariViewController.modalPresentationStyle = .none
parent.applyModification(to: safariViewController)
return safariViewController
}

func updateUIViewController(_ safariViewController: SFSafariViewController, context: Context) {
parent.applyModification(to: safariViewController)
}
}
}
1 change: 0 additions & 1 deletion Sources/BetterSafariView/SafariView/SafariView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public struct SafariView {
///
/// This color preference is ignored if the view controller is in Private Browsing mode or displaying an antiphishing warning.
/// After the view controller is presented, changes made are not reflected.
/// Use `preferredControlAccentColor(_:)` instead of using the view’s [accentColor(_:)](apple-reference-documentation://ls%2Fdocumentation%2Fswiftui%2Fview%2Faccentcolor(_%3A)) method.
///
/// - Parameters:
/// - color: The color to use as a control accent color. If `nil`, the accent color continues to be inherited.
Expand Down
4 changes: 2 additions & 2 deletions Sources/BetterSafariView/SafariView/SafariViewPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ extension SafariViewPresenter {
case let (.none, .some(newItem)):
presentSafariViewController(with: newItem)
case let (.some(oldItem), .some(newItem)) where oldItem.id != newItem.id:
dismissSafariViewController(completion: {
dismissSafariViewController() {
self.presentSafariViewController(with: newItem)
})
}
case let (.some, .some(newItem)):
updateSafariViewController(with: newItem)
case (.some, .none):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ import AuthenticationServices
///
public struct WebAuthenticationSession {

/// A completion handler for the web authentication session.
public typealias CompletionHandler = ASWebAuthenticationSession.CompletionHandler

/// A completion handler for the web authentication session.
public typealias OnCompletion = (_ result: Result<URL, Error>) -> Void

// MARK: Representation Properties

let url: URL
Expand All @@ -27,20 +31,48 @@ public struct WebAuthenticationSession {
/// Creates a web authentication session instance.
///
/// - Parameters:
/// - URL: A URL with the `http` or `https` scheme pointing to the authentication webpage.
/// - url: A URL with the `http` or `https` scheme pointing to the authentication webpage.
/// - callbackURLScheme: The custom URL scheme that the app expects in the callback URL.
/// - completionHandler: A completion handler the session calls when it completes successfully, or when the user cancels the session.
/// - callbackURL: A URL using the scheme indicated by the `callbackURLScheme` parameter that indicates the outcome of the authentication attempt.
/// - error: An error that indicates the reason for the cancelation.
///
public init(
url: URL,
callbackURLScheme: String?,
completionHandler: @escaping CompletionHandler
completionHandler: @escaping (_ callbackURL: URL?, _ error: Error?) -> Void // Replaced from WebAuthenticationSession.CompletionHandler for the completion suggestion.
) {
self.url = url
self.callbackURLScheme = callbackURLScheme
self.completionHandler = completionHandler
}

/// Creates a web authentication session instance.
///
/// - Parameters:
/// - url: A URL with the `http` or `https` scheme pointing to the authentication webpage.
/// - callbackURLScheme: The custom URL scheme that the app expects in the callback URL.
/// - onCompletion: A completion handler the session calls when it completes successfully, or when the user cancels the session.
/// - result: A `Result` indicating whether the operation succeeded or failed.
///
public init(
url: URL,
callbackURLScheme: String?,
onCompletion: @escaping (_ result: Result<URL, Error>) -> Void // Replaced from WebAuthenticationSession.OnCompletion for the completion suggestion.
) {
self.url = url
self.callbackURLScheme = callbackURLScheme
self.completionHandler = { callbackURL, error in
if let callbackURL = callbackURL {
onCompletion(.success(callbackURL))
} else if let error = error {
onCompletion(.failure(error))
} else {
assertionFailure("Both callbackURL and error are nil.")
}
}
}

// MARK: Modifiers

var prefersEphemeralWebBrowserSession: Bool = false
Expand Down

0 comments on commit 72c58fe

Please sign in to comment.