diff --git a/GradientLoadingBar/Classes/GradientLoadingBarController.swift b/GradientLoadingBar/Classes/GradientLoadingBarController.swift index bafc8cc..462f7a0 100644 --- a/GradientLoadingBar/Classes/GradientLoadingBarController.swift +++ b/GradientLoadingBar/Classes/GradientLoadingBarController.swift @@ -12,7 +12,7 @@ import LightweightObservable /// Typealias for controller to match pod name. public typealias GradientLoadingBar = GradientLoadingBarController -/// The `GradientLoadingBarController` mediates between the `GradientLoadingBarViewModel` and the corresponding `GradientView`. +/// The `GradientLoadingBarController` mediates between the `GradientLoadingBarViewModel` and the corresponding `GradientActivityIndicatorView`. open class GradientLoadingBarController { // MARK: - Public properties diff --git a/GradientLoadingBar/Classes/ViewModel/GradientActivityIndicatorViewModel.swift b/GradientLoadingBar/Classes/ViewModel/GradientActivityIndicatorViewModel.swift index 5a250bc..e4f3c3c 100644 --- a/GradientLoadingBar/Classes/ViewModel/GradientActivityIndicatorViewModel.swift +++ b/GradientLoadingBar/Classes/ViewModel/GradientActivityIndicatorViewModel.swift @@ -29,12 +29,12 @@ final class GradientActivityIndicatorViewModel { return progressAnimationStateSubject.asObservable } - /// + /// Observable color array for the gradient layer (of type `CGColor`). var gradientLayerColors: Observable<[CGColor]> { return gradientLayerColorsSubject.asObservable } - /// + /// Boolean flag, whether the view is currently hidden. var isHidden = false { didSet { if isHidden { @@ -45,14 +45,14 @@ final class GradientActivityIndicatorViewModel { } } - /// Colors used for the gradient. + /// Color array used for the gradient (of type `UIColor`). var gradientColors = UIColor.GradientLoadingBar.gradientColors { didSet { gradientLayerColorsSubject.value = makeGradientLayerColors() } } - /// Duration for the progress animation. + /// The duration for the progress animation. var progressAnimationDuration = TimeInterval.GradientLoadingBar.progressDuration // MARK: - Private properties @@ -74,9 +74,11 @@ final class GradientActivityIndicatorViewModel { // MARK: - Private methods - /// Simulate infinte animation - Therefore we'll reverse the colors and remove the first and last item - /// to prevent duplicate values at the "inner edges" destroying the infinite look. + /// Maps the current `gradientColors` given by the user as an array of `UIColor`, + /// to an array of type `CGColor`, so we can use it for our gradient layer. private func makeGradientLayerColors() -> [CGColor] { + // Simulate infinte animation - Therefore we'll reverse the colors and remove the first and last item + // to prevent duplicate values at the "inner edges" destroying the infinite look. let reversedColors = gradientColors .reversed() .dropFirst() diff --git a/GradientLoadingBar/Classes/Views/GradientActivityIndicatorView+AnimateIsHidden.swift b/GradientLoadingBar/Classes/Views/GradientActivityIndicatorView+AnimateIsHidden.swift index 829932f..16b934c 100644 --- a/GradientLoadingBar/Classes/Views/GradientActivityIndicatorView+AnimateIsHidden.swift +++ b/GradientLoadingBar/Classes/Views/GradientActivityIndicatorView+AnimateIsHidden.swift @@ -8,12 +8,14 @@ import UIKit -// Source -// https://gist.github.com/fxm90/723b5def31b46035cd92a641e3b184f6 - +/// Helper methods to fade-in and -out the `GradientActivityIndicatorView` and update the `isHidden` flag +/// accordingly, as the progress-animation is started and stopped based on this flag. /// /// We add these methods as public extensions on `GradientActivityIndicatorView` instead of `UIView`, /// in order to avoid conflicts with other frameworks. +/// +/// Source: +/// - [Github Gist – UIView+AnimateIsHidden.swift](https://gist.github.com/fxm90/723b5def31b46035cd92a641e3b184f6) public extension GradientActivityIndicatorView { // MARK: - Public methods diff --git a/GradientLoadingBar/Classes/Views/GradientActivityIndicatorView.swift b/GradientLoadingBar/Classes/Views/GradientActivityIndicatorView.swift index 87ddef1..ac15310 100644 --- a/GradientLoadingBar/Classes/Views/GradientActivityIndicatorView.swift +++ b/GradientLoadingBar/Classes/Views/GradientActivityIndicatorView.swift @@ -18,22 +18,13 @@ open class GradientActivityIndicatorView: UIView { // MARK: - Public properties + /// Boolean flag, whether the view is currently hidden. open override var isHidden: Bool { didSet { viewModel.isHidden = isHidden } } - /// Duration for the progress animation. - public var progressAnimationDuration: TimeInterval { - get { - return viewModel.progressAnimationDuration - } - set { - viewModel.progressAnimationDuration = newValue - } - } - /// Colors used for the gradient. public var gradientColors: [UIColor] { get { @@ -44,6 +35,16 @@ open class GradientActivityIndicatorView: UIView { } } + /// Duration for the progress animation. + public var progressAnimationDuration: TimeInterval { + get { + return viewModel.progressAnimationDuration + } + set { + viewModel.progressAnimationDuration = newValue + } + } + // MARK: - Private properties /// Layer holding the gradient. @@ -57,7 +58,7 @@ open class GradientActivityIndicatorView: UIView { return layer }() - /// + /// View model containing all logic related to this view. private let viewModel = GradientActivityIndicatorViewModel() /// The dispose bag for the observables.