Ok, here is very simple demo of the approach. The idea is to keep NavigationLink out of List and activate it manually on row tap (which becomes easily tappable w/o navigation link inside)... everything else, like animations, effects, and kind of highlight is up to you.
import SwiftUI
import UIKit
struct TestCustomCellHighlight: View {
@State var selection: Int = -1
@State var highlight = false
@State var showDetails = false
init() {
UITableViewCell.appearance().selectionStyle = .none
}
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: Text("Details \(self.selection)"), isActive: $showDetails) {
EmptyView()
}
List(0..<20, id: \.self) { i in
HStack {
Text("Item \(i)")
Spacer()
}
.padding(.vertical, 6)
.background(Color.white) // to be tappable row-wide
.overlay(self.highlightView(for: i))
.onTapGesture {
self.selection = i
self.highlight = true
// delay link activation to see selection effect
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
self.highlight = false
self.showDetails = true
}
}
}
}
}
}
private func highlightView(for index: Int) -> AnyView {
if self.highlight && self.selection == index {
return AnyView(Rectangle().inset(by: -5).fill(Color.red.opacity(0.5)))
} else {
return AnyView(EmptyView())
}
}
}
struct TestCustomCellHighlight_Previews: PreviewProvider {
static var previews: some View {
TestCustomCellHighlight()
}
}
Button
it works – Expostulation