Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect taps on a List cell row in SwiftUI?

Given a basic List with Text, how can i make the whole "cell" from left side of the screen to right, tappable in a List, not just the "Hello world" text?

    List {
         VStack {
             Text("Hello world")
         }    
         .contentShape(Rectangle())
         .onTapGesture {
            print("Tapped cell")  // This only triggers when you directly tap the Text
         }
     }
like image 752
bogen Avatar asked Sep 12 '25 17:09

bogen


1 Answers

Add a Button and entire cell is tappable now:

VStack {
    Button(action: {
        print("Tapped")
    }) {
        Text("Hello world")
    }
}
like image 134
RTXGamer Avatar answered Sep 14 '25 07:09

RTXGamer