Skip to content

Commit 72c58fe

Browse files
committed
Bump to v2.2.0
2 parents 2efb01a + f5aaaa8 commit 72c58fe

File tree

6 files changed

+113
-8
lines changed

6 files changed

+113
-8
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
# Changelog
22

3+
## [v2.2.0](https://github.com/stleamist/BetterSafariView/releases/tag/v2.2.0) (2020-08-26)
4+
### Added
5+
- `SafariView` now conforms to `View` protocol, so it can be used even in the `.sheet()` or the `.fullScreenCover()` modifiers for the advanced usage.
6+
- Added `accentColor(_:)` modifier to `SafariView` as a convenience method of `preferredControlAccentColor(_:)`.
7+
- Added a new initializer of `WebAuthenticationSession` where the `onCompletion` closure receives a `Result` instance, which contains either a `URL` or an `Error`.
8+
9+
### Fixed
10+
- Fixed typos on the markup.
11+
312
## [v2.1.0](https://github.com/stleamist/BetterSafariView/releases/tag/v2.1.0) (2020-08-24)
413
### Changed
514
- Coordinators are now in charge of view controller presentations, following the structure of [VisualEffects](https://github.com/twostraws/VisualEffects).
615

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

1120
## [v2.0.0](https://github.com/stleamist/BetterSafariView/releases/tag/v2.0.0) (2020-08-16)
1221
### Added

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ struct ContentView: View {
147147
Add the following line to the `dependencies` in your [`Package.swift`](https://developer.apple.com/documentation/swift_packages/package) file:
148148

149149
```swift
150-
.package(url: "https://github.com/stleamist/BetterSafariView.git", .upToNextMajor(from: "2.1.0"))
150+
.package(url: "https://github.com/stleamist/BetterSafariView.git", .upToNextMajor(from: "2.2.0"))
151151
```
152152

153153
Next, add `BetterSafariView` as a dependency for your targets:
@@ -166,7 +166,7 @@ import PackageDescription
166166
let package = Package(
167167
name: "MyPackage",
168168
dependencies: [
169-
.package(url: "https://github.com/stleamist/BetterSafariView.git", .upToNextMajor(from: "2.1.0"))
169+
.package(url: "https://github.com/stleamist/BetterSafariView.git", .upToNextMajor(from: "2.2.0"))
170170
],
171171
targets: [
172172
.target(name: "MyTarget", dependencies: ["BetterSafariView"])
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import SwiftUI
2+
import SafariServices
3+
4+
// A `View` conformance for the advanced usage.
5+
extension SafariView: View {
6+
7+
// To apply `ignoresSafeArea(_:edges:)` modifier to the `UIViewRepresentable`,
8+
// define nested `Representable` struct and wrap it with `View`.
9+
public var body: some View {
10+
if #available(iOS 14.0, *) {
11+
Representable(parent: self)
12+
.ignoresSafeArea(.container, edges: .all)
13+
} else {
14+
Representable(parent: self)
15+
.edgesIgnoringSafeArea(.all)
16+
}
17+
}
18+
19+
/// Sets the accent color for the control buttons on the navigation bar and the toolbar.
20+
///
21+
/// This color preference is ignored if the view controller is in Private Browsing mode or displaying an antiphishing warning.
22+
/// After the view controller is presented, changes made are not reflected.
23+
///
24+
/// - Note:
25+
/// This modifier is a convenience method of `preferredControlAccentColor(_:)`.
26+
///
27+
/// - Parameters:
28+
/// - accentColor: The color to use as a control accent color. If `nil`, the accent color continues to be inherited.
29+
///
30+
@available(iOS 14.0, *)
31+
public func accentColor(_ accentColor: Color?) -> Self {
32+
return self.preferredControlAccentColor(accentColor)
33+
}
34+
}
35+
36+
extension SafariView {
37+
38+
struct Representable: UIViewControllerRepresentable {
39+
40+
// MARK: Parent Copying
41+
42+
private var parent: SafariView
43+
44+
init(parent: SafariView) {
45+
self.parent = parent
46+
}
47+
48+
// MARK: UIViewControllerRepresentable
49+
50+
func makeUIViewController(context: Context) -> SFSafariViewController {
51+
let safariViewController = SFSafariViewController(
52+
url: parent.url,
53+
configuration: parent.configuration
54+
)
55+
// Disable interactive pop gesture recognizer
56+
safariViewController.modalPresentationStyle = .none
57+
parent.applyModification(to: safariViewController)
58+
return safariViewController
59+
}
60+
61+
func updateUIViewController(_ safariViewController: SFSafariViewController, context: Context) {
62+
parent.applyModification(to: safariViewController)
63+
}
64+
}
65+
}

Sources/BetterSafariView/SafariView/SafariView.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public struct SafariView {
8181
///
8282
/// This color preference is ignored if the view controller is in Private Browsing mode or displaying an antiphishing warning.
8383
/// After the view controller is presented, changes made are not reflected.
84-
/// Use `preferredControlAccentColor(_:)` instead of using the view’s [accentColor(_:)](apple-reference-documentation://ls%2Fdocumentation%2Fswiftui%2Fview%2Faccentcolor(_%3A)) method.
8584
///
8685
/// - Parameters:
8786
/// - color: The color to use as a control accent color. If `nil`, the accent color continues to be inherited.

Sources/BetterSafariView/SafariView/SafariViewPresenter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ extension SafariViewPresenter {
5757
case let (.none, .some(newItem)):
5858
presentSafariViewController(with: newItem)
5959
case let (.some(oldItem), .some(newItem)) where oldItem.id != newItem.id:
60-
dismissSafariViewController(completion: {
60+
dismissSafariViewController() {
6161
self.presentSafariViewController(with: newItem)
62-
})
62+
}
6363
case let (.some, .some(newItem)):
6464
updateSafariViewController(with: newItem)
6565
case (.some, .none):

Sources/BetterSafariView/WebAuthenticationSession/WebAuthenticationSession.swift

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ import AuthenticationServices
1616
///
1717
public struct WebAuthenticationSession {
1818

19+
/// A completion handler for the web authentication session.
1920
public typealias CompletionHandler = ASWebAuthenticationSession.CompletionHandler
2021

22+
/// A completion handler for the web authentication session.
23+
public typealias OnCompletion = (_ result: Result<URL, Error>) -> Void
24+
2125
// MARK: Representation Properties
2226

2327
let url: URL
@@ -27,20 +31,48 @@ public struct WebAuthenticationSession {
2731
/// Creates a web authentication session instance.
2832
///
2933
/// - Parameters:
30-
/// - URL: A URL with the `http` or `https` scheme pointing to the authentication webpage.
34+
/// - url: A URL with the `http` or `https` scheme pointing to the authentication webpage.
3135
/// - callbackURLScheme: The custom URL scheme that the app expects in the callback URL.
3236
/// - completionHandler: A completion handler the session calls when it completes successfully, or when the user cancels the session.
37+
/// - callbackURL: A URL using the scheme indicated by the `callbackURLScheme` parameter that indicates the outcome of the authentication attempt.
38+
/// - error: An error that indicates the reason for the cancelation.
3339
///
3440
public init(
3541
url: URL,
3642
callbackURLScheme: String?,
37-
completionHandler: @escaping CompletionHandler
43+
completionHandler: @escaping (_ callbackURL: URL?, _ error: Error?) -> Void // Replaced from WebAuthenticationSession.CompletionHandler for the completion suggestion.
3844
) {
3945
self.url = url
4046
self.callbackURLScheme = callbackURLScheme
4147
self.completionHandler = completionHandler
4248
}
4349

50+
/// Creates a web authentication session instance.
51+
///
52+
/// - Parameters:
53+
/// - url: A URL with the `http` or `https` scheme pointing to the authentication webpage.
54+
/// - callbackURLScheme: The custom URL scheme that the app expects in the callback URL.
55+
/// - onCompletion: A completion handler the session calls when it completes successfully, or when the user cancels the session.
56+
/// - result: A `Result` indicating whether the operation succeeded or failed.
57+
///
58+
public init(
59+
url: URL,
60+
callbackURLScheme: String?,
61+
onCompletion: @escaping (_ result: Result<URL, Error>) -> Void // Replaced from WebAuthenticationSession.OnCompletion for the completion suggestion.
62+
) {
63+
self.url = url
64+
self.callbackURLScheme = callbackURLScheme
65+
self.completionHandler = { callbackURL, error in
66+
if let callbackURL = callbackURL {
67+
onCompletion(.success(callbackURL))
68+
} else if let error = error {
69+
onCompletion(.failure(error))
70+
} else {
71+
assertionFailure("Both callbackURL and error are nil.")
72+
}
73+
}
74+
}
75+
4476
// MARK: Modifiers
4577

4678
var prefersEphemeralWebBrowserSession: Bool = false

0 commit comments

Comments
 (0)