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

[gradle] Generate method to create drawable or font resource accessors by a file path. #4909

Closed
wants to merge 1 commit into from

Conversation

terrakok
Copy link
Collaborator

@terrakok terrakok commented May 31, 2024

Now we can get resource accessors by the path.

Icon(
  painterResource(Res.drawable.byPath("drawable/my_icon.xml")),
  contentDescription = null
)

The new API doesn't work with qualifiers and environment. It associates a concrete file with a new resource instance.
If there are two icons: drawable-night/my_icon.xml and drawable-light/my_icon.xml, users are supposed to select a right icon by their own.

It doesn't work for strings resources. There is no a such thing as a full qualified key for the string in a text representation. (as path for other resource types) We need to combine an xml file path + key inside. It is not what we want.

I understand that someone would like to have something like a runtime search in their string resources based on a string key and a current environment but it is a huge performance problem. That's why we converted XML files to the internal format and use generated classes instead. To iterate by files in the runtime is not possible.

Note: there is a way to generate a special map: key -> value and use for the search but it requires more resources to maintain it then brings a profit.

So, for the case it's possible to save strings to the regular txt file and read it as string on app's side.

Fixes #4880

Release Notes

Features - Resources

  • Generate method to create drawable or font resource accessors by a file path.

@terrakok
Copy link
Collaborator Author

terrakok commented Jun 5, 2024

After an internal discussion we agreed that the right way is to add utility functions to convert ByteArrays to ImageBitmap/XmlElement/SvgElement in the compose core library.

#4925

To use strings as keys for resources is different story and will be discussed separately.

@terrakok terrakok closed this Jun 5, 2024
@terrakok terrakok deleted the k.tskh/res-by-path branch July 10, 2024 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support getting resources by key
1 participant