NavigationLink selection wrong behavior on iPad

Originator:nossa.dev
Number:rdar://FB7685059 Date Originated:2020/05/02
Status:Open Resolved:
Product:SwiftUI Framework Product Version:
Classification:Incorrect/Unexpected Behavior Reproducible:Yes
 
Description:
Using a NavigationLink on iPad landscape inside a NavigationView with DoubleColumnNavigationViewStyle, the selection parameter get setted to nil when you try to select another link and there is already a selected item.

Steps to reproduce:
I have attached the minimum ContentView code to reproduce the issue.
You have to create NavigationLinks using `init<V>(destination: Destination, tag: V, selection: Binding<V?>, label: () -> Label) where V : Hashable`

Expected:
The selection Binding should be updated accordingly to the current selected item.

Actual result:
The selection Binding is updated correctly only when the selection is currently nil. Otherwise it is setted to nil instead of the actual selection tag value.

```
import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationView {
            MasterView()
                .navigationBarTitle(Text("Master"))
            DetailView()
        }.navigationViewStyle(DoubleColumnNavigationViewStyle())
    }
}

struct MasterView: View {
    private var dates = ["First", "Second", "Third"]
    
    @State var selection: Int? = nil

    var body: some View {
        VStack(alignment: .leading, spacing: 10) {
            NavigationLink(destination: DetailView(selectedViewName: dates[0]), tag: 0, selection: $selection) {
                Text(dates[0])
                if (selection == 0) {
                    Text("SELECTED")
                }
            }
            NavigationLink(destination: DetailView(selectedViewName: dates[1]), tag: 1, selection: $selection) {
                Text(dates[1])
                if (selection == 1) {
                    Text("SELECTED")
                }
            }
            NavigationLink(destination: DetailView(selectedViewName: dates[2]), tag: 2, selection: $selection) {
                Text(dates[2])
                if (selection == 2) {
                    Text("SELECTED")
                }
            }
            
//            Spacer()
        }
    }
}

struct DetailView: View {
    var selectedViewName: String?

    var body: some View {
        Group {
            if selectedViewName != nil {
                Text(selectedViewName!)
            } else {
                Text("Detail view content goes here")
            }
        }.navigationBarTitle(Text("Detail"))
    }
}


struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

```

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!