fun Modifier.coloredShadow(
color: Color,
shape: Shape,
alpha: Float = 0.2F,
shadowRadius: Dp = 0.dp,
offsetY: Dp = 0.dp,
offsetX: Dp = 0.dp,
) = coloredShadow(color, shape, alpha, shadowRadius, DpOffset(offsetX, offsetY))
fun Modifier.coloredShadow(
color: Color,
shape: Shape,
alpha: Float = 0.2F,
shadowRadius: Dp = 0.dp,
offset: DpOffset = DpOffset(0.dp, 0.dp),
) = composed {
val density = LocalDensity.current
val shadowColor = remember(color, alpha) { color.copy(alpha).toArgb() }
val paint = remember(shadowRadius, offset.x, offset.y, shadowColor, density) { Paint().apply {
val frameworkPaint = asFrameworkPaint()
with(density) {
frameworkPaint.color = Color.Transparent.toArgb()
frameworkPaint.setShadowLayer(
shadowRadius.toPx(),
offset.x.toPx(),
offset.y.toPx(),
shadowColor
)
}
}}
drawBehind {
drawIntoCanvas {
it.drawOutline(
shape.createOutline(size, layoutDirection, this),
paint
)
}
}
}