Skip to content

Commit a2f0b2d

Browse files
authored
Merge pull request #33 from SDWebImage/improvement_view_modifier
Change the implementation of indicator by using view modifier
2 parents 98ffc78 + 14bb4be commit a2f0b2d

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
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/Indicator/ProgressIndicator.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public struct ProgressIndicator: PlatformViewRepresentable {
3535
case .bar:
3636
progressStyle = .bar
3737
#endif
38-
default:
38+
case .default:
3939
progressStyle = .default
4040
}
4141
let uiView = ProgressIndicatorWrapper()
@@ -99,7 +99,9 @@ public struct ProgressIndicator: PlatformViewRepresentable {
9999
extension ProgressIndicator {
100100
public enum Style {
101101
case `default`
102+
#if os(iOS)
102103
case bar
104+
#endif
103105
}
104106
}
105107
#endif

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)