♻️ :: renamed infinteGradientColors to gradientLayerColors

This commit is contained in:
Felix Mau
2019-08-27 15:54:53 +02:00
parent 0f0214eab6
commit d8e82c0dfc
3 changed files with 20 additions and 20 deletions
@@ -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()
@@ -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<AnimationState>
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()
@@ -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