Created
June 22, 2024 08:53
-
-
Save SEAbdulbasit/5cfe055294e13cbb18bb202369f1a8d6 to your computer and use it in GitHub Desktop.
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
@Composable | |
fun CardGradient(modifier: Modifier = Modifier) { | |
Card( | |
modifier = Modifier.padding(16.dp).fillMaxWidth().aspectRatio(600 / 400f) | |
.clip(RoundedCornerShape(16.dp)) | |
) { | |
Gradient() | |
} | |
} | |
@Composable | |
fun Gradient() { | |
Box( | |
modifier = Modifier.fillMaxSize() | |
) { | |
Layout(content = { | |
Box(modifier = Modifier.fillMaxSize().drawWithContent { | |
drawRect( | |
Brush.radialGradient( | |
colors = listOf( | |
Color(0xff3e91f0), Color.Transparent | |
), | |
center = Offset(this.size.width * 0.05f, this.size.height / 2), | |
radius = size.width * 2, | |
) | |
) | |
}) | |
Box(modifier = Modifier.fillMaxSize().drawWithContent { | |
drawRect( | |
Brush.radialGradient( | |
colors = listOf( | |
Color(0xffFF8A58), Color.Transparent | |
), | |
center = Offset(0f, this.size.height), | |
radius = size.height, | |
) | |
) | |
}) | |
Box(modifier = Modifier.fillMaxSize().drawWithContent { | |
drawRect( | |
Brush.radialGradient( | |
colors = listOf( | |
Color(0xff58EBFF), Color.Transparent | |
), | |
center = Offset( | |
this.size.width * 1.1f, this.size.height * .100f | |
), | |
radius = size.height, | |
) | |
) | |
}) | |
Box(modifier = Modifier.fillMaxSize().drawWithContent { | |
drawRect( | |
Brush.radialGradient( | |
colors = listOf( | |
Color(0xff8c54eb), Color.Transparent | |
), | |
center = Offset( | |
this.size.width, this.size.height * 0.9f | |
), | |
radius = size.height, | |
) | |
) | |
}) | |
}, measurePolicy = { measurables, constraints -> | |
val placeables = measurables.map { it.measure(constraints) } | |
layout(constraints.maxWidth, constraints.maxHeight) { | |
placeables.forEach { it.place(0, 0) } | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment