valentinilk / compose-shimmer

A simple shimmer library for Jetpack Compose.
https://valentinilk.github.io/compose-shimmer/
Apache License 2.0
673 stars 37 forks source link

Change animation speed #9

Closed aniluMango closed 2 years ago

aniluMango commented 2 years ago

How can i change speed of shimmer effect ?

hoboris commented 2 years ago

The README says you create a custom shimmer, the following example is provided:

fun Modifier.shimmer(
    duration: Int
): Modifier = composed {
    val shimmer = rememberShimmer(
        shimmerBounds = ShimmerBounds.View,
        theme = createCustomTheme(duration),
    )
     shimmer(customShimmer = shimmer)
}

If you want to tweak more parameters you can also add something like

fun Modifier.shimmer(
    duration: Int,
    delay: Int,
    easing: Easing = LinearEasing,
    repeatMode: RepeatMode = RepeatMode.Restart
): Modifier = composed {
    val shimmer = rememberShimmer(
        shimmerBounds = ShimmerBounds.View,
        theme = defaultShimmerTheme.copy(
            animationSpec = infiniteRepeatable(
                animation = tween(
                    durationMillis = duration,
                    easing = easing,
                    delayMillis = delay,
                ),
                repeatMode = repeatMode,
            )
        ),
    )
    shimmer(customShimmer = shimmer)
}
valentinilk commented 2 years ago

Currently you can only change the duration of a shimmer. So the time it takes the shimmer to skim across your view. I was actually thinking of providing a way to really change the speed of the shimmer. So dp/s or a similar unit.