♻️ :: Rename property

This commit is contained in:
Felix Mau
2022-03-23 09:32:35 +01:00
parent 285d8ef2d4
commit 8b257545ee
3 changed files with 9 additions and 9 deletions
@@ -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)
}
@@ -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))
}
}
@@ -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
}
}
}