Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions Progress/Classes/Prog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public final class Prog {
internal var progressors: [[Progressor]] = []
internal var maxEndingAnimationDuration: TimeInterval = 0.4
internal var fadingDuration: TimeInterval = 0.2
internal var competedAnimation = false

// MARK: - Progressors
var builtInProgressorTypes: [String: Progressor.Type] = [
Expand Down Expand Up @@ -113,6 +114,7 @@ public final class Prog {
print("\(parent) is already in progress")
return
}
shared.competedAnimation = false
shared.progressParents.append(parent)
shared.progressors.append([])

Expand All @@ -122,6 +124,11 @@ public final class Prog {
}

static func recursiveStart(in parent: ProgressParent, remainingTypes: [ProgressorType], completion: @escaping (()->Void)) {
if shared.competedAnimation {
shared.competedAnimation = true
completion()
}

if let type = remainingTypes.first {
start(in: parent, type: type) {
var remain = remainingTypes
Expand Down Expand Up @@ -172,13 +179,14 @@ public final class Prog {
- parameter completion: callback function after all the ending animation
*/
public static func end(in parent: ProgressParent, completion: @escaping (()->Void) = {}) {
recursiveEnd(in: parent, remainingProgressors: progressors(of: parent).reversed()) {
if let index = shared.progressParents.index(where: { $0 === parent}) {
shared.progressParents.remove(at: index)
shared.progressors.remove(at: index)
shared.competedAnimation = true
recursiveEnd(in: parent, remainingProgressors: progressors(of: parent).reversed()) {
if let index = shared.progressParents.index(where: { $0 === parent}) {
shared.progressParents.remove(at: index)
shared.progressors.remove(at: index)
}
completion()
}
completion()
}
}

static func recursiveEnd(in parent: ProgressParent, remainingProgressors: [Progressor], completion: @escaping (()->Void)) {
Expand Down