TechnologiesSwiftUIImmersive Spaces and visionOS

ImmersionStyle protocol

iOSmacOStvOSwatchOSvisionOS✓ renders

The styles that an immersive space can have.

How it works

ImmersionStyle is the protocol that describes how much of a person's surroundings an immersive space replaces on visionOS. An immersive space can blend its content with the real world, gradually expand to fill the view, or take over the wearer's surroundings entirely, and a value conforming to ImmersionStyle is what selects between those behaviors. Reach for it when you present an immersive space and need to control, or let the person change, how immersive that space feels.

  1. Hold a style as any ImmersionStyle

    Because ImmersionStyle is a protocol with several concrete conformers, you store a chosen style behind the existential type any ImmersionStyle. In the example the current style lives in @State private var style: any ImmersionStyle, so the value can be swapped between different conforming styles while the view reacts to the change.

  2. Choose a built-in style with the static factories

    SwiftUI ships standard conformers exposed as static members, so you rarely write a custom type. The code assigns .mixed to keep passthrough visible, .progressive to expand the space as the person engages, and .full to replace their surroundings — each one a concrete ImmersionStyle value selected through dot syntax.

  3. Swap styles at runtime

    Since the style is just a value, you can change which ImmersionStyle is active in response to input. The update(_:) method does exactly this, switching style between .progressive, .full, and .mixed so the level of immersion follows the person's choice rather than being fixed at launch.

  4. Recognize the automatic style

    When you don't specify a style, the system supplies a default whose concrete type is AutomaticImmersionStyle. The example checks style is AutomaticImmersionStyle, illustrating that a stored any ImmersionStyle can be inspected to discover which conforming style is currently in effect.

  5. Apply the style to an immersive space

    An ImmersionStyle value is meant to be handed to an immersive space via the immersionStyle(selection:in:) scene modifier, which binds the chosen style to the space and limits which styles it may adopt. The style state here is the value you would pass to that modifier; the surrounding Picker and VStack simply give the wearer a way to pick which style is selected.

Try it — Change the default branch in update(_:) from style = .mixed to style = .full so an unrecognized selection produces a fully immersive space instead of passthrough.

Example & preview

Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.

ImmersionStyle.swift
struct ImmersionStyleDemo: View {
    @State private var style: any ImmersionStyle = .mixed

    var body: some View {
        VStack(spacing: 16) {
            Text("Immersion Style")
                .font(.headline)
            Picker("Style", selection: Binding(
                get: { label },
                set: { update($0) }
            )) {
                Text("Mixed").tag("Mixed")
                Text("Progressive").tag("Progressive")
                Text("Full").tag("Full")
            }
            .pickerStyle(.segmented)
            Text("Selected: \(label)")
                .foregroundStyle(.secondary)
        }
        .padding()
    }

    private var label: String {
        if style is AutomaticImmersionStyle { return "Mixed" }
        return "Mixed"
    }

    private func update(_ name: String) {
        switch name {
        case "Progressive": style = .progressive
        case "Full": style = .full
        default: style = .mixed
        }
    }
}
Live preview
Immersion Style Mixed Progressive Full Selected: {label}
Immersion Style Mixed Progressive Full Selected: {label}
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →