Skip to content

Commit 4e8055d

Browse files
minor code improvements
1 parent 40d1a5f commit 4e8055d

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

Sources/ComponentsKit/ProgressBar/Models/ProgressBarVM.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import SwiftUI
22

33
/// A model that defines the appearance properties for a a progress bar component.
44
public struct ProgressBarVM: ComponentVM {
5-
/// The color of the progress bar..
5+
/// The color of the progress bar.
66
///
77
/// Defaults to `.accent`.
88
public var color: ComponentColor = .accent

Sources/ComponentsKit/ProgressBar/SUProgressBar.swift

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ public struct SUProgressBar: View {
66

77
/// A model that defines the appearance properties.
88
public var model: ProgressBarVM
9-
10-
@Binding private var currentValue: CGFloat
9+
/// A binding to control the current value.
10+
@Binding public var currentValue: CGFloat
1111

1212
private var progress: CGFloat {
1313
let range = self.model.maxValue - self.model.minValue
@@ -43,45 +43,34 @@ public struct SUProgressBar: View {
4343
HStack(spacing: 4) {
4444
RoundedRectangle(cornerRadius: self.model.computedCornerRadius)
4545
.foregroundStyle(self.model.barColor.color)
46-
.frame(
47-
width: geometry.size.width * self.progress,
48-
height: self.model.barHeight
49-
)
46+
.frame(width: geometry.size.width * self.progress)
5047
RoundedRectangle(cornerRadius: self.model.computedCornerRadius)
5148
.foregroundStyle(self.model.backgroundColor.color)
52-
.frame(width: geometry.size.width * (1 - self.progress), height: self.model.barHeight)
49+
.frame(width: geometry.size.width * (1 - self.progress))
5350
}
54-
.animation(.spring, value: self.progress)
5551

5652
case .filled:
5753
ZStack(alignment: .leading) {
5854
RoundedRectangle(cornerRadius: self.model.computedCornerRadius)
5955
.foregroundStyle(self.model.color.main.color)
60-
.frame(width: geometry.size.width, height: self.model.barHeight)
56+
.frame(width: geometry.size.width)
6157

6258
RoundedRectangle(cornerRadius: self.model.innerCornerRadius)
6359
.foregroundStyle(self.model.color.contrast.color)
64-
.frame(
65-
width: (geometry.size.width - self.model.innerBarPadding * 2) * self.progress,
66-
height: self.model.barHeight - self.model.innerBarPadding * 2
67-
)
60+
.frame(width: (geometry.size.width - self.model.innerBarPadding * 2) * self.progress)
6861
.padding(.vertical, self.model.innerBarPadding)
6962
.padding(.horizontal, self.model.innerBarPadding)
7063
}
71-
.animation(.spring, value: self.progress)
7264

7365
case .striped:
7466
ZStack(alignment: .leading) {
7567
RoundedRectangle(cornerRadius: self.model.computedCornerRadius)
7668
.foregroundStyle(self.model.color.main.color)
77-
.frame(width: geometry.size.width, height: self.model.barHeight)
69+
.frame(width: geometry.size.width)
7870

7971
RoundedRectangle(cornerRadius: self.model.innerCornerRadius)
8072
.foregroundStyle(self.model.color.contrast.color)
81-
.frame(
82-
width: (geometry.size.width - self.model.innerBarPadding * 2) * self.progress,
83-
height: self.model.barHeight - self.model.innerBarPadding * 2
84-
)
73+
.frame(width: (geometry.size.width - self.model.innerBarPadding * 2) * self.progress)
8574
.padding(.vertical, self.model.innerBarPadding)
8675
.padding(.horizontal, self.model.innerBarPadding)
8776

@@ -90,17 +79,17 @@ public struct SUProgressBar: View {
9079
.cornerRadius(self.model.computedCornerRadius)
9180
.clipped()
9281
}
93-
.animation(.spring, value: self.progress)
9482
}
9583
}
84+
.animation(.spring, value: self.progress)
9685
.frame(height: self.model.barHeight)
9786
.onAppear {
9887
self.model.validateMinMaxValues()
9988
}
10089
}
10190
}
10291

103-
// MARK: - Properties
92+
// MARK: - Helpers
10493

10594
struct StripesShape: Shape {
10695
var model: ProgressBarVM

0 commit comments

Comments
 (0)