The indicator's progress arg, now become Double instead of CGFloat, because its limited to [0, 1]
This commit is contained in:
parent
077e8b52c3
commit
60f353180d
|
@ -194,10 +194,10 @@ public struct StretchLoadingView: View {
|
|||
|
||||
public struct StretchProgressView: View {
|
||||
|
||||
@Binding public var progress: CGFloat
|
||||
@Binding public var progress: Double
|
||||
|
||||
public var body: some View {
|
||||
StretchyShape(progress: Double(progress), mode: .stretchy)
|
||||
StretchyShape(progress: progress, mode: .stretchy)
|
||||
.frame(width: 140, height: 10)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import SDWebImage
|
|||
class ImageManager : ObservableObject {
|
||||
@Published var image: PlatformImage? // loaded image, note when progressive loading, this will published multiple times with different partial image
|
||||
@Published var isLoading: Bool = false // whether network is loading or cache is querying, should only be used for indicator binding
|
||||
@Published var progress: CGFloat = 0 // network progress, should only be used for indicator binding
|
||||
@Published var progress: Double = 0 // network progress, should only be used for indicator binding
|
||||
|
||||
var manager: SDWebImageManager
|
||||
weak var currentOperation: SDWebImageOperation? = nil
|
||||
|
@ -49,9 +49,9 @@ class ImageManager : ObservableObject {
|
|||
guard let self = self else {
|
||||
return
|
||||
}
|
||||
let progress: CGFloat
|
||||
let progress: Double
|
||||
if (expectedSize > 0) {
|
||||
progress = CGFloat(receivedSize) / CGFloat(expectedSize)
|
||||
progress = Double(receivedSize) / Double(expectedSize)
|
||||
} else {
|
||||
progress = 0
|
||||
}
|
||||
|
|
|
@ -12,14 +12,14 @@ import SwiftUI
|
|||
/// A type to build the indicator
|
||||
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
|
||||
public struct Indicator<T> where T : View {
|
||||
var content: (Binding<Bool>, Binding<CGFloat>) -> T
|
||||
var content: (Binding<Bool>, Binding<Double>) -> T
|
||||
|
||||
/// Create a indicator with builder
|
||||
/// - Parameter builder: A builder to build indicator
|
||||
/// - 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.
|
||||
/// - Parameter progress: A Binding to control the progress during loading. If no progress can be reported, the value is 0.
|
||||
/// - Parameter progress: A Binding to control the progress during loading. Value between [0, 1]. If no progress can be reported, the value is 0.
|
||||
/// Associate a indicator when loading image with url
|
||||
public init(@ViewBuilder content: @escaping (_ isAnimating: Binding<Bool>, _ progress: Binding<CGFloat>) -> T) {
|
||||
public init(@ViewBuilder content: @escaping (_ isAnimating: Binding<Bool>, _ progress: Binding<Double>) -> T) {
|
||||
self.content = content
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import SwiftUI
|
|||
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
|
||||
public struct ProgressIndicator: PlatformViewRepresentable {
|
||||
@Binding var isAnimating: Bool
|
||||
@Binding var progress: CGFloat
|
||||
@Binding var progress: Double
|
||||
var style: Style
|
||||
|
||||
/// Create indicator with animation binding, progress binding and the style
|
||||
|
@ -21,7 +21,7 @@ public struct ProgressIndicator: PlatformViewRepresentable {
|
|||
/// - isAnimating: The binding to control the animation
|
||||
/// - progress: The binding to update the progress
|
||||
/// - style: The indicator style
|
||||
public init(_ isAnimating: Binding<Bool>, progress: Binding<CGFloat>, style: Style = .default) {
|
||||
public init(_ isAnimating: Binding<Bool>, progress: Binding<Double>, style: Style = .default) {
|
||||
self._isAnimating = isAnimating
|
||||
self._progress = progress
|
||||
self.style = style
|
||||
|
|
|
@ -285,7 +285,7 @@ extension WebImage {
|
|||
|
||||
/// Associate a indicator when loading image with url, convenient method with block
|
||||
/// - Parameter content: A view that describes the indicator.
|
||||
public func indicator<T>(@ViewBuilder content: @escaping (_ isAnimating: Binding<Bool>, _ progress: Binding<CGFloat>) -> T) -> some View where T : View {
|
||||
public func indicator<T>(@ViewBuilder content: @escaping (_ isAnimating: Binding<Bool>, _ progress: Binding<Double>) -> T) -> some View where T : View {
|
||||
return indicator(Indicator(content: content))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue