How do I force a remeasure after an offset so the ...
# compose
t
How do I force a remeasure after an offset so the UI take just the space needed?
j
You make your offset a state, then it happens automatically
t
Copy code
@Preview
@Composable
fun test() {
    Row(Modifier.padding(16.dp)) {
        val offset by remember { mutableStateOf((-50).dp) }
        Box(Modifier.size(100.dp).background(Color.Red))
        Box(Modifier.size(100.dp).offset(x = offset).background(Color.Blue))
    }
}
Making it a state doesn't solve for me 🤔 look at the blank space at the end
j
Well that's how your boxes look with the offset applied, there's nothing to force there
I thought you meant after the offset changes In which case a State would trigger recomposition
t
I understand, but I would like to know if there's a way to remove the spacing after the offset is applied
j
I think you'd have to change your layout. The blue box still takes up the "empty" space, it's just being drawn outside its own bounds
Probably a custom Arrangement on your Row could get the overlapping effect you're trying for 🤔
s
Can you try adding spacedBy(-50.dp) as the horizontal arrangement of the row?
👀 1
t
With the arrangment it works indeed! Thanks for the help!
j
I'm impressed spacedBy with a negative value worked, that's cool!
s
I was surprised too the first time I used it and it just worked 😂