How to Active NavigationLink at Change Data in iOS 16

NavigationLink(destination:isActive:label:) is deprecated in iOS 16

How to implement below View in iOS 16 without Deprecated?

struct ContentView: View {

  @State var isPresentedDetailView = false

  @State var isPresentedImageView = false



  var body: some View {

    NavigationStack {

      List {

        HStack {

          Button("Name") { isPresentedDetailView.toggle() }



          NavigationLink(isActive: $isPresentedDetailView) {

            Text("Detail View")

          } label: {

            EmptyView()

          }

          .frame(width: 0, height: 0)

          .hidden()



          Image(systemName: "person")

            .onTapGesture {

              isPresentedImageView.toggle()

            }



          NavigationLink(isActive: $isPresentedImageView) {

            Image(systemName: "person")

          } label: {

            EmptyView()

          }

          .frame(width: 0, height: 0)

          .hidden()

        }

      }

    }

  }

}
Answered by zunda in 723249022

I fixed with navigationDestination(isPresented:)

import SwiftUI



struct ContentView: View {

  @State var isPresentedDetailView = false

  @State var isPresentedImageView = false



  var body: some View {

    NavigationStack {

      List {

        HStack {

          Text("Name")

            .onTapGesture {

              isPresentedDetailView.toggle()

            }



          Image(systemName: "person")

            .onTapGesture {

              isPresentedImageView.toggle()

            }

        }

      }

      .navigationDestination(isPresented: $isPresentedImageView) {

        Image(systemName: "person")

      }

      .navigationDestination(isPresented: $isPresentedDetailView) {

        Text("Detail View")

      }

    }

  }

}

Can you please watch https://developer.apple.com/wwdc22/10054, it goes into great detail step by step about the new navigation APIs

https://developer.apple.com/wwdc22/10054 doesn't explain multi NavigationLink in one cell.

Accepted Answer

I fixed with navigationDestination(isPresented:)

import SwiftUI



struct ContentView: View {

  @State var isPresentedDetailView = false

  @State var isPresentedImageView = false



  var body: some View {

    NavigationStack {

      List {

        HStack {

          Text("Name")

            .onTapGesture {

              isPresentedDetailView.toggle()

            }



          Image(systemName: "person")

            .onTapGesture {

              isPresentedImageView.toggle()

            }

        }

      }

      .navigationDestination(isPresented: $isPresentedImageView) {

        Image(systemName: "person")

      }

      .navigationDestination(isPresented: $isPresentedDetailView) {

        Text("Detail View")

      }

    }

  }

}
How to Active NavigationLink at Change Data in iOS 16
 
 
Q