From 5548e9ddec8b73150532589c929aff9f2c52ead1 Mon Sep 17 00:00:00 2001 From: "seongho.hong" Date: Thu, 12 Sep 2019 19:19:23 +0900 Subject: [PATCH] Support init with optional url --- Example/SDWebImageSwiftUIDemo/ContentView.swift | 4 ++-- SDWebImageSwiftUI/Classes/AnimatedImage.swift | 2 +- SDWebImageSwiftUI/Classes/ImageManager.swift | 4 ++-- SDWebImageSwiftUI/Classes/WebImage.swift | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Example/SDWebImageSwiftUIDemo/ContentView.swift b/Example/SDWebImageSwiftUIDemo/ContentView.swift index 6285607..effa25f 100644 --- a/Example/SDWebImageSwiftUIDemo/ContentView.swift +++ b/Example/SDWebImageSwiftUIDemo/ContentView.swift @@ -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) } diff --git a/SDWebImageSwiftUI/Classes/AnimatedImage.swift b/SDWebImageSwiftUI/Classes/AnimatedImage.swift index f68107c..a3e1175 100644 --- a/SDWebImageSwiftUI/Classes/AnimatedImage.swift +++ b/SDWebImageSwiftUI/Classes/AnimatedImage.swift @@ -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 } diff --git a/SDWebImageSwiftUI/Classes/ImageManager.swift b/SDWebImageSwiftUI/Classes/ImageManager.swift index efad3a4..3ea21c1 100644 --- a/SDWebImageSwiftUI/Classes/ImageManager.swift +++ b/SDWebImageSwiftUI/Classes/ImageManager.swift @@ -26,11 +26,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 diff --git a/SDWebImageSwiftUI/Classes/WebImage.swift b/SDWebImageSwiftUI/Classes/WebImage.swift index 22777cf..7f99490 100644 --- a/SDWebImageSwiftUI/Classes/WebImage.swift +++ b/SDWebImageSwiftUI/Classes/WebImage.swift @@ -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