diff --git a/SDWebImageSwiftUI/Classes/Indicator/ActivityIndicator.swift b/SDWebImageSwiftUI/Classes/Indicator/ActivityIndicator.swift index 87f9881e..aac5e20a 100644 --- a/SDWebImageSwiftUI/Classes/Indicator/ActivityIndicator.swift +++ b/SDWebImageSwiftUI/Classes/Indicator/ActivityIndicator.swift @@ -12,9 +12,11 @@ import SwiftUI /// An activity indicator (system style) public struct ActivityIndicator: PlatformViewRepresentable { @Binding var isAnimating: Bool + var style: Style - public init(_ isAnimating: Binding) { + public init(_ isAnimating: Binding, style: Style = .medium) { self._isAnimating = isAnimating + self.style = style } #if os(macOS) @@ -25,7 +27,14 @@ public struct ActivityIndicator: PlatformViewRepresentable { #if os(iOS) || os(tvOS) public func makeUIView(context: UIViewRepresentableContext) -> UIActivityIndicatorView { - let indicator = UIActivityIndicatorView(style: .medium) + let activityStyle: UIActivityIndicatorView.Style + switch style { + case .medium: + activityStyle = .medium + case .large: + activityStyle = .large + } + let indicator = UIActivityIndicatorView(style: activityStyle) indicator.hidesWhenStopped = true return indicator } @@ -37,8 +46,16 @@ public struct ActivityIndicator: PlatformViewRepresentable { #if os(macOS) public func makeNSView(context: NSViewRepresentableContext) -> NSProgressIndicator { + let controlSize: NSControl.ControlSize + switch style { + case .medium: + controlSize = .small + case .large: + controlSize = .regular + } let indicator = NSProgressIndicator() indicator.style = .spinning + indicator.controlSize = controlSize indicator.isDisplayedWhenStopped = false return indicator } @@ -49,4 +66,11 @@ public struct ActivityIndicator: PlatformViewRepresentable { #endif } + +extension ActivityIndicator { + public enum Style { + case medium + case large + } +} #endif diff --git a/SDWebImageSwiftUI/Classes/Indicator/Indicator.swift b/SDWebImageSwiftUI/Classes/Indicator/Indicator.swift index 9e67a29c..b434ea52 100644 --- a/SDWebImageSwiftUI/Classes/Indicator/Indicator.swift +++ b/SDWebImageSwiftUI/Classes/Indicator/Indicator.swift @@ -34,11 +34,27 @@ extension Indicator { } } + /// Activity Indicator with style + /// - Parameter style: style + public static func activity(style: ActivityIndicator.Style) -> Indicator { + Indicator { isAnimating, _ in + ActivityIndicator(isAnimating, style: style) + } + } + /// Progress Indicator public static var progress: Indicator { Indicator { isAnimating, progress in ProgressIndicator(isAnimating, progress: progress) } } + + /// Progress Indicator with style + /// - Parameter style: style + public static func progress(style: ProgressIndicator.Style) -> Indicator { + Indicator { isAnimating, progress in + ProgressIndicator(isAnimating, progress: progress, style: style) + } + } } #endif diff --git a/SDWebImageSwiftUI/Classes/Indicator/ProgressIndicator.swift b/SDWebImageSwiftUI/Classes/Indicator/ProgressIndicator.swift index 81ac09ff..9ac613c2 100644 --- a/SDWebImageSwiftUI/Classes/Indicator/ProgressIndicator.swift +++ b/SDWebImageSwiftUI/Classes/Indicator/ProgressIndicator.swift @@ -13,10 +13,12 @@ import SwiftUI public struct ProgressIndicator: PlatformViewRepresentable { @Binding var isAnimating: Bool @Binding var progress: CGFloat + var style: Style - public init(_ isAnimating: Binding, progress: Binding) { + public init(_ isAnimating: Binding, progress: Binding, style: Style = .default) { self._isAnimating = isAnimating self._progress = progress + self.style = style } #if os(macOS) @@ -27,9 +29,18 @@ public struct ProgressIndicator: PlatformViewRepresentable { #if os(iOS) || os(tvOS) public func makeUIView(context: UIViewRepresentableContext) -> ProgressIndicatorWrapper { + let progressStyle: UIProgressView.Style + switch style { + #if os(iOS) + case .bar: + progressStyle = .bar + #endif + default: + progressStyle = .default + } let uiView = ProgressIndicatorWrapper() let view = uiView.wrapped - view.progressViewStyle = .default + view.progressViewStyle = progressStyle return uiView } @@ -81,4 +92,11 @@ public struct ProgressIndicator: PlatformViewRepresentable { } #endif } + +extension ProgressIndicator { + public enum Style { + case `default` + case bar + } +} #endif diff --git a/SDWebImageSwiftUI/Classes/WebImage.swift b/SDWebImageSwiftUI/Classes/WebImage.swift index 87f887d1..e087b418 100644 --- a/SDWebImageSwiftUI/Classes/WebImage.swift +++ b/SDWebImageSwiftUI/Classes/WebImage.swift @@ -169,11 +169,12 @@ extension WebImage { } } +// Indicator extension WebImage { /// Associate a indicator when loading image with url /// - Parameter indicator: The indicator type, see `Indicator` - public func indicator(_ indicator: Indicator) -> WebImage { + public func indicator(_ indicator: Indicator?) -> WebImage { var result = self result.indicator = indicator return result