简体   繁体   中英

Coil placeholder not showing if vectorpainter is used in jetpack compose

I am using the following code to display an image.

       AsyncImage(
               model = createImageUrl(audio.image_path),
                   contentDescription = "Song Artwork",
                    modifier = Modifier.fillMaxHeight()
                                       .aspectRatio(1f)
                                       .padding(horizontal = 4.dp),
                    placeholder = rememberVectorPainter(image = Icons.Outlined.MusicNote)
                )

The placeholder image is not being shown. Howeve, if I use placeHolder = painterResource(R.drawable.someDrawableInMyResource), the drawable is being shown when image is loaded.

What am I doing wrong?

I found what I was doing wrong. I was in dark theme and the image vector`s tint color matched my background and thus nothing was being shown.

May help someone.

Edit: Well my question changed.. How to change placeholder tint to match my theme?

var loaded by remember {
        mutableStateOf(false)
    }
    AsyncImage(
        model = createImageUrl(audio.image_path),
        contentDescription = "Song Artwork",
        modifier = Modifier.fillMaxHeight().aspectRatio(1f).padding(horizontal = 4.dp),
        placeholder = rememberVectorPainter(image = Icons.Default.MusicNote),
        error = rememberVectorPainter(image = Icons.Default.MusicNote),
        fallback = rememberVectorPainter(image = Icons.Default.MusicNote),
        onSuccess = {
            loaded = true
        },
        colorFilter = if (!loaded) ColorFilter.tint(LocalContentColor.current) else null
    )

I used this workaround and this works. I am open for another clean suggestions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM