-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
113 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters