https://kotlinlang.org logo
#compose
Title
# compose
h

Halil Ozercan

07/22/2020, 7:40 PM
What is the right way of finding the size of a
Box
after it is created? Or any other
Composable
for that matter?
p

pavi2410

07/22/2020, 7:46 PM
Checkout
Modifier.drawWithContent
Copy code
val (boxSize, setBoxSize) = state { 0 }

Box(modifier = Modifier.drawWithContent {
    drawContent()
    setBoxSize(size)
})
I tried something like this
👍 1
h

Halil Ozercan

07/22/2020, 7:50 PM
Thanks, that did the trick 🙂
z

Zach Klippenstein (he/him) [MOD]

07/22/2020, 7:52 PM
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

Leland Richardson [G]

07/22/2020, 8:08 PM
question: what are you using it for?
the
onPositioned
modifier will likely have an
onSizeChanged
sibling API soon which would be even better
h

Halil Ozercan

07/22/2020, 8:37 PM
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
4 Views