From d8e82c0dfc8bcca9bf2cc76b22c70d9355f912fb Mon Sep 17 00:00:00 2001 From: Felix Mau Date: Tue, 27 Aug 2019 15:39:40 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20renamed=20`infinteGra?= =?UTF-8?q?dientColors`=20to=20`gradientLayerColors`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ntActivityIndicatorViewModelTestCase.swift | 20 +++++++++---------- .../GradientActivityIndicatorViewModel.swift | 16 +++++++-------- .../Views/GradientActivityIndicatorView.swift | 4 ++-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Example/Tests/ViewModel/GradientActivityIndicatorViewModelTestCase.swift b/Example/Tests/ViewModel/GradientActivityIndicatorViewModelTestCase.swift index 1feb4db..0e95c02 100644 --- a/Example/Tests/ViewModel/GradientActivityIndicatorViewModelTestCase.swift +++ b/Example/Tests/ViewModel/GradientActivityIndicatorViewModelTestCase.swift @@ -44,13 +44,13 @@ class GradientActivityIndicatorViewModelTestCase: XCTestCase { XCTAssertEqual(viewModel.animationState.value, expectedAnimationState) } - // MARK: - Test observable `infinteGradientColors` + // MARK: - Test observable `gradientLayerColors` - func testInitializerShouldSetInfinteGradientColorsBasedOnCurrentGradientColors() { - let extectedInfinteGradientColors = - makeInfiniteGradientColors(from: viewModel.gradientColors) + func testInitializerShouldSetGradientLayerColorsBasedOnCurrentGradientColors() { + let extectedGradientLayerColors = + makeGradientLayerColors(from: viewModel.gradientColors) - XCTAssertEqual(viewModel.infinteGradientColors.value, extectedInfinteGradientColors) + XCTAssertEqual(viewModel.gradientLayerColors.value, extectedGradientLayerColors) } // MARK: - Test setting property `isHidden` @@ -80,7 +80,7 @@ class GradientActivityIndicatorViewModelTestCase: XCTestCase { // MARK: - Test setting property `gradientColors` - func testSettingGradientColorsShouldUpdateInfinteGradientColors() { + func testSettingGradientColorsShouldUpdateGradientLayerColors() { // Given let colors: [UIColor] = [.red, .yellow, .green] @@ -88,17 +88,17 @@ class GradientActivityIndicatorViewModelTestCase: XCTestCase { viewModel.gradientColors = colors // Then - let extectedInfinteGradientColors = - makeInfiniteGradientColors(from: colors) + let extectedGradientLayerColors = + makeGradientLayerColors(from: colors) - XCTAssertEqual(viewModel.infinteGradientColors.value, extectedInfinteGradientColors) + XCTAssertEqual(viewModel.gradientLayerColors.value, extectedGradientLayerColors) } } // MARK: - Helpers extension GradientActivityIndicatorViewModelTestCase { - private func makeInfiniteGradientColors(from gradientColors: [UIColor]) -> [CGColor] { + private func makeGradientLayerColors(from gradientColors: [UIColor]) -> [CGColor] { let reversedColors = gradientColors .reversed() .dropFirst() diff --git a/GradientLoadingBar/Classes/ViewModel/GradientActivityIndicatorViewModel.swift b/GradientLoadingBar/Classes/ViewModel/GradientActivityIndicatorViewModel.swift index b81e0d6..137ea78 100644 --- a/GradientLoadingBar/Classes/ViewModel/GradientActivityIndicatorViewModel.swift +++ b/GradientLoadingBar/Classes/ViewModel/GradientActivityIndicatorViewModel.swift @@ -26,8 +26,8 @@ class GradientActivityIndicatorViewModel { } /// - var infinteGradientColors: Observable<[CGColor]> { - return infinteGradientColorsSubject.asObservable + var gradientLayerColors: Observable<[CGColor]> { + return gradientLayerColorsSubject.asObservable } /// @@ -44,7 +44,7 @@ class GradientActivityIndicatorViewModel { /// Colors used for the gradient. var gradientColors = UIColor.GradientLoadingBar.gradientColors { didSet { - infinteGradientColorsSubject.value = makeInfiniteGradientColors() + gradientLayerColorsSubject.value = makeGradientLayerColors() } } @@ -55,7 +55,7 @@ class GradientActivityIndicatorViewModel { private let animationStateSubject: Variable - private let infinteGradientColorsSubject: Variable<[CGColor]> + private let gradientLayerColorsSubject: Variable<[CGColor]> // MARK: - Initializer @@ -63,16 +63,16 @@ class GradientActivityIndicatorViewModel { // As the view is visible initially, we need to set-up the observables accordingly. animationStateSubject = Variable(.animating(duration: progressAnimationDuration)) - // Small workaround as calls to `self.makeInfiniteGradientColors()` aren't allowed before all properties have been initialized. - infinteGradientColorsSubject = Variable([]) - infinteGradientColorsSubject.value = makeInfiniteGradientColors() + // Small workaround as calls to `self.makeGradientLayerColors()` aren't allowed before all properties have been initialized. + gradientLayerColorsSubject = Variable([]) + gradientLayerColorsSubject.value = makeGradientLayerColors() } // 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. - private func makeInfiniteGradientColors() -> [CGColor] { + private func makeGradientLayerColors() -> [CGColor] { let reversedColors = gradientColors .reversed() .dropFirst() diff --git a/GradientLoadingBar/Classes/Views/GradientActivityIndicatorView.swift b/GradientLoadingBar/Classes/Views/GradientActivityIndicatorView.swift index 9c3193c..e50524b 100644 --- a/GradientLoadingBar/Classes/Views/GradientActivityIndicatorView.swift +++ b/GradientLoadingBar/Classes/Views/GradientActivityIndicatorView.swift @@ -111,8 +111,8 @@ open class GradientActivityIndicatorView: UIView { } private func bindViewModelToView() { - viewModel.infinteGradientColors.subscribeDistinct { [weak self] newInfinteGradientColors, _ in - self?.gradientLayer.colors = newInfinteGradientColors + viewModel.gradientLayerColors.subscribeDistinct { [weak self] newGradientLayerColors, _ in + self?.gradientLayer.colors = newGradientLayerColors }.disposed(by: &disposeBag) viewModel.animationState.subscribeDistinct { [weak self] newAnimationState, _ in