How can I get the center of any composable element...
# compose
n
How can I get the center of any composable element? I was trying using
onGloballyPositioned{..}
(I also have some other code and I want to avoid adding it this modifier since it’s called a lot.) Is there any method/modifier where I can get any alternative of `Rect`/
bounds
?
d
What do you need the Rect/Bounds for? Maybe there are other ways to achieve what you are trying to do
n
I need center position/coordinates of the composable element. How can I get that?
z
Why do you need them?
n
I’m trying to draw some animation from the center of the composable element.
w
this can't be done without size which you would get from onSizeChanged Modifier and then you can calculate center from onGloballyPositioned coordinates , and everytime onSizeChanged is called recalculate the center !
n
Right. That’s what I’m trying right now with
onGloballyPositioned{..}
. I was asking if there’s any other way.
z
If your animation is just drawing, you can use a drawBehind modifier (or other draw modifier) and then you have access to the size from the DrawScope
1
n
Yeah, Thanks.