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

[Resource] Drawable scaling from other density-qualified resource #4368

Closed
xiaozhikang0916 opened this issue Feb 26, 2024 · 4 comments · Fixed by #4969
Closed

[Resource] Drawable scaling from other density-qualified resource #4368

xiaozhikang0916 opened this issue Feb 26, 2024 · 4 comments · Fixed by #4969
Assignees
Labels
enhancement New feature or request resources

Comments

@xiaozhikang0916
Copy link
Contributor

xiaozhikang0916 commented Feb 26, 2024

As Android Devices Compatibility guide shows,

To provide good graphical quality on devices with different pixel densities, provide multiple versions of each bitmap in your app—one for each density bucket, at a corresponding resolution. Otherwise, Android must scale your bitmap so it occupies the same visible space on each screen, resulting in scaling artifacts such as blurring.

Which indicates that if drawable with qualifier matches current screen is not found, Android will fetch drawable with other qualifier and scale it to fit.

In our prectice, we only provide drawable-xxhdpi to keep the product apk small. But in the generated compose resources, it just fail if the best-match drawable not found.

IMO, it would be nice to have features that:

  1. Scaling drawable from other density-qualified resource if best-matched not found,
  2. Attaching qualifiers info in the resources returned by Res.
@dima-avdeev-jb
Copy link
Contributor

Thanks for this feature request! We will discuss it.

@terrakok
Copy link
Collaborator

Could you elaborate why the default drawable dir is not suitable for you?

@xiaozhikang0916
Copy link
Contributor Author

Your question bring me to a rethought of my usage.

In some of our usages, we don't specify the size of drawable or ImageView, just set it to wrap_content and apply a drawable to it. The drawable itself, with size in pixel and density qualifier info can determine the size in Dp. But in compose resources, the size modifier will be required for variant devices density.

That is what I requested in feature 1. But I am not sure if it is a good prectice in UI coding.

Anyway, feature 2 will be helpful not only in this case, but also any other if more customization needed.

@terrakok
Copy link
Collaborator

I need more examples for "if more customization needed". I guess it should be covered by #4197

terrakok added a commit that referenced this issue Jun 20, 2024
… android logic (#4969)

In general, Android prefers scaling down a larger original image to
scaling up a smaller original image:
https://developer.android.com/guide/topics/resources/providing-resources#BestMatch

Fixes #4368

## Release Notes
### Highlights - Resources
- If there is no resource with suitable density, use resource with the
most suitable density, otherwise use default (similar to the Android
logic)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request resources
Projects
None yet
3 participants