Shimmer effect created with jetpack compose 🥳
-
Lets create a list of color
val colors = listOf( Color.Gray.copy(alpha = 0.9f), Color.Gray.copy(alpha = 0.8f), Color.Gray.copy(alpha = 0.9f))
-
We need a background. We will create it with Brush. This object has start and end offset. So we should animate it. Look at the picture and you will get the idea 🧐
val brush = linearGradient(
colors = colors,
start = Offset(
currentOffset.value - calculatedOffSet,
currentOffset.value - calculatedOffSet
),
end = Offset(
currentOffset.value,
currentOffset.value
),
)
3.Animation is here! This is the power of compose 😎
val currentOffset = animateFloatAsState(
targetValue = if (animPlayed) calculatedMaxValue else 0f,
animationSpec = infiniteRepeatable(
tween(
durationMillis = animDuration,
delayMillis = animDelay,
easing = LinearEasing
),
repeatMode = RepeatMode.Restart
)
)
LaunchedEffect(key1 = true) {
animPlayed = true
}
Please fork this project and do not forget support star ⭐🙌