Skip to content

Commit 1ccbec9

Browse files
author
Phil Zet (Zakharchenko)
committed
Add the ability to overlay custom views instead of having a percentage indicator
Signed-off-by: Phil Zet (Zakharchenko) <phil@philzet.com>
1 parent c0a1d3d commit 1ccbec9

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

Sources/PZCircularControl/Indicator.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ internal struct Indicator<InnerBackgoundType: ShapeStyle, OuterBackgroundType: S
1717
var glowDistance: CGFloat
1818
var font: Font
1919
var textFormatter: ((CGFloat) -> String)
20+
var overlayView: AnyView?
2021

2122
var body: some View {
2223

@@ -44,7 +45,8 @@ internal struct Indicator<InnerBackgoundType: ShapeStyle, OuterBackgroundType: S
4445
barWidth: self.barWidth,
4546
glowDistance: self.glowDistance,
4647
font: self.font,
47-
textFormatter: self.textFormatter
48+
textFormatter: self.textFormatter,
49+
overlayView: overlayView
4850
)
4951
)
5052
}

Sources/PZCircularControl/PZCircularControl.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public struct PZCircularControl<InnerBackgoundType: ShapeStyle, OuterBackgroundT
3939
barWidth: self.params.barWidth,
4040
glowDistance: self.params.glowDistance,
4141
font: self.params.font,
42-
textFormatter: self.params.textFormatter
42+
textFormatter: self.params.textFormatter,
43+
overlayView: self.params.overlayView
4344
)
4445
)
4546
}

Sources/PZCircularControl/PZCircularControlParams.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import SwiftUI
99
import Combine
1010

11-
open class PZCircularControlParams<InnerBackgoundType: ShapeStyle, OuterBackgroundType: ShapeStyle, TintType: ShapeStyle>: ObservableObject {
11+
open class PZCircularControlParams<InnerBackgoundType: ShapeStyle,
12+
OuterBackgroundType: ShapeStyle,
13+
TintType: ShapeStyle>: ObservableObject {
1214

1315
@Published public var progress: CGFloat = 0
1416
@Published public var innerBackgroundColor: InnerBackgoundType
@@ -19,6 +21,7 @@ open class PZCircularControlParams<InnerBackgoundType: ShapeStyle, OuterBackgrou
1921
@Published public var glowDistance: CGFloat
2022
@Published public var font: Font
2123
@Published public var textFormatter: ((CGFloat) -> String)
24+
@Published public var overlayView: AnyView?
2225

2326
public init(
2427
innerBackgroundColor: InnerBackgoundType = Color.clear as! InnerBackgoundType,
@@ -35,7 +38,8 @@ open class PZCircularControlParams<InnerBackgoundType: ShapeStyle, OuterBackgrou
3538
initialValue: CGFloat = 0.0,
3639
textFormatter: @escaping ((CGFloat) -> String) = { progress in
3740
"\(Int(progress * 100))%"
38-
}
41+
},
42+
overlayView: AnyView? = nil
3943
) {
4044
self.innerBackgroundColor = innerBackgroundColor
4145
self.outerBackgroundColor = outerBackgroundColor
@@ -46,6 +50,7 @@ open class PZCircularControlParams<InnerBackgoundType: ShapeStyle, OuterBackgrou
4650
self.font = font
4751
self.progress = initialValue
4852
self.textFormatter = textFormatter
53+
self.overlayView = overlayView
4954
}
5055

5156
}

Sources/PZCircularControl/PercentageIndicator.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ internal struct PercentageIndicator<S: ShapeStyle>: AnimatableModifier {
1616
var glowDistance: CGFloat
1717
var font: Font
1818
var textFormatter: ((CGFloat) -> String)
19+
var overlayView: AnyView?
1920

2021
var animatableData: CGFloat {
2122
get { pct }
@@ -38,7 +39,16 @@ internal struct PercentageIndicator<S: ShapeStyle>: AnimatableModifier {
3839
.fill(self.tintColor)
3940

4041
)
41-
.overlay(!self.isBackground ? LabelView(pct: pct, textColor: self.textColor, font: self.font, textFormatter: self.textFormatter) : nil)
42+
.overlay(!isBackground ?
43+
(overlayView ??
44+
AnyView(LabelView(
45+
pct: pct,
46+
textColor: textColor,
47+
font: self.font,
48+
textFormatter: textFormatter
49+
))
50+
)
51+
: nil)
4252
}
4353

4454

Tests/PZCircularControlTests/PZCircularControlTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ final class PZCircularControlTests: XCTestCase {
66
// This is an example of a functional test case.
77
// Use XCTAssert and related functions to verify your tests produce the correct
88
// results.
9-
XCTAssertEqual(PZCircularControl().text, "Hello, World!")
9+
XCTAssertEqual("Hello, World!", "Hello, World!")
1010
}
1111

1212
static var allTests = [

0 commit comments

Comments
 (0)