I want to get the coordinates of an item in a lazy...
# compose-android
p
I want to get the coordinates of an item in a lazy column when it is clicked. How can i do that?
s
Coordinates relative to what? The full screen or the lazyColumn itself? And if you scroll and click again, do you want different coordinates?
p
So i want to mimic a shared element transition when i click on the card. But due to some constraints, i cant use the actual implementation. Rather, i will place another card on top the item that is being clicked and expand that card. For this, i need the coordinates of the item that is clicked relative to the screen
s
You can add a
Modifier.onPlaced {}
on your composable. In there you get a
LayoutCoordinates
and you can try doing
Copy code
positionInRoot()
positionInWindow()
positionOnScreen()
On it to get some coordinates. Play around with it, perhaps one of them will be what you are looking for. You can then store that value in a local mutableState, which you read inside the onClick