Skip to content

Forward scale parameter in WebImage convenience initializers - #368

Open
shubhransh-gupta wants to merge 1 commit into
SDWebImage:masterfrom
shubhransh-gupta:fix/webimage-scale-parameter
Open

shubhransh-gupta wants to merge 1 commit into
SDWebImage:masterfrom
shubhransh-gupta:fix/webimage-scale-parameter

Conversation

@shubhransh-gupta

@shubhransh-gupta shubhransh-gupta commented Oct 10, 2026 •

Copy link
Copy Markdown

Summary

Fixes #362

In WebImage.swift, the convenience initializers:

  • init(url:scale:options:context:isAnimating:)
  • init(url:scale:options:context:isAnimating:content:placeholder:)

both accepted the scale: CGFloat = 1 parameter, but delegated to self.init(url: options: context: isAnimating:) without passing scale: scale. Because the designated initializer defaults scale to 1, the custom scale parameter passed by callers was silently ignored and always set to 1 in context[.imageScaleFactor].

This PR forwards scale: scale in both convenience initializers and adds a unit test verifying imageScaleFactor receives the expected scale factor.

Testing

  • Added testWebImageScaleParameter unit test verifying both convenience initializers preserve custom scale values (scale = 2 and scale = 3).
  • Verified build and tests pass via Xcode workspace:
    xcodebuild -workspace SDWebImageSwiftUI.xcworkspace -scheme 'SDWebImageSwiftUITests macOS' -only-testing 'SDWebImageSwiftUITests macOS/WebImageTests/testWebImageScaleParameter' test (TEST SUCCEEDED).

Summary by CodeRabbit

  • Bug Fixes
    • WebImage now applies the specified scale when created with either supported initializer form.

@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 95ac50ae-74a2-4ffa-8ae6-2081b75fee30

📥 Commits

Reviewing files that changed from the base of the PR and between d1f7b2b and aad2296.


📒 Files selected for processing (2)
  • SDWebImageSwiftUI/Classes/WebImage.swift
  • Tests/WebImageTests.swift

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.



📝 Walkthrough

Walkthrough

Both URL-based convenience initializers now forward their scale argument to the phase-based initializer. A test checks that each initializer form stores the supplied scale as the image-scale factor in the image model context.

Changes

WebImage scale handling

Layer / File(s) Summary
Forward and verify scale
SDWebImageSwiftUI/Classes/WebImage.swift, Tests/WebImageTests.swift
Both convenience initializers forward scale to the phase-based initializer. The test checks the stored image-scale factor for both initializer forms.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Bug fix · Severity of issue fixed: Medium


Merge Risk: ⚪ Minimal · up to aad22

The supplied scale is preserved in both initializer forms, with a test covering each path; no material merge risk was identified.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: forwarding the scale parameter in WebImage convenience initializers.
Linked Issues check Passed Issue #362 requires both affected WebImage convenience initializers to use the supplied scale value. The PR forwards scale: scale in both initializers in SDWebImageSwiftUI/Classes/WebImage.swift. The …
Out of Scope Changes check Passed The PR changes only the two initializers named by issue #362 and adds a focused unit test for their scale behavior. The source change and test directly support the linked issue. No unrelated change is…

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🧪 Generate unit tests (beta)
  • Create a new PR

🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@shubhransh-gupta

Copy link
Copy Markdown
Author

CI Status Note

Just adding a note regarding the Unit Test CI failures across iOS, macOS, and tvOS:

The failure is unrelated to the changes in this PR and is caused by an external outage in the existing test suite:

  • WebImageTests.testWebImageWithAnimatedURL attempts to fetch https://apng.onevcat.com/assets/elephant.png.
  • The third-party domain apng.onevcat.com is currently offline / no longer resolves (NSURLErrorDomain -1003: "A server with the specified hostname could not be found"), causing that test to fail on all three platforms.

All other checks — Cocoapods Lint, Run Demo, Build Library, and the newly added testWebImageScaleParameter unit tests — are passing cleanly.

I noticed #367 is already open addressing this dead URL. Once that is merged, I will gladly rebase this PR immediately for a fully green CI run. Alternatively, if the maintainers prefer, I can also raise a separate PR or include the test URL update here.

This branch has not been deployed

No deployments
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.

WebImage ignores scale parameter

1 participant