Has anyone written a composable that can display a...
# compose
z
Has anyone written a composable that can display an image from firebase storage? I had something working on an older alpha but I’m curious if there’s a new option.
m
AFAICT, there are recipes for using Firebase Storage with Coil and Glide. You could then use Accompanist (https://github.com/google/accompanist) as the composable wrapper.
👍 2
z
Thanks!
I’ve been heading that direction, this works but I’m not happy with it yet.
Copy code
@Composable
fun NetworkImage(url: String, modifier: Modifier = Modifier, @DrawableRes placeholder : Int = R.drawable.placeholder) {
    if (url.isEmpty()) {
        Image(painter = painterResource(id = placeholder), modifier = modifier, contentDescription = "Placeholder")
        return
    }

    val reference = Firebase.storage.getReference(url)
    var downloadUrl by remember { mutableStateOf("") }
    reference.downloadUrl.addOnCompleteListener {
        downloadUrl = it.result.toString()
    }

    CoilImage(modifier = modifier, contentScale = ContentScale.Crop, data = downloadUrl, contentDescription = "")
}
m