I have a use case where I want to navigate to a destination view but also perform an event when the user interacts.
Outside of a List this code seems to work:
NavigationLink(destination: MyDestinationView()) {
HStack { /* content here */ }
}
.simultaneousGesture(TapGesture().onEnded { /* my action */ })
However, once you put that in a List either the navigation or the action, not both, will fire. Typically tapping anywhere in the HStack will navigate, but tapping on the Text objects will fire the action and not navigate. Is this an issue with List or is there an intended way of doing this that I am not seeing?
I also messed with contentShape and it ended up making the HStack fire the action and only the very edges of the cell would navigate. Like the rowItem could only handle 1 gesture event at a time.
I tried something like in the ForEach creating a view that had a body of: (view also had a state var of shouldNavigate)
Group {
NavigationLink(destination: MyView(), isActive: $shouldNavigate) { EmptyView() }
Button(action: { shouldNavigate = true }) {
HStack { /* myContent */ }
}
}
and that did not have the intended affect and made individual rows: one empty with chevron and one with the content but no chevron.