Last active
January 25, 2025 16:58
-
-
Save igorescodro/a52acad5abc0b149ae6a6e4dfb53f81a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@Composable | |
fun Modifier.shimmerable( | |
shape: Shape = RoundedCornerShape(8.dp), | |
color: Color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f) | |
): Modifier { | |
if (!LocalShimmerState.current.isLoading) return this | |
return this | |
.shimmer() | |
.background(color = color, shape = shape) | |
.drawWithContent { | |
// Do not draw the actual content. | |
} | |
} | |
data class ShimmerState(val isLoading: Boolean) | |
val LocalShimmerState = compositionLocalOf { ShimmerState(isLoading = false) } | |
@Composable | |
fun ShimmerProvider(isLoading: Boolean = true, content: @Composable (Boolean) -> Unit) { | |
CompositionLocalProvider( | |
value = LocalShimmerState provides ShimmerState(isLoading = isLoading), | |
content = { content(isLoading) }, | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment