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.13k stars 114 forks source link

placeholder not working, StateListDrawable cannot be cast to BitmapDrawable #97

Closed andreas-kkday closed 2 years ago

andreas-kkday commented 2 years ago

Please complete the following information:

Describe the Bug:

Use placeholder code in README

FrescoImage(
            imageUrl = uri,
            // Crop, Fit, Inside, FillHeight, FillWidth, None
            contentScale = ContentScale.Crop,
            // shows an image with a circular revealed animation.
            circularReveal = CircularReveal(duration = 250),
            // shows a placeholder ImageBitmap when loading.
            placeHolder = ImageBitmap.imageResource(android.R.drawable.btn_default),
            // shows an error ImageBitmap when the request failed.
            error = ImageBitmap.imageResource(android.R.drawable.stat_notify_error),
            previewPlaceholder = android.R.drawable.btn_default,
            modifier = Modifier.height(90.dp)
        )

App crash

java.lang.ClassCastException: android.graphics.drawable.StateListDrawable cannot be cast to android.graphics.drawable.BitmapDrawable
        at androidx.compose.ui.res.ImageResources_androidKt.imageResource(ImageResources.android.kt:39)
        at androidx.compose.ui.res.ImageResources_androidKt.imageResource(ImageResources.android.kt:58)
        at com.kkday.component.TextViewWithImageTagComposeKt.TextWithImageButtonCompose(TextViewWithImageTagCompose.kt:31)
        at com.example.composeapplication.MainActivityKt.Greeting(MainActivity.kt:69)

Expected Behavior:

I could not find placeholder example in the project.

skydoves commented 2 years ago

Hey @andreas-kkday, The crash shows you used StateListDrawable instead of the BitmapDrawable. Could you try to build with another single-state image? such as ic_android.xml or something just an icon image.

andreas-kkday commented 2 years ago

Thank you, using .png image resource is working.