Skip to content

Commit a6a6d58

Browse files
committed
Use View Modifier instead of new view type for indicator, simplify the code
1 parent 98ffc78 commit a6a6d58

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

SDWebImageSwiftUI/Classes/Indicator/Indicator.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,15 @@ public struct Indicator<T> where T : View {
2323
}
2424
}
2525

26-
/// A implementation detail View with indicator
26+
/// A implementation detail View Modifier with indicator
2727
/// SwiftUI View Modifier construced by using a internal View type which modify the `body`
2828
/// It use type system to represent the view hierarchy, and Swift `some View` syntax to hide the type detail for users
29-
struct IndicatorView<T, Content> : View where T : View, Content : View {
29+
struct IndicatorViewModifier<T> : ViewModifier where T : View {
3030
@ObservedObject var imageManager: ImageManager
3131

3232
var indicator: Indicator<T>
33-
var content: Content
3433

35-
var body: some View {
34+
func body(content: Content) -> some View {
3635
if (imageManager.image != nil) && !imageManager.isLoading {
3736
// Disable Indiactor
3837
return AnyView(content)
@@ -46,12 +45,6 @@ struct IndicatorView<T, Content> : View where T : View, Content : View {
4645
)
4746
}
4847
}
49-
50-
public init(_ view: Content, indicator: Indicator<T>, imageManager: ImageManager) {
51-
self.content = view
52-
self.indicator = indicator
53-
self.imageManager = imageManager
54-
}
5548
}
5649

5750
#if os(macOS) || os(iOS) || os(tvOS)

SDWebImageSwiftUI/Classes/WebImage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ extension WebImage {
138138
/// Associate a indicator when loading image with url
139139
/// - Parameter indicator: The indicator type, see `Indicator`
140140
public func indicator<T>(_ indicator: Indicator<T>) -> some View where T : View {
141-
return IndicatorView(self, indicator: indicator, imageManager: imageManager)
141+
return self.modifier(IndicatorViewModifier(imageManager: imageManager, indicator: indicator))
142142
}
143143

144144
/// Associate a indicator when loading image with url, convenient method with block

0 commit comments

Comments
 (0)