Post

Replies

Boosts

Views

Activity

Reply to SwiftUI : NavigationStack in new iOS 18 TabView pushes twice when path in parameter
@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
Aug ’24
Reply to SwiftUI : NavigationStack in new iOS 18 TabView pushes twice when path in parameter
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() }
Aug ’24