Compose resources miss "assets" resources, no way to get Res id from it's name, no way to load bitmap from stream/bytes/file
I tried to upgrade compose multiplatform from 1.5.12 to 1.6.0 and found out that I can't load resources anymore :( Resources are images with metadata which are stored like commonMain/images/[type]/[imageId]/config.json commonMain/[type]/[imageId]/image.png commonMain/[type]/[imageId]/thumbnail.webp
Android has assets api to support own resource hierarchy, compose 1.5.12 successfully loads images in the same way by using path, but in 1.6.0 I only limited to single folder which is really hard to use when you have hundreds of images, which also can have the same name, for example 1.png can be avatar with id 1, and emoji with id 1, but their absolute path is different so no problem with compose 1.5
Even if I write a script which will rename all files and puts in the one folder I can't get avatar_1.png, because there is no api like context.resources.getIdentifier() on android platform
Also there is no api to load images like BitmapFactory.decodeResource on android.
Unfortunately for now I go back to the compose 1.5.12 with handmade font loading & localisation
I encountered the same issue in my CMP Webview library with CMP 1.6.0. Previously, I would place the HTML files in the commonMain/resources/assets folder. This would automatically package the files into the Android assets folder, allowing us to load them using the webView.loadUrl("file:///android_asset/$fileName") method. However, after upgrading to 1.6.0, we moved the HTML files to the commonMain/composeResources/files/assets folder, but got FILE_NOT_FOUND error.
Would be very useful to be able to load images inside files/ as drawables too. With my usecase I need to load the images by their name (country flags), so they have to be in files/ directory.
Or let us load drawables by their name as String.
THank you for the enhancement. We understand your use case and will think about it.
One of the possible variants is
val myDrawable: DrawableResource = Res.getAsDrawableResource("path/to/drawable/file")
+1 to getting resources by name Need that for runtime translations
Please, make url paths absolute for JS!
NOT: composeResources/package.name/values/strings.commonMain.cvr BUT: /composeResources/package.name/values/strings.commonMain.cvr
When url is dynamically changed via window.history.pushState() resources cannot be found giving 404 error
@terrakok
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.