Skip to content

Commit 4345bd4

Browse files
committed
Change to use the empty Image as static variable
1 parent 963dac4 commit 4345bd4

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

SDWebImageSwiftUI/Classes/SDWebImageSwiftUI.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ extension Image {
2626
self.init(uiImage: platformImage)
2727
#endif
2828
}
29+
30+
static var empty = Image(platformImage: PlatformImage())
2931
}
3032

3133
#if os(macOS)

SDWebImageSwiftUI/Classes/WebImage.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import SDWebImage
1212
/// A Image View type to load image from url. Supports static/animated image format.
1313
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
1414
public struct WebImage : View {
15-
static var emptyImage = PlatformImage()
1615
var configurations: [(Image) -> Image] = []
1716

1817
var placeholder: AnyView?
@@ -113,7 +112,7 @@ public struct WebImage : View {
113112
} else {
114113
// Should not use `EmptyView`, which does not respect to the container's frame modifier
115114
// Using a empty image instead for better compatible
116-
configurations.reduce(Image(platformImage: WebImage.emptyImage)) { (previous, configuration) in
115+
configurations.reduce(Image.empty) { (previous, configuration) in
117116
configuration(previous)
118117
}
119118
}

Tests/AnimatedImageTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class AnimatedImageTests: XCTestCase {
150150
XCTAssert(view.isKind(of: SDAnimatedImageView.self))
151151
XCTAssertEqual(context.coordinator.userInfo?["foo"] as? String, "bar")
152152
}
153-
.placeholder(WebImage.emptyImage)
153+
.placeholder(PlatformImage())
154154
.indicator(SDWebImageActivityIndicator.medium)
155155
// Image
156156
.resizable()

0 commit comments

Comments
 (0)