Skip to content

[Drawable Painter] Fix AnimatedImageDrawable rendered in wrong size for systems below Android 12#1817

Merged
bentrengrove merged 1 commit into
google:mainfrom
landicefu:main
Apr 28, 2025
Merged

[Drawable Painter] Fix AnimatedImageDrawable rendered in wrong size for systems below Android 12#1817
bentrengrove merged 1 commit into
google:mainfrom
landicefu:main

Conversation

@landicefu

Copy link
Copy Markdown
Contributor

AnimatedImageDrawable doesn't respect bounds set to it when the Android version is below 12.

On Android version below 12, if we use the current way to render (setBounds), the size doesn't change with the container at all. It's always following intrinsic size which is wrong.

I've created a sample project for you to test it out.
issue-demo-animated-image-drawable.zip

Also, you can see from following videos to understand the issue.

Tested on Android 10

android.10.11.result.mov

Tested on Android 12

android.12.result.mov

Following is the commit in AOSP to add setBounds to AnimatedImageDrawable.
https://cs.android.com/android/_/android/platform/frameworks/base/+/be969efdb0234b7b39636ec0a586dbb708ec480d

This first appeared in android-12.0.0_r1, and this is the proof.
image

@landicefu landicefu changed the title [Drawable Painter] Fix rendered in wrong size for AnimatedImageDrawable below Android 12 [Drawable Painter] Fix AnimatedImageDrawable rendered in wrong size for systems below Android 12 Apr 21, 2025
@landicefu

landicefu commented Apr 25, 2025

Copy link
Copy Markdown
Contributor Author

@bentrengrove Hello. We are affected by this problem pretty seriously because we use a lot of animated webp images in our app. Coil is using DrawablePaint for Drawables.
I wonder is there a chance this can be merged and release soon so we can ask coil to do an update?

We now use a custom version of AsyncImage and in it we use a modified DrawablePainter, but people can easily forget about the problem and use the vanilla AsyncImage which still have the problem.

Thanks in advance.

@bentrengrove

Copy link
Copy Markdown
Collaborator

Unfortunately, this is intentional behaviour. I suggest forking this implementation if that is what is required for your use case, we couldn't ship this because we would suddenly be scaling every drawable.

This was previously closed here https://github.com/google/accompanist/pull/1771/files

@landicefu

landicefu commented Apr 28, 2025

Copy link
Copy Markdown
Contributor Author

@bentrengrove How about adding condition to apply this only for AnimatedImageDrawable on systems below Android 12? This is definitely wrong rendering behavior and not intentional. The root cause is in the framework base, but that's not something we can change now.

Otherwise, I can only suggest coil to make a fork and fix this, and I don't think the position off is intentional, although it's AnimatedImageDrawable who was not following the spec.

@bentrengrove

Copy link
Copy Markdown
Collaborator

OK. Yes, I would accept a PR that only applied this workaround as you describe. On Android <12 and for AnimatedImageDrawable. Would you be willing to make those changes?

@bentrengrove bentrengrove reopened this Apr 28, 2025
@landicefu

Copy link
Copy Markdown
Contributor Author

No problem. I will make that change today. Thank you very much for considering this!!!

@landicefu

Copy link
Copy Markdown
Contributor Author

I've made the changes. Let me know if anything should be further adjusted. Thanks

@bentrengrove bentrengrove enabled auto-merge April 28, 2025 03:51
@bentrengrove

Copy link
Copy Markdown
Collaborator

Looks like you just have spotless errors

./gradlew :drawablepainter:spotlessApply

auto-merge was automatically disabled April 28, 2025 04:01

Head branch was pushed to by a user without write access

@landicefu

Copy link
Copy Markdown
Contributor Author

Okay. It's done.

@bentrengrove bentrengrove enabled auto-merge April 28, 2025 04:03
@bentrengrove bentrengrove merged commit 9dcd688 into google:main Apr 28, 2025
@bentrengrove

Copy link
Copy Markdown
Collaborator

This has been released as 0.37.3

@landicefu

Copy link
Copy Markdown
Contributor Author

thank you!! ❤️

@jgranger1 jgranger1 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not shore what this is about not shore what I need to do I'm I supposed to do something

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.

4 participants