Skip to content

Commit 601c62e

Browse files
committed
Add haptic for 50%
1 parent d1f5eb4 commit 601c62e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Sources/CompactSlider/CompactSlider+Dragging.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,20 @@ extension CompactSlider {
161161
}
162162

163163
func updateLinearProgress(_ newValue: Double, isEnded: Bool) {
164-
let newValue = newValue.clampedOrRotated(rotated: options.contains(.loopValues))
164+
var newValue = newValue.clampedOrRotated(rotated: options.contains(.loopValues))
165165
let progressAndIndex = nearestProgress(for: newValue)
166166

167167
guard let linearProgressStep = step?.linearProgressStep else {
168-
if progress.update(newValue, at: progressAndIndex.index), (newValue == 1 || newValue == 0) {
168+
let precision: Double = style.type.isCenter ? 250 : 500
169+
let isHalf = (newValue * precision).rounded() / precision == 0.5
170+
171+
// Help to find the 0 value for the center type.
172+
if isHalf, style.type.isCenter {
173+
newValue = 0.5
174+
}
175+
176+
if progress.update(newValue, at: progressAndIndex.index),
177+
(newValue == 1 || isHalf || newValue == 0) {
169178
HapticFeedback.vibrate(isEnabled: isHapticFeedbackEnabled)
170179
}
171180

0 commit comments

Comments
 (0)