Skip to content

Commit 60f3531

Browse files
committed
The indicator's progress arg, now become Double instead of CGFloat, because its limited to [0, 1]
1 parent 077e8b5 commit 60f3531

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

Example/SDWebImageSwiftUIDemo/Espera.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,10 @@ public struct StretchLoadingView: View {
194194

195195
public struct StretchProgressView: View {
196196

197-
@Binding public var progress: CGFloat
197+
@Binding public var progress: Double
198198

199199
public var body: some View {
200-
StretchyShape(progress: Double(progress), mode: .stretchy)
200+
StretchyShape(progress: progress, mode: .stretchy)
201201
.frame(width: 140, height: 10)
202202
}
203203
}

SDWebImageSwiftUI/Classes/ImageManager.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import SDWebImage
1313
class ImageManager : ObservableObject {
1414
@Published var image: PlatformImage? // loaded image, note when progressive loading, this will published multiple times with different partial image
1515
@Published var isLoading: Bool = false // whether network is loading or cache is querying, should only be used for indicator binding
16-
@Published var progress: CGFloat = 0 // network progress, should only be used for indicator binding
16+
@Published var progress: Double = 0 // network progress, should only be used for indicator binding
1717

1818
var manager: SDWebImageManager
1919
weak var currentOperation: SDWebImageOperation? = nil
@@ -49,9 +49,9 @@ class ImageManager : ObservableObject {
4949
guard let self = self else {
5050
return
5151
}
52-
let progress: CGFloat
52+
let progress: Double
5353
if (expectedSize > 0) {
54-
progress = CGFloat(receivedSize) / CGFloat(expectedSize)
54+
progress = Double(receivedSize) / Double(expectedSize)
5555
} else {
5656
progress = 0
5757
}

SDWebImageSwiftUI/Classes/Indicator/Indicator.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import SwiftUI
1212
/// A type to build the indicator
1313
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
1414
public struct Indicator<T> where T : View {
15-
var content: (Binding<Bool>, Binding<CGFloat>) -> T
15+
var content: (Binding<Bool>, Binding<Double>) -> T
1616

1717
/// Create a indicator with builder
1818
/// - Parameter builder: A builder to build indicator
1919
/// - Parameter isAnimating: A Binding to control the animation. If image is during loading, the value is true, else (like start loading) the value is false.
20-
/// - Parameter progress: A Binding to control the progress during loading. If no progress can be reported, the value is 0.
20+
/// - Parameter progress: A Binding to control the progress during loading. Value between [0, 1]. If no progress can be reported, the value is 0.
2121
/// Associate a indicator when loading image with url
22-
public init(@ViewBuilder content: @escaping (_ isAnimating: Binding<Bool>, _ progress: Binding<CGFloat>) -> T) {
22+
public init(@ViewBuilder content: @escaping (_ isAnimating: Binding<Bool>, _ progress: Binding<Double>) -> T) {
2323
self.content = content
2424
}
2525
}

SDWebImageSwiftUI/Classes/Indicator/ProgressIndicator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ import SwiftUI
1313
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
1414
public struct ProgressIndicator: PlatformViewRepresentable {
1515
@Binding var isAnimating: Bool
16-
@Binding var progress: CGFloat
16+
@Binding var progress: Double
1717
var style: Style
1818

1919
/// Create indicator with animation binding, progress binding and the style
2020
/// - Parameters:
2121
/// - isAnimating: The binding to control the animation
2222
/// - progress: The binding to update the progress
2323
/// - style: The indicator style
24-
public init(_ isAnimating: Binding<Bool>, progress: Binding<CGFloat>, style: Style = .default) {
24+
public init(_ isAnimating: Binding<Bool>, progress: Binding<Double>, style: Style = .default) {
2525
self._isAnimating = isAnimating
2626
self._progress = progress
2727
self.style = style

SDWebImageSwiftUI/Classes/WebImage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ extension WebImage {
285285

286286
/// Associate a indicator when loading image with url, convenient method with block
287287
/// - Parameter content: A view that describes the indicator.
288-
public func indicator<T>(@ViewBuilder content: @escaping (_ isAnimating: Binding<Bool>, _ progress: Binding<CGFloat>) -> T) -> some View where T : View {
288+
public func indicator<T>(@ViewBuilder content: @escaping (_ isAnimating: Binding<Bool>, _ progress: Binding<Double>) -> T) -> some View where T : View {
289289
return indicator(Indicator(content: content))
290290
}
291291
}

0 commit comments

Comments
 (0)