diff --git a/Sources/Sliders/Base/DefaultHorizontalValueView.swift b/Sources/Sliders/Base/DefaultHorizontalValueView.swift index 7a98b11..4763187 100644 --- a/Sources/Sliders/Base/DefaultHorizontalValueView.swift +++ b/Sources/Sliders/Base/DefaultHorizontalValueView.swift @@ -3,7 +3,7 @@ import SwiftUI public struct DefaultHorizontalValueView: View { public var body: some View { Capsule() - .foregroundColor(.accentColor) + .foregroundColor(Color.accentColor) .frame(height: 3) } } diff --git a/Sources/Sliders/Base/DefaultVerticalValueView.swift b/Sources/Sliders/Base/DefaultVerticalValueView.swift index bf64502..e1fdb49 100644 --- a/Sources/Sliders/Base/DefaultVerticalValueView.swift +++ b/Sources/Sliders/Base/DefaultVerticalValueView.swift @@ -3,7 +3,7 @@ import SwiftUI public struct DefaultVerticalValueView: View { public var body: some View { Capsule() - .foregroundColor(.accentColor) + .foregroundColor(Color.accentColor) .frame(width: 3) } } diff --git a/Sources/Sliders/PointSlider/Styles/Rectangular/RectangularPointSliderStyle.swift b/Sources/Sliders/PointSlider/Styles/Rectangular/RectangularPointSliderStyle.swift index 2d5d872..6b0e9e2 100644 --- a/Sources/Sliders/PointSlider/Styles/Rectangular/RectangularPointSliderStyle.swift +++ b/Sources/Sliders/PointSlider/Styles/Rectangular/RectangularPointSliderStyle.swift @@ -17,14 +17,16 @@ public struct RectangularPointSliderStyle: PointSlider yBounds: configuration.yBounds, yStep: configuration.yStep )) - .accentColor(.accentColor) - + .accentColor(Color.accentColor) + return GeometryReader { geometry in ZStack { if self.options.contains(.interactiveTrack) { track.gesture( DragGesture(minimumDistance: 0) .onChanged { gestureValue in + configuration.onEditingChanged(true) + let computedValueX = valueFrom( distance: gestureValue.location.x, availableDistance: geometry.size.width, @@ -33,7 +35,7 @@ public struct RectangularPointSliderStyle: PointSlider leadingOffset: self.thumbSize.width / 2, trailingOffset: self.thumbSize.width / 2 ) - + let computedValueY = configuration.yBounds.upperBound - valueFrom( distance: gestureValue.location.y, availableDistance: geometry.size.height, @@ -42,10 +44,9 @@ public struct RectangularPointSliderStyle: PointSlider leadingOffset: self.thumbSize.height / 2, trailingOffset: self.thumbSize.height / 2 ) - + configuration.x.wrappedValue = computedValueX configuration.y.wrappedValue = computedValueY - configuration.onEditingChanged(true) } .onEnded { _ in configuration.onEditingChanged(false) @@ -54,7 +55,7 @@ public struct RectangularPointSliderStyle: PointSlider } else { track } - + ZStack { self.thumb .frame(width: self.thumbSize.width, height: self.thumbSize.height) @@ -80,6 +81,8 @@ public struct RectangularPointSliderStyle: PointSlider .gesture( DragGesture() .onChanged { gestureValue in + configuration.onEditingChanged(true) + if configuration.dragOffset.wrappedValue == nil { let gragOffsetX = gestureValue.startLocation.x - distanceFrom( value: configuration.x.wrappedValue, @@ -88,7 +91,7 @@ public struct RectangularPointSliderStyle: PointSlider leadingOffset: self.thumbSize.width / 2, trailingOffset: self.thumbSize.width / 2 ) - + let dragOffsetY = gestureValue.startLocation.y - (geometry.size.height - distanceFrom( value: configuration.y.wrappedValue, availableDistance: geometry.size.height, @@ -96,10 +99,10 @@ public struct RectangularPointSliderStyle: PointSlider leadingOffset: self.thumbSize.height / 2, trailingOffset: self.thumbSize.height / 2 )) - + configuration.dragOffset.wrappedValue = CGPoint(x: gragOffsetX, y: dragOffsetY) } - + let computedValueX = valueFrom( distance: gestureValue.location.x - (configuration.dragOffset.wrappedValue?.x ?? 0), availableDistance: geometry.size.width, @@ -108,7 +111,7 @@ public struct RectangularPointSliderStyle: PointSlider leadingOffset: self.thumbSize.width / 2, trailingOffset: self.thumbSize.width / 2 ) - + let computedValueY = valueFrom( distance: geometry.size.height - (gestureValue.location.y - (configuration.dragOffset.wrappedValue?.y ?? 0)), availableDistance: geometry.size.height, @@ -117,23 +120,22 @@ public struct RectangularPointSliderStyle: PointSlider leadingOffset: self.thumbSize.height / 2, trailingOffset: self.thumbSize.height / 2 ) - + configuration.x.wrappedValue = computedValueX configuration.y.wrappedValue = computedValueY - configuration.onEditingChanged(true) } .onEnded { _ in configuration.dragOffset.wrappedValue = nil configuration.onEditingChanged(false) } ) - + } .frame(width: geometry.size.width, height: geometry.size.height) } .frame(minWidth: self.thumbInteractiveSize.width, minHeight: self.thumbInteractiveSize.height) } - + public init(track: Track, thumb: Thumb, thumbSize: CGSize = CGSize(width: 27, height: 27), thumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), options: PointSliderOptions = .defaultOptions) { self.track = track self.thumb = thumb @@ -176,6 +178,6 @@ extension RectangularPointSliderStyle where Thumb == DefaultThumb, Track == Defa public struct DefaultRectangularPointTrack: View { public var body: some View { Rectangle() - .foregroundColor(.accentColor) + .foregroundColor(Color.accentColor) } } diff --git a/Sources/Sliders/RangeSlider/Styles/Horizontal/HorizontalRangeSliderStyle.swift b/Sources/Sliders/RangeSlider/Styles/Horizontal/HorizontalRangeSliderStyle.swift index 8a4f8f5..d361625 100644 --- a/Sources/Sliders/RangeSlider/Styles/Horizontal/HorizontalRangeSliderStyle.swift +++ b/Sources/Sliders/RangeSlider/Styles/Horizontal/HorizontalRangeSliderStyle.swift @@ -7,12 +7,12 @@ public struct HorizontalRangeSliderStyle Void let onSelectUpper: () -> Void @@ -28,8 +28,8 @@ public struct HorizontalRangeSliderStyle Void = {}, onSelectUpper: @escaping () -> Void = {}) { diff --git a/Sources/Sliders/RangeSlider/Styles/Vertical/VerticalRangeSliderStyle.swift b/Sources/Sliders/RangeSlider/Styles/Vertical/VerticalRangeSliderStyle.swift index 3ea2fd9..eb2b815 100644 --- a/Sources/Sliders/RangeSlider/Styles/Vertical/VerticalRangeSliderStyle.swift +++ b/Sources/Sliders/RangeSlider/Styles/Vertical/VerticalRangeSliderStyle.swift @@ -7,10 +7,10 @@ public struct VerticalRangeSliderStyle some View { @@ -25,8 +25,8 @@ public struct VerticalRangeSliderStyle: View { @Environment(\.rangeTrackConfiguration) var configuration let view: AnyView let mask: AnyView - + public var body: some View { GeometryReader { geometry in self.view - .accentColor(.accentColor) + .accentColor(Color.accentColor) .mask( ZStack { self.mask diff --git a/Sources/Sliders/RangeTrack/Vertical/VerticalRangeTrack.swift b/Sources/Sliders/RangeTrack/Vertical/VerticalRangeTrack.swift index 0f25601..a4bea69 100644 --- a/Sources/Sliders/RangeTrack/Vertical/VerticalRangeTrack.swift +++ b/Sources/Sliders/RangeTrack/Vertical/VerticalRangeTrack.swift @@ -5,11 +5,11 @@ public struct VerticalRangeTrack: View { @Environment(\.rangeTrackConfiguration) var configuration let view: AnyView let mask: AnyView - + public var body: some View { GeometryReader { geometry in self.view - .accentColor(.accentColor) + .accentColor(Color.accentColor) .mask( ZStack { self.mask diff --git a/Sources/Sliders/ValueSlider/Styles/Horizontal/HorizontalValueSliderStyle.swift b/Sources/Sliders/ValueSlider/Styles/Horizontal/HorizontalValueSliderStyle.swift index 1970f77..5eb9d61 100644 --- a/Sources/Sliders/ValueSlider/Styles/Horizontal/HorizontalValueSliderStyle.swift +++ b/Sources/Sliders/ValueSlider/Styles/Horizontal/HorizontalValueSliderStyle.swift @@ -15,14 +15,15 @@ public struct HorizontalValueSliderStyle: ValueSliderS leadingOffset: self.thumbSize.width / 2, trailingOffset: self.thumbSize.width / 2) ) - .accentColor(.accentColor) - + .accentColor(Color.accentColor) + return GeometryReader { geometry in ZStack { if self.options.contains(.interactiveTrack) { track.gesture( DragGesture(minimumDistance: 0) .onChanged { gestureValue in + configuration.onEditingChanged(true) let computedValue = valueFrom( distance: gestureValue.location.x, availableDistance: geometry.size.width, @@ -32,7 +33,6 @@ public struct HorizontalValueSliderStyle: ValueSliderS trailingOffset: self.thumbSize.width / 2 ) configuration.value.wrappedValue = computedValue - configuration.onEditingChanged(true) } .onEnded { _ in configuration.onEditingChanged(false) @@ -41,7 +41,7 @@ public struct HorizontalValueSliderStyle: ValueSliderS } else { track } - + ZStack { self.thumb .frame(width: self.thumbSize.width, height: self.thumbSize.height) @@ -60,6 +60,8 @@ public struct HorizontalValueSliderStyle: ValueSliderS .gesture( DragGesture(minimumDistance: 0) .onChanged { gestureValue in + configuration.onEditingChanged(true) + if configuration.dragOffset.wrappedValue == nil { configuration.dragOffset.wrappedValue = gestureValue.startLocation.x - distanceFrom( value: configuration.value.wrappedValue, @@ -80,7 +82,6 @@ public struct HorizontalValueSliderStyle: ValueSliderS ) configuration.value.wrappedValue = computedValue - configuration.onEditingChanged(true) } .onEnded { _ in configuration.dragOffset.wrappedValue = nil @@ -92,7 +93,7 @@ public struct HorizontalValueSliderStyle: ValueSliderS } .frame(minHeight: self.thumbInteractiveSize.height) } - + public init(track: Track, thumb: Thumb, thumbSize: CGSize = CGSize(width: 27, height: 27), thumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), options: ValueSliderOptions = .defaultOptions) { self.track = track self.thumb = thumb diff --git a/Sources/Sliders/ValueSlider/Styles/Vertical/VerticalValueSliderStyle.swift b/Sources/Sliders/ValueSlider/Styles/Vertical/VerticalValueSliderStyle.swift index 7811ede..ebfe5c0 100644 --- a/Sources/Sliders/ValueSlider/Styles/Vertical/VerticalValueSliderStyle.swift +++ b/Sources/Sliders/ValueSlider/Styles/Vertical/VerticalValueSliderStyle.swift @@ -15,14 +15,15 @@ public struct VerticalValueSliderStyle: ValueSliderSty leadingOffset: self.thumbSize.height / 2, trailingOffset: self.thumbSize.height / 2) ) - .accentColor(.accentColor) - + .accentColor(Color.accentColor) + return GeometryReader { geometry in ZStack { if self.options.contains(.interactiveTrack) { track.gesture( DragGesture(minimumDistance: 0) .onChanged { gestureValue in + configuration.onEditingChanged(true) let computedValue = configuration.bounds.upperBound - valueFrom( distance: gestureValue.location.y, availableDistance: geometry.size.height, @@ -32,7 +33,6 @@ public struct VerticalValueSliderStyle: ValueSliderSty trailingOffset: self.thumbSize.height / 2 ) configuration.value.wrappedValue = computedValue - configuration.onEditingChanged(true) } .onEnded { _ in configuration.onEditingChanged(false) @@ -41,7 +41,7 @@ public struct VerticalValueSliderStyle: ValueSliderSty } else { track } - + ZStack { self.thumb .frame(width: self.thumbSize.width, height: self.thumbSize.height) @@ -60,6 +60,8 @@ public struct VerticalValueSliderStyle: ValueSliderSty .gesture( DragGesture(minimumDistance: 0) .onChanged { gestureValue in + configuration.onEditingChanged(true) + if configuration.dragOffset.wrappedValue == nil { configuration.dragOffset.wrappedValue = gestureValue.startLocation.y - (geometry.size.height - distanceFrom( value: configuration.value.wrappedValue, @@ -69,7 +71,7 @@ public struct VerticalValueSliderStyle: ValueSliderSty trailingOffset: self.thumbSize.height / 2 )) } - + let computedValue = valueFrom( distance: geometry.size.height - (gestureValue.location.y - (configuration.dragOffset.wrappedValue ?? 0)), availableDistance: geometry.size.height, @@ -78,9 +80,8 @@ public struct VerticalValueSliderStyle: ValueSliderSty leadingOffset: self.thumbSize.height / 2, trailingOffset: self.thumbSize.height / 2 ) - + configuration.value.wrappedValue = computedValue - configuration.onEditingChanged(true) } .onEnded { _ in configuration.dragOffset.wrappedValue = nil @@ -92,7 +93,7 @@ public struct VerticalValueSliderStyle: ValueSliderSty } .frame(minWidth: self.thumbInteractiveSize.width) } - + public init(track: Track, thumb: Thumb, thumbSize: CGSize = CGSize(width: 27, height: 27), thumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), options: ValueSliderOptions = .defaultOptions) { self.track = track self.thumb = thumb diff --git a/Sources/Sliders/ValueTrack/Horizontal/HorizontalValueTrack.swift b/Sources/Sliders/ValueTrack/Horizontal/HorizontalValueTrack.swift index a67e7ac..4847314 100644 --- a/Sources/Sliders/ValueTrack/Horizontal/HorizontalValueTrack.swift +++ b/Sources/Sliders/ValueTrack/Horizontal/HorizontalValueTrack.swift @@ -7,10 +7,10 @@ public struct HorizontalValueTrack: View { @Environment(\.valueTrackConfiguration) var configuration let view: AnyView let mask: AnyView - + public var body: some View { GeometryReader { geometry in - self.view.accentColor(.accentColor) + self.view.accentColor(Color.accentColor) .mask( ZStack { self.mask diff --git a/Sources/Sliders/ValueTrack/Vertical/VerticalValueTrack.swift b/Sources/Sliders/ValueTrack/Vertical/VerticalValueTrack.swift index 4f89997..c5ce36f 100644 --- a/Sources/Sliders/ValueTrack/Vertical/VerticalValueTrack.swift +++ b/Sources/Sliders/ValueTrack/Vertical/VerticalValueTrack.swift @@ -7,10 +7,10 @@ public struct VerticalValueTrack: View { @Environment(\.valueTrackConfiguration) var configuration let view: AnyView let mask: AnyView - + public var body: some View { GeometryReader { geometry in - self.view.accentColor(.accentColor) + self.view.accentColor(Color.accentColor) .mask( ZStack { self.mask