From 612d7d0755c29bbef622b5bb6dd8d6a4e6119236 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sat, 14 Sep 2019 17:53:37 -0500 Subject: [PATCH] Adjusted the progress bar so that it will make it to 100% --- iOS/Progress/NavigationProgressView.swift | 12 ++++---- .../UINavigationController+Progress.swift | 28 ++++++++----------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/iOS/Progress/NavigationProgressView.swift b/iOS/Progress/NavigationProgressView.swift index 8f51d8b9d..0d0ac4e3f 100644 --- a/iOS/Progress/NavigationProgressView.swift +++ b/iOS/Progress/NavigationProgressView.swift @@ -45,7 +45,6 @@ public final class NavigationProgressView: UIView { } } - /* ====================================================================== */ // MARK: - initializer /* ====================================================================== */ @@ -119,14 +118,15 @@ public final class NavigationProgressView: UIView { // MARK: - Method /* ====================================================================== */ - internal func setProgress(_ progress: Float, animated: Bool) { - let duration: TimeInterval = animated ? 0.1 : 0 + internal func setProgress(_ progress: Float, animated: Bool, completion: @escaping () -> Void) { + let duration: TimeInterval = animated ? 0.2 : 0 self.progress = progress - UIView.animate(withDuration: duration, animations: { - self.layoutIfNeeded() - }) + UIView.animate(withDuration: duration, animations: { self.layoutIfNeeded() }) { _ in + completion() + } + } } diff --git a/iOS/Progress/UINavigationController+Progress.swift b/iOS/Progress/UINavigationController+Progress.swift index bad5e6890..d70435ffe 100644 --- a/iOS/Progress/UINavigationController+Progress.swift +++ b/iOS/Progress/UINavigationController+Progress.swift @@ -95,9 +95,9 @@ public extension UINavigationController { - parameter progress: The new progress value. - parameter animated: true if the change should be animated, false if the change should happen immediately. */ - func setProgress(_ progress: Float, animated: Bool) { + func setProgress(_ progress: Float, animated: Bool, completion: @escaping () -> Void) { progressView.bar.alpha = 1 - progressView.setProgress(progress, animated: animated) + progressView.setProgress(progress, animated: animated, completion: completion) } /** @@ -105,26 +105,22 @@ public extension UINavigationController { */ func finishProgress() { progressView.bar.alpha = 1 - progressView.setProgress(1, animated: true) - - UIView.animate(withDuration: 0.25, - animations: { - self.progressView.bar.alpha = 0 - }, completion: { finished in - self.progressView.progress = 0 + progressView.setProgress(1, animated: true) { + UIView.animate(withDuration: 0.5, animations: { self.progressView.bar.alpha = 0 }) { finished in + self.progressView.progress = 0 + } } - ) } /** While progress is changed to 0.0, the bar will fade out. */ func cancelProgress() { - progressView.setProgress(0, animated: true) - - UIView.animate(withDuration: 0.25, animations: { - self.progressView.bar.alpha = 0 - }) + progressView.setProgress(0, animated: true) { + UIView.animate(withDuration: 0.5, animations: { + self.progressView.bar.alpha = 0 + }) + } } func updateAccountRefreshProgressIndicator() { @@ -137,7 +133,7 @@ public extension UINavigationController { } } else { let percent = Float(progress.numberCompleted) / Float(progress.numberOfTasks) - setProgress(percent, animated: true) + setProgress(percent, animated: true) {} } }