Merge pull request #323 from Kyle-Ye/feature/kyle/scale
Add Image scale support in WebImage init
This commit is contained in:
commit
03c468bac2
|
@ -108,16 +108,17 @@ public struct WebImage<Content> : View where Content: View {
|
||||||
|
|
||||||
/// Create a web image with url, placeholder, custom options and context. Optional can support animated image using Binding.
|
/// Create a web image with url, placeholder, custom options and context. Optional can support animated image using Binding.
|
||||||
/// - Parameter url: The image url
|
/// - Parameter url: The image url
|
||||||
|
/// - Parameter scale: The scale to use for the image. The default is 1. Set a different value when loading images designed for higher resolution displays. For example, set a value of 2 for an image that you would name with the @2x suffix if stored in a file on disk.
|
||||||
/// - Parameter options: The options to use when downloading the image. See `SDWebImageOptions` for the possible values.
|
/// - Parameter options: The options to use when downloading the image. See `SDWebImageOptions` for the possible values.
|
||||||
/// - 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 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. The binding value should be `true` when initialized to setup the correct animated image class. If not, you must provide the `.animatedImageClass` explicitly. When the animation started, this binding can been used to start / stop the animation.
|
/// - Parameter isAnimating: The binding for animation control. The binding value should be `true` when initialized to setup the correct animated image class. If not, you must provide the `.animatedImageClass` explicitly. When the animation started, this binding can been used to start / stop the animation.
|
||||||
public init(url: URL?, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil, isAnimating: Binding<Bool> = .constant(true)) where Content == Image {
|
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, options: options, context: context, isAnimating: isAnimating) { phase in
|
||||||
phase.image ?? Image(platformImage: .empty)
|
phase.image ?? Image(platformImage: .empty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public init<I, P>(url: URL?, 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 {
|
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, options: options, context: context, isAnimating: isAnimating) { phase in
|
||||||
if let i = phase.image {
|
if let i = phase.image {
|
||||||
content(i)
|
content(i)
|
||||||
|
@ -127,9 +128,12 @@ public struct WebImage<Content> : View where Content: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(url: URL?, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil, isAnimating: Binding<Bool> = .constant(true), transaction: Transaction = Transaction(), @ViewBuilder content: @escaping (WebImagePhase) -> Content) {
|
public init(url: URL?, scale: CGFloat = 1, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil, isAnimating: Binding<Bool> = .constant(true), transaction: Transaction = Transaction(), @ViewBuilder content: @escaping (WebImagePhase) -> Content) {
|
||||||
self._isAnimating = isAnimating
|
self._isAnimating = isAnimating
|
||||||
var context = context ?? [:]
|
var context = context ?? [:]
|
||||||
|
if context[.imageScaleFactor] == nil {
|
||||||
|
context[.imageScaleFactor] = scale
|
||||||
|
}
|
||||||
// provide animated image class if the initialized `isAnimating` is true, user can still custom the image class if they want
|
// provide animated image class if the initialized `isAnimating` is true, user can still custom the image class if they want
|
||||||
if isAnimating.wrappedValue {
|
if isAnimating.wrappedValue {
|
||||||
if context[.animatedImageClass] == nil {
|
if context[.animatedImageClass] == nil {
|
||||||
|
|
Loading…
Reference in New Issue