frankelot
12/27/2020, 4:34 PMTimo Drick
12/27/2020, 4:40 PMTimo Drick
12/27/2020, 4:42 PMAdam Powell
12/27/2020, 5:20 PMAdam Powell
12/27/2020, 5:20 PMAdam Powell
12/27/2020, 5:22 PMAdam Powell
12/27/2020, 5:23 PMModifier.size
- as opposed to Modifier.preferredSize
- tells an element to disregard the constraints it is measured with and be the given size anyway.Adam Powell
12/27/2020, 5:24 PMModifier.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 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 sizeAdam Powell
12/27/2020, 5:34 PMAdam Powell
12/27/2020, 5:35 PMwrapContentSize
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
?frankelot
12/27/2020, 5:38 PMTimo Drick
12/27/2020, 5:39 PMTimo Drick
12/27/2020, 5:41 PMfrankelot
12/27/2020, 5:44 PMAdam Powell
12/27/2020, 5:44 PMModifier.layout {}
uses the same DSL as the Layout
composableAdam Powell
12/27/2020, 5:45 PMfrankelot
12/27/2020, 5:45 PMAdam Powell
12/27/2020, 5:47 PMAdam Powell
12/27/2020, 5:48 PMAdam Powell
12/27/2020, 5:49 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 existAdam Powell
12/27/2020, 5:53 PMAdam Powell
12/27/2020, 5:55 PMAdam Powell
12/27/2020, 5:57 PMTimo Drick
12/27/2020, 5:58 PMTimo Drick
12/27/2020, 5:59 PMAdam Powell
12/27/2020, 6:00 PMfrankelot
12/27/2020, 6:00 PMAdam Powell
12/27/2020, 6:02 PMAdam Powell
12/27/2020, 6:04 PMAdam Powell
12/27/2020, 6:05 PMAdam Powell
12/27/2020, 6:05 PMAdam Powell
12/27/2020, 6:06 PMAdam Powell
12/27/2020, 6:07 PMAdam Powell
12/27/2020, 6:09 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 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 PMfrankelot
12/27/2020, 6:16 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 coalescenceAdam Powell
12/27/2020, 6:18 PMModifier.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 automaticallyAdam Powell
12/27/2020, 6:20 PMTimo 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