Skip to content

Instantly share code, notes, and snippets.

@itsSiddharthGupta
Created November 17, 2024 10:44
Show Gist options
  • Save itsSiddharthGupta/8606db51fff7f1db3ad1efbd0204c3de to your computer and use it in GitHub Desktop.
Save itsSiddharthGupta/8606db51fff7f1db3ad1efbd0204c3de to your computer and use it in GitHub Desktop.
Shimmer Modifier
fun Modifier.shimmerEffect() = composed {
val size = remember { mutableStateOf(IntSize(0, 0)) }
val transition = rememberInfiniteTransition()
val startOffsetX = transition.animateFloat(
initialValue = -2 * size.value.width.toFloat(),
targetValue = 2 * size.value.width.toFloat(),
animationSpec = infiniteRepeatable(
animation = tween(1000)
)
)
background(
brush = Brush.linearGradient(
colors = listOf(
Color(0xFFB8B5B5),
Color(0xFF8F8B8B),
Color(0xFFB8B5B5),
),
start = Offset(startOffsetX.value, 0f),
end = Offset(startOffsetX.value + size.value.width.toFloat(), size.value.height.toFloat())
)
).onGloballyPositioned {
size.value = it.size
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment