Skip to content

Commit 0e7b1b6

Browse files
authored
delay fix for range sliders (#75)
1 parent cc4ab4a commit 0e7b1b6

File tree

2 files changed

+8
-31
lines changed

2 files changed

+8
-31
lines changed

Sources/Sliders/RangeSlider/Styles/Horizontal/HorizontalRangeSliderStyle.swift

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ public struct HorizontalRangeSliderStyle<Track: View, LowerThumb: View, UpperThu
1313

1414
private let options: RangeSliderOptions
1515

16-
let onSelectLower: () -> Void
17-
let onSelectUpper: () -> Void
1816

1917
public func makeBody(configuration: Self.Configuration) -> some View {
2018
GeometryReader { geometry in
@@ -45,15 +43,11 @@ public struct HorizontalRangeSliderStyle<Track: View, LowerThumb: View, UpperThu
4543
),
4644
y: geometry.size.height / 2
4745
)
48-
.onTapGesture {
49-
self.onSelectLower()
50-
}
5146
.gesture(
52-
DragGesture()
47+
DragGesture(minimumDistance: 0)
5348
.onChanged { gestureValue in
5449
configuration.onEditingChanged(true)
5550

56-
self.onSelectLower()
5751

5852
if configuration.dragOffset.wrappedValue == nil {
5953
configuration.dragOffset.wrappedValue = gestureValue.startLocation.x - distanceFrom(
@@ -103,15 +97,11 @@ public struct HorizontalRangeSliderStyle<Track: View, LowerThumb: View, UpperThu
10397
),
10498
y: geometry.size.height / 2
10599
)
106-
.onTapGesture {
107-
self.onSelectUpper()
108-
}
109100
.gesture(
110-
DragGesture()
101+
DragGesture(minimumDistance: 0)
111102
.onChanged { gestureValue in
112103
configuration.onEditingChanged(true)
113104

114-
self.onSelectUpper()
115105

116106
if configuration.dragOffset.wrappedValue == nil {
117107
configuration.dragOffset.wrappedValue = gestureValue.startLocation.x - distanceFrom(
@@ -152,9 +142,7 @@ public struct HorizontalRangeSliderStyle<Track: View, LowerThumb: View, UpperThu
152142
.frame(minHeight: max(self.lowerThumbInteractiveSize.height, self.upperThumbInteractiveSize.height))
153143
}
154144

155-
public init(track: Track, lowerThumb: LowerThumb, upperThumb: UpperThumb, lowerThumbSize: CGSize = CGSize(width: 27, height: 27), upperThumbSize: CGSize = CGSize(width: 27, height: 27), lowerThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), upperThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), options: RangeSliderOptions = .defaultOptions,
156-
onSelectLower: @escaping () -> Void = {},
157-
onSelectUpper: @escaping () -> Void = {}) {
145+
public init(track: Track, lowerThumb: LowerThumb, upperThumb: UpperThumb, lowerThumbSize: CGSize = CGSize(width: 27, height: 27), upperThumbSize: CGSize = CGSize(width: 27, height: 27), lowerThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), upperThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), options: RangeSliderOptions = .defaultOptions) {
158146
self.track = track
159147
self.lowerThumb = lowerThumb
160148
self.upperThumb = upperThumb
@@ -163,15 +151,12 @@ public struct HorizontalRangeSliderStyle<Track: View, LowerThumb: View, UpperThu
163151
self.lowerThumbInteractiveSize = lowerThumbInteractiveSize
164152
self.upperThumbInteractiveSize = upperThumbInteractiveSize
165153
self.options = options
166-
self.onSelectLower = onSelectLower
167-
self.onSelectUpper = onSelectUpper
168154
}
169155
}
170156

171157
extension HorizontalRangeSliderStyle where Track == DefaultHorizontalRangeTrack {
172158
public init(lowerThumb: LowerThumb, upperThumb: UpperThumb, lowerThumbSize: CGSize = CGSize(width: 27, height: 27), upperThumbSize: CGSize = CGSize(width: 27, height: 27), lowerThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), upperThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), options: RangeSliderOptions = .defaultOptions,
173-
onSelectLower: @escaping () -> Void = {},
174-
onSelectUpper: @escaping () -> Void = {}) {
159+
) {
175160
self.track = DefaultHorizontalRangeTrack()
176161
self.lowerThumb = lowerThumb
177162
self.upperThumb = upperThumb
@@ -180,16 +165,13 @@ extension HorizontalRangeSliderStyle where Track == DefaultHorizontalRangeTrack
180165
self.lowerThumbInteractiveSize = lowerThumbInteractiveSize
181166
self.upperThumbInteractiveSize = upperThumbInteractiveSize
182167
self.options = options
183-
self.onSelectLower = onSelectLower
184-
self.onSelectUpper = onSelectUpper
185168

186169
}
187170
}
188171

189172
extension HorizontalRangeSliderStyle where LowerThumb == DefaultThumb, UpperThumb == DefaultThumb {
190173
public init(track: Track, lowerThumbSize: CGSize = CGSize(width: 27, height: 27), upperThumbSize: CGSize = CGSize(width: 27, height: 27), lowerThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), upperThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), options: RangeSliderOptions = .defaultOptions,
191-
onSelectLower: @escaping () -> Void = {},
192-
onSelectUpper: @escaping () -> Void = {}) {
174+
) {
193175
self.track = track
194176
self.lowerThumb = DefaultThumb()
195177
self.upperThumb = DefaultThumb()
@@ -198,16 +180,13 @@ extension HorizontalRangeSliderStyle where LowerThumb == DefaultThumb, UpperThum
198180
self.lowerThumbInteractiveSize = lowerThumbInteractiveSize
199181
self.upperThumbInteractiveSize = upperThumbInteractiveSize
200182
self.options = options
201-
self.onSelectLower = onSelectLower
202-
self.onSelectUpper = onSelectUpper
203183

204184
}
205185
}
206186

207187
extension HorizontalRangeSliderStyle where LowerThumb == DefaultThumb, UpperThumb == DefaultThumb, Track == DefaultHorizontalRangeTrack {
208188
public init(lowerThumbSize: CGSize = CGSize(width: 27, height: 27), upperThumbSize: CGSize = CGSize(width: 27, height: 27), lowerThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), upperThumbInteractiveSize: CGSize = CGSize(width: 44, height: 44), options: RangeSliderOptions = .defaultOptions,
209-
onSelectLower: @escaping () -> Void = {},
210-
onSelectUpper: @escaping () -> Void = {}) {
189+
) {
211190
self.track = DefaultHorizontalRangeTrack()
212191
self.lowerThumb = DefaultThumb()
213192
self.upperThumb = DefaultThumb()
@@ -216,8 +195,6 @@ extension HorizontalRangeSliderStyle where LowerThumb == DefaultThumb, UpperThum
216195
self.lowerThumbInteractiveSize = lowerThumbInteractiveSize
217196
self.upperThumbInteractiveSize = upperThumbInteractiveSize
218197
self.options = options
219-
self.onSelectLower = onSelectLower
220-
self.onSelectUpper = onSelectUpper
221198
}
222199
}
223200

Sources/Sliders/RangeSlider/Styles/Vertical/VerticalRangeSliderStyle.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public struct VerticalRangeSliderStyle<Track: View, LowerThumb: View, UpperThumb
4343
)
4444
)
4545
.gesture(
46-
DragGesture()
46+
DragGesture(minimumDistance: 0)
4747
.onChanged { gestureValue in
4848
configuration.onEditingChanged(true)
4949

@@ -96,7 +96,7 @@ public struct VerticalRangeSliderStyle<Track: View, LowerThumb: View, UpperThumb
9696
)
9797
)
9898
.gesture(
99-
DragGesture()
99+
DragGesture(minimumDistance: 0)
100100
.onChanged { gestureValue in
101101
configuration.onEditingChanged(true)
102102

0 commit comments

Comments
 (0)