Skip to content

Commit 01b56b3

Browse files
committed
13.7.2
1 parent 1d462d7 commit 01b56b3

File tree

4 files changed

+75
-28
lines changed

4 files changed

+75
-28
lines changed

ProgressHUD/Sources/ProgressHUD.swift

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,14 @@ public extension ProgressHUD {
204204
}
205205
}
206206

207+
//-------------------------------------------------------------------------------------------------------------------------------------------
208+
class func showFailed(_ error: Error?, interaction: Bool = true, delay: TimeInterval? = nil) {
209+
210+
DispatchQueue.main.async {
211+
shared.setup(text: error?.localizedDescription, animatedIcon: .failed, interaction: interaction, delay: delay)
212+
}
213+
}
214+
207215
//-------------------------------------------------------------------------------------------------------------------------------------------
208216
class func showAdded(_ text: String? = nil, interaction: Bool = true, delay: TimeInterval? = nil) {
209217

@@ -223,6 +231,16 @@ public extension ProgressHUD {
223231
}
224232
}
225233

234+
//-------------------------------------------------------------------------------------------------------------------------------------------
235+
class func show(_ text: String? = nil, symbol: String, interaction: Bool = true, delay: TimeInterval? = nil) {
236+
237+
let image = UIImage(systemName: symbol)?.withTintColor(shared.colorAnimation, renderingMode: .alwaysOriginal)
238+
239+
DispatchQueue.main.async {
240+
shared.setup(text: text, staticImage: image, interaction: interaction, delay: delay)
241+
}
242+
}
243+
226244
//-------------------------------------------------------------------------------------------------------------------------------------------
227245
class func showSuccess(_ text: String? = nil, image: UIImage? = nil, interaction: Bool = true, delay: TimeInterval? = nil) {
228246

@@ -239,6 +257,14 @@ public extension ProgressHUD {
239257
}
240258
}
241259

260+
//-------------------------------------------------------------------------------------------------------------------------------------------
261+
class func showError(_ error: Error?, image: UIImage? = nil, interaction: Bool = true, delay: TimeInterval? = nil) {
262+
263+
DispatchQueue.main.async {
264+
shared.setup(text: error?.localizedDescription, staticImage: image ?? shared.imageError, interaction: interaction, delay: delay)
265+
}
266+
}
267+
242268
// MARK: - Progress
243269
//-------------------------------------------------------------------------------------------------------------------------------------------
244270
class func showProgress(_ progress: CGFloat, interaction: Bool = false) {
@@ -385,8 +411,9 @@ private extension ProgressHUD {
385411
let count = text?.count ?? 0
386412
let delay = delay ?? Double(count) * 0.03 + 1.25
387413

388-
timer = Timer.scheduledTimer(withTimeInterval: delay, repeats: false) { [self] _ in
389-
dismissHUD()
414+
timer = Timer.scheduledTimer(withTimeInterval: delay, repeats: false) { [weak self] _ in
415+
guard let self = self else { return }
416+
self.dismissHUD()
390417
}
391418
}
392419
}
@@ -934,7 +961,7 @@ private extension ProgressHUD {
934961
let height = view.frame.size.height
935962
let center = CGPoint(x: width / 2, y: height / 2)
936963
let radius = width / 2
937-
964+
938965
let duration = 1.0
939966

940967
let animationScale = CABasicAnimation(keyPath: "transform.scale")

ProgressHUD/app/ViewController.swift

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class ViewController: UITableViewController {
2626

2727
private var timer: Timer?
2828
private var status: String?
29+
private var counter = 0.0
2930

3031
private let textShort = "Please wait..."
3132
private let textLong = "Please wait. We need some more time to work out this situation."
@@ -113,18 +114,23 @@ extension ViewController {
113114
//-------------------------------------------------------------------------------------------------------------------------------------------
114115
func actionProgressStart(_ status: String? = nil) {
115116

116-
timer?.invalidate()
117-
timer = nil
117+
counter = 0
118+
ProgressHUD.showProgress(status, counter/100)
118119

119-
var intervalCount = 0.0
120-
ProgressHUD.showProgress(status, intervalCount/100)
120+
timer = Timer.scheduledTimer(withTimeInterval: 0.025, repeats: true) { [weak self] _ in
121+
guard let self = self else { return }
122+
self.actionProgress(status)
123+
}
124+
}
121125

122-
timer = Timer.scheduledTimer(withTimeInterval: 0.025, repeats: true) { [self] _ in
123-
intervalCount += 1
124-
ProgressHUD.showProgress(status, intervalCount/100)
125-
if (intervalCount >= 100) {
126-
actionProgressStop(status)
127-
}
126+
//-------------------------------------------------------------------------------------------------------------------------------------------
127+
func actionProgress(_ status: String?) {
128+
129+
counter += 1
130+
ProgressHUD.showProgress(status, counter/100)
131+
132+
if (counter >= 100) {
133+
actionProgressStop(status)
128134
}
129135
}
130136

@@ -134,7 +140,7 @@ extension ViewController {
134140
timer?.invalidate()
135141
timer = nil
136142

137-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
143+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
138144
ProgressHUD.showSucceed(status, interaction: false, delay: 0.75)
139145
}
140146
}
@@ -213,22 +219,22 @@ extension ViewController {
213219
// MARK: - UITableViewDelegate
214220
//-----------------------------------------------------------------------------------------------------------------------------------------------
215221
extension ViewController {
216-
222+
217223
//-------------------------------------------------------------------------------------------------------------------------------------------
218224
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
219-
225+
220226
tableView.deselectRow(at: indexPath, animated: true)
221-
227+
222228
if (indexPath.section == 0) && (indexPath.row == 1) { view.endEditing(true) }
223229
if (indexPath.section == 0) && (indexPath.row == 2) { ProgressHUD.dismiss() }
224230
if (indexPath.section == 0) && (indexPath.row == 3) { ProgressHUD.remove() }
225-
231+
226232
if (indexPath.section == 1) {
227233
if (indexPath.row == 0) { ProgressHUD.show(); status = nil }
228234
if (indexPath.row == 1) { ProgressHUD.show(textShort); status = textShort }
229235
if (indexPath.row == 2) { ProgressHUD.show(textLong); status = textLong }
230236
}
231-
237+
232238
if (indexPath.section == 2) {
233239
if (indexPath.row == 0) { ProgressHUD.animationType = .none }
234240
if (indexPath.row == 1) { ProgressHUD.animationType = .systemActivityIndicator }
@@ -244,27 +250,27 @@ extension ViewController {
244250
if (indexPath.row == 11) { ProgressHUD.animationType = .circleStrokeSpin }
245251
ProgressHUD.show(status)
246252
}
247-
253+
248254
if (indexPath.section == 3) {
249255
if (indexPath.row == 0) { actionProgressStart() }
250256
if (indexPath.row == 1) { actionProgressStart(textShort) }
251257
if (indexPath.row == 2) { actionProgressStart(textLong) }
252258
}
253-
259+
254260
if (indexPath.section == 4) {
255261
if (indexPath.row == 0) { ProgressHUD.showProgress(0.1, interaction: true) }
256262
if (indexPath.row == 1) { ProgressHUD.showProgress(0.4, interaction: true) }
257263
if (indexPath.row == 2) { ProgressHUD.showProgress(0.6, interaction: true) }
258264
if (indexPath.row == 3) { ProgressHUD.showProgress(0.9, interaction: true) }
259265
}
260-
266+
261267
if (indexPath.section == 5) {
262268
if (indexPath.row == 0) { ProgressHUD.showSuccess() }
263269
if (indexPath.row == 1) { ProgressHUD.showSuccess(textSuccess) }
264270
if (indexPath.row == 2) { ProgressHUD.showError() }
265271
if (indexPath.row == 3) { ProgressHUD.showError(textError) }
266272
}
267-
273+
268274
if (indexPath.section == 6) {
269275
if (indexPath.row == 0) { ProgressHUD.showSucceed() }
270276
if (indexPath.row == 1) { ProgressHUD.showSucceed(textSucceed) }
@@ -273,7 +279,7 @@ extension ViewController {
273279
if (indexPath.row == 4) { ProgressHUD.showAdded() }
274280
if (indexPath.row == 5) { ProgressHUD.showAdded(textAdded) }
275281
}
276-
282+
277283
if (indexPath.section == 7) {
278284
if (indexPath.row == 0) { ProgressHUD.show(randomText(), icon: .heart) }
279285
if (indexPath.row == 1) { ProgressHUD.show(randomText(), icon: .doc) }
@@ -296,7 +302,7 @@ extension ViewController {
296302
if (indexPath.row == 18) { ProgressHUD.show(randomText(), icon: .search) }
297303
}
298304
}
299-
305+
300306
//-------------------------------------------------------------------------------------------------------------------------------------------
301307
func randomText() -> String? {
302308

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77
## WHAT'S NEW
88

9+
### Version: 13.7.2
10+
11+
- The `showFailed` and `showError` methods can now handle `Error?` parameters as well.
12+
- SF Symbols can be displayed by defining it's name `ProgressHUD.show(symbol: "car.fill")`
13+
- Fix the `setupDelayTimer` method. Now `[weak self]` is used within the timer's closure to prevent potential retain cycles and avoid memory leaks.
14+
915
### Version: 13.7.1
1016

1117
- The `mediaSize` and `marginSize` options are now available to adjust the HUD dimensions.
@@ -84,6 +90,14 @@ ProgressHUD.show(icon: .heart)
8490
ProgressHUD.show("Some text...", icon: .privacy, delay: 2.0)
8591
```
8692

93+
```swift
94+
ProgressHUD.show(symbol: "box.truck")
95+
```
96+
97+
```swift
98+
ProgressHUD.show("Some text...", symbol: "figure.2.arms.open")
99+
```
100+
87101
```swift
88102
ProgressHUD.dismiss()
89103
```
@@ -98,7 +112,7 @@ ProgressHUD.remove()
98112

99113
## CUSTOMIZATION
100114

101-
You can customize the color, font, image, animation type, and some other options by using the following methods:
115+
You can customize attributes like color, font, image, animation type, size, and more by using these methods:
102116

103117
```swift
104118
ProgressHUD.animationType = .circleStrokeSpin
@@ -141,7 +155,7 @@ ProgressHUD.imageSuccess = UIImage(named: "success.png")
141155
ProgressHUD.imageError = UIImage(named: "error.png")
142156
```
143157

144-
The list of predefined animation and icon types are as follows:
158+
A comprehensive list of the predefined animation and icon types:
145159

146160
```swift
147161
public enum AnimationType {

VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
13.7.1
1+
13.7.2

0 commit comments

Comments
 (0)