Skip to content

Commit 8ba520f

Browse files
authored
Merge pull request #20 from SDWebImage/fix_webimage_editing_empty
Fix WebImage showing empty image when entering edit mode
2 parents 0c17688 + 88b0d86 commit 8ba520f

File tree

5 files changed

+39
-28
lines changed

5 files changed

+39
-28
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ profile
1818
DerivedData
1919
*.hmap
2020
*.ipa
21+
IDEWorkspaceChecks.plist
2122

2223
# Bundler
2324
.bundle

Example/Podfile.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ PODS:
88
- libwebp/mux (1.0.3):
99
- libwebp/demux
1010
- libwebp/webp (1.0.3)
11-
- SDWebImage (5.2.2):
12-
- SDWebImage/Core (= 5.2.2)
13-
- SDWebImage/Core (5.2.2)
14-
- SDWebImageSwiftUI (0.3.0):
11+
- SDWebImage (5.2.3):
12+
- SDWebImage/Core (= 5.2.3)
13+
- SDWebImage/Core (5.2.3)
14+
- SDWebImageSwiftUI (0.3.1):
1515
- SDWebImage (~> 5.1)
1616
- SDWebImageWebPCoder (0.2.5):
1717
- libwebp (~> 1.0)
@@ -22,7 +22,7 @@ DEPENDENCIES:
2222
- SDWebImageWebPCoder
2323

2424
SPEC REPOS:
25-
https://github.com/cocoapods/specs.git:
25+
trunk:
2626
- libwebp
2727
- SDWebImage
2828
- SDWebImageWebPCoder
@@ -33,10 +33,10 @@ EXTERNAL SOURCES:
3333

3434
SPEC CHECKSUMS:
3535
libwebp: 057912d6d0abfb6357d8bb05c0ea470301f5d61e
36-
SDWebImage: 5fcdb02cc35e05fc35791ec514b191d27189f872
37-
SDWebImageSwiftUI: 9fa220c3c9a69a383f2db5fabc97748ac4e4b696
36+
SDWebImage: 46a7f73228f84ce80990c786e4372cf4db5875ce
37+
SDWebImageSwiftUI: 1b67183dd2ef0321b2ccf578775de8e47eaceb77
3838
SDWebImageWebPCoder: 947093edd1349d820c40afbd9f42acb6cdecd987
3939

4040
PODFILE CHECKSUM: 3fb06a5173225e197f3a4bf2be7e5586a693257a
4141

42-
COCOAPODS: 1.7.5
42+
COCOAPODS: 1.8.3

Example/SDWebImageSwiftUIDemo/ContentView.swift

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ extension String : Identifiable {
1717
}
1818
}
1919

20-
let imageURLs = [
20+
struct ContentView: View {
21+
@State var imageURLs = [
2122
"http://assets.sbnation.com/assets/2512203/dogflops.gif",
2223
"https://raw.githubusercontent.com/liyong03/YLGIFImage/master/YLGIFImageDemo/YLGIFImageDemo/joy.gif",
2324
"http://apng.onevcat.com/assets/elephant.png",
@@ -30,8 +31,6 @@ let imageURLs = [
3031
"https://nokiatech.github.io/heif/content/image_sequences/starfield_animation.heic",
3132
"https://nr-platform.s3.amazonaws.com/uploads/platform/published_extension/branding_icon/275/AmazonS3.png",
3233
"http://via.placeholder.com/200x200.jpg"]
33-
34-
struct ContentView: View {
3534
@State var animated: Bool = true // You can change between WebImage/AnimatedImage
3635

3736
var body: some View {
@@ -73,30 +72,37 @@ struct ContentView: View {
7372
}
7473

7574
func contentView() -> some View {
76-
List(imageURLs) { url in
77-
NavigationLink(destination: DetailView(url: url, animated: self.animated)) {
78-
HStack {
79-
#if os(iOS) || os(tvOS) || os(macOS)
80-
if self.animated {
81-
AnimatedImage(url: URL(string:url))
82-
.resizable()
83-
.scaledToFit()
84-
.frame(width: CGFloat(100), height: CGFloat(100), alignment: .center)
85-
} else {
75+
List {
76+
ForEach(imageURLs) { url in
77+
NavigationLink(destination: DetailView(url: url, animated: self.animated)) {
78+
HStack {
79+
#if os(iOS) || os(tvOS) || os(macOS)
80+
if self.animated {
81+
AnimatedImage(url: URL(string:url))
82+
.resizable()
83+
.scaledToFit()
84+
.frame(width: CGFloat(100), height: CGFloat(100), alignment: .center)
85+
} else {
86+
WebImage(url: URL(string:url))
87+
.resizable()
88+
.scaledToFit()
89+
.frame(width: CGFloat(100), height: CGFloat(100), alignment: .center)
90+
}
91+
#else
8692
WebImage(url: URL(string:url))
8793
.resizable()
8894
.scaledToFit()
8995
.frame(width: CGFloat(100), height: CGFloat(100), alignment: .center)
96+
#endif
97+
Text((url as NSString).lastPathComponent)
9098
}
91-
#else
92-
WebImage(url: URL(string:url))
93-
.resizable()
94-
.scaledToFit()
95-
.frame(width: CGFloat(100), height: CGFloat(100), alignment: .center)
96-
#endif
97-
Text((url as NSString).lastPathComponent)
9899
}
99100
}
101+
.onDelete(perform: { (indexSet) in
102+
indexSet.forEach { (index) in
103+
self.imageURLs.remove(at: index)
104+
}
105+
})
100106
}
101107
}
102108

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ Tips:
129129

130130
1. Use `Switch` (right-click on macOS) to switch between `WebImage` and `AnimatedImage`.
131131
2. Use `Reload` (right-click on macOS/force press on watchOS) to clear cache.
132+
3. Use `Swipe` to delete one image item.
132133

133134
## Screenshot
134135

SDWebImageSwiftUI/Classes/WebImage.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public struct WebImage : View {
4545
let emptyImage = Image(uiImage: UIImage())
4646
#endif
4747
image = emptyImage
48+
// load remote image here, SwiftUI sometimes will create a new View struct without calling `onAppear` (like enter EditMode) :)
49+
// this can ensure we load the image, SDWebImage take care of the duplicated query
50+
self.imageManager.load()
4851
}
4952
return configurations.reduce(image) { (previous, configuration) in
5053
configuration(previous)

0 commit comments

Comments
 (0)