Interesting benefit of the `tapAction` modifier in...
# compose
f
Interesting benefit of the
tapAction
modifier in SwiftUI.
Copy code
Text("hello")
.tapAction { println("tapped") }
Over
Copy code
Clickable(onClick = { println("tapped") }){
     Text("hello")
}
You get
{ println("tapped") }
over
(onClick = { println("tapped") })
a
it will not be required to write "onClick =" though
f
Why not?
Oh right, because you don't need to name it
a
yes, it is optional here
f
Not naming the argument is arguably worse though
Copy code
Clickable ( { println("tapped") }){
     Text ("hello")
}
And you will need to name it if there is some other arguments. Anyway the point is you get to take advantage of the trailing lamda syntax
a
They also had such example in the video
Copy code
Button(action: {}) {
   Text("Add room")
}
In Compose it is almost the same
Copy code
Button(onClick = {}) {
   Text("Add room")
}
not sure then why do they provide both ways of adding click callbacks, with wrapping and with a modifier
v
For me this example with clicking is a clear argument in favor of the Compose approach. In SwiftUI an element is tappable (can have on-click), while in Compose a whole region is clickable (can contain multiple elements). IMO the Compose approach is more general and also is close to the intuitive understanding of how a GUI works.
1