Philip S
06/01/2021, 8:52 AM@Composable
fun MyList(items: List<Items>, isLoading: Boolean)
I thought about using a flag as shown above and then if-else to determine if it should show the real view or just the shimmer variant. If you have implemented shimmer loading what worked best for you? Did you perhaps find a more elegant solution?patrick
06/01/2021, 8:57 AM.shimmer(isLoading = true)
.
Not sure how feasible it is, but would be very handy to just drop this on composables and have a shimmer overlay the composable or so (while keeping all shimmer modifier animations in sync.Philip S
06/01/2021, 9:03 AMpatrick
06/01/2021, 9:19 AMBoris Kachscovsky
06/01/2021, 2:09 PMfun Modifier.shimmer(
gradientAngle: Float = ShimmerAngle,
gradientWidth: Float = ShimmerWidth,
alphaLight: Float = ShimmerAlphaLight,
alphaDark: Float = ShimmerAlphaDark,
): Modifier = this.then(
composed {
val animatedValue by rememberInfiniteTransition().animateFloat(
initialValue = 0.0f,
targetValue = 1.0f,
animationSpec = ShimmerAnimationSpec
)
ShimmerModifier(
animatedVal = animatedValue,
isLight = Theme.isLight,
gradientAngle = gradientAngle,
gradientWidth = gradientWidth,
alphaLight = alphaLight,
alphaDark = alphaDark,
)
}
)
The Modifier itself is a class that extends DrawCacheModifier
, and draws the gradient based on the animated value passed in.Boris Kachscovsky
06/01/2021, 3:21 PMPhilip S
06/02/2021, 6:42 AMpatrick
06/02/2021, 7:46 AM