diff --git a/seeker/src/main/java/dev/vivvvek/seeker/Seeker.kt b/seeker/src/main/java/dev/vivvvek/seeker/Seeker.kt index c48d2fc..90bc99e 100644 --- a/seeker/src/main/java/dev/vivvvek/seeker/Seeker.kt +++ b/seeker/src/main/java/dev/vivvvek/seeker/Seeker.kt @@ -62,8 +62,10 @@ import androidx.compose.ui.graphics.drawscope.inset import androidx.compose.ui.graphics.drawscope.rotateRad import androidx.compose.ui.graphics.drawscope.translate import androidx.compose.ui.graphics.graphicsLayer +import androidx.compose.ui.hapticfeedback.HapticFeedbackType import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.platform.LocalHapticFeedback import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.semantics.disabled import androidx.compose.ui.semantics.semantics @@ -99,6 +101,7 @@ import kotlin.math.atan2 * The first segment must start form the start value of the [range], and all the segments must lie in * the specified [range], else an [IllegalArgumentException] will be thrown. * will be thrown. + * @param segmentChangeHapticFeedback enables haptic feedback when the current segment gets updated * @param enabled whether or not component is enabled and can be interacted with or not * @param colors [SeekerColors] that will be used to determine the color of the Slider parts in * different state. See [SeekerDefaults.seekerColors] to customize. @@ -122,6 +125,7 @@ fun Seeker( onValueChange: (Float) -> Unit, onValueChangeFinished: (() -> Unit)? = null, segments: List = emptyList(), + segmentChangeHapticFeedback: Boolean = false, enabled: Boolean = true, colors: SeekerColors = SeekerDefaults.seekerColors(), dimensions: SeekerDimensions = SeekerDefaults.seekerDimensions(), @@ -165,6 +169,16 @@ fun Seeker( segmentToPxValues(segments, range, widthPx) } + var isDragging = false + if (segmentChangeHapticFeedback) { + val haptics = LocalHapticFeedback.current + + LaunchedEffect(state.currentSegment) { + if (!isDragging) return@LaunchedEffect + haptics.performHapticFeedback(HapticFeedbackType.LongPress) + } + } + LaunchedEffect(thumbValue, segments) { state.currentSegment(thumbValue, segments) } @@ -193,6 +207,7 @@ fun Seeker( LaunchedEffect(widthPx, range) { state.onDrag = { + isDragging = true dragPositionX += it + pressOffset pressOffset = 0f @@ -231,6 +246,7 @@ fun Seeker( reverseDirection = isRtl, orientation = Orientation.Horizontal, onDragStopped = { + isDragging = false onValueChangeFinished?.invoke() }, interactionSource = interactionSource