Hi, my composable is moving the offset, but the ba...
# compose
j
Hi, my composable is moving the offset, but the background color is not moving. If I look in the layout inspector, I can clearly see that the offset has been moved. But the background color is still displayed at the old offset. What’s the problem?
Copy code
@Composable
private fun QuackSelectedTabUnderBar(
    modifier: Modifier = Modifier,
    color: QuackColor,
    offsetProvider: Density.() -> IntOffset,
    widthProvider: Density.() -> Dp,
) {
    val density = LocalDensity.current

    Box(
        modifier = Modifier
            .offset(offset = offsetProvider)
            .then(other = modifier)
            .height(height = QuackTabUnderBarHeight)
            .width(width = density.widthProvider())
            .background(color = color.value)
    )
}
I used
Modifier.offset(offset: Density.() -> IntOffset)
for moving offset.
f
Have you tried moving
offset
modifier to after
background
modifier?
b
That actually looks the right way round to me already
If you are trying to use a lambda as well to avoid recomposition, you would also have to do the same width modifier if that's changing as well. There isn't a width {} modifier though so you would have to use layout {}
Does moving the background to after the layout work now?
j
Wow! Now it works! Obviously it didn't work when I did it before, but now I try it again, it works. Thank you so much!