SwitUI - Two navigationLink in a list
Try the following approach - the idea is to hide links in background of visible content and make them inactive for UI, but activated programmatically.
Tested with Xcode 12 / iOS 14.
struct MultiNavLink: View {
var body: some View {
return
NavigationView {
List {
OneRowView()
}.navigationBarTitle("MultiNavLink", displayMode: .inline)
}
}
}
struct OneRowView: View {
@State var mb_isActive1 = false
@State var mb_isActive2 = false
var body: some View {
ZStack {
Text("Single tap::go to destination1\nDouble tap,go to destination2")
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.contentShape(Rectangle())
.background(Group {
NavigationLink(destination: Text("Destination1"), isActive: $mb_isActive1) {
EmptyView() }
.buttonStyle(PlainButtonStyle())
NavigationLink(destination: Text("Destination2"), isActive: $mb_isActive2) {
EmptyView() }
.buttonStyle(PlainButtonStyle())
}.disabled(true))
.highPriorityGesture(TapGesture(count: 2).onEnded {
self.mb_isActive2 = true
})
.onTapGesture(count: 1) {
self.mb_isActive1 = true
}
}
}
SwiftUI NavigationLink issue with multi selections
I can reproduce your issue, and I think this is a bug.
However using the following NavigationLink
setup with selection
and tag
seems to works for me.
struct ContentView: View {
@State var cars = [Car(name: "A"), Car(name: "B"), Car(name: "C"), Car(name: "D")]
@State private var showCar: UUID?
var body: some View {
NavigationView {
LazyVStack(spacing: 30) {
ForEach(cars) { car in
NavigationLink(
destination: CarDetailsView(car: car),
tag: car.id,
selection: $showCar,
label: { CarRowView(car: car) }
)
}
}
}
}
}
struct CarDetailsView: View {
@Environment(\.dismiss) private var dismiss
@State var car: Car
var body: some View {
Button("Back \(car.name)") {
dismiss()
}
}
}
struct Car: Identifiable, Hashable {
let id = UUID()
var name: String
}
struct CarRowView: View {
var car: Car
var body: some View {
Text(car.name)
}
}
Multiple NavigationLink in SwiftUI
Put your views inside a VStack:
struct Test : View {
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: Text("First")) {
Text("Visible")
}
NavigationLink(destination: Text("Second")) {
Text("Invisible")
}
//EDIT: Also Invisible
Text("Not rendered")
}
}
}
}
Related Topics
Could Not Cast Value of Type 'Uitableviewcell' to '(Appname).(Customcellname)'
iOS Check If Application Has Access to Microphone
React Native Xcode Project Product Archive Fails with Duplicate Symbols for Architecture Arm64
Swift 3 - How to Make Timer Work in Background
Round Top Corners of a Uiview and Add Border
How to Stop Symbolicate Adding "<Redacted>" Pieces to iOS Crash Log
Swift: Navigate to New Viewcontroller Using Button
Cannot Assign to Property in Protocol - Swift Compiler Error
How to Install iOS 7.0 and iOS 8.0 Simulators in Xcode 6.1
Make Uicollectionview Zoomable
iOS 11 Layout Guidance About Safe Area for iPhone X
Selecting a Word in a Uitextview
Does Webkit in iOS 11 (Beta) Support Webrtc
Constant Movement in Spritekit
Exc_Bad_Access Automatic Handling