The accepted answer works, but it seems like the view does not really get de-initialized, leading to memory leaks.
There is a workaround to listen to the scenePhase changes as suggested and call dismissWindow(id: "Your-Window-Id"). Then onDisappear will be called as well and the view is de-initialized correctly.
.onDisappear {
// ...
}
.onChange(of: scenePhase) { oldValue, newValue in
if newValue == .background {
dismissWindow(id: "Your-Window-Id")
}
}
Is there already a feedback for this or a fix planned @Vision Pro Engineer? Even though the workaround works, it still seems a bit odd.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: