Lucas Kivi
03/11/2025, 9:11 PMshadow
without causing recompositions?Zach Klippenstein (he/him) [MOD]
03/12/2025, 3:14 PMZach Klippenstein (he/him) [MOD]
03/12/2025, 3:15 PMLucas Kivi
03/12/2025, 7:04 PM/**
* A shadow [Modifier] that allows elevation changes to animate and skip recompositions.
*/
fun Modifier.shadow(
clip: Boolean = false,
shape: Shape = RectangleShape,
ambientColor: Color = DefaultShadowColor,
spotColor: Color = DefaultShadowColor,
elevationProvider: () -> Dp,
): Modifier = graphicsLayer {
val elevation = elevationProvider()
// Do nothing if no shadow will be shown.
if (elevation > 0.dp || clip) {
this.shadowElevation = elevation.toPx()
this.shape = shape
this.clip = clip
this.ambientShadowColor = ambientColor
this.spotShadowColor = spotColor
}
}
However something about this if
statement in the compose.ui
version fixes an issue where my shadow’s clips are interfering with each other when one disappears to `0.dp`:
) = if (elevation > 0.dp || clip) {
this then ShadowGraphicsLayerElement(elevation, shape, clip, ambientColor, spotColor)
} else {
this
}
This issue obviously only occurs when there are multiple shadows in the same real estate!Lucas Kivi
03/14/2025, 3:24 PM