Post

Replies

Boosts

Views

Activity

Reply to SwiftUI : NavigationStack in new iOS 18 TabView pushes twice when path in parameter
@sjb_s @dderg @brebispanique @DTS Engineer Here is the full code (a modification of @sjb_s 's example) that still DOESN'T work well. The main reason is that navigationDestination is located in View extension. It is how it is designed in my real app where I have a single navigationDestination for the whole app and all possible routes inside it. Everything works well in iOS 17.x with this approach, but still doesn't work well in iOS 18.0 Beta 5. Any ideas? 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) } .withAppRouter() } } } extension View { func withAppRouter() -> some View { navigationDestination(for: Item.self) { item in DetailView(item: item) } } } struct DetailView: View { var item: Item var body: some View { Text("Details...\(item.name)") } }
Aug ’24
Reply to iOS 18 beta bug: NavigationStack pushes the same view twice
@DTS Engineer thank you for your answer. But what I don't want to use the type-erased data representation and still want to use my custom data type. I need that for correct programmatic routing in my app and for understanding of the exact path of my current router. There is an Apple's API for that so I expect to use my custom type. It is still NOT FIXED in Xcode 16 beta 5 + iOS 18.0 beta 5 and the same issue happens. Any plans to fix it? Thank you. enum RouterDestination: Hashable { case next }
Aug ’24
Reply to SwiftUI : NavigationStack in new iOS 18 TabView pushes twice when path in parameter
I also face similar issue and wrote about it in another post: https://developer.apple.com/forums/thread/760041 I can confirm that the usage NavigationPath fixes this issue but the other issues appear. A views that weren't pushed appear in path and I have to pop the several times. So it seems that the combination TabView + NavigationStack inside is buggy. Two notes: I tried to use iOS 17+ @Observable approach. It didn’t help. Using @State var path: [RouterDestination] = [] directly inside View seems to help. But it is not what I want as I need this property to be @Published and located inside custom Router class where I can get an access to it, and use for programmatic navigation if needed.
Jul ’24