Last active
December 20, 2022 17:51
-
-
Save mhrohani1385/0f4943e80ec0df2366f731a7190a5f51 to your computer and use it in GitHub Desktop.
A placeholder with animation for android compose
This file contains hidden or 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
fun Modifier.gradientProcessingBackground() : Modifier = composed { | |
val infiniteYTransition = rememberInfiniteTransition() | |
val state = infiniteYTransition.animateFloat( | |
initialValue = 0f, | |
targetValue = 0.7f, | |
animationSpec = infiniteRepeatable( | |
animation = tween(500, easing = EaseInOutExpo), | |
repeatMode = RepeatMode.Restart | |
) | |
) | |
val animationY by state | |
val mainColor = | |
MaterialTheme.colors.secondary.overlay(MaterialTheme.colors.background, 0.7f) | |
val backColor = MaterialTheme.colors.background | |
val gradient = remember(animationY) { | |
Statics.gradiantBrush(y = animationY, mainColor, backColor) | |
} | |
clip(RoundedCornerShape(4.dp)) | |
.background(gradient) | |
} | |
fun gradiantBrush(y: Float, mainColor: Color, backColor: Color): Brush { | |
val yC = (y * 0.7f) + 0.3f | |
return Brush.linearGradient( | |
0f to backColor, | |
yC - 0.3f to mainColor, | |
yC to mainColor, | |
1f to backColor | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment