Nino
11/12/2026, 4:00 PMCrossfade with an elevated Card (dropping shadows). Is there any way to avoid the clipping of the Card during the Crossfade animation?Nino
11/12/2026, 4:01 PMvar switch by remember { mutableStateOf(false) }
LaunchedEffect(Unit) {
while (true) {
delay(2.seconds)
switch = !switch
}
}
Crossfade(
modifier = Modifier.padding(vertical = 16.dp),
targetState = switch,
animationSpec = tween(1_500),
) { state ->
if (state) {
Card(
modifier = Modifier.padding(horizontal = 16.dp),
elevation = CardDefaults.cardElevation(
defaultElevation = 8.dp,
),
) {
Text(
modifier = Modifier.padding(16.dp),
text = "One",
)
}
} else {
Card(
modifier = Modifier.padding(horizontal = 16.dp),
elevation = CardDefaults.cardElevation(
defaultElevation = 8.dp,
),
) {
Text(
modifier = Modifier.padding(16.dp),
text = "Two",
)
}
}
}Nino
11/12/2026, 4:02 PMCard itself insead of the Crossfade. Unfortunately, I’m working with a design system and the component “above” the Card in the List has some padding and I can’t modify it.
Is there any hope ?Zoltan Demant
11/13/2026, 6:05 AMBox(
modifier = Modifier.padding(ShadowRoom),
propagateMinConstraints = true,
content = { content() },
)
modifier.overhang:
layout { measurable, constraints ->
val room = ShadowRoom.roundToPx()
val placeable = measurable.measure(constraints.offset(room * 2, room * 2))
val width = (placeable.width - room * 2).coerceAtLeast(0)
val height = (placeable.height - room * 2).coerceAtLeast(0)
layout(width, height) {
placeable.place(-room, -room)
}
AnimatedContent(
modifier = modifier.overhang(definition),
...
content = { currentState -> Room(definition) { content(currentState) } },
)