Skip to content

hamurcuabi/ShimmerEffectWithJetPackCompose

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ShimmerEffectWithJetPackCompose

Shimmer effect created with jetpack compose 🥳

How It Works 🙄

  1. 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))

  2. 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 🙌

About

Shimmer effect created with jetpack compose.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages