https://kotlinlang.org logo
Title
a

Alexander Maryanovsky

02/28/2022, 8:57 PM
I’m trying to create a
Column
with a
VerticalScrollBar
that grows with its contents until it reaches the maximum available space and then becomes scrollable. The code looks approximately like this:
Box{
    Column(
        modifier = Modifier.verticalScroll(scrollState)
    ) {
        ...
    }
    VerticalScrollbar(
        modifier = Modifier.align(Alignment.CenterEnd).matchParentSize()
    )
}
Without the scrollbar, it works fine. Unfortunately, as soon as I add the scrollbar, it stretches the
Box
to fill all the available height. It doesn’t seem to respect the
matchParentSize
modifier.
Solved it in the meanwhile by noting the height of the box and column via
onGloballyPositioned
and only showing the scrollbar if the column is taller than the box.
t

Tobias Suchalla

03/01/2022, 7:03 AM
You might be able to solve this with
Modifier.height(IntrinsicSize.Min)
on the Box. Manually measuring usually takes two compositions to get things done, which may result in subtle jank. Your case is somewhat similar to the official exampe: https://developer.android.com/jetpack/compose/layouts/intrinsic-measurements#intrinsics-in-action