Merge pull request #2 from cozzin/optionalURL
Support init with optional url
This commit is contained in:
commit
820c716242
|
@ -14,10 +14,10 @@ struct ContentView: View {
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
WebImage(url: URL(string: "https://nokiatech.github.io/heif/content/images/ski_jump_1440x960.heic")!)
|
WebImage(url: URL(string: "https://nokiatech.github.io/heif/content/images/ski_jump_1440x960.heic"))
|
||||||
.scaledToFit()
|
.scaledToFit()
|
||||||
.frame(width: 300, height: 300, alignment: .center)
|
.frame(width: 300, height: 300, alignment: .center)
|
||||||
AnimatedImage(url: URL(string: "https://raw.githubusercontent.com/liyong03/YLGIFImage/master/YLGIFImageDemo/YLGIFImageDemo/joy.gif")!)
|
AnimatedImage(url: URL(string: "https://raw.githubusercontent.com/liyong03/YLGIFImage/master/YLGIFImageDemo/YLGIFImageDemo/joy.gif"))
|
||||||
// .scaledToFit() // Apple's Bug ? Custom UIView does not passthrough the `contentMode` from Swift UI layout system into UIKit layout system
|
// .scaledToFit() // Apple's Bug ? Custom UIView does not passthrough the `contentMode` from Swift UI layout system into UIKit layout system
|
||||||
.frame(width: 400, height: 300, alignment: .center)
|
.frame(width: 400, height: 300, alignment: .center)
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ public struct AnimatedImage: ViewRepresentable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(url: URL, placeholder: Image? = nil, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil) {
|
public init(url: URL?, placeholder: Image? = nil, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil) {
|
||||||
self.url = url
|
self.url = url
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,11 +23,11 @@ class ImageManager : ObservableObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var url: URL
|
var url: URL?
|
||||||
var options: SDWebImageOptions
|
var options: SDWebImageOptions
|
||||||
var context: [SDWebImageContextOption : Any]?
|
var context: [SDWebImageContextOption : Any]?
|
||||||
|
|
||||||
init(url: URL, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil) {
|
init(url: URL?, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil) {
|
||||||
self.url = url
|
self.url = url
|
||||||
self.options = options
|
self.options = options
|
||||||
self.context = context
|
self.context = context
|
||||||
|
|
|
@ -10,14 +10,14 @@ import SwiftUI
|
||||||
import SDWebImage
|
import SDWebImage
|
||||||
|
|
||||||
public struct WebImage : View {
|
public struct WebImage : View {
|
||||||
public var url: URL
|
public var url: URL?
|
||||||
public var placeholder: Image?
|
public var placeholder: Image?
|
||||||
public var options: SDWebImageOptions
|
public var options: SDWebImageOptions
|
||||||
public var context: [SDWebImageContextOption : Any]?
|
public var context: [SDWebImageContextOption : Any]?
|
||||||
|
|
||||||
@ObservedObject var imageManager: ImageManager
|
@ObservedObject var imageManager: ImageManager
|
||||||
|
|
||||||
public init(url: URL, placeholder: Image? = nil, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil) {
|
public init(url: URL?, placeholder: Image? = nil, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil) {
|
||||||
self.url = url
|
self.url = url
|
||||||
self.placeholder = placeholder
|
self.placeholder = placeholder
|
||||||
self.options = options
|
self.options = options
|
||||||
|
|
Loading…
Reference in New Issue