Hello everyone, I wanted to post this as a sanity check before I create a Feedback for this bug.
I'm using Xcode 16.1 Beta (167B5001e) along with iOS 18.1 Beta.
When using a NavigationStack with a bindable path and navigating to another view while searching, it won't allow you to "pop to root" by resetting the path.
Here's some simple code:
// Base code from:
// https://sarunw.com/posts/how-to-pop-to-root-view-in-swiftui/
import SwiftUI
struct ContentView: View {
@State private var path: [Int] = []
var body: some View {
NavigationStack(path: $path) {
Button("Start") {
path.append(1)
}
.navigationDestination(for: Int.self) { int in
DetailView(path: $path, count: int)
}
.navigationTitle("Home")
}
}
}
struct DetailView: View {
@Binding var path: [Int]
@State private var searchText = ""
let count: Int
var body: some View {
Button("Go deeper") {
path.append(count + 1)
}
.navigationBarTitle(count.description)
.toolbar {
ToolbarItem(placement: .bottomBar) {
Button("Pop to Root") {
path = []
}
}
}
.searchable(text: $searchText)
}
}
To reproduce:
- Start app and tap "Start".
- Tap "Go deeper" to push a couple views onto the stack.
- With any DetailView, tap the Search bar to make it active.
- While the search bar is active, tap "Go deeper" to push another view.
- Tap "Pop to root".
You'll see that the path does indeed get reset, but the NavigationStack doesn't navigate anywhere. You're left with just empty views to go back to.
Here's a link to a video from the simulator:
https://streamable.com/m4bg5g
The above video shows it working normally, then another run that uses the search bar to show the issue. Identical code works as normal on iOS 17.
If anyone has any ideas, I'm all ears. Thank you for your time!
@bwalton It does pop to the root in iOS 18.0 beta, and this might be a regression in the 18.1 beta. Please file a bug report using Feedback Assistant and share the feedback number here for the record, see Bug Reporting: How and Why?