Git Product home page Git Product logo

Comments (4)

chrisbanes avatar chrisbanes commented on March 29, 2024 1

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.

from accompanist.

Bradleycorn avatar Bradleycorn commented on March 29, 2024

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!")
    }
}

from accompanist.

github-actions avatar github-actions commented on March 29, 2024

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.

from accompanist.

chrisbanes avatar chrisbanes commented on March 29, 2024

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

from accompanist.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.