I'm using ```Modifier .onGloballyPositioned { ...
# compose
n
I'm using
Copy code
Modifier
    .onGloballyPositioned {
        position.value = it.positionInParent()
    }
which is incredibly useful but I would need the value as DpOffset rather than Offset. Is that conversion at all possible?
a
it is, but reaching for it is generally a sign that there's a better way to do something
and the question involving
onGloballyPositioned
suggests that this code might be trying to do something across multiple frames that might be better expressed using
Layout
n
ah ok lol, well I have the width of my parent Box in dp and my offset in Floats, so I was trying to find a solution.
to be clear, I am moving a tile (Box) from one end of a board (parent Box) to the other, and I need to know when I reach that other end.
So I should look at
Layout
rather than
onGloballyPositioned
?
a
Probably;
Layout
can measure and position multiple sibling elements together with full knowledge of the connection between them. Adjusting child positioning with a combo of offsets/onGloballyPositioned means the code is iterating positions and trying to converge on a layout solution
n
Thanks! I'll dive into it!
👍 1