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.

Home Page:https://skydoves.github.io/landscapist/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Coil] Placeholder plugin doesn't work

alaegin opened this issue · comments

Please complete the following information:

  • Library Version v2.1.7
  • Affected Device(s) Google Pixel 7 Pro with Android 13, Samsung Galaxy S20FE with Android 13

Describe the Bug:

PlaceholderPlugin.Loading doesn't work at all. Even in sample benchmark app.

I've cleaned benchmark activity for testing purposes:

class MainActivity : ComponentActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    setContent {
      val imageComponent = imageComponent {
        +PlaceholderPlugin.Loading(painterResource(id = R.drawable.poster))
      }

      CompositionLocalProvider(LocalImageComponent provides imageComponent) {
        Column {
          CoilImageProfiles()
        }
      }
    }
  }
}

// Image was replaced with extra big one to ensure the loading delay.
@Composable
fun CoilImageProfiles() {
  CoilImage(
    modifier = Modifier.size(120.dp),
    imageModel = { "https://www.kenrockwell.com/nikon/d810/sample-images/file-types/810_3435-LARGE-FINE-OPT-QUAL.JPG" },
    component = LocalImageComponent.current,
  )
}

There should be exactly one placeholder and exactly one image then. But, when I open the app I see only a white screen and the target image after several seconds.

I've tried to debug this issue and found out that Loading state was not called at all inside the onImageStateChanged (Seems like that placeholder works based on these states)

The entire state log:

2023-03-14 20:59:06.986  3854-3854  System.out  com...ves.benchmark.landscapist.app  I  com.skydoves.landscapist.coil.CoilImageState$None@de0d496
2023-03-14 20:59:07.073  3854-3854  System.out  com...ves.benchmark.landscapist.app  I  com.skydoves.landscapist.coil.CoilImageState$None@de0d496
2023-03-14 20:59:10.697  3854-3854  System.out  com...ves.benchmark.landscapist.app  I  Success(drawable=android.graphics.drawable.BitmapDrawable@8d542e2, dataSource=NETWORK)

It had just been showing the None state for several seconds until the image was loaded.

Reproduction:

@Composable
fun CoilImageProfiles() {
  CoilImage(
    modifier = Modifier.size(120.dp),
    imageModel = { "https://www.kenrockwell.com/nikon/d810/sample-images/file-types/810_3435-LARGE-FINE-OPT-QUAL.JPG" },
    component = LocalImageComponent.current,
    onImageStateChanged = {
      println(it) // <- Prints only None and Success states
    }
  )
}

Expected Behavior:

I expect placeholder plugin to call placeholder image while target image is being loaded.

This issue was solved in the new release, 2.1.8. Thank you for reporting this important issue!