Bradleycorn
11/12/2020, 12:09 AMCoilImage
composable from the Accompanist library that @cb put together? I’m wondering what’s the best way to use a placeholder image resource when my composable is displayed via a @Preview
? During preview the image state is Empty
, so I thought about using the content composable and setting a placeholder image when image state is empty. That works. But, the placeholder image is also displayed briefly (before the actual image is loaded) when the app is run on a device, and I don’t want that.Tash
11/12/2020, 12:12 AM@Preview
you could pass in a placeholder composable, but in the real implementation it could be blank?Bradleycorn
11/12/2020, 12:17 AMBlogPost(post: Post)
composable that takes a post object and renders the blog post. It contains an image, title, author, text, etc. So the CoilImage is in the BlogPost composable. I want to build a Preview for BlogPost like so:
@Preview
@Composable
fun postPreview() {
val post = GetMockPost()
BlogPost(post)
}
Rafs
11/12/2020, 12:20 AMCoilImage
started crashing after I upgraded to alpha06
Bradleycorn
11/12/2020, 12:21 AMBlogPost
a “slot api” so that you could pass it content for the “empty” state:
@Composable
fun BlogPost(
post: Post,
empty: @Composable()->Unit = {},
content: @Composable () -> Unit =())
Tash
11/12/2020, 12:25 AMBradleycorn
11/12/2020, 12:30 AMBlogPost
composable so that I can provide an image during preview, and nothing when the app runs.Tash
11/12/2020, 1:02 AM@Composable
fun BlogPost(post: Post, content: @Composable: () -> Unit) {
...
}
@Composable
fun BlogImageContent(placeholder: @Composable: () -> Unit) {
...
}
@Preview
fun BlogPreview() {
BlogPost {
BlogImageContent {
placeholder()
}
}
}
cb
11/12/2020, 7:24 AMThe placeholder image is also displayed briefly (before the actual image is loaded) when the app is run on a device, and I don't want that.
Sounds like a bug to me. Initial thought is that I could change the logic so that the placeholder is only shown after X milliseconds after the request starts.
Bradleycorn
11/12/2020, 9:54 PMcb
11/12/2020, 9:54 PMBradleycorn
11/12/2020, 9:55 PM