Skip to content

Commit

Permalink
Add support for tvOS & visionOS
Browse files Browse the repository at this point in the history
  • Loading branch information
vsanthanam committed Mar 23, 2024
1 parent 518296c commit 8272537
Show file tree
Hide file tree
Showing 19 changed files with 58 additions and 44 deletions.
4 changes: 3 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ let package = Package(
name: "SafariUI",
platforms: [
.iOS(.v14),
.macCatalyst(.v14)
.macCatalyst(.v14),
.tvOS(.v14),
.visionOS(.v1)
],
products: [
.library(
Expand Down
4 changes: 4 additions & 0 deletions Sources/SafariUI/SafariUI.docc/SafariView.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ UI features include the following:

- Note: In Mac apps built with Mac Catalyst, SafariView launches the default web browser instead of displaying a modal window. SafariView is not compatible with macOS, tvOS, or watchOS.

### Presenting the view in your interface

You can present a `SafariView` using the built-in presentation view modifiers:

- ``SwiftUI/View/safari(isPresented:onDismiss:safariView:)``
Expand All @@ -27,6 +29,8 @@ You can present a `SafariView` using the built-in presentation view modifiers:

You can also use sheet presentation, or any other presentation mechanism of your choice.

- Important: Don’t embed an `SafariView` as a child of a complex view inside your app. Always present it modally using `.sheet`, or using one of the provided modifiers. Do not wrap it in a view.

## Topics

### Creating a Safari View
Expand Down
1 change: 1 addition & 0 deletions Sources/SafariUI/SafariUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
@_exported import SafariView
@_exported import WebAuthentication

@available(iOS 14.0, macCatalyst 14.0, tvOS 14.0, visionOS 1.0, *)
struct SafariUIHolder {}
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
4 changes: 2 additions & 2 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
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
4 changes: 2 additions & 2 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
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
18 changes: 9 additions & 9 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,22 @@ 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()
}

/// 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 +265,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

0 comments on commit 8272537

Please sign in to comment.