Add a shimmer while loading an image using coil and compose

Viewed 544

Loading an image from a web URL and displaying a shimmer during load. Are there any better ways to handle this?

val context = LocalContext.current
val imageLoader = ImageLoader(context)

val request = ImageRequest.Builder(context)
        .data(thumbnailUrl)
        .build()

val painter = rememberImagePainter(
        request = request,
        imageLoader = imageLoader
    )

val state = painter.state

Image(
  painter = painter,
  contentDescription = "thumbnail image",
  modifier = Modifier
            .fillMaxSize()
            .placeholder(
                visible = state is 
  ImagePainter.State.Loading,
                color = PlaceholderDefaults.color(
                    backgroundColor = MyTheme.colors.shimmer.copy(0.1f),
                ),
                highlight = PlaceholderHighlight.shimmer(),
            ),
        contentScale = ContentScale.Crop
    )

How would you add a token to this request? I tried setting the header with a token but no response. Any suggestions?

0 Answers
Related