NavigationLink stops working if I add a .onLongPressGesture to my label element.
Since .onTapGesture and .onLongPressGesture work well together, I thought these could coexist as well.
I’ve found answers that solved this for the old NavigationLink(titleKey:destination:isActive:) but none for the new NavigationLink(value:label:)
import SwiftUI
struct CombineLongPressAndNavigationLink: View {
@State private var rowColor: Color = .red
var body: some View {
NavigationStack {
ForEach(0..<50) { index in
NavigationLink(value: index) {
Rectangle().fill(rowColor)
.frame(height: 40)
.overlay {
Text("Navigate to (index)")
}
// Uncomment and NavigationLink stops working
// .onLongPressGesture {
// rowColor = rowColor == .red ? .green : .red
// }
}
}
.navigationDestination(for: Int.self) { index in
Text("(index)")
}
}
}
}