What's New / App UI: SwiftUI, AppKit & UIKit

What's new in _WebKit_SwiftUI

+4 NewvisionOS

_WebKit_SwiftUI is a Swift cross-import overlay, not a standalone framework. Its API is available only when a target imports both WebKit and SwiftUI, adding SwiftUI surface for web content.

The 27 SDK adds 4 APIs, with no deprecations or removals. The new struct WebViewImmersiveEnvironmentView ships with its nested WebViewImmersiveEnvironmentView.Body and a View modifier, View.onWebViewImmersiveEnvironmentRequest, for handling immersive environment requests from web content.

New

4
struct

WebViewImmersiveEnvironmentView

NewvisionOS
public struct WebViewImmersiveEnvironmentView : View

A SwiftUI view that renders a specific website-provided immersive environment.

Place this view in your app's Immersive Space hierarchy. Initialize it with the WebPage.ImmersiveEnvironment received from the presentation callback to render that specific environment.

Declaration
@MainActor public struct WebViewImmersiveEnvironmentView : View {

    /// Creates an immersive environment view from a ``WebPage/ImmersiveEnvironment``.
    @MainActor public init(_ environment: WebPage.ImmersiveEnvironment)

    /// Creates an immersive environment view from a `WKImmersiveEnvironment`.
    @MainActor public init(_ environment: WKImmersiveEnvironment)

    /// The content and behavior of the view.
    ///
    /// When you implement a custom view, you must implement a computed
    /// `body` property to provide the content for your view. Return a view
    /// that's composed of built-in views that SwiftUI provides, plus other
    /// composite views that you've already defined:
    ///
    ///     struct MyView: View {
    ///         var body: some View {
    ///             Text("Hello, World!")
    ///         }
    ///     }
    ///
    /// For more information about composing views and a view hierarchy,
    /// see <doc:Declaring-a-Custom-View>.
    @MainActor @preconcurrency public var body: some View { get }

    /// The type of view representing the body of this view.
    ///
    /// When you create a custom view, Swift infers this type from your
    /// implementation of the required ``View/body-swift.property`` property.
    @available(visionOS 27.0, *)
    @available(macOS, unavailable, introduced: 9999)
    @available(iOS, unavailable, introduced: 9999)
    @available(tvOS, unavailable)
    @available(watchOS, unavailable)
    public typealias Body = some View
}
extension

WebViewImmersiveEnvironmentView

NewvisionOS
extension WebViewImmersiveEnvironmentView : Sendable
Declaration
extension WebViewImmersiveEnvironmentView : Sendable {
}
func

View.onWebViewImmersiveEnvironmentRequest

NewvisionOS
nonisolated public func onWebViewImmersiveEnvironmentRequest(shouldAllow: @escaping @MainActor @Sendable (_ sourceFrame: WebPage.FrameInfo) async -> Bool, present: @escaping @MainActor @Sendable (_ environment: WebPage.ImmersiveEnvironment) async throws -> Void, dismiss: @escaping @MainActor @Sendable (_ environment: WebPage.ImmersiveEnvironment) async -> Void) -> some View

Manages the lifecycle of immersive environments requested by websites.

Use this modifier to control authorization, presentation, and dismissal of immersive environments from websites.

Parameters

shouldAllow
An async closure called when a website requests an immersive environment. This can be used to request user consent or apply custom authorization logic. It receives the source WebPage.FrameInfo and should return true to allow the environment presentation, or false to deny it.
present
An async throwing closure called after the environment has loaded and is ready for presentation. It receives the WebPage.ImmersiveEnvironment. Use this to open an Immersive Space containing a WebViewImmersiveEnvironmentView initialized with this environment. If another immersive space is already being presented, dismiss it first. This closure should return after the presentation transition completes.
dismiss
An async closure called when the website or the application asks to dismiss the immersive environment. It receives the WebPage.ImmersiveEnvironment to dismiss. This closure should return after the dismissal transition completes.

ReturnsA modified view that manages immersive environment lifecycle.

typealias

WebViewImmersiveEnvironmentView.Body

NewvisionOS
public typealias Body = some View

The type of view representing the body of this view.

When you create a custom view, Swift infers this type from your implementation of the required body-swift.property property.

No APIs match your filter.

← More in App UI: SwiftUI, AppKit & UIKit