How it works
MixedImmersionStyle is an immersion style that displays your app's virtual content alongside passthrough video of the person's real surroundings, so the digital scene appears to coexist with the physical room rather than replace it. Reach for it when you open an immersive space but want people to remain aware of and connected to their environment — the default, least-enveloping option on visionOS. You don't construct it directly in most code; instead you refer to it through the ImmersionStyle protocol's mixed value and hand that to the immersionStyle(selection:in:) modifier. Switching to a different conforming style, such as FullImmersionStyle, changes how completely the virtual content occludes the world.
Refer to the style through ImmersionStyle.mixed
Rather than calling an initializer, you name the style through the
ImmersionStyleprotocol's staticmixedmember. In the example the selected style is held in@State private var style: any ImmersionStyle = .mixed, declared as an existentialany ImmersionStyleso it can also hold other conforming styles.MixedImmersionStyleis the concrete type that.mixedresolves to.Store the active style in state you can change
Because immersion style is a runtime choice, you keep it in mutable state so the view updates when it changes. Here
styleis@State, and thesetclosure of theBindingreassignsstyle = .mixed. Keeping the value in state is what lets a control drive whichImmersionStyleis in effect.Distinguish styles by their concrete type
Each immersion style is a distinct type conforming to
ImmersionStyle, so you can tell them apart at runtime. Thegetclosure usesString(describing: type(of: style)), which reports"MixedImmersionStyle"when.mixedis active and"FullImmersionStyle"for the full style — the same names used as thetagvalues on thePickerrows.Offer the alternatives alongside mixed
MixedImmersionStylesits in a family withFullImmersionStyleandProgressiveImmersionStyle. ThePickerlistsText("Mixed")andText("Full")so the choice between blending content into the room and fully enveloping the person is explicit. In an immersive-space app you would pass the chosen value to theimmersionStyle(selection:in:)modifier on your scene.
set closure from style = .mixed to style = .full so selecting a different segment swaps the active ImmersionStyle, and watch the displayed type name update accordingly.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.
struct MixedImmersionStyleDemo: 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: { String(describing: type(of: style)) },
set: { _ in style = .mixed }
)) {
Text("Mixed").tag("MixedImmersionStyle")
Text("Full").tag("FullImmersionStyle")
}
.pickerStyle(.segmented)
Text("Mixed blends virtual content with your real surroundings.")
.font(.caption)
.foregroundStyle(.secondary)
.multilineTextAlignment(.center)
}
.padding()
}
}