rob42
10/02/2024, 9:52 AMModifier.widthIn()
might be ignored when used inside AnimatedContent(Modifier.weight(1f) { ... }
?
It is respected when the AnimatedContent
has no weight modifier, or when using a plain Box
instead of AnimatedContentrob42
10/02/2024, 9:56 AMRow(Modifier.size(200.dp)) {
Box(Modifier.background(Color.Blue).width(50.dp).fillMaxHeight())
Box(Modifier.weight(1f)) {
Box(Modifier.background(Color.Green).widthIn(max = 50.dp)) {
Box(Modifier.fillMaxSize()) // <-- *Is* constrained to 50dp
}
}
}
AnimatedContent(Modifier.weight(1f)):
Row(Modifier.size(200.dp)) {
Box(Modifier.background(Color.Blue).width(50.dp).fillMaxHeight())
val transition = updateTransition(targetState = 1)
transition.AnimatedContent(Modifier.weight(1f)) {
Box(Modifier.background(Color.Green).widthIn(max = 50.dp)) {
Box(Modifier.fillMaxSize()) // <-- Is *not* constrained to 50dp
}
}
}
AnimatedContent(Modifier):
Row(Modifier.size(200.dp)) {
Box(Modifier.background(Color.Blue).width(50.dp).fillMaxHeight())
val transition = updateTransition(targetState = 1)
transition.AnimatedContent(Modifier) {
Box(Modifier.background(Color.Green).widthIn(max = 50.dp)) {
Box(Modifier.fillMaxSize()) // <-- *Is* constrained to 50dp
}
}
}
rob42
10/02/2024, 9:56 AMDoris Liu
10/03/2024, 9:22 PMBox
by default doesn't propagate minConstraints, which means the minWidth as the result of the weight
modifier doesn't get propagated down to the content inside Box(Modifier.weight(..)) {..}
The Layout
used by AnimatedContent simply passes the constraints from parent to children without any modification to the constraints, therefore you get the 200.dp
width. If you add propagateMinConstraints = true
to Box with weight modifier, you'll get the same resultrob42
10/05/2024, 8:29 AMDoris Liu
10/07/2024, 9:46 PMwidthIn
. The widthIn
modifier is sort of a soft requirement in that it conforms to (or gets constrained by) the incoming constraints: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]nMain/kotlin/androidx/compose/foundation/layout/Size.kt;l=827 The end result is that the constraints from widthIn
gets coerced in the range of width constraints of weight
in this case