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()
}
}
}
}
}
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")
}
}
}
}