coil icon indicating copy to clipboard operation
coil copied to clipboard

Add support for applying transformation placeholder/error drawables

Open Stonos opened this issue 5 years ago • 14 comments

Is your feature request related to a problem? Please describe. Suppose an ImageView showing the user's avatar. The user's avatar is loaded with a placeholder and has the CircleCropTransformation transformation applied to it. The placeholder will not be round which may cause the app to not look right on places where the avatar is expected to always be a circle.

Describe the solution you'd like It should be possible to apply tranformations to the placeholder/error drawable as well. This could either be something like transformationsPlaceholder(...) or enablePlaceholderTransformations(true).

Another option would be to provide an overload on placeholder that accepts a RequestDisposable as an argument (similar to how Glide does it). This would also solve #27.

Stonos avatar Aug 16 '19 12:08 Stonos

I'm running into the same problem, trying to set a placeholder image that is circle cropped. I'm getting a square placeholder image then the circle cropped image that is loaded. Is this issue still not resolved?

[UPDATE] Learned that Glide may not support this as well. For a simple workaround, created circle cropped placeholder image which for my purposes is probably better.

alanleedev avatar Dec 24 '19 04:12 alanleedev

@colinrtwhite do you want this functionality?

mario avatar Jan 06 '20 22:01 mario

I'd like to add this eventually as part of supporting chaining requests (similar to this issue https://github.com/coil-kt/coil/issues/27). I haven't settled on an API yet, though.

colinrtwhite avatar Jan 07 '20 04:01 colinrtwhite

any updates on chaining requests? would love to have it.

gowthamgts avatar Nov 21 '20 07:11 gowthamgts

Hi, any update on this enhancement, or If anyone can help how we can transform the error placeholder.

jaswinder01 avatar Dec 02 '20 11:12 jaswinder01

Any updates?

Daphne-CoffeeIT avatar Apr 07 '21 09:04 Daphne-CoffeeIT

This enhancement would be great. For those who look for a basic workaround see below;

sampleImageView.load(imageUrl) {
    target(
        onSuccess = {
            sampleImageView.load(imageUrl) {
                crossfade(true)
                transformations(RoundedCornersTransformation(30f))
            }
        },
        onError = {
            handleError(it)
        }
    )
}

I know, it looks ugly as hell 🤮

yektasarioglu avatar May 28 '21 10:05 yektasarioglu

Hi, any update on this enhancement, or If anyone can help how we can transform the error placeholder.

appdev avatar Aug 19 '21 01:08 appdev

@colinrtwhite Is this enhancement planned? I really need it

android-1995 avatar Aug 27 '21 08:08 android-1995

Seconding here that this I also really need this. I use rounded corners on my AppWidget images and using the RoundedCornersTransformation with coil is the only feasible way I can send a rounded error drawable to the widget.

OxygenCobalt avatar Nov 14 '21 18:11 OxygenCobalt

so long time never update, lose hope

Qdafengzi avatar Nov 29 '21 03:11 Qdafengzi

I solved this problem use Gilde 😈

appdev avatar Dec 22 '21 09:12 appdev

fun ImageView.loadImage(url: String?) {
    load(url) {
        transformations(RoundedCornersTransformation(context.getDp(R.dimen.radius_image))).placeholder(
            R.drawable.profile_avatar_logo
        ).error(R.drawable.profile_avatar_logo)
    }

}

fun ImageView.loadCircleImage(url: String?) {
    load(url) {
        transformations(CircleCropTransformation()).placeholder(R.drawable.profile_avatar_logo)
            .error(R.drawable.profile_avatar_logo)
    }
}

fun ImageView.loadImage(id: Int) {
    load(id) {
        transformations(RoundedCornersTransformation(context.getDp(R.dimen.radius_image))).placeholder(
            R.drawable.profile_avatar_logo
        ).error(R.drawable.profile_avatar_logo)
    }
}

fun ImageView.loadCircleImage(id: Int) {
    load(id) {
        transformations(CircleCropTransformation()).placeholder(R.drawable.profile_avatar_logo)
            .error(R.drawable.profile_avatar_logo)
    }
}

Sanaebadi97 avatar Dec 26 '21 07:12 Sanaebadi97

I'm having the same issue. Also I've used CircleImageView from an external library to get round images, but Coil don't change image from placeholder to downloaded one, so I tried to use basic ImageViews and it seems there topic-related issue with them too. Almost three years without progress?

iskaldvind avatar Mar 13 '22 16:03 iskaldvind

Currently I think using oval shape is the best choice:

<shape android:shape="oval"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke android:width="1dp" android:color="#ffffffff" />
    <solid android:color="#ff7be0dd" />
</shape>
fun ImageView.loadCircleImage(image: Any?) = load(image) {
    crossfade(true)
    transformations(CircleCropTransformation())
    placeholder(R.drawable.round_7be0dd_stroke_white)
    error(R.drawable.round_ff8bff_stroke_white)
}

smzh369 avatar Jun 28 '23 02:06 smzh369