Skip to content

Commit

Permalink
Add the ability to overlay custom views instead of having a percentag…
Browse files Browse the repository at this point in the history
…e indicator

Signed-off-by: Phil Zet (Zakharchenko) <[email protected]>
  • Loading branch information
Phil Zet (Zakharchenko) committed Nov 13, 2021
1 parent c0a1d3d commit 1ccbec9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Sources/PZCircularControl/Indicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal struct Indicator<InnerBackgoundType: ShapeStyle, OuterBackgroundType: S
var glowDistance: CGFloat
var font: Font
var textFormatter: ((CGFloat) -> String)
var overlayView: AnyView?

var body: some View {

Expand Down Expand Up @@ -44,7 +45,8 @@ internal struct Indicator<InnerBackgoundType: ShapeStyle, OuterBackgroundType: S
barWidth: self.barWidth,
glowDistance: self.glowDistance,
font: self.font,
textFormatter: self.textFormatter
textFormatter: self.textFormatter,
overlayView: overlayView
)
)
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/PZCircularControl/PZCircularControl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public struct PZCircularControl<InnerBackgoundType: ShapeStyle, OuterBackgroundT
barWidth: self.params.barWidth,
glowDistance: self.params.glowDistance,
font: self.params.font,
textFormatter: self.params.textFormatter
textFormatter: self.params.textFormatter,
overlayView: self.params.overlayView
)
)
}
Expand Down
9 changes: 7 additions & 2 deletions Sources/PZCircularControl/PZCircularControlParams.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import SwiftUI
import Combine

open class PZCircularControlParams<InnerBackgoundType: ShapeStyle, OuterBackgroundType: ShapeStyle, TintType: ShapeStyle>: ObservableObject {
open class PZCircularControlParams<InnerBackgoundType: ShapeStyle,
OuterBackgroundType: ShapeStyle,
TintType: ShapeStyle>: ObservableObject {

@Published public var progress: CGFloat = 0
@Published public var innerBackgroundColor: InnerBackgoundType
Expand All @@ -19,6 +21,7 @@ open class PZCircularControlParams<InnerBackgoundType: ShapeStyle, OuterBackgrou
@Published public var glowDistance: CGFloat
@Published public var font: Font
@Published public var textFormatter: ((CGFloat) -> String)
@Published public var overlayView: AnyView?

public init(
innerBackgroundColor: InnerBackgoundType = Color.clear as! InnerBackgoundType,
Expand All @@ -35,7 +38,8 @@ open class PZCircularControlParams<InnerBackgoundType: ShapeStyle, OuterBackgrou
initialValue: CGFloat = 0.0,
textFormatter: @escaping ((CGFloat) -> String) = { progress in
"\(Int(progress * 100))%"
}
},
overlayView: AnyView? = nil
) {
self.innerBackgroundColor = innerBackgroundColor
self.outerBackgroundColor = outerBackgroundColor
Expand All @@ -46,6 +50,7 @@ open class PZCircularControlParams<InnerBackgoundType: ShapeStyle, OuterBackgrou
self.font = font
self.progress = initialValue
self.textFormatter = textFormatter
self.overlayView = overlayView
}

}
Expand Down
12 changes: 11 additions & 1 deletion Sources/PZCircularControl/PercentageIndicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ internal struct PercentageIndicator<S: ShapeStyle>: AnimatableModifier {
var glowDistance: CGFloat
var font: Font
var textFormatter: ((CGFloat) -> String)
var overlayView: AnyView?

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

)
.overlay(!self.isBackground ? LabelView(pct: pct, textColor: self.textColor, font: self.font, textFormatter: self.textFormatter) : nil)
.overlay(!isBackground ?
(overlayView ??
AnyView(LabelView(
pct: pct,
textColor: textColor,
font: self.font,
textFormatter: textFormatter
))
)
: nil)
}


Expand Down
2 changes: 1 addition & 1 deletion Tests/PZCircularControlTests/PZCircularControlTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ final class PZCircularControlTests: XCTestCase {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct
// results.
XCTAssertEqual(PZCircularControl().text, "Hello, World!")
XCTAssertEqual("Hello, World!", "Hello, World!")
}

static var allTests = [
Expand Down

0 comments on commit 1ccbec9

Please sign in to comment.