Unable to Retain Main App Window State When Transitioning to Immersive Space

In Vision OS app, I have two types of windows:

  1. Main App Window – This is the default window that launches when the app starts. It displays the video listings and other primary content.
  2. Immersive Space Window – This opens only when a user starts streaming or playing a video.

Issue: When entering the immersive space, the main app window remains visible in front of it unless manually closed. To avoid this, I currently close the main window when transitioning to immersive space and reopen it when exiting from immersive space. However, this causes the app to restart instead of resuming from its previous state.

Desired Behavior:

I want the main app window to retain its state and seamlessly resume from where it was before entering immersive mode, rather than restarting.

Attempts & Challenges:

  • Tried managing opacity, visibility but none worked as expected.
  • Couldn’t find a way to push the main window to the background while bringing the immersive space to the foreground.

Looking for a solution to keep the main window’s state intact while transitioning between immersive and normal modes.

Unfortunately, there aren't too many great options for this in visionOS right now. I've approached this in two ways so far.

Idea 1: manage the opacity / alpha of the main window. Apple did this in the Hello World. This is only suitable for quick trips into a space where the user won't be interacting with much. They may still see the window bar even though the window contents are hidden.

Some tips to improve this option

  • Use plain window style to remove the glass background, then add your own glass background when you want to show content
  • try using .persistentSystemOverlays(.hidden) to hide the window bar when you're in the space

Idea 2: keep track of window state and restore it when reopening the main window. You could keep track of navigation history, scroll position, view state, etc. This could be a great option and is less of a hack. But if your window has very complex views and hierarchy, this could be end up being very complex.

Unable to Retain Main App Window State When Transitioning to Immersive Space
 
 
Q