---
title: "onImmersionChange(initial:_:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/compositorcontent/onimmersionchange(initial:_:)"
---

# onImmersionChange(initial:_:)

Performs an action when the immersion state of your app changes.

## Declaration

```swift
nonisolated func onImmersionChange(initial: Bool = true, _ action: @escaping (ImmersionChangeContext, ImmersionChangeContext) -> Void) -> some CompositorContent

```

## Parameters

- `initial`: Whether the action should be run when this view initially appears.
- `action`: A closure to run when the immersion changes.

## Discussion

Discussion Depending on the immersion style used for the Immersive Space in your app, the amount of immersion can be controlled by actions such as turning the Digital Crown. Use this modifier to define a closure that is run when the immersion state changes.
