Hi, I'm working on visionOS and find I can't get onDisappear event just on the first window after app launch. It comes like that:
WindowGroup(id:"WindowA"){
MyView()
.onDisappear(){
print("WindowA disappear")
}
}
WindowGroup(id:"WindowB"){
MyView()
.onDisappear(){
print("WindowB disappear")
}
}
WindowGroup(id:"WindowC"){
MyView()
.onDisappear(){
print("WindowC disappear")
}
}
- When the app first launch, it will open WindowA automatically
- And then I open WindowB and WindowC programatically.
- Then I tap the close button on window bar below window.
- If I close WindowB/WindowC, I can receive onDisappear event
- If I close WindowA, I can't receive onDisappear event
- If I reopen WindowA after it is closed and then close it again by tap the close button below window, I can receive onDisappear event
Is there any logic difference for the first window on app launch? How can I get onDisappear Event for it.
I'm using Xcode 16 beta 2
@wangdinglu , try also putting scenePhase
in the view you want to check the phase of.
scenePhase gives you different values depending on where you read it from. The app level is an aggregate of the phases of the windows of your app.
If you put it in the view, it reports the phase of the view.
For instance, if you have a ContentView and an ImmersiveSpace, and with the ImmersiveSpace open you want to see when ContentView is closed (and it's the only window open), scenePhase in ContentView would tell you when that window was closed.