https://kotlinlang.org logo
#compose
Title
# compose
f

Fudge

06/05/2019, 10:00 PM
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

Andrey Kulikov

06/05/2019, 10:07 PM
it will not be required to write "onClick =" though
f

Fudge

06/05/2019, 10:08 PM
Why not?
Oh right, because you don't need to name it
a

Andrey Kulikov

06/05/2019, 10:09 PM
yes, it is optional here
f

Fudge

06/05/2019, 10:13 PM
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

Andrey Kulikov

06/05/2019, 10:15 PM
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

voddan

06/06/2019, 8:39 AM
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
2 Views