Change to use the empty Image as static variable

This commit is contained in:
DreamPiggy 2020-02-02 10:56:27 +08:00
parent 963dac42e7
commit 4345bd4b5d
3 changed files with 4 additions and 3 deletions

View File

@ -26,6 +26,8 @@ extension Image {
self.init(uiImage: platformImage)
#endif
}
static var empty = Image(platformImage: PlatformImage())
}
#if os(macOS)

View File

@ -12,7 +12,6 @@ import SDWebImage
/// A Image View type to load image from url. Supports static/animated image format.
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public struct WebImage : View {
static var emptyImage = PlatformImage()
var configurations: [(Image) -> Image] = []
var placeholder: AnyView?
@ -113,7 +112,7 @@ public struct WebImage : View {
} else {
// Should not use `EmptyView`, which does not respect to the container's frame modifier
// Using a empty image instead for better compatible
configurations.reduce(Image(platformImage: WebImage.emptyImage)) { (previous, configuration) in
configurations.reduce(Image.empty) { (previous, configuration) in
configuration(previous)
}
}

View File

@ -150,7 +150,7 @@ class AnimatedImageTests: XCTestCase {
XCTAssert(view.isKind(of: SDAnimatedImageView.self))
XCTAssertEqual(context.coordinator.userInfo?["foo"] as? String, "bar")
}
.placeholder(WebImage.emptyImage)
.placeholder(PlatformImage())
.indicator(SDWebImageActivityIndicator.medium)
// Image
.resizable()