<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macOS: 26.0.0 -",
    "visionOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/CompositorContent/onImmersionChange(initial:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI17CompositorContentPAAE17onImmersionChange7initial_QrSb_yAA0fG7ContextV_AGtctF"
  },
  "title" : "onImmersionChange(initial:_:)"
}
-->

# onImmersionChange(initial:_:)

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

```
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.

- oldValue: The value representing the old state of immersion.
- newValue: The value representing the current state of immersion.

## 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.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)