From a91f2a6395dd98908ab495c998b4a5cd02d71547 Mon Sep 17 00:00:00 2001 From: Varun Santhanam Date: Sat, 23 Mar 2024 15:39:44 -0700 Subject: [PATCH] Add support for visionOS 1.x --- Package.swift | 3 ++- Sources/SafariView/DismissButtonStyle.swift | 2 +- Sources/SafariView/Environment.swift | 18 +++++++------- .../SafariView/ExcludedActivityTypes.swift | 2 +- Sources/SafariView/IncludedActivities.swift | 2 +- Sources/SafariView/Modifiers.swift | 16 ++++++------- .../Presentation/BoolPresentation.swift | 8 +++---- .../Presentation/BoolURLPresentation.swift | 4 ++-- .../Presentation/ItemPresentation.swift | 8 +++---- .../Presentation/URLPresentation.swift | 4 ++-- .../WrappedItemPresentation.swift | 4 ++-- Sources/SafariView/PrewarmingToken.swift | 2 +- Sources/SafariView/SafariView.swift | 24 +++++++++++-------- 13 files changed, 51 insertions(+), 46 deletions(-) diff --git a/Package.swift b/Package.swift index 6d5d0901c..c7d906c07 100644 --- a/Package.swift +++ b/Package.swift @@ -7,7 +7,8 @@ let package = Package( name: "SafariUI", platforms: [ .iOS(.v14), - .macCatalyst(.v14) + .macCatalyst(.v14), + .visionOS(.v1) ], products: [ .library( diff --git a/Sources/SafariView/DismissButtonStyle.swift b/Sources/SafariView/DismissButtonStyle.swift index 7b34d93e1..8dfcdd98a 100644 --- a/Sources/SafariView/DismissButtonStyle.swift +++ b/Sources/SafariView/DismissButtonStyle.swift @@ -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`` diff --git a/Sources/SafariView/Environment.swift b/Sources/SafariView/Environment.swift index 5b476b9a8..8111aa0ef 100644 --- a/Sources/SafariView/Environment.swift +++ b/Sources/SafariView/Environment.swift @@ -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`` @@ -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 { @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/Sources/SafariView/ExcludedActivityTypes.swift b/Sources/SafariView/ExcludedActivityTypes.swift index c4cb65f8e..0fa31681c 100644 --- a/Sources/SafariView/ExcludedActivityTypes.swift +++ b/Sources/SafariView/ExcludedActivityTypes.swift @@ -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``. diff --git a/Sources/SafariView/IncludedActivities.swift b/Sources/SafariView/IncludedActivities.swift index 3f3ac81a8..c1e9d8cfd 100644 --- a/Sources/SafariView/IncludedActivities.swift +++ b/Sources/SafariView/IncludedActivities.swift @@ -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`` diff --git a/Sources/SafariView/Modifiers.swift b/Sources/SafariView/Modifiers.swift index 8547da5e2..36517a624 100644 --- a/Sources/SafariView/Modifiers.swift +++ b/Sources/SafariView/Modifiers.swift @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/Sources/SafariView/Presentation/BoolPresentation.swift b/Sources/SafariView/Presentation/BoolPresentation.swift index e96d7b2af..aeb95f081 100644 --- a/Sources/SafariView/Presentation/BoolPresentation.swift +++ b/Sources/SafariView/Presentation/BoolPresentation.swift @@ -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`. @@ -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 @@ -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) } diff --git a/Sources/SafariView/Presentation/BoolURLPresentation.swift b/Sources/SafariView/Presentation/BoolURLPresentation.swift index ec3ca4b84..acf112c37 100644 --- a/Sources/SafariView/Presentation/BoolURLPresentation.swift +++ b/Sources/SafariView/Presentation/BoolURLPresentation.swift @@ -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`. @@ -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( diff --git a/Sources/SafariView/Presentation/ItemPresentation.swift b/Sources/SafariView/Presentation/ItemPresentation.swift index caeee2ba3..b9cab2408 100644 --- a/Sources/SafariView/Presentation/ItemPresentation.swift +++ b/Sources/SafariView/Presentation/ItemPresentation.swift @@ -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. @@ -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: ViewModifier where Item: Identifiable { // MARK: - Initializers @@ -283,11 +283,11 @@ private struct ItemModifier: 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) } diff --git a/Sources/SafariView/Presentation/URLPresentation.swift b/Sources/SafariView/Presentation/URLPresentation.swift index b37dd4950..49786d74e 100644 --- a/Sources/SafariView/Presentation/URLPresentation.swift +++ b/Sources/SafariView/Presentation/URLPresentation.swift @@ -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. @@ -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( diff --git a/Sources/SafariView/Presentation/WrappedItemPresentation.swift b/Sources/SafariView/Presentation/WrappedItemPresentation.swift index 59871a4d4..c16af644e 100644 --- a/Sources/SafariView/Presentation/WrappedItemPresentation.swift +++ b/Sources/SafariView/Presentation/WrappedItemPresentation.swift @@ -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. @@ -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: ViewModifier where ID: Hashable { // MARK: - Initializer diff --git a/Sources/SafariView/PrewarmingToken.swift b/Sources/SafariView/PrewarmingToken.swift index 6658e2fec..a2a75a3bd 100644 --- a/Sources/SafariView/PrewarmingToken.swift +++ b/Sources/SafariView/PrewarmingToken.swift @@ -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. diff --git a/Sources/SafariView/SafariView.swift b/Sources/SafariView/SafariView.swift index ffef8fe97..902b4fd15 100644 --- a/Sources/SafariView/SafariView.swift +++ b/Sources/SafariView/SafariView.swift @@ -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 @@ -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?, @@ -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, @@ -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 @@ -120,7 +120,7 @@ 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) @@ -128,14 +128,18 @@ public struct SafariView: View { } /// 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) } @@ -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) }