Skip to content

Commit

Permalink
Enabled to display the knob on the slider
Browse files Browse the repository at this point in the history
  • Loading branch information
tsuzukihashi committed Jun 13, 2020
1 parent 1cf1e43 commit b834faf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions DemoApp/DemoApp/Views/NeumorphismSliderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ struct NeumorphismSliderView: View {
Text("VALUE: \(value)")
.foregroundColor(self.neumorphism.fontColor())

NeumorphismSlider(showPointer: true, value: self.$value, changeHandler: {
// call change method
}) {
// call ended method
}

NeumorphismSlider(value: self.$value, changeHandler: {
// call change method
}) {
Expand Down
13 changes: 12 additions & 1 deletion Sources/CustomViews/NeumorphismSlider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ public struct NeumorphismSlider: View {
private let barColor: Color?
private let height: CGFloat
private let width: CGFloat
private var showPointer: Bool

public init(
width: CGFloat = 300,
height: CGFloat = 16,
tipColor: Color? = nil,
barColor: Color? = nil,
showPointer: Bool = false,
value: Binding<Double>,
changeHandler: (() -> Void)? = nil,
endedHandler: (() -> Void)? = nil
Expand All @@ -26,6 +28,7 @@ public struct NeumorphismSlider: View {
self.width = width
self.tipColor = tipColor
self.barColor = barColor
self.showPointer = showPointer
self._value = value
self.changeHandler = changeHandler
self.endedHandler = endedHandler
Expand All @@ -39,14 +42,22 @@ public struct NeumorphismSlider: View {
height: height
)

ZStack (alignment: .trailing){
ZStack(alignment: .trailing) {
RoundedRectangle(cornerRadius: self.height / 2)
.fill(barColor ?? self.neumorphism.color.darkerColor())
.frame(
width: self.width * CGFloat(value),
height: height * 0.8,
alignment: .leading)
.padding(.init(top: 8, leading: 2, bottom: 8, trailing: 2))
if self.showPointer {
ZStack {
Circle()
.fill(self.neumorphism.color)
.frame(width: self.height * 1.5, height: self.height * 1.5)
.shadow(color: self.neumorphism.color.darkerColor(), radius: 4, x: 0, y: 0)
}
}
}
}.gesture(
DragGesture(minimumDistance: 0)
Expand Down

0 comments on commit b834faf

Please sign in to comment.