compose-multiplatform icon indicating copy to clipboard operation
compose-multiplatform copied to clipboard

Compose resources miss "assets" resources, no way to get Res id from it's name, no way to load bitmap from stream/bytes/file

Open andrey-shikhov opened this issue 1 year ago • 6 comments

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

andrey-shikhov avatar Mar 16 '24 16:03 andrey-shikhov

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.

KevinnZou avatar Mar 18 '24 03:03 KevinnZou

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.

dshatz avatar Mar 19 '24 13:03 dshatz

THank you for the enhancement. We understand your use case and will think about it.

pjBooms avatar Mar 19 '24 17:03 pjBooms

One of the possible variants is

val myDrawable: DrawableResource = Res.getAsDrawableResource("path/to/drawable/file")

terrakok avatar Mar 19 '24 17:03 terrakok

+1 to getting resources by name Need that for runtime translations

H4kt avatar Apr 10 '24 13:04 H4kt

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

rsktash avatar May 05 '24 12:05 rsktash

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

okushnikov avatar Aug 26 '24 13:08 okushnikov