SDWebImage / SDWebImageSwiftUI

SwiftUI Image loading and Animation framework powered by SDWebImage
https://sdwebimage.github.io/SDWebImageSwiftUI
MIT License
2.18k stars 224 forks source link

How can we specify URL image scale in WebImage #322

Closed Kyle-Ye closed 3 months ago

Kyle-Ye commented 3 months ago

The corresponding SwiftUI.AsyncImage snippets.

let scale = UIScreen.main.scale
let imageName = "\(baseURL)/\(name)_\(Int(scale))x.png"

return AsyncImage(
    url: URL(string: imageName),
    scale: scale
) { image in
    ...
} placeholder: {
    ...
}
dreampiggy commented 3 months ago

Using .context([.imageScaleFactor] = 2) ?

See SDWebImageContext.h

dreampiggy commented 3 months ago

Maybe we can polish this API to automatically pass down the scale into the context arg used in SDWebImage Core

Kyle-Ye commented 3 months ago

Maybe we can polish this API to automatically pass down the scale into the context arg used in SDWebImage Core

+1. See the following documentation of AsyncImage.

Kyle-Ye commented 3 months ago

.context([.imageScale] = 2)

Do you mean using context: [.imageScaleFactor: 2] in current init API?

  1. [SDWebImageContextOption : Any] is using Any so .imageScaleFactor can pass a non-number here.

  2. Another way is appending scale = 1 in all WebImage's init. But what if user set both scale and context: [.imageScaleFactor: 2] at the same time?

dreampiggy commented 3 months ago
  1. Any is the only way in Objc API...I already have a plan for SDWebImage 6 which use the enum associated object and each key value should be typed.
  2. Follow the same design, if the user provided context contains .imageScale, then it has the highest priority. Since the the scale = 1 is default param
Kyle-Ye commented 3 months ago

Can we expect a new 3.0.5 or 3.1.0 release?