Thread
#compose
    Colton Idle

    Colton Idle

    1 year ago
    How do I get the size of a composable AFTER it's been laid out and measured? i.e. I want to know that my image is laid out on the screen at a final resolution of 200px x 400px.
    In standard android-view land, if I wanted to get the size of an imageView being laid out I would do something like this
    imageView.viewTreeObserver.addOnPreDrawListener(
           object : ViewTreeObserver.OnPreDrawListener {
               override fun onPreDraw(): Boolean {
                   viewTreeObserver.removeOnPreDrawListener(this)
                   //get size of view and do something with it.
                   return true
        }
    })
    android ktx made this simpler by adding this
    view.doOnPreDraw { 
    //get size of view and do something with it.
    }
    how do I grab this in compose though, without potentially grabbing a size of 0 because it hasn't been laid out?
    Albert Chang

    Albert Chang

    1 year ago
    Modifier.onSizeChanged()
    r

    romainguy

    1 year ago
    @Colton Idle from Android-KTX,
    doOnLayout()
    is more appropriate
    Colton Idle

    Colton Idle

    1 year ago
    Whoops. @romainguy that's what I meant. @Albert Chang thanks. I will try that.