Skip to content

Commit ea349b6

Browse files
committed
Merge branch 'develop'
2 parents 444ab9b + 034a26b commit ea349b6

File tree

5 files changed

+30
-43
lines changed

5 files changed

+30
-43
lines changed

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,23 @@ struct LandmarkRow: View {
8282
| placeholderImage | _(optional)_<br />`Image` to display whilst remote image data is being fetched and decoded. | `nil` |
8383
| transition | _(optional)_<br />transition to occur when showing the loaded image. | `nil` |
8484

85+
## Progress / Loading Indicators
86+
87+
Using function `.progress` .
88+
Display a loading indicator on top of the placeholder as the image loads.
89+
Once the image has finished downloading, the supplied loading indicator will hide
90+
Call `progress` on your `RemoteImageView` and return `some View`
91+
92+
### Example
93+
94+
```swift
95+
96+
).progress({ progress in
97+
return MyProgressBarView(progress: progress)
98+
})
99+
100+
```
101+
85102
## Image Processing
86103

87104
Using function `.imageProcessing` .

Sources/SwURL/RemoteImage/ProgressBar.swift

-37
This file was deleted.

Sources/SwURL/RemoteImage/RemoteImageView.swift

+10-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public struct RemoteImageView: View {
1919
var url: URL
2020
var placeholderImage: Image?
2121
fileprivate var _imageProcessing: ((Image) -> AnyView)
22+
fileprivate var _loadingIndicator: ((CGFloat) -> AnyView)?
2223

2324
let transitionType: ImageTransitionType
2425

@@ -29,7 +30,7 @@ public struct RemoteImageView: View {
2930
TransitioningImage(
3031
placeholder: placeholderImage.process(with: _imageProcessing),
3132
finalImage: remoteImage.image.process(with: _imageProcessing),
32-
percentageComplete: CGFloat(remoteImage.progress),
33+
loadingIndicator: _loadingIndicator?(CGFloat(remoteImage.progress)),
3334
transitionType: transitionType
3435
).onAppear {
3536
// bug in swift ui when onAppear called multiple times
@@ -67,6 +68,14 @@ public extension RemoteImageView {
6768

6869
return mut
6970
}
71+
72+
func progress<T: View>(_ progress: @escaping (CGFloat) -> T) -> some View {
73+
var mut = self
74+
mut._loadingIndicator = { percentageComplete in
75+
return AnyView(progress(percentageComplete))
76+
}
77+
return mut
78+
}
7079
}
7180

7281
fileprivate extension Optional where Wrapped == Image {

Sources/SwURL/RemoteImage/TransitioningImage.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import SwiftUI
1111
struct TransitioningImage: View {
1212
var placeholder: AnyView?
1313
var finalImage: AnyView?
14+
var loadingIndicator: AnyView?
1415

15-
let percentageComplete: CGFloat
1616
let transitionType: ImageTransitionType
1717

1818
public var body: some View {
@@ -21,6 +21,8 @@ struct TransitioningImage: View {
2121
self.placeholder
2222
.transition(self.transitionType.t)
2323
.animation(self.transitionType.animation)
24+
25+
loadingIndicator
2426
}
2527

2628
self.finalImage?

SwURL.xcodeproj/project.pbxproj

-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
/* End PBXAggregateTarget section */
2222

2323
/* Begin PBXBuildFile section */
24-
475F3D282345449100CB5714 /* ProgressBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 475F3D272345449100CB5714 /* ProgressBar.swift */; };
2524
OBJ_38 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_10 /* Logger.swift */; };
2625
OBJ_39 /* CGImage+Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_12 /* CGImage+Data.swift */; };
2726
OBJ_40 /* FileManager+Paths.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_14 /* FileManager+Paths.swift */; };
@@ -58,7 +57,6 @@
5857
/* End PBXContainerItemProxy section */
5958

6059
/* Begin PBXFileReference section */
61-
475F3D272345449100CB5714 /* ProgressBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressBar.swift; sourceTree = "<group>"; };
6260
OBJ_10 /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
6361
OBJ_12 /* CGImage+Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CGImage+Data.swift"; sourceTree = "<group>"; };
6462
OBJ_14 /* FileManager+Paths.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FileManager+Paths.swift"; sourceTree = "<group>"; };
@@ -109,7 +107,6 @@
109107
OBJ_20 /* RemoteImage.swift */,
110108
OBJ_21 /* RemoteImageView.swift */,
111109
OBJ_22 /* TransitioningImage.swift */,
112-
475F3D272345449100CB5714 /* ProgressBar.swift */,
113110
);
114111
path = RemoteImage;
115112
sourceTree = "<group>";
@@ -286,7 +283,6 @@
286283
OBJ_45 /* Downloader.swift in Sources */,
287284
OBJ_46 /* RemoteImage.swift in Sources */,
288285
OBJ_47 /* RemoteImageView.swift in Sources */,
289-
475F3D282345449100CB5714 /* ProgressBar.swift in Sources */,
290286
OBJ_48 /* TransitioningImage.swift in Sources */,
291287
OBJ_49 /* SwURL.swift in Sources */,
292288
);

0 commit comments

Comments
 (0)