Created
June 26, 2023 16:36
-
-
Save chiragthummar/7289018140e2b4e05e296f960c6545b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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