skydoves / landscapist

🌻 A pluggable, highly optimized Jetpack Compose and Kotlin Multiplatform image loading library that fetches and displays network images with Glide, Coil, and Fresco.
https://skydoves.github.io/landscapist/
Apache License 2.0
2.07k stars 113 forks source link

Shimmer effect is not working for GlideImage #42

Closed atonamy closed 3 years ago

atonamy commented 3 years ago

Describe the Bug: Shimmer Effect is not working for GlideImage

GlideImage(
        modifier = modifier,
        contentScale = contentScale,
        imageModel = someImageUrl,
        shimmerParams = ShimmerParams(
                    baseColor = Color.White,
                    highlightColor = Color.Black,
                    durationMillis = 350,
                    dropOff = 0.65f,
                    tilt = 20f
          )
    )

This example doesn't show any shimmer effect :( Looks like is not working.

Expected Behavior: It should show shimmer effect while loading the image.

skydoves commented 3 years ago

Hi @atonamy Could you build using the demo project? There are two possibilities.

atonamy commented 3 years ago

Hi @atonamy Could you build using the demo project? There are two possibilities.

  • Image loading is too fast. Then please make slow your network environment, (WIFI)
  • baseColor or highlightColor is same as the background color. Then you can't see the shimmer because it was overlapped.

When I set the same same baseColor with ComposeView background color is not working properly when I changed baseColor of shimmerParams or background color of ComposeView to different one it started working.

atonamy commented 3 years ago

Also circularRevealedEnabled property not reviling properly some images for example image like this

The outcome the circle is not completing animation and keep corners rounded:

And withCrossFade also not working

GlideImage(
            modifier = modifier,
            requestBuilder = Glide
            .with(LocalView.current)
            .asBitmap()
            .transition(withCrossFade(5000)),
            contentScale = contentScale,
            imageModel = imageUrl.toString(),
            shimmerParams = ShimmerParams(
                baseColor = Color.LightGray,
                highlightColor = Color.White,
                durationMillis = 500
            )
    )

As you can see no cross fade at all

Shall I create separate issues for this?

skydoves commented 3 years ago

Hi @atonamy Could you build using the demo project? There are two possibilities.

  • Image loading is too fast. Then please make slow your network environment, (WIFI)
  • baseColor or highlightColor is same as the background color. Then you can't see the shimmer because it was overlapped.

When I set the same same baseColor with ComposeView background color is not working properly when I changed baseColor of shimmerParams or background color of ComposeView to different one it started working.

That seems to work correctly. The shimmer works but you can't see because the color is the same. Use different colors with the background color.

skydoves commented 3 years ago

Also circularRevealedEnabled property not reviling properly some images for example image like this

The outcome the circle is not completing animation and keep corners rounded:

And withCrossFade also not working

GlideImage(
            modifier = modifier,
            requestBuilder = Glide
            .with(LocalView.current)
            .asBitmap()
            .transition(withCrossFade(5000)),
            contentScale = contentScale,
            imageModel = imageUrl.toString(),
            shimmerParams = ShimmerParams(
                baseColor = Color.LightGray,
                highlightColor = Color.White,
                durationMillis = 500
            )
    )

As you can see no cross fade at all

Shall I create separate issues for this?

Could you build again with this option on your modifier? .aspectRatio(3.0f). withCrossFade will not work correctly and that is the expected result. Because the internal Glide image processor on this library doesn't use the ImageView concept for rendering fetched images. You can use the CrossFade Composable function instead!

atonamy commented 3 years ago

.aspectRatio(3.0f)

Unfortunately this option didn't help.

Then if withCrossFade is not working why this examples shows in README.md file ?

Screenshot 2021-08-24 at 1 17 26 PM Screenshot 2021-08-24 at 1 17 51 PM
skydoves commented 3 years ago

Whoops, the README should be modified. Glide's Transition.ViewAdapter interfaces are based on the Android's View, so we should build the corssfade effect using the CrossFade in Jetpack Compose like the below. (Just a simple example without shimmer and circular reveal animation)

Crossfade(
    targetState = poster,
    animationSpec = tween(3000)
  ) {

    GlideImage(
      imageModel = it?.poster!!,
      modifier = Modifier.aspectRatio(0.8f),
      bitmapPalette = BitmapPalette {
        palette = it
      }
    )
  }

Also, the circular reveal animation seems like a bug! I will try to fix it in the next version. Thanks!

skydoves commented 3 years ago

Fixed on a new SNAPSHOT release: 1.3.7-SNAPSHOT. This will be included in the next stable release. Thanks for your report!