Hello,
I am new to swiftUI and VisionOS but I developed an app with a window and an ImmersiveSpace. I want the Immersive space to be dismissed when the window/app is closed.
I have the code below using the state of ScenePhase and it was working fine in Vision OS 1.1 but it stopped working with VisionOS 2.0.
Any idea what I am doing wrong? Is there another way to handle the dismissal of ImmersiveSpace when my main Window is closed?
@main
struct MyApp: App {
@State private var viewModel = ViewModel()
var body: some Scene {
@Environment(\.scenePhase) var scenePhase
@Environment(\.dismissImmersiveSpace) var dismissImmersiveSpace
WindowGroup {
SideBarView()
.environment(viewModel)
.frame(width: 1150,height: 700)
.onChange(of: scenePhase, { oldValue, newValue in
if newValue == .inactive || newValue == .background {
Task {
await dismissImmersiveSpace()
viewModel.immersiveSpaceIsShown = false
}
}
})
}.windowResizability(.contentSize)
ImmersiveSpace(id: "ImmersiveSpace") {
ImmersiveView(area: viewModel.currentModel)
.environment(viewModel)
}
}
}