Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for visionOS 1.x #38

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ let package = Package(
name: "SafariUI",
platforms: [
.iOS(.v14),
.macCatalyst(.v14)
.macCatalyst(.v14),
.visionOS(.v1)
],
products: [
.library(
Expand Down
2 changes: 1 addition & 1 deletion Sources/SafariView/DismissButtonStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import SafariServices

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
public extension SafariView {

/// An enumeration describing the various dismiss buttons styles available in a ``SafariView``
Expand Down
18 changes: 9 additions & 9 deletions Sources/SafariView/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import SwiftUI

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
public extension EnvironmentValues {

/// The additional activies to include the share sheet displayed inside a ``SafariView``
Expand Down Expand Up @@ -64,7 +64,7 @@ public extension EnvironmentValues {

}

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
extension EnvironmentValues {

var safariViewEntersReaderIfAvailable: Bool {
Expand Down Expand Up @@ -94,7 +94,7 @@ extension EnvironmentValues {

}

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
private struct SafariViewEntersReaderIfAvailableEnvironmentKey: EnvironmentKey {

// MARK: - EnvironmentKey
Expand All @@ -105,7 +105,7 @@ private struct SafariViewEntersReaderIfAvailableEnvironmentKey: EnvironmentKey {

}

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
private struct SafariViewBarCollapsingEnabledEnvironmentKey: EnvironmentKey {

// MARK: - EnvironmentKey
Expand All @@ -116,7 +116,7 @@ private struct SafariViewBarCollapsingEnabledEnvironmentKey: EnvironmentKey {

}

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
private struct SafariViewControlTintColorEnvironmentKey: EnvironmentKey {

// MARK: - EnvironmentKey
Expand All @@ -127,7 +127,7 @@ private struct SafariViewControlTintColorEnvironmentKey: EnvironmentKey {

}

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
private struct SafariViewBarTintColorEnvironmentKey: EnvironmentKey {

// MARK: - EnvironmentKey
Expand All @@ -138,7 +138,7 @@ private struct SafariViewBarTintColorEnvironmentKey: EnvironmentKey {

}

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
private struct SafariViewDismissButtonStyleEnvironmentKey: EnvironmentKey {

// MARK: - EnvironmentKey
Expand All @@ -149,7 +149,7 @@ private struct SafariViewDismissButtonStyleEnvironmentKey: EnvironmentKey {

}

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
private struct SafariViewIncludedActivitiesEnvironmentKey: EnvironmentKey {

// MARK: - EnvironmentKey
Expand All @@ -160,7 +160,7 @@ private struct SafariViewIncludedActivitiesEnvironmentKey: EnvironmentKey {

}

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
private struct SafariViewExcludedActivityTypesEnvironmentKey: EnvironmentKey {

// MARK: - EnvironmentKey
Expand Down
2 changes: 1 addition & 1 deletion Sources/SafariView/ExcludedActivityTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import Foundation
import UIKit

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
public extension SafariView {

/// A struct used to exclude activity types from the share sheet of a ``SafariView``.
Expand Down
2 changes: 1 addition & 1 deletion Sources/SafariView/IncludedActivities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import Foundation
import UIKit

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
public extension SafariView {

/// A struct used to include custom activities in the share sheet of a ``SafariView``
Expand Down
16 changes: 8 additions & 8 deletions Sources/SafariView/Modifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import SwiftUI

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
public extension View {

/// Set the automatic reader behavior of safari views within this view
Expand Down Expand Up @@ -224,7 +224,7 @@ public extension View {

}

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
private struct SafariViewEntersReaderIfAvailableModifier: ViewModifier {

// MARK: - Initializers
Expand All @@ -250,7 +250,7 @@ private struct SafariViewEntersReaderIfAvailableModifier: ViewModifier {

}

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
private struct SafariViewBarCollapsingEnabledModifier: ViewModifier {

// MARK: - Initializers
Expand All @@ -275,7 +275,7 @@ private struct SafariViewBarCollapsingEnabledModifier: ViewModifier {
private let barCollapsingEnabled: Bool
}

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
private struct SafariViewControlTintColorModifier: ViewModifier {

// MARK: - Initializers
Expand All @@ -301,7 +301,7 @@ private struct SafariViewControlTintColorModifier: ViewModifier {

}

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
private struct SafariViewBarTintColorModifier: ViewModifier {

// MARK: - Initializers
Expand All @@ -327,7 +327,7 @@ private struct SafariViewBarTintColorModifier: ViewModifier {

}

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
private struct SafariViewDismissButtonStyleModifier: ViewModifier {

// MARK: - Initializers
Expand All @@ -353,7 +353,7 @@ private struct SafariViewDismissButtonStyleModifier: ViewModifier {

}

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
private struct SafariViewIncludedActivitiesModifier: ViewModifier {

// MARK: - Initializers
Expand All @@ -379,7 +379,7 @@ private struct SafariViewIncludedActivitiesModifier: ViewModifier {

}

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
private struct SafariViewExcludedActivityTypesModifier: ViewModifier {

// MARK: - Initializers
Expand Down
8 changes: 4 additions & 4 deletions Sources/SafariView/Presentation/BoolPresentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import SafariServices
import SwiftUI
import UIKit

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
public extension View {

/// Presents a ``SafariView`` when a binding to a Boolean value that you provide is `true`.
Expand Down Expand Up @@ -88,7 +88,7 @@ public extension View {

}

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
private struct IsPresentedModifier: ViewModifier {

// MARK: - Initializer
Expand Down Expand Up @@ -309,11 +309,11 @@ private struct IsPresentedModifier: ViewModifier {
let configuration = SFSafariViewController.Configuration()
configuration.entersReaderIfAvailable = entersReaderIfAvailable
configuration.barCollapsingEnabled = barCollapsingEnabled
if #available(iOS 15.0, macCatalyst 15.0, *),
if #available(iOS 15.0, macCatalyst 15.0, visionOS 1.0, *),
let activityButton {
configuration.activityButton = unsafeDowncast(activityButton, to: SafariView.ActivityButton.self)
}
if #available(iOS 15.2, *),
if #available(iOS 15.2, visionOS 1.0, *),
let eventAttribution {
configuration.eventAttribution = unsafeDowncast(eventAttribution, to: UIEventAttribution.self)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/SafariView/Presentation/BoolURLPresentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import Foundation
import SwiftUI

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
public extension View {

/// Presents a ``SafariView`` when a binding to a Boolean value that you provide is `true`.
Expand Down Expand Up @@ -85,7 +85,7 @@ public extension View {

}

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
private struct BoolURLPresentation: ViewModifier {

init(
Expand Down
8 changes: 4 additions & 4 deletions Sources/SafariView/Presentation/ItemPresentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import SafariServices
import SwiftUI
import UIKit

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
public extension View {

/// Presents a ``SafariView`` using the given item as a data source for the view’s content.
Expand Down Expand Up @@ -101,7 +101,7 @@ public extension View {

}

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
private struct ItemModifier<Item>: ViewModifier where Item: Identifiable {

// MARK: - Initializers
Expand Down Expand Up @@ -283,11 +283,11 @@ private struct ItemModifier<Item>: ViewModifier where Item: Identifiable {
let configuration = SFSafariViewController.Configuration()
configuration.entersReaderIfAvailable = entersReaderIfAvailable
configuration.barCollapsingEnabled = barCollapsingEnabled
if #available(iOS 15.0, macCatalyst 15.0, *),
if #available(iOS 15.0, macCatalyst 15.0, visionOS 1.0, *),
let activityButton {
configuration.activityButton = unsafeDowncast(activityButton, to: SafariView.ActivityButton.self)
}
if #available(iOS 15.2, *),
if #available(iOS 15.2, visionOS 1.0, *),
let eventAttribution {
configuration.eventAttribution = unsafeDowncast(eventAttribution, to: UIEventAttribution.self)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/SafariView/Presentation/URLPresentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import Foundation
import SwiftUI

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
public extension View {

/// Presents a ``SafariView`` using the given URL.
Expand Down Expand Up @@ -78,7 +78,7 @@ public extension View {

}

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
private struct URLPresentation: ViewModifier {

init(
Expand Down
4 changes: 2 additions & 2 deletions Sources/SafariView/Presentation/WrappedItemPresentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import SwiftUI

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
public extension View {

/// Presents a ``SafariView`` using the given item as a data source for the view’s content.
Expand Down Expand Up @@ -102,7 +102,7 @@ public extension View {

}

@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
private struct WrappedItemPresentation<Item, ID>: ViewModifier where ID: Hashable {

// MARK: - Initializer
Expand Down
2 changes: 1 addition & 1 deletion Sources/SafariView/PrewarmingToken.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import SafariServices

@available(iOS 15.0, macCatalyst 15.0, *)
@available(iOS 15.0, macCatalyst 15.0, visionOS 1.0, *)
public extension SafariView {

/// A type created when SafariServices begins prewarming a connection.
Expand Down
24 changes: 14 additions & 10 deletions Sources/SafariView/SafariView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import SwiftUI
import UIKit

/// A wrapper for `SFSafariViewController` in SwiftUI
@available(iOS 14.0, macCatalyst 14.0, *)
@available(iOS 14.0, macCatalyst 14.0, visionOS 1.0, *)
public struct SafariView: View {

// MARK: - Initializers
Expand Down Expand Up @@ -61,7 +61,7 @@ public struct SafariView: View {
/// - onInitialLoad: Closure to execute on initial load
/// - onInitialRedirect: Closure to execute on intial redirect
/// - onOpenInBrowser: Closure to execute if a user moves from a `SafariView` to `Safari.app`
@available(iOS 15.0, macCatalyst 15.0, *)
@available(iOS 15.0, macCatalyst 15.0, visionOS 1.0, *)
public init(
url: URL,
activityButton: ActivityButton?,
Expand All @@ -87,7 +87,7 @@ public struct SafariView: View {
/// - onInitialLoad: Closure to execute on initial load
/// - onInitialRedirect: Closure to execute on intial redirect
/// - onOpenInBrowser: Closure to execute if a user moves from a `SafariView` to `Safari.app`
@available(iOS 15.2, macCatalyst 15.2, *)
@available(iOS 15.2, macCatalyst 15.2, visionOS 1.0, *)
public init(
url: URL,
activityButton: ActivityButton? = nil,
Expand All @@ -105,7 +105,7 @@ public struct SafariView: View {
}

/// A convenience typealias for [`SFSafariViewController.ActivityButton`](https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller/activitybutton)
@available(iOS 15.0, macCatalyst 15.0, *)
@available(iOS 15.0, macCatalyst 15.0, visionOS 1.0, *)
public typealias ActivityButton = SFSafariViewController.ActivityButton

/// Prewarm the connection to a list of provided URLs
Expand All @@ -120,22 +120,26 @@ public struct SafariView: View {
///
/// - Parameter URLs: The URLs to prewarm
/// - Returns: A prewarming token for the provided URLs.
@available(iOS 15.0, macCatalyst 15.0, *)
@available(iOS 15.0, macCatalyst 15.0, visionOS 1.0, *)
@discardableResult
public static func prewarmConnections(to URLs: [URL]) -> PrewarmingToken {
let token = SFSafariViewController.prewarmConnections(to: URLs)
return .init(token, urls: URLs)
}

/// Clears the safari view's cache using [Swift Concurrency](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/concurrency/).
@available(iOS 16.0, macCatalyst 16.0, *)
@available(iOS 16.0, macCatalyst 16.0, visionOS 1.0, *)
public static func clearWebsiteData() async {
await SFSafariViewController.DataStore.default.clearWebsiteData()
await withUnsafeContinuation { continuation in
SafariView.clearWebsiteData {
continuation.resume()
}
}
}

/// Clears the safari view's cache using a completion handler.
/// - Parameter completionHandler: Closure to execute after the operation completes
@available(iOS 16.0, macCatalyst 16.0, *)
@available(iOS 16.0, macCatalyst 16.0, visionOS 1.0, *)
public static func clearWebsiteData(completionHandler: (() -> Void)?) {
SFSafariViewController.DataStore.default.clearWebsiteData(completionHandler: completionHandler)
}
Expand Down Expand Up @@ -265,11 +269,11 @@ public struct SafariView: View {
let configuration = SFSafariViewController.Configuration()
configuration.entersReaderIfAvailable = entersReaderIfAvailable
configuration.barCollapsingEnabled = barCollapsingEnabled
if #available(iOS 15.0, macCatalyst 15.0, *),
if #available(iOS 15.0, macCatalyst 15.0, visionOS 1.0, *),
let activityButton {
configuration.activityButton = unsafeDowncast(activityButton, to: SafariView.ActivityButton.self)
}
if #available(iOS 15.2, *),
if #available(iOS 15.2, visionOS 1.0, *),
let eventAttribution {
configuration.eventAttribution = unsafeDowncast(eventAttribution, to: UIEventAttribution.self)
}
Expand Down
Loading