Skip to content

Commit 57ed6ef

Browse files
committed
Use the only ZStack one state for indicator, instead of removing that indicator view from hierarchy
1 parent af4569f commit 57ed6ef

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

SDWebImageSwiftUI/Classes/ImageManager.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import SDWebImage
1111

1212
class ImageManager : ObservableObject {
1313
@Published var image: PlatformImage? // loaded image, note when progressive loading, this will published multiple times with different partial image
14-
@Published var isLoading: Bool = false // whether network is loading or cache is querying
15-
@Published var progress: CGFloat = 0 // network progress
14+
@Published var isLoading: Bool = false // whether network is loading or cache is querying, should only be used for indicator binding
15+
@Published var progress: CGFloat = 0 // network progress, should only be used for indicator binding
1616

1717
var manager = SDWebImageManager.shared
1818
weak var currentOperation: SDWebImageOperation? = nil

SDWebImageSwiftUI/Classes/Indicator/Indicator.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,12 @@ struct IndicatorViewModifier<T> : ViewModifier where T : View {
3232
var indicator: Indicator<T>
3333

3434
func body(content: Content) -> some View {
35-
Group {
36-
if imageManager.isFinished {
37-
// Disable Indiactor
38-
content
35+
ZStack {
36+
content
37+
if imageManager.isLoading {
38+
indicator.content($imageManager.isLoading, $imageManager.progress)
3939
} else {
40-
// Enable indicator
41-
ZStack {
42-
content
43-
indicator.content($imageManager.isLoading, $imageManager.progress)
44-
}
40+
indicator.content($imageManager.isLoading, $imageManager.progress).hidden()
4541
}
4642
}
4743
}

SDWebImageSwiftUI/Classes/WebImage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public struct WebImage : View {
6262
.onDisappear {
6363
guard self.cancelOnDisappear else { return }
6464
// When using prorgessive loading, the previous partial image will cause onDisappear. Filter this case
65-
if self.imageManager.isLoading && !self.imageManager.isIncremental {
65+
if !self.imageManager.isFinished && !self.imageManager.isIncremental {
6666
self.imageManager.cancel()
6767
}
6868
}

0 commit comments

Comments
 (0)