Is there some sort of `this` equivalent on compose...
# compose
u
Is there some sort of
this
equivalent on compose clicks, to get the "view" reference? (for analytics purposes of logging "Button X was clicked" -- generically, not locally manually in every lambda)
z
What type of value would you expect
this
to contain?
Anyway, there isn’t, because there's no obvious answer to that question.
But you have to pass the click handler when you define the button, so you can define whatever identifier you need there
u
with views i passed in the view instance, and looked up lets say id, and text if a textview, basically its used as breadcrumbs for logging purposes
j
There's no such thing as instances of any composables drawn on the screen. At least not on the normal API surface. You could implement your own Modifier.clickable that logs clicks or you custom Button composable that adds onClick logging.. but you would have to pass custom identifiers if you want to see which button was clicked. There are no id's in the code by default, so what could be logged anyway to identify the "thing" clicked..
z
with views i passed in the view instance, and looked up lets say id
Right, but you had to assign some id to your view at some point. You don’t have to do that in compose, but you can create whatever identifiers you want for purposes like this and just pass them specifically to the logging code.
t
There is, however, a semantics tree, which is meant for stuff like this
u
Yea im aware there is no instance, hence the quotes in the question I know I could do something like this
Copy code
Button(
   text = text,
   onClick = LoggedClickable(text = text) { ... }
)
Just wondering if there is something fool proof
@tad could you please ellaborate? Havent heard of that one
u
hmm, I skimmed throught it, is this however available at runtime? not just test/tool time?
t
It has to be for the accessibility delegate to work
🙌 1
whether it has a public API is a different question
It looks like the answer is "no", the SemanticsOwner is held by AndroidComposeView which is internal
u
If it were available, there would probably be a noticable performance hit, right?