Skip to content

Commit a6ca56f

Browse files
committed
Documentation
1 parent f013481 commit a6ca56f

File tree

4 files changed

+61
-23
lines changed

4 files changed

+61
-23
lines changed

Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/CircularProgress.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import UIKit
55
struct CircularProgress: View {
66
@State private var model = CircularProgressVM {
77
$0.label = "0"
8-
$0.style = .striped
8+
$0.style = .light
99
$0.minValue = 0
1010
$0.maxValue = 100
1111
}
@@ -15,7 +15,7 @@ struct CircularProgress: View {
1515
var body: some View {
1616
VStack {
1717
PreviewWrapper(title: "SwiftUI") {
18-
SUCircularProgress(model: self.model, currentValue: self.progress)
18+
SUCircularProgress(currentValue: self.progress, model: self.model)
1919
}
2020
Form {
2121
ComponentColorPicker(selection: self.$model.color)

Sources/ComponentsKit/Components/CircularProgress/Models/CircularProgressStyle.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Foundation
22

33
extension CircularProgressVM {
44
public enum Style {
5+
/// Defines the visual styles for the circular progress component.
56
case light
67
case striped
78
}

Sources/ComponentsKit/Components/CircularProgress/Models/CircularProgressVM.swift

Lines changed: 5 additions & 9 deletions
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 circular progress component.
44
public struct CircularProgressVM: ComponentVM {
5-
/// The color of the circular progress indicator.
5+
/// The color of the circular progress.
66
///
77
/// Defaults to `.accent`.
88
public var color: ComponentColor = .accent
@@ -12,32 +12,28 @@ public struct CircularProgressVM: ComponentVM {
1212
/// Defaults to `.light`.
1313
public var style: Style = .light
1414

15-
/// The predefined size of the circular progress indicator.
15+
/// The size of the circular progress.
1616
///
1717
/// Defaults to `.medium`.
1818
public var size: ComponentSize = .medium
1919

20-
/// The minimum value for the progress range.
20+
/// The minimum value of the circular progress.
2121
///
2222
/// Defaults to `0`.
2323
public var minValue: CGFloat = 0
2424

25-
/// The maximum value for the progress range.
25+
/// The maximum value of the circular progress.
2626
///
2727
/// Defaults to `100`.
2828
public var maxValue: CGFloat = 100
2929

3030
/// The width of the circular progress stroke.
31-
///
32-
/// If not provided, the line width is automatically adjusted based on the size.
3331
public var lineWidth: CGFloat?
3432

3533
/// An optional label to display inside the circular progress.
3634
public var label: String?
3735

38-
/// A custom font to display the label with.
39-
///
40-
/// If not provided, the font is automatically adjusted based on the size.
36+
/// The font used for the circular progress label text.
4137
public var font: UniversalFont?
4238

4339
/// Initializes a new instance of `CircularProgressVM` with default values.

Sources/ComponentsKit/Components/CircularProgress/SUCircularProgress.swift

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,38 @@
11
import SwiftUI
22

3+
/// A SwiftUI component that displays a circular progress.
34
public struct SUCircularProgress: View {
5+
// MARK: - Properties
6+
7+
/// A model that defines the appearance properties.
48
public var model: CircularProgressVM
9+
10+
/// The current progress value.
511
public var currentValue: CGFloat
612

13+
// MARK: - Initializer
14+
15+
/// Initializer.
16+
/// - Parameters:
17+
/// - currentValue: Current progress.
18+
/// - model: A model that defines the appearance properties.
719
public init(
8-
model: CircularProgressVM = .init(),
9-
currentValue: CGFloat = 0
20+
currentValue: CGFloat = 0,
21+
model: CircularProgressVM = .init()
1022
) {
11-
self.model = model
1223
self.currentValue = currentValue
24+
self.model = model
1325
}
1426

27+
// MARK: - Body
28+
1529
public var body: some View {
1630
let normalized = self.model.progress(for: currentValue)
1731

1832
switch self.model.style {
1933
case .light:
2034
ZStack {
35+
// Background part
2136
Path { path in
2237
path.addArc(
2338
center: self.model.center,
@@ -31,8 +46,12 @@ public struct SUCircularProgress: View {
3146
self.model.color.main.color.opacity(0.3),
3247
lineWidth: self.model.circularLineWidth
3348
)
34-
.frame(width: self.model.preferredSize.width, height: self.model.preferredSize.height)
49+
.frame(
50+
width: self.model.preferredSize.width,
51+
height: self.model.preferredSize.height
52+
)
3553

54+
// Foreground part
3655
Path { path in
3756
path.addArc(
3857
center: self.model.center,
@@ -51,8 +70,12 @@ public struct SUCircularProgress: View {
5170
)
5271
)
5372
.rotationEffect(.degrees(-90))
54-
.frame(width: self.model.preferredSize.width, height: self.model.preferredSize.height)
73+
.frame(
74+
width: self.model.preferredSize.width,
75+
height: self.model.preferredSize.height
76+
)
5577

78+
// Optional label
5679
if let label = self.model.label {
5780
Text(label)
5881
.font(self.model.titleFont.font)
@@ -62,6 +85,7 @@ public struct SUCircularProgress: View {
6285

6386
case .striped:
6487
ZStack {
88+
// Striped background part
6589
Path { path in
6690
path.addArc(
6791
center: self.model.center,
@@ -71,7 +95,10 @@ public struct SUCircularProgress: View {
7195
clockwise: false
7296
)
7397
}
74-
.trim(from: self.model.backgroundArcStart(for: normalized), to: self.model.backgroundArcEnd(for: normalized))
98+
.trim(
99+
from: self.model.backgroundArcStart(for: normalized),
100+
to: self.model.backgroundArcEnd(for: normalized)
101+
)
75102
.stroke(
76103
.clear,
77104
style: StrokeStyle(
@@ -92,7 +119,10 @@ public struct SUCircularProgress: View {
92119
clockwise: false
93120
)
94121
}
95-
.trim(from: self.model.backgroundArcStart(for: normalized), to: self.model.backgroundArcEnd(for: normalized))
122+
.trim(
123+
from: self.model.backgroundArcStart(for: normalized),
124+
to: self.model.backgroundArcEnd(for: normalized)
125+
)
96126
.stroke(
97127
style: StrokeStyle(
98128
lineWidth: self.model.circularLineWidth,
@@ -102,9 +132,12 @@ public struct SUCircularProgress: View {
102132
}
103133
}
104134
.rotationEffect(.degrees(-90))
105-
.frame(width: self.model.preferredSize.width,
106-
height: self.model.preferredSize.height)
135+
.frame(
136+
width: self.model.preferredSize.width,
137+
height: self.model.preferredSize.height
138+
)
107139

140+
// Foreground part
108141
Path { path in
109142
path.addArc(
110143
center: self.model.center,
@@ -114,7 +147,10 @@ public struct SUCircularProgress: View {
114147
clockwise: false
115148
)
116149
}
117-
.trim(from: self.model.progressArcStart(for: normalized), to: self.model.progressArcEnd(for: normalized))
150+
.trim(
151+
from: self.model.progressArcStart(for: normalized),
152+
to: self.model.progressArcEnd(for: normalized)
153+
)
118154
.stroke(
119155
self.model.color.main.color,
120156
style: StrokeStyle(
@@ -123,9 +159,12 @@ public struct SUCircularProgress: View {
123159
)
124160
)
125161
.rotationEffect(.degrees(-90))
126-
.frame(width: self.model.preferredSize.width,
127-
height: self.model.preferredSize.height)
162+
.frame(
163+
width: self.model.preferredSize.width,
164+
height: self.model.preferredSize.height
165+
)
128166

167+
// Optional label
129168
if let label = self.model.label {
130169
Text(label)
131170
.font(self.model.titleFont.font)
@@ -136,6 +175,8 @@ public struct SUCircularProgress: View {
136175
}
137176
}
138177

178+
// MARK: - Helpers
179+
139180
struct StripesShapeCircularProgress: Shape, @unchecked Sendable {
140181
var model: CircularProgressVM
141182

0 commit comments

Comments
 (0)