I have a List and in each row I put a button at the left end and a text label on the right next to it. I want this button to have an action and the entire row to also have a tap gesture. So how can I properly distinguish between the gestures so that when the use taps the button it does the action of the button, and when the user tap anywhere else in the row, it does the tap gesture of the row?
Here is my code for now:
List {
ForEach(items) { item in
HStack {
Button {
buttonAction()
} label: {
Image(systemName: "circle.fill")
}
Text("Row Title")
}
.onTapGesture {
rowAction()
}
}
}
Now, when I tap the button or the text it does the rowAction()
, whereas when I tap other places in the row it does the buttonAction()
.
HelloVictor2000 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.