Bug in Navigation From Section Rows

I've created a little demo of this. I have two sections, each of which have two rows. Each row has a navigation link to different text. When I click on a row in Section 1, both rows within that section fire and I get two navigation transitions. It's the same with rows in Section 2. The code is below. Each row should fire individually, not as a group.


struct NavLink : View {
    
    var body: some View {
        NavigationView {
            List {
                Section (header: Text("Section Header 1").font(.headline)) {
                    VStack (alignment: .leading) {
                        HStack {
                            NavigationLink(destination: Text("This will go to view 1.")) {
                                Text("Text1: ")
                                    .bold()
                                Text("More text 1")
                            }
                        }
                        Divider()
                        HStack {
                            NavigationLink(destination: Text("This will This will go to view 2.")) {
                                Text("Text2: ")
                                    .bold()
                                Text("More text 2")
                            }
                        }
                    }
                }
                Section (header: Text("Section Header 2").font(.headline)) {
                    VStack (alignment: .leading) {
                        HStack {
                            NavigationLink(destination: Text("This will go to view 3.")) {
                                Text("Text3: ")
                                    .bold()
                                Text("More text 3")
                            }
                        }
                        Divider()
                        HStack {
                            NavigationLink(destination: Text("This will go to view 4.")) {
                                Text("Text4: ")
                                    .bold()
                                Text("More text 4")
                            }
                        }
                    }
                }
            }
            .navigationBarTitle(Text("NavLink Demo"), displayMode: .automatic)
            .listStyle(.grouped)
        }
    }
}

Replies

I'm using macOS 10.14.5.

So, each cell is a HStack, correct ?


And when you hit, let's say, text1 and you go to view1, then view 2 ?

Yes, sir. Example: click on any row in Section 1 (yes, I'm countiung from 1, not 0) and it will first navigate to View 1 and then back and then navigate to View 2 and stay at View 2.

As I'm sure you know, tableviews consist of sections and rows. I should be able to indvidually navigate separately from any row in a section. I can see both rows highlight when I click on a row.


Since I'm using macOS 10.14.5, I don't have the suggestion app, thus I'm crying in my beer here, in hopes that the good folks at Apple take notice.

The bug is still there in Xcode beta 4.

Found what I guess one could call a fix. Instead of using VStacks, use Groups. Working code is below.


import SwiftUI

struct NavLink : View {
    
    var body: some View {
        NavigationView {
            List {
                Section (header: Text("Section Header 1").font(.headline)) {
                    Group {
                        HStack {
                            NavigationLink(destination: Text("This will go to view 1.")) {
                                Text("Text1: ")
                                    .bold()
                                Text("More text 1")
                            }
                        }
                        HStack {
                            NavigationLink(destination: Text("This will go to view 2.")) {
                                Text("Text2: ")
                                    .bold()
                                Text("More text 2")
                            }
                        }
                    }
                }
                Section (header: Text("Section Header 2").font(.headline)) {
                    Group {
                        HStack {
                            NavigationLink(destination: Text("This will go to view 3.")) {
                                Text("Text3: ")
                                    .bold()
                                Text("More text 3")
                            }
                        }
                        HStack {
                            NavigationLink(destination: Text("This will go to view 4.")) {
                                Text("Text4: ")
                                    .bold()
                                Text("More text 4")
                            }
                        }
                    }
                }
            }
            .navigationBarTitle(Text("NavLink Demo"), displayMode: .automatic)
            .listStyle(GroupedListStyle())
        }
    }
}
    
#if DEBUG
struct NavLink_Previews : PreviewProvider {
    static var previews: some View {
        NavLink()
    }
}
#endif