frankelot
12/27/2020, 4:34 PMTimo Drick
12/27/2020, 4:40 PMAdam Powell
12/27/2020, 5:20 PMModifier.size
- as opposed to Modifier.preferredSize
- tells an element to disregard the constraints it is measured with and be the given size anyway.Modifier.size(100.dp)
inside a container that is only 50dp large, it will do what you ask for, but the parent will position that element as if it were only 50dpfrankelot
12/27/2020, 5:24 PMcontentAligment
for Box
is already
contentAlignment: Alignment = Alignment.TopStart,
Adam Powell
12/27/2020, 5:25 PMfrankelot
12/27/2020, 5:26 PMAdam Powell
12/27/2020, 5:27 PMfrankelot
12/27/2020, 5:27 PMbut the parent will position that element as if it were only 50dpgot it, any ways to avoid this then 🤔
Adam Powell
12/27/2020, 5:29 PMModifier.wrapContentSize
is an example of this; it relaxes a minimum size constraint and lets you supply options for how the element should be positioned within the minimum sizewrapContentSize
has an unbounded
parameter that permits the element to be larger than the available size, which seems particularly relevant for your case 🙂frankelot
12/27/2020, 5:35 PM.wrapContentSize(Alignment.TopStart, true)
seems to fix the issue 🎉Adam Powell
12/27/2020, 5:36 PMModifier.wrapContentSize(desiredAlignment, unbounded = true)
.size(animatedUnconstrainedSize)
frankelot
12/27/2020, 5:38 PMImage
composable, and not to the parent container Box
?Timo Drick
12/27/2020, 5:39 PMfrankelot
12/27/2020, 5:44 PMAdam Powell
12/27/2020, 5:44 PMModifier.layout {}
uses the same DSL as the Layout
composablefrankelot
12/27/2020, 5:45 PMAdam Powell
12/27/2020, 5:47 PMfrankelot
12/27/2020, 5:50 PMoffset
modifier parametersAdam Powell
12/27/2020, 5:52 PMoffset
modifier is present. Clipping to parents is opt-in in compose and implies additional drawing behavior that is normally decoupled from layout - clipping as part of this default layout conflict resolution would introduce a dependency that doesn't need to existTimo Drick
12/27/2020, 5:58 PMAdam Powell
12/27/2020, 6:00 PMfrankelot
12/27/2020, 6:00 PMAdam Powell
12/27/2020, 6:02 PMfrankelot
12/27/2020, 6:10 PM.wrapContentSize(Alignment, true)
on a child basically tells its parent “I will ignore your constraints and position myself with this aligment
)“, am I getting it right?… failing to use .`wrapContentSize`` on the child will just center (whenever it violates the parent constrains)Adam Powell
12/27/2020, 6:11 PMfrankelot
12/27/2020, 6:11 PMunbounded
parameter determines if this applies for the max
constrains or notAdam Powell
12/27/2020, 6:11 PMTimo Drick
12/27/2020, 6:13 PM@Composable
fun <T> CrossHeightAnimation(current: T, children: @Composable() (T) -> Unit) {
var lastHeight by rememberState<Float?> { null }
val height = animatedFloat(initVal = 0f)
Box(modifier = Modifier.fillMaxWidth()
.height(if (height.isRunning) height.value.dp else lastHeight?.dp ?: 0.dp)
.wrapContentHeight(align = Alignment.Bottom, unbounded = true)
.onSizeChanged { size ->
val newHeight = with(AmbientDensity.current) { size.height.toDp().value }
lastHeight.let { lh ->
if (lh == null) {
height.snapTo(newHeight)
} else if (lh != newHeight) {
height.snapTo(lh)
height.animateTo(newHeight, anim = tween(500))
}
}
if (lastHeight != newHeight)
lastHeight = newHeight
}) {
children(current)
}
}
frankelot
12/27/2020, 6:13 PMAdam Powell
12/27/2020, 6:17 PMonSizeChanged
-> lastHeight
-> .height()
modifier; those are the kinds of things that form layouts that don't complete in a single pass, or that relayout until they hit some sort of coalescenceModifier.animateContentSize
as wellTimo Drick
12/27/2020, 6:18 PMAdam Powell
12/27/2020, 6:19 PMTimo Drick
12/27/2020, 6:19 PMAdam Powell
12/27/2020, 6:20 PMmutableStateOf
state inside it, the system knows when to relayout automaticallyTimo Drick
12/27/2020, 6:23 PMfrankelot
12/27/2020, 7:04 PMAdam Powell
12/27/2020, 7:11 PMfrankelot
12/27/2020, 8:16 PMTimo Drick
12/27/2020, 8:34 PM