Thread
#compose
    Geert

    Geert

    1 year ago
    Are there no standard function to receive files from the resources folder? I have some json files included, but I can only find functions for imageassets, not for text.
    j

    Joost Klitsie

    1 year ago
    What does a UI framework has to do with json files?
    André Kindwall

    André Kindwall

    1 year ago
    There is
    stringResource
    for strings.xml resources. If you want to get json assets then you can always get context with
    ContextAmbient.current
    j

    Joost Klitsie

    1 year ago
    I mean there are ways in Android to get files, and then there are ways to remember actions in compose. I'd say, you should combine it. I think if you check the code of the image asset loading you can probably make your own composable file loader
    Geert

    Geert

    1 year ago
    @André Kindwall yeah I know. I was just wondering why there wasn’t a standard function
    But what @Joost Klitsie said, it is a UI framework
    I’m looking into it to much from an android perspective I guess
    j

    Joost Klitsie

    1 year ago
    if you open
    androidx.compose.ui.res.ImageResource.kt
    I think you can copy/paste the code and adjust what you need. It looks like
    loadResource
    might help you out
    Javier

    Javier

    1 year ago
    @Geert load a json from
    resources
    folder is not even an Android thing, you can achieve it with an extension function which only depends on JVM.
    fun Any.readResource(file: String): String = this::class.java.classLoader.getResource(file)!!.readText()
    for example for reading the text of your json files
    Geert

    Geert

    1 year ago
    Thank you! This is a nice option, never used classloaders before, except for testing.
    Javier

    Javier

    1 year ago
    Yeah, I use it for testing too, that is the reason I use
    !!