Is there a way to have composable fill the remaini...
# compose
a
Is there a way to have composable fill the remaining width but cap it's min width? I am trying to make a composable use
Modifier.weight(1f)
but cap it's min width to a specific width (using
Modifier.widthIn()
Doesn't seem to be working and the widthIn is ignored. I tried setting
requiredWidthIn()
as well Code in 🧵
Copy code
Row(
    Modifier
        .fillMaxWidth()
        .horizontalScroll(rememberScrollState())
) {
    repeat(10) {
        Box(
            Modifier
                .debugBorder(Color.Black)
                .requiredWidthIn(48.dp)
                .weight(1f)
                .height(48.dp)
                .background(randomColor())
        )
    }
}
Produces this notice how the items are less than 48.dp (should be either square or width > height)
messed with the order of the modifiers as well. no luck
Found a workaround (ultra specific for my case though) Separate my content from the spacing:
Copy code
Row(Modifier.fillMaxWidth().horizontalScroll(rememberScrollState())) {
    repeat(10) {
        Box(
            Modifier
                .debugBorder(Color.Black)
                .width(48.dp)
                .height(48.dp)
                .background(randomColor())
        )
        Box(Modifier.weight(1f))
    }
}
d
.requiredWidthIn
takes two parameters. They both have default value of
Dp.Unspecified
. That may be throwing off your first code sample.
.requiredWidth
is a single parameter version of the modifier.
a
i used
requiredWidthIn
intentionally. the first parameter is the min width you need, which is my case.
requiredWith()
sets the width to a fixed size, which I don't want to do
j
Does
defaultMinSize(minWidth = ##.dp)
work? I think it should
today i learned 1
a
it does not
j
hmm, bummer
👍 1
a
i seems like a bug on weight() tbh