Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Image Loading] Display something better when in Preview #150

Closed
2 tasks
chrisbanes opened this issue Nov 18, 2020 · 4 comments
Closed
2 tasks

[Image Loading] Display something better when in Preview #150

chrisbanes opened this issue Nov 18, 2020 · 4 comments
Labels
stale Stale issues which are marked for closure

Comments

@chrisbanes
Copy link
Contributor

Currently CoilImage, PicassoImage, and GlideImage all have different issues when used in @Preview. We should do something better.

  • Make sure that using each of these functions does not crash the preview
  • Think about adding a placeholder parameter to be displayed when in preview.
@Bradleycorn
Copy link

This may be a terrible/impossible idea (I'm still very new to Compose and in way over my head here), but ...

Is there some way that you can "detect" that the composable is being rendered as a preview?

If so, maybe when the *Image() composable detects that it's in preview mode, it attempts to use a (developer defined) PreviewImageLoader if it exists instead of its normal ImageLoader. Defining a PreviewImageLoader could be as simple as defining a map of the url's that are used in previews to local resources to load when one of the url's is found?

Or maybe you don't need the detection and PreviewImageLoader at all ... Maybe the developer could supply the standard ImageLoader with a map of url->drawable, and anytime the loader is asked to load one of those urls, it will use the drawable instead of trying to fetch the url.

Another (probably really bad) idea ... when the data parameter is parsed and is a string, check to see if it's a URL or if its specifies drawable (like "R.drawable.my_preview_image"). If it's determined to be a drawable, the actual resource could be parsed out, and the drawable loaded and returned. Something like this extension method on R.drawable could be used to parse the drawable string into an actual drawable int:

fun R.drawable.fromString(drawable: String): Int {
    try {
        val field = javaClass.getField(drawable.replace("R.drawable.", ""))
        return field.getInt(field)
    } catch (ex: Exception) {
        TODO("Uh oh!")
    }
}

@chrisbanes
Copy link
Contributor Author

I like the idea of a PreviewImageLoader but ImageLoader isn't a class we own. Same for the equivalent classes for GlideImage and PicassoImage.

We could abstract these away behind a ImageLoadEngine class and do something similar though.

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the stale Stale issues which are marked for closure label May 19, 2021
@chrisbanes
Copy link
Contributor Author

Closing this, as previewPlaceholder was added a few releases ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Stale issues which are marked for closure
Projects
None yet
Development

No branches or pull requests

2 participants