mirror of
https://github.com/fxm90/GradientLoadingBar.git
synced 2026-06-16 12:24:31 +00:00
♻️ :: Rename property
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user