Skip to content

Commit d07c67a

Browse files
committed
More comments and small fixes
1 parent 168d7e2 commit d07c67a

File tree

9 files changed

+98
-16
lines changed

9 files changed

+98
-16
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ https://github.com/buh/CompactSlider.git
5050

5151
# Documentation
5252

53-
- [CompactSlider](https://swiftpackageindex.com/buh/compactslider/2.0.0/documentation/compactslider/compactslider)
54-
- [SystemSlider](https://swiftpackageindex.com/buh/compactslider/2.0.0/documentation/compactslider/systemslider)
53+
- [CompactSlider](https://swiftpackageindex.com/buh/compactslider/2.0.1/documentation/compactslider/compactslider)
54+
- [SystemSlider](https://swiftpackageindex.com/buh/compactslider/2.0.1/documentation/compactslider/systemslider)
5555

5656
## Version 1.0 (deprecated)
5757

Sources/CompactSlider/Components/Background/EnvironmentBackgroundViewKey.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ extension EnvironmentValues {
2424
// MARK: - View
2525

2626
extension View {
27+
/// Set a custom background view for the slider.
28+
///
29+
/// - Parameter backgroundView: a custom background view. The view builder provides the configuration and padding.
2730
public func compactSliderBackground<V: View>(
2831
@ViewBuilder backgroundView: @escaping (
2932
_ configuration: CompactSliderStyleConfiguration,

Sources/CompactSlider/Components/Background/GridBackgroundView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import SwiftUI
77

8+
/// A background view for a grid slider.
89
public struct GridBackgroundView<
910
BackgroundShapeStyle: ShapeStyle,
1011
GridShapeStyle: ShapeStyle

Sources/CompactSlider/Components/Background/GridView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import SwiftUI
77

8+
/// A grid view. It renders a grid with a specified size and padding, using the `Grid` shape.
89
public struct GridView<GridShapeStyle: ShapeStyle>: View {
910
@Environment(\.colorScheme) var colorScheme
1011

Sources/CompactSlider/Components/Grid/Grid.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,42 @@
55

66
import SwiftUI
77

8+
/// A grid shape type.
89
public enum GridType: Equatable, Sendable {
910
case square
1011
case circle
1112
}
1213

14+
/// A grid shape. It can be a square or a circle.
15+
///
16+
/// If it needs to to render in reverse order, set `inverse` to `true` and make `eoFill` to `true`.
17+
/// For example:
18+
/// ```swift
19+
/// Grid(countX: 10, countY: 10, size: 10, inverse: true)
20+
/// .fill(Color.blue, style: .init(eoFill: true))
21+
/// ```
1322
public struct Grid: Shape {
23+
/// A grid shape type.
1424
let type: GridType
25+
/// The number of shapes in the X-axis.
1526
let countX: Int
27+
/// The number of shapes in the Y-axis.
1628
let countY: Int
29+
/// The size of grid shapes.
1730
let size: CGFloat
31+
/// The padding from the edges.
1832
let padding: EdgeInsets
33+
/// Enable to render in reverse order, using `eoFill`.
1934
let inverse: Bool
2035

36+
/// Create a grid shape.
37+
///
38+
/// - Parameters:
39+
/// - type: a grid shape type (default is `.circle`).
40+
/// - countX: the number of shapes in the X-axis.
41+
/// - countY: the number of shapes in the Y-axis.
42+
/// - size: the size of grid shapes.
43+
/// - padding: the padding from the edges (default is `.zero`).
2144
public init(
2245
type: GridType = .circle,
2346
countX: Int,

Sources/CompactSlider/Components/Handle/EnvironmentHandleStyleKey.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ extension EnvironmentValues {
1717
}
1818

1919
extension View {
20+
/// Set a handle style for a compact slider.
21+
///
22+
/// - Parameter style: a handle style.
2023
public func compactSliderHandleStyle(_ style: HandleStyle) -> some View {
2124
environment(\.handleStyle, style)
2225
}

Sources/CompactSlider/Components/Handle/CompactSliderStyleHandleView.swift renamed to Sources/CompactSlider/Components/Handle/EnvironmentHandleViewKey.swift

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,6 @@
55

66
import SwiftUI
77

8-
public struct CompactSliderStyleHandleView: View {
9-
@Environment(\.compactSliderHandleView) var handleView
10-
11-
public var body: some View {
12-
handleView
13-
.allowsTightening(false)
14-
}
15-
}
16-
17-
// MARK: - Environment
18-
198
struct HandleViewKey: EnvironmentKey {
209
static var defaultValue: AnyView =
2110
HandleViewContainerView { configuration, style, _, _ in
@@ -25,7 +14,7 @@ struct HandleViewKey: EnvironmentKey {
2514
}
2615

2716
extension EnvironmentValues {
28-
public var compactSliderHandleView: AnyView {
17+
var compactSliderHandleView: AnyView {
2918
get { self[HandleViewKey.self] }
3019
set { self[HandleViewKey.self] = newValue }
3120
}
@@ -34,6 +23,10 @@ extension EnvironmentValues {
3423
// MARK: - View
3524

3625
extension View {
26+
/// Set a custom handle view for the slider.
27+
///
28+
/// - Parameter handleView: a custom handle view. The view builder provides the configuration,
29+
/// style, progress, and index. The index is the index of the handle for multiple handles.
3730
public func compactSliderHandle<V: View>(
3831
@ViewBuilder handleView: @escaping (
3932
_ configuration: CompactSliderStyleConfiguration,

Sources/CompactSlider/Components/Handle/HandleStyle.swift

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import SwiftUI
77

8+
/// A handle type. It could be a rectangle, rounded rectangle, circle, capsule, or a symbol.
89
public enum HandleType: Equatable {
910
case rectangle
1011
case roundedRectangle
@@ -14,18 +15,30 @@ public enum HandleType: Equatable {
1415
case `default`
1516
}
1617

18+
/// A handle alignment with the progress view. It could be inside, center, or outside.
19+
///
20+
/// - inside: The handle is inside the progress view.
21+
/// - center: The handle is in the center of the edge of the progress view.
22+
/// - outside: The handle is outside the progress view.
1723
public enum HandleProgressAlignment: Equatable {
1824
case inside, center, outside
1925
}
2026

2127
/// A handle style.
2228
public struct HandleStyle: Equatable {
29+
/// The handle type.
2330
public let type: HandleType
31+
/// The visibility of the handle. It could be always visible, hidden, or visible on focus (on drag or hover).
2432
public let visibility: CompactSliderVisibility
33+
/// The alignment of the handle with the progress view.
2534
public let progressAlignment: HandleProgressAlignment
35+
/// The color of the handle.
2636
public let color: Color
37+
/// The width of the handle.
2738
public let width: CGFloat
39+
/// The corner radius of the handle.
2840
public let cornerRadius: CGFloat
41+
/// The stroke style of the handle. If it's nil the handle will be filled.
2942
public let strokeStyle: StrokeStyle?
3043

3144
init(
@@ -50,6 +63,14 @@ public struct HandleStyle: Equatable {
5063
// MARK: - Constructors
5164

5265
extension HandleStyle {
66+
/// Creates a rectangle handle style.
67+
///
68+
/// - Parameters:
69+
/// - visibility: a visibility of the handle.
70+
/// - progressAlignment: a handle alignment with the progress view.
71+
/// - color: a handle color.
72+
/// - width: a handle width. It's used to calculate the position of the handle and progress view.
73+
/// - strokeStyle: a handle stroke style. If it's nil the handle will be filled.
5374
public static func rectangle(
5475
visibility: CompactSliderVisibility = .default,
5576
progressAlignment: HandleProgressAlignment = .center,
@@ -68,6 +89,15 @@ extension HandleStyle {
6889
)
6990
}
7091

92+
/// Creates a rounded rectangle handle style.
93+
///
94+
/// - Parameters:
95+
/// - visibility: a visibility of the handle.
96+
/// - progressAlignment: a handle alignment with the progress view.
97+
/// - color: a handle color.
98+
/// - width: a handle width. It's used to calculate the position of the handle and progress view.
99+
/// - cornerRadius: a handle corner radius.
100+
/// - strokeStyle: a handle stroke style. If it's nil the handle will be filled.
71101
public static func roundedRectangle(
72102
visibility: CompactSliderVisibility = .default,
73103
progressAlignment: HandleProgressAlignment = .center,
@@ -87,6 +117,14 @@ extension HandleStyle {
87117
)
88118
}
89119

120+
/// Creates a circle handle style.
121+
///
122+
/// - Parameters:
123+
/// - visibility: a visibility of the handle.
124+
/// - progressAlignment: a handle alignment with the progress view.
125+
/// - color: a handle color.
126+
/// - radius: a handle radius. It's used to calculate the position of the handle and progress view.
127+
/// - strokeStyle: a handle stroke style. If it's nil the handle will be filled.
90128
public static func circle(
91129
visibility: CompactSliderVisibility = .default,
92130
progressAlignment: HandleProgressAlignment = .center,
@@ -105,6 +143,14 @@ extension HandleStyle {
105143
)
106144
}
107145

146+
/// Creates a capsule handle style.
147+
///
148+
/// - Parameters:
149+
/// - visibility: a visibility of the handle.
150+
/// - progressAlignment: a handle alignment with the progress view.
151+
/// - color: a handle color.
152+
/// - width: a handle width. It's used to calculate the position of the handle and progress view.
153+
/// - strokeStyle: a handle stroke style. If it's nil the handle will be filled.
108154
public static func capsule(
109155
visibility: CompactSliderVisibility = .default,
110156
progressAlignment: HandleProgressAlignment = .center,
@@ -123,6 +169,14 @@ extension HandleStyle {
123169
)
124170
}
125171

172+
/// Creates a symbol handle style. The symbol is a system image. For example, "circle.fill".
173+
///
174+
/// - Parameters:
175+
/// - name: a system image name.
176+
/// - visibility: a visibility of the handle.
177+
/// - progressAlignment: a handle alignment with the progress view.
178+
/// - color: a handle color.
179+
/// - width: a handle width. It's used to calculate the position of the handle and progress view.
126180
public static func symbol(
127181
_ name: String,
128182
visibility: CompactSliderVisibility = .default,

Sources/CompactSlider/Styles/HandleViewWrapper.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ import SwiftUI
77

88
struct HandleViewWrapper: View {
99
@Environment(\.handleStyle) var environmentHandleStyle
10+
@Environment(\.compactSliderHandleView) var handleView
1011
var handleStyle: HandleStyle { environmentHandleStyle.byType(configuration.type) }
1112
let configuration: CompactSliderStyleConfiguration
1213

1314
var body: some View {
1415
if configuration.isHandleVisible(handleStyle: handleStyle) {
1516
if configuration.progress.isMultipleValues, configuration.progress.progresses.count == 0 {
16-
Rectangle().fill(Color.clear)
17+
Rectangle()
18+
.fill(Color.clear)
19+
.allowsTightening(false)
1720
} else {
18-
CompactSliderStyleHandleView()
21+
handleView
22+
.allowsTightening(false)
1923
}
2024
}
2125
}

0 commit comments

Comments
 (0)