shadowCompat

fun Modifier.shadowCompat(elevation: Dp, shape: Shape = RectangleShape, clip: Boolean = elevation > 0.dp, ambientColor: Color = DefaultShadowColor, spotColor: Color = DefaultShadowColor, colorCompat: Color = Color.Unspecified, forceColorCompat: Boolean = false): Modifier(source)

Creates a shadow replacement that can be tinted with the library's color compat mechanism on API levels before 28, the earliest version to support the native shadow colors. If the current API level is 28 or above, shadowCompat falls back to the framework's shadow, unless forceColorCompat is true.

Refer to shadow's docs for details on the first five parameters: elevation, shape, clip, ambientColor, and spotColor.

colorCompat takes a Color that's used to tint the shadow on API levels 27 and below. If the passed value is Color.Black – the default shadow color – this falls back to the normal shadow. If Color.Unspecified is passed, the actual tint is calculated as a blend of the ambientColor and spotColor, mixed in proportion to their current theme alphas. Setting any other value disables this blending behavior.

The color blending formula gives good results only if the ambient and spot colors are both fully opaque; i.e., only if both have maximum alpha values.

NB: Tinted shadows are clipped to the root composable's bounds.


fun Modifier.shadowCompat(shape: Shape, clip: Boolean = true, block: ShadowCompatScope.() -> Unit): Modifier(source)

The lambda version of shadowCompat that allows for modification of shadow properties without recomposition.

shape works like normal. clip defaults to true instead of elevation > 0.dp, since that value isn't set until the lambda runs.

The rest of the original parameters – elevation, ambientColor, spotColor, colorCompat, and forceColorCompat – are now inside block.

Unlike the original, this version never falls back to the framework's shadow, but it does disable internal layer compositing whenever possible.

NB: Tinted shadows are clipped to the root composable's bounds.