Skip to content

Instantly share code, notes, and snippets.

@chiragthummar
Created June 26, 2023 16:36
Show Gist options
  • Save chiragthummar/7289018140e2b4e05e296f960c6545b8 to your computer and use it in GitHub Desktop.
Save chiragthummar/7289018140e2b4e05e296f960c6545b8 to your computer and use it in GitHub Desktop.
fun Modifier.shimmerEffect(): Modifier = composed {
var size by remember {
mutableStateOf(IntSize.Zero)
}
val transition = rememberInfiniteTransition()
val startOffsetX by transition.animateFloat(
initialValue = -2 * size.width.toFloat(),
targetValue = 2 * size.width.toFloat(),
animationSpec = infiniteRepeatable(
animation = tween(2000)
)
)
background(
brush = Brush.linearGradient(
colors = listOf(
Color(0xB9B5B5),
Color(0xDDFFFFFF),
Color(0xC2C1C1),
),
start = Offset(startOffsetX, 0f),
end = Offset(startOffsetX + size.width.toFloat(), size.height.toFloat())
)
).onGloballyPositioned {
size = it.size
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment