Collapsing NavigationStack When NavigationSplitView is Backgrounded on iPadOS 17.x

I'm pursuing a design that necessitates a dual app architecture — using a NavigationStack for compact-sized screens, and a NavigationSplitView for regular-sized screens.

I've encountered what might be a bug in NavigationSplitView on iPadOS 17.x. Or perhaps it's a mistake in my code.

When navigating into nested views (relying on NavigationPath), everything works fine... until I background the app on iPad.

At this point, the navigation stack appears to collapse in the NavigationSplitView detail area — merging the parent and child views.

Adding to the mystery... I can reproduce this bug on iPadOS 17.x. But the problem goes away when running on iPadOS 18.x beta.

Key questions:

  1. Is there a problem in my code?
  2. Should I file a feedback with the Apple SwiftUI team?
  3. If iPadOS 18.x fixes this bug, can I expect a SwiftUI fix to be back-ported to 17.x or earlier?

Steps to reproduce:

  1. Run my sample code on iPadOS simulator.
  2. Navigate to select a color, and then a shape.
  3. Put the app into the background (e.g., go to Home Screen).
  4. Return to app.

What you can expect:

When running on iPadOS 17.x, you'll see that the two most recent views in the stack have merged (meaning the title has changed, and the "back" button has disappeared).

On iPadOS 18.x, you'll see that everything is working fine (title isn't changed, and back button remains available).

Answered by Vision Pro Engineer in 797142022

Hey @p98 ,

Sorry for the delay, would you mind mentioning me with the "@" sign, it makes it easier for me to see when there's a response :)

Ah I see what the issue is now. This is a known issue with the toolbar item disappearing in the content view of a NavigationSplitView in 11inch iPads. Please file a bug report at https://feedbackassistant.apple.com and post the FB number here. You'll be able to follow the status of it if you do this.

Also, you mentioned

when trying to add .searchable() with its own NavigationStack to the root-level sidebar section of NavigationSplitView. It seems that NavigationStack isn't something that SwiftUI wants in that part of the NavigationSplitView.

Although you shouldn't add NavigationStack, you can definitely add the .searchable modifier here. Just add it to the bottom of your NavigationSplitView and you can control the placement yourself to be in the sidebar, as shown here. https://developer.apple.com/documentation/swiftui/adding-a-search-interface-to-your-app#Control-the-placement-programmatically

Before backgrounding the app:

After backgrounding the app:

hi @p98 ,

I downloaded your project and ran it on iPad simulators on both iOS 17.5 and iOS 18. I was unable to reproduce the issue on iOS 17.5 though, is there a specific device that you've seen this happen with more often? Or even a lower iOS version?

One other thing to note, NavigationSplitView will automatically collapse for you when the body is compact. Your use case might be different, but in this simplified project, if you remove the variables to check whether the size class is compact and just run bodyRegular no matter what, you'll se that it'll collapse into the NavigationStack for you when you turn the iPad.

Thank you for the quick reply.

I'm still seeing the buggy behavior on my side. Here are the steps I'm taking:

  1. Open sample project in Xcode 15.4.
  2. Run on simulator for iPad Pro 11-inch (M4) with iOS 17.5.
  3. Use sidebar to select color.
  4. Use detail view to select shape.
  5. Make note of detail view title ("Color + Shape") and presence of "< Shapes" back button in top left of detail view.
  6. Put app into background (e.g., press ⇧⌘H, or use the simulator's Home button).
  7. Wait 2–5 seconds.
  8. Bring app back into foreground.
  9. Note that app detail view's title has changed ("Shapes") and back button is missing.

Let me know if those steps work for you.

I appreciate your advice regarding NavigationSplitView and its (very helpful) automatic adaptation for compact screens. That was actually my first choice. I ran into trouble, however, when trying to add .searchable() with its own NavigationStack to the root-level sidebar section of NavigationSplitView. It seems that NavigationStack isn't something that SwiftUI wants in that part of the NavigationSplitView. Thus, the less-optimal workaround with dynamic rendering based on @Environment(\.horizontalSizeClass).

Accepted Answer

Hey @p98 ,

Sorry for the delay, would you mind mentioning me with the "@" sign, it makes it easier for me to see when there's a response :)

Ah I see what the issue is now. This is a known issue with the toolbar item disappearing in the content view of a NavigationSplitView in 11inch iPads. Please file a bug report at https://feedbackassistant.apple.com and post the FB number here. You'll be able to follow the status of it if you do this.

Also, you mentioned

when trying to add .searchable() with its own NavigationStack to the root-level sidebar section of NavigationSplitView. It seems that NavigationStack isn't something that SwiftUI wants in that part of the NavigationSplitView.

Although you shouldn't add NavigationStack, you can definitely add the .searchable modifier here. Just add it to the bottom of your NavigationSplitView and you can control the placement yourself to be in the sidebar, as shown here. https://developer.apple.com/documentation/swiftui/adding-a-search-interface-to-your-app#Control-the-placement-programmatically

Thanks for confirming the known issue, @Vision Pro Engineer. I have opened FB14493265.

I appreciate the recommendations on .searchable. You're right, SwiftUI's flexibility on search-field placement is helpful. The trouble is, my search results require nested/hierarchical navigation. Thus, the theoretical need for NavigationStack (paired with NavigationPath) at some level inside or above .searchable, which seems to be quietly forbidden by NavigationSplitView in its parent sidebar view.

Collapsing NavigationStack When NavigationSplitView is Backgrounded on iPadOS 17.x
 
 
Q