What is the right way of finding the size of a `Bo...
# compose
h
What is the right way of finding the size of a
Box
after it is created? Or any other
Composable
for that matter?
p
Checkout
Modifier.drawWithContent
Copy code
val (boxSize, setBoxSize) = state { 0 }

Box(modifier = Modifier.drawWithContent {
    drawContent()
    setBoxSize(size)
})
I tried something like this
👍 1
h
Thanks, that did the trick 🙂
z
The
onPositioned
modifier is probably a better fit for this use case: https://developer.android.com/reference/kotlin/androidx/ui/core/package-summary#onpositioned_1
l
question: what are you using it for?
the
onPositioned
modifier will likely have an
onSizeChanged
sibling API soon which would be even better
h
I'm trying to calculate a drag gesture with respect to the size of the view itself. In other words, drag's behavior will depend on the percentage.
This is what I came up with after using
onPositioned
. All media controllers are written in Compose. Only the video surface is inflated by
AndroidView
.
👏 4