AFAIK there's no way to programmatically detect when an ImmersiveSpaceContent is dismissed by a user (i.e. by pressing the home button).
By comparison, ImmersiveView has .onAppear()
and .onDisappear()
:
ImmersiveSpace(id: appModel.immersiveSpaceID) {
ImmersiveView()
.environment(appModel)
.onAppear {
appModel.immersiveSpaceState = .open
}
.onDisappear {
appModel.immersiveSpaceState = .closed
}
}
In comparison:
// No similar callbacks for here:
struct MyImmersiveSpace: ImmersiveSpaceContent {
var body: CompositorLayer { /* ... */ }
}
Hi there, I actually found a way to do this via the layerRenderer state!
For reference:
func renderLoop() async throws {
// Render loop.
while true {
if self._layerRenderer.state == .invalidated {
// background.
} else if self._layerRenderer.state == .paused {
// inactive
} else {
// active
}
}
}