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 {
|
||||
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()
|
||||
.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
|
||||
.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
|
||||
}
|
||||
|
||||
|
|
|
@ -23,11 +23,11 @@ class ImageManager : ObservableObject {
|
|||
}
|
||||
}
|
||||
|
||||
var url: URL
|
||||
var url: URL?
|
||||
var options: SDWebImageOptions
|
||||
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.options = options
|
||||
self.context = context
|
||||
|
|
|
@ -10,14 +10,14 @@ import SwiftUI
|
|||
import SDWebImage
|
||||
|
||||
public struct WebImage : View {
|
||||
public var url: URL
|
||||
public var url: URL?
|
||||
public var placeholder: Image?
|
||||
public var options: SDWebImageOptions
|
||||
public var context: [SDWebImageContextOption : Any]?
|
||||
|
||||
@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.placeholder = placeholder
|
||||
self.options = options
|
||||
|
|
Loading…
Reference in New Issue