Skip to content

SDAnimatedImageView, 判断前后image相同时会return,若外部利用runtime覆盖UIImageView.setImage,SDAnimatedImageView这个行为会阻断调用栈#3874

Merged
dreampiggy merged 1 commit intoSDWebImage:masterfrom
CloudlessMoon:master
Apr 10, 2026

Conversation

@CloudlessMoon
Copy link
Copy Markdown
Contributor

@CloudlessMoon CloudlessMoon commented Apr 3, 2026

SDAnimatedImageView, 判断前后image相同时会return,若外部利用runtime覆盖UIImageView.setImage,SDAnimatedImageView这个行为会阻断调用栈,这里应该保持UIImageView的默认行为,调用super.image = image;

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an image synchronization issue that could occur when repeated image assignments were made, ensuring consistent display behavior.

…tImage,SDAnimatedImageView这个行为会阻断调用栈,这里应该保持UIImageView的默认行为,调用super.image = image;
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e68283b4-0d22-4c42-bc13-45099392e184

📥 Commits

Reviewing files that changed from the base of the PR and between 2de3a49 and 874baf1.

📒 Files selected for processing (1)
  • SDWebImage/Core/SDAnimatedImageView.m

📝 Walkthrough

Walkthrough

In SDAnimatedImageView's setImage: method, a single line was added to assign super.image = image when the new image is identical to the current image, ensuring the superclass property remains synchronized on the early-exit path.

Changes

Cohort / File(s) Summary
Image Property Synchronization
SDWebImage/Core/SDAnimatedImageView.m
Added superclass image property assignment in setImage: method when new image matches current image, ensuring consistent state on early exit.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A hop, a skip, a sync so sweet,
When images match, they both compete,
But now the parent stays aligned,
No property left behind!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is written in Chinese and describes a specific technical issue with SDAnimatedImageView's image comparison and method swizzling behavior, directly related to the code change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dreampiggy
Copy link
Copy Markdown
Contributor

dreampiggy commented Apr 10, 2026

You can do the test by yourself ? Maybe I can not test this behavior changes locally.

I remember this code is referenced from YYAnimatedImageView: https://github.com/ibireme/YYImage/blob/42ba209608cb332887a33ebcae1bde50c52b151d/YYImage/YYAnimatedImageView.m#L278

super.setImage may cause current animation stopped even it's the same image. So maybe at that time this cause some visual glitch during the Collection/TableView scrolling. Which is not UI friendly

@CloudlessMoon
Copy link
Copy Markdown
Contributor Author

你可以自己做一下测试吗?也许我无法在本地测试这种行为变化。

我记得这段代码是在 YYAnimatedImageView 中引用的: https://github.com/ibireme/YYImage/blob/42ba209608cb332887a33ebcae1bde50c52b151d/YYImage/YYAnimatedImageView.m#L278

super.setImage即使是同一张图片,也可能导致当前动画停止。所以,那时可能会出现一些视觉问题。 glitch在 Collection/TableView 滚动期间,这会造成界面不友好。

① 我测试iOS 13 - iOS 26,SDAnimatedImageView设置相同的SDAnimatedImage,没有使当前动画停止。
② 设置普通的UIImage时应该回归到UIImageView/NSImageView.setImage的默认行为

@dreampiggy
Copy link
Copy Markdown
Contributor

OK. You can integrate the changes to your App and have a check. Currently just merge in.

@dreampiggy dreampiggy merged commit 4bb1649 into SDWebImage:master Apr 10, 2026
3 of 8 checks passed
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.

2 participants