https://kotlinlang.org logo
#compose
Title
# compose
c

Colton Idle

05/31/2021, 4:35 AM
Anyone know how to use accompnist/coil +
Crossfade()
? The docs state that you CAN crossfade, but not exactly how? I also looked at Owl sample app but didn't see usage of crossfade either.
a

Albert Chang

05/31/2021, 5:08 AM
Something like
Copy code
val painter = rememberCoilPainter(request = request)
Crossfade(targetState = painter.loadState is ImageLoadState.Success) { success ->
    if (success) Image(painter = painter, contentDescription = contentDescription)
}
👆 1
c

cb

05/31/2021, 10:18 AM
If you want to use Compose
Crossfade
then Albert’s answer is correct.
c

Colton Idle

05/31/2021, 1:09 PM
I didn't even realize compose had Crossfade. I was originally talking about coils Crossfade though
From the original coil docs: Requests can be configured with an optional trailing lambda:
Copy code
imageView.load("<https://www.example.com/image.jpg>") {
    crossfade(true)
    placeholder(R.drawable.image)
    transformations(CircleCropTransformation())
}
Anyone know how I would use coil crossfade, or does it not make sense in a compose world and I should instead use composes crossfade?
c

cb

06/02/2021, 10:29 PM
Coil’s crossfade doesn’t work in Accompanist as we don’t currently implement the special
Target
interface required. Any reason why you’re not using
fadeIn
?
c

Colton Idle

06/02/2021, 11:23 PM
Just seemed quicker to be able to add a quick Crossfade = true boolean. 😁 So if I want to do it in the supported way should I use fadeIn or crossFade?
Was finally able to circle back to this. Ideas why my placeholder doesn't show?
Copy code
val painter = rememberCoilPainter(request = imageUrl)

Crossfade(targetState = painter.loadState) {
    when (it) {
        ImageLoadState.Empty -> {}
        is ImageLoadState.Loading -> {
            Spacer(modifier = Modifier.matchParentSize().background(Color(0xffff0000)))
        }
        is ImageLoadState.Success -> {
            Image(
                painter = painter,
                contentDescription = null,
                contentScale = ContentScale.Crop,
                alpha = alpha)
        }
        is ImageLoadState.Error -> {}
    }
}
c

cb

06/08/2021, 6:36 AM
Because the parent
Crossfade
doesn’t have a size? The match parent size is probably resolving to 0,0
4 Views