|
9 | 9 | import Foundation
|
10 | 10 | import SwiftUI
|
11 | 11 |
|
12 |
| -/// A container view to hold the indicator builder |
13 |
| -public struct Indicator : View { |
| 12 | +/// A type to build the indicator |
| 13 | +public struct Indicator { |
14 | 14 | var builder: (Binding<Bool>, Binding<CGFloat>) -> AnyView
|
15 |
| - public typealias Body = Never |
16 |
| - public var body: Never { |
17 |
| - fatalError() |
18 |
| - } |
| 15 | + |
| 16 | + /// Create a indicator with builder |
| 17 | + /// - Parameter builder: A builder to build indicator |
| 18 | + /// - 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. |
| 19 | + /// - Parameter progress: A Binding to control the progress during loading. If no progress can be reported, the value is 0. |
| 20 | + /// Associate a indicator when loading image with url |
19 | 21 | public init<T>(@ViewBuilder builder: @escaping (_ isAnimating: Binding<Bool>, _ progress: Binding<CGFloat>) -> T) where T : View {
|
20 | 22 | self.builder = { isAnimating, progress in
|
21 | 23 | AnyView(builder(isAnimating, progress))
|
22 | 24 | }
|
23 | 25 | }
|
24 | 26 | }
|
| 27 | + |
| 28 | +#if os(macOS) || os(iOS) || os(iOS) |
| 29 | +extension Indicator { |
| 30 | + /// Activity Indicator |
| 31 | + public static var activity: Indicator { |
| 32 | + Indicator { isAnimating, _ in |
| 33 | + ActivityIndicator(isAnimating) |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + /// Progress Indicator |
| 38 | + public static var progress: Indicator { |
| 39 | + Indicator { isAnimating, progress in |
| 40 | + ProgressIndicator(isAnimating, progress: progress) |
| 41 | + } |
| 42 | + } |
| 43 | +} |
| 44 | +#endif |
0 commit comments