Skip to content

Change the implementation of indicator by using view modifier #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions SDWebImageSwiftUI/Classes/Indicator/Indicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ public struct Indicator<T> where T : View {
}
}

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

var indicator: Indicator<T>
var content: Content

var body: some View {
func body(content: Content) -> some View {
if (imageManager.image != nil) && !imageManager.isLoading {
// Disable Indiactor
return AnyView(content)
Expand All @@ -46,12 +45,6 @@ struct IndicatorView<T, Content> : View where T : View, Content : View {
)
}
}

public init(_ view: Content, indicator: Indicator<T>, imageManager: ImageManager) {
self.content = view
self.indicator = indicator
self.imageManager = imageManager
}
}

#if os(macOS) || os(iOS) || os(tvOS)
Expand Down
4 changes: 3 additions & 1 deletion SDWebImageSwiftUI/Classes/Indicator/ProgressIndicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public struct ProgressIndicator: PlatformViewRepresentable {
case .bar:
progressStyle = .bar
#endif
default:
case .default:
progressStyle = .default
}
let uiView = ProgressIndicatorWrapper()
Expand Down Expand Up @@ -99,7 +99,9 @@ public struct ProgressIndicator: PlatformViewRepresentable {
extension ProgressIndicator {
public enum Style {
case `default`
#if os(iOS)
case bar
#endif
}
}
#endif
2 changes: 1 addition & 1 deletion SDWebImageSwiftUI/Classes/WebImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ extension WebImage {
/// Associate a indicator when loading image with url
/// - Parameter indicator: The indicator type, see `Indicator`
public func indicator<T>(_ indicator: Indicator<T>) -> some View where T : View {
return IndicatorView(self, indicator: indicator, imageManager: imageManager)
return self.modifier(IndicatorViewModifier(imageManager: imageManager, indicator: indicator))
}

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