Tokamak icon indicating copy to clipboard operation
Tokamak copied to clipboard

Add support for `tag` argument in `NavigationLink`

Open MaxDesiatov opened this issue 3 years ago • 0 comments

This initializer is currently missing:

public init<V>(
  destination: Destination,
  tag: V,
  selection: Binding<V?>,
  @ViewBuilder label: () -> Label
) where V: Hashable

Test case:

struct ContentView: View {
    @State private var selection: String? = nil

    var body: some View {
        NavigationView {
            VStack {
                NavigationLink(destination: Text("Second View"), tag: "Second", selection: $selection) { EmptyView() }
                NavigationLink(destination: Text("Third View"), tag: "Third", selection: $selection) { EmptyView() }
                Button("Tap to show second") {
                    self.selection = "Second"
                }
                Button("Tap to show third") {
                    self.selection = "Third"
                }
            }
            .navigationBarTitle("Navigation")
        }
    }
}

MaxDesiatov avatar Dec 04 '20 16:12 MaxDesiatov