From 8b257545eeac3fb0a53272001ff457a2fcc195f8 Mon Sep 17 00:00:00 2001 From: Felix Mau Date: Wed, 23 Mar 2022 09:32:35 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20Rename=20property?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GradientLoadingBarView+ViewModelTestCase.swift | 10 +++++----- .../SwiftUI/GradientLoadingBarView.swift | 2 +- .../ViewModel/GradientLoadingBarView+ViewModel.swift | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Example/ExampleTests/ViewModel/GradientLoadingBarView+ViewModelTestCase.swift b/Example/ExampleTests/ViewModel/GradientLoadingBarView+ViewModelTestCase.swift index 2140e31..0ce7431 100644 --- a/Example/ExampleTests/ViewModel/GradientLoadingBarView+ViewModelTestCase.swift +++ b/Example/ExampleTests/ViewModel/GradientLoadingBarView+ViewModelTestCase.swift @@ -27,23 +27,23 @@ final class GradientLoadingBarView_ViewModelTestCase: XCTestCase { XCTAssertEqual(viewModel.gradientColors, expectedGradientColors) } - // MARK: - Test property `offset` + // MARK: - Test property `horizontalOffset` - func test_initialOffset_shouldBeZero() { + func test_initialHorizontalOffset_shouldBeZero() { // When let viewModel = GradientLoadingBarView.ViewModel(gradientColors: [], progressDuration: 1) // Then - XCTAssertEqual(viewModel.offset, 0) + XCTAssertEqual(viewModel.horizontalOffset, 0) } - func test_settingSize_shouldUpdateOffset() { + func test_settingSize_shouldUpdateHorizontalOffset() { // Given let viewModel = GradientLoadingBarView.ViewModel(gradientColors: [], progressDuration: 1) let size = CGSize(width: .random(in: 1 ... 100_000), height: .random(in: 1 ... 100_000)) var receivedValues = [CGFloat]() - let subscription = viewModel.$offset.sink { + let subscription = viewModel.$horizontalOffset.sink { receivedValues.append($0) } diff --git a/GradientLoadingBar/SwiftUI/GradientLoadingBarView.swift b/GradientLoadingBar/SwiftUI/GradientLoadingBarView.swift index e69efc4..6a68342 100644 --- a/GradientLoadingBar/SwiftUI/GradientLoadingBarView.swift +++ b/GradientLoadingBar/SwiftUI/GradientLoadingBarView.swift @@ -52,7 +52,7 @@ public struct GradientLoadingBarView: View { .overlay(// LinearGradient(colors: viewModel.gradientColors, startPoint: .leading, endPoint: .trailing) .frame(width: viewModel.gradientWidth) - .offset(x: viewModel.offset, y: 0)) + .offset(x: viewModel.horizontalOffset, y: 0)) } } diff --git a/GradientLoadingBar/ViewModel/GradientLoadingBarView+ViewModel.swift b/GradientLoadingBar/ViewModel/GradientLoadingBarView+ViewModel.swift index c8947db..b752055 100644 --- a/GradientLoadingBar/ViewModel/GradientLoadingBarView+ViewModel.swift +++ b/GradientLoadingBar/ViewModel/GradientLoadingBarView+ViewModel.swift @@ -19,7 +19,7 @@ extension GradientLoadingBarView { let gradientColors: [Color] @Published - private(set) var offset: CGFloat = 0 + private(set) var horizontalOffset: CGFloat = 0 @Published var size: CGSize = .zero { @@ -27,11 +27,11 @@ extension GradientLoadingBarView { // This will stop any ongoing animation. // Source: https://stackoverflow.com/a/59150940 withAnimation(.linear(duration: 0)) { - offset = -size.width + horizontalOffset = -size.width } withAnimation(.linear(duration: progressDuration).repeatForever(autoreverses: false)) { - offset = size.width + horizontalOffset = size.width } } }