I was using a NavigationPath (this is in my real app, not in my test code), and found that removing that fixed all my issues. My use is pretty simple and I don't need to use a path with the NavigationStack
Post
Replies
Boosts
Views
Activity
@ulian_onua I spoke too soon, and the issue does still occur, just much less frequently than before. While most of the time I no longer see the double-push of views, in some situations the exact same code will do a double-push. I don't know what makes those situations different than the situations where it doesn't happen.
So, in short, the issue is NOT fixed in iOS 18.1 beta 2
This is a content view for a test app that had the issue pre-beta 5, but works fine on my iPad with beta 5
import SwiftUI
class Item: Identifiable, Hashable {
var name: String
init(name: String) {
self.name = name
}
static func == (lhs: Item, rhs: Item) -> Bool {
lhs.name == rhs.name
}
func hash(into hasher: inout Hasher) {
hasher.combine(name)
}
}
class Model: ObservableObject {
@Published var path = [Item]()
}
struct ContentView: View {
var items = [
Item(name: "Item 1"),
Item(name: "Item 2"),
Item(name: "Item 3"),
]
@StateObject private var model = Model()
var body: some View {
TabView {
Text("Go to Tab 2")
.tabItem { Label("Tab 1", systemImage: "storefront") }
.tag("1")
tab2()
.tabItem { Label("Tab 2", systemImage: "globe") }
.tag("2")
}
}
@ViewBuilder
func tab2() -> some View {
NavigationStack(path: $model.path) {
List(items) { item in
NavigationLink(item.name, value: item)
}
.navigationDestination(for: Item.self) { item in
DetailView(item: item)
}
}
}
}
struct DetailView: View {
var item: Item
var body: some View {
Text("Details...\(item.name)")
}
}
#Preview {
ContentView()
}
Only tried on my iPad as yet, and it does seem to be fixed in beta 5
I can confirm that everything works correct when using the NavigationStack outside a TabView. Inside a TabView, even if there is only a single tab, exhibits incorrect behaviour
I am seeing the same thing. App that works fine on 17.5 is quite broken on 18. I also notice that after navigating back and forth a few times the whole navigation stack seems corrupted. Old views that you have previously popped re-appear in the wrong context in the navigation stack, and views are not completely drawn