Are there no standard function to receive files fr...
# compose
g
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
What does a UI framework has to do with json files?
a
There is
stringResource
for strings.xml resources. If you want to get json assets then you can always get context with
ContextAmbient.current
j
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
g
@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
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
j
@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()
👍 1
for example for reading the text of your json files
g
Thank you! This is a nice option, never used classloaders before, except for testing.
j
Yeah, I use it for testing too, that is the reason I use
!!