Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions SDWebImageSwiftUI/Classes/WebImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ public struct WebImage<Content> : 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<Bool> = .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<I, P>(url: URL?, scale: CGFloat = 1, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil, isAnimating: Binding<Bool> = .constant(true), @ViewBuilder content: @escaping (Image) -> I, @ViewBuilder placeholder: @escaping () -> P) where Content == _ConditionalContent<I, P>, 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 {
Expand Down
10 changes: 10 additions & 0 deletions Tests/WebImageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Loading