Skip to content

Fix Recycling of Animated Images#49850

Closed
NickGerleman wants to merge 1 commit into
facebook:mainfrom
NickGerleman:export-D70668516
Closed

Fix Recycling of Animated Images#49850
NickGerleman wants to merge 1 commit into
facebook:mainfrom
NickGerleman:export-D70668516

Conversation

@NickGerleman
Copy link
Copy Markdown
Contributor

Summary:
RCTUIImageViewAnimated has some bugs around reuse.

  1. Recycling will set image to null, which will no-op on comparison to self.image, but self.image is always null when the image is animated, because RCTUIImageViewAnimated handles rendering the frames itself. This means we don't properly do things like invalidating the DisplayLink when the image is first recycled.

  2. If we ever set superclass image to nil, we make some change to the underlying CALayer, which causes the content to remain black, even though we customize our own displayLayer. Diffing layer descriptions, we seem to afterward have a contentsMultiplyColor and contentsSwizzle on the layer that aren't public.

The solution I have in this diff is to, instead of drawing layers ourselves, update backing UIImage image to the frame. I think this would fix some other bugs as well, like tintColor not applying to animated images. My guess is that this shouldn't add too much extra work, since UIImageView should just be propagating the UIImage to the layer in a same way that we were before. This same bug may have also been possible before when switching between animated and non-animated image sources I think.

Changelog:
[iOS][Fixed] - Fix Recycling of Animated Images

Differential Revision: D70668516

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner labels Mar 6, 2025
@NickGerleman NickGerleman force-pushed the export-D70668516 branch 4 times, most recently from d99245c to cfd0eaf Compare March 6, 2025 19:03
Summary:
`RCTUIImageViewAnimated` has some bugs around reuse.

1. Recycling will set `image` to null, which will no-op on comparison to `self.image`, but `self.image` is always null when the image is animated, because  `RCTUIImageViewAnimated` handles rendering the frames itself. This means we don't properly do things like invalidating the DisplayLink when the image is first recycled.

2. If we ever set superclass image to nil, we make some change to the underlying CALayer, which causes the content to remain black, even though we customize our own `displayLayer`. Diffing layer descriptions, we seem to afterward have a `contentsMultiplyColor` and `contentsSwizzle` on the layer that aren't public.

The solution I have in this diff is to, instead of drawing layers ourselves, update backing UIImage image to the frame. I think this would fix some other bugs as well, like tintColor not applying to animated images. My guess is that this shouldn't add too much extra work, since `UIImageView` should just be propagating the `UIImage` to the layer in a same way that we were before. This same bug may have also been possible before when switching between animated and non-animated image sources I think.

Changelog:
[iOS][Fixed] - Fix Recycling of Animated Images

Reviewed By: cipolleschi, joevilches

Differential Revision: D70668516
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D70668516

@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D70668516

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Mar 6, 2025
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request has been merged in 1a9adfb.

@react-native-bot
Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @NickGerleman in 1a9adfb

When will my fix make it into a release? | How to file a pick request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants