From 7481fb95f04398c459ce65b534ebca96ee4ecfbf Mon Sep 17 00:00:00 2001 From: Felix Mau Date: Thu, 29 Aug 2019 15:31:20 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20Removed=20`gradientCo?= =?UTF-8?q?lors`=20from=20initializer=20and=20use=20a=20computed=20propert?= =?UTF-8?q?y=20instead.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As the gradient-colors are mutable after the initialization, it makes more sense to provide these as a computed property. --- .../Classes/GradientLoadingBarController.swift | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/GradientLoadingBar/Classes/GradientLoadingBarController.swift b/GradientLoadingBar/Classes/GradientLoadingBarController.swift index 04c6686..4346e90 100644 --- a/GradientLoadingBar/Classes/GradientLoadingBarController.swift +++ b/GradientLoadingBar/Classes/GradientLoadingBarController.swift @@ -27,13 +27,23 @@ open class GradientLoadingBarController { /// View containing the gradient layer. public let gradientView = GradientActivityIndicatorView() + /// Colors used for the gradient. + public var gradientColors: [UIColor] { + get { + return gradientView.gradientColors + } + set { + gradientView.gradientColors = newValue + } + } + /// Singleton instance. public static var shared = GradientLoadingBar() // MARK: - Private properties /// View model containing logic for the gradient view. - private let viewModel: GradientLoadingBarViewModel + private let viewModel = GradientLoadingBarViewModel() /// The dispose bag for the observables. private var disposeBag = DisposeBag() @@ -44,20 +54,16 @@ open class GradientLoadingBarController { /// /// Parameters: /// - height: Height of the gradient bar. - /// - gradientColors: Colors used for the gradient. /// - isRelativeToSafeArea: Flag whether the top layout constraint should respect `safeAreaLayoutGuide`. /// /// Returns: Instance with gradient bar public init(height: Double = 2.5, - gradientColors: [UIColor] = UIColor.GradientLoadingBar.gradientColors, isRelativeToSafeArea: Bool = true) { self.height = height self.isRelativeToSafeArea = isRelativeToSafeArea - gradientView.gradientColors = gradientColors gradientView.fadeOut(duration: 0) - viewModel = GradientLoadingBarViewModel() bindViewModelToView() }