Last active
April 7, 2024 22:17
-
-
Save arthurgonzaga/598267f570e38425fc52f97b30e0619d to your computer and use it in GitHub Desktop.
Improved version of https://gist.github.com/cedrickring/0497965b0658d6727aaec531f59e8c5c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.compose.ui.Modifier | |
import androidx.compose.ui.composed | |
import androidx.compose.ui.draw.drawBehind | |
import androidx.compose.ui.graphics.Color | |
import androidx.compose.ui.graphics.Paint | |
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas | |
import androidx.compose.ui.graphics.toArgb | |
import androidx.compose.ui.unit.Dp | |
import androidx.compose.ui.unit.dp | |
fun Modifier.coloredShadow( | |
color: Color, | |
alpha: Float = 0.2f, | |
borderRadius: Dp = 0.dp, | |
shadowRadius: Dp = 20.dp, | |
offsetY: Dp = 0.dp, | |
offsetX: Dp = 0.dp | |
) = composed { | |
val shadowColor = color.copy(alpha = alpha).toArgb() | |
val transparent = color.copy(alpha= 0f).toArgb() | |
this.drawBehind { | |
this.drawIntoCanvas { | |
val paint = Paint() | |
val frameworkPaint = paint.asFrameworkPaint() | |
frameworkPaint.color = transparent | |
frameworkPaint.setShadowLayer( | |
shadowRadius.toPx(), | |
offsetX.toPx(), | |
offsetY.toPx(), | |
shadowColor | |
) | |
it.drawRoundRect( | |
0f, | |
0f, | |
this.size.width, | |
this.size.height, | |
borderRadius.toPx(), | |
borderRadius.toPx(), | |
paint | |
) | |
} | |
} | |
} |
figma has spread
attribute for shadows
how can i implement shadows with spread
in compose?
by the way thank you
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found a workaround for circular items on StackOverflow (second answer)