diff --git a/SDWebImageSwiftUI/Classes/WebImage.swift b/SDWebImageSwiftUI/Classes/WebImage.swift index 51c3e97a..54e019a8 100644 --- a/SDWebImageSwiftUI/Classes/WebImage.swift +++ b/SDWebImageSwiftUI/Classes/WebImage.swift @@ -111,13 +111,13 @@ public struct WebImage : View where Content: View { /// - Parameter context: A context contains different options to perform specify changes or processes, see `SDWebImageContextOption`. This hold the extra objects which `options` enum can not hold. /// - Parameter isAnimating: The binding for animation control. When the animation started, this binding can been used to start / stop the animation. You can still customize the `.animatedImageClass` context for advanced custom animation. public init(url: URL?, scale: CGFloat = 1, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil, isAnimating: Binding = .constant(true)) where Content == Image { - self.init(url: url, options: options, context: context, isAnimating: isAnimating) { phase in + self.init(url: url, scale: scale, options: options, context: context, isAnimating: isAnimating) { phase in phase.image ?? Image(platformImage: .empty) } } public init(url: URL?, scale: CGFloat = 1, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil, isAnimating: Binding = .constant(true), @ViewBuilder content: @escaping (Image) -> I, @ViewBuilder placeholder: @escaping () -> P) where Content == _ConditionalContent, I: View, P: View { - self.init(url: url, options: options, context: context, isAnimating: isAnimating) { phase in + self.init(url: url, scale: scale, options: options, context: context, isAnimating: isAnimating) { phase in if let i = phase.image { content(i) } else { diff --git a/Tests/WebImageTests.swift b/Tests/WebImageTests.swift index 2270dfa6..2df9d4d8 100644 --- a/Tests/WebImageTests.swift +++ b/Tests/WebImageTests.swift @@ -178,4 +178,14 @@ class WebImageTests: XCTestCase { self.waitForExpectations(timeout: 5, handler: nil) ViewHosting.expel() } + + func testWebImageScaleParameter() throws { + let imageUrl = URL(string: "https://example.com/test.png") + let imageView1 = WebImage(url: imageUrl, scale: 2) + XCTAssertEqual(imageView1.imageModel.context?[.imageScaleFactor] as? CGFloat, 2) + + let imageView2 = WebImage(url: imageUrl, scale: 3, content: { $0 }, placeholder: { Text("Loading") }) + XCTAssertEqual(imageView2.imageModel.context?[.imageScaleFactor] as? CGFloat, 3) + } } +