Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
andrey-shikhov opened this issue Mar 16, 2024 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@andrey-shikhov
Copy link

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 andrey-shikhov added enhancement New feature or request submitted labels Mar 16, 2024
@KevinnZou
Copy link

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.

@dshatz
Copy link

dshatz commented Mar 19, 2024

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.

@pjBooms
Copy link
Collaborator

pjBooms commented Mar 19, 2024

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

@terrakok
Copy link
Collaborator

One of the possible variants is

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

@H4kt
Copy link

H4kt commented Apr 10, 2024

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

@rustamsmax
Copy link

rustamsmax commented May 5, 2024

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

@terrakok terrakok closed this as not planned Won't fix, can't repro, duplicate, stale Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

8 participants