ursus
05/05/2026, 10:25 PManimateBounds
@Composable
private fun BlueBar(isExpanded: Boolean) {
LookaheadScope {
Box(
modifier = Modifier
.padding(16.dp)
.animateBounds(this) <-------
.padding(horizontal = 16.dp, vertical = 16.dp)
.then(if (isExpanded) Modifier.fillMaxWidth() else Modifier.width(100.dp))
.then(if (isExpanded) Modifier.height(32.dp) else Modifier.height(64.dp))
.background(Color.Blue, MaterialTheme.shapes.extraLarge)
)
}
}
and there is this odd translation effect to it (see video)
what's that about? I'm only changing width and height. How do I get rid of it?Vidmantas Kerbelis
05/07/2026, 9:50 AM@Composable
private fun BlueBar(isExpanded: Boolean) {
LookaheadScope {
Box(
modifier = Modifier
.padding(16.dp)
.padding(horizontal = 16.dp, vertical = 16.dp)
.background(Color.Blue, MaterialTheme.shapes.extraLarge)
.animateBounds(this)
.then(if (isExpanded) Modifier.fillMaxWidth() else Modifier.width(100.dp))
.then(if (isExpanded) Modifier.height(32.dp) else Modifier.height(64.dp))
)
}
}
Sorry, late answer, but maybe still relevantursus
05/07/2026, 6:52 PMLookaheadScope {
Box(
modifier = Modifier
.padding(top = 16.dp)
.background(Color.Blue, MaterialTheme.shapes.extraLarge)
.animateBounds(this)
.then(if (isExpanded) Modifier.fillMaxWidth() else Modifier.width(64.dp))
.then(if (isExpanded) Modifier.height(32.dp) else Modifier.height(64.dp))
)
}
^^this works
LookaheadScope {
Box(
modifier = Modifier
.padding(top = 16.dp)
.animateBounds(this)
.background(Color.Blue, MaterialTheme.shapes.extraLarge)
.then(if (isExpanded) Modifier.fillMaxWidth() else Modifier.width(64.dp))
.then(if (isExpanded) Modifier.height(32.dp) else Modifier.height(64.dp))
)
}
this makes it translate
so..why does coloring background give it translation I don't getursus
05/07/2026, 6:56 PMpadding(top=)
LookaheadScope {
Box(
modifier = Modifier
.background(Color.Blue, MaterialTheme.shapes.extraLarge)
.animateBounds(this)
.padding(top = if (isExpanded) 64.dp else 24.dp)
.then(if (isExpanded) Modifier.fillMaxWidth() else Modifier.width(64.dp))
.then(if (isExpanded) Modifier.height(32.dp) else Modifier.height(64.dp))
)
}
since now the semantics is different, padding after background "grows" the colored surface, not offsets itVidmantas Kerbelis
05/07/2026, 6:57 PMursus
05/07/2026, 6:58 PMVidmantas Kerbelis
05/07/2026, 7:07 PMursus
05/07/2026, 7:08 PMursus
05/07/2026, 7:08 PMVidmantas Kerbelis
05/07/2026, 7:13 PMursus
05/07/2026, 7:14 PManimateBounds has modifier argument