Fix SeekBar behavior
This commit is contained in:
@@ -26,7 +26,7 @@ fun SeekBar(
|
|||||||
onDragEnd: () -> Unit,
|
onDragEnd: () -> Unit,
|
||||||
color: Color,
|
color: Color,
|
||||||
backgroundColor: Color,
|
backgroundColor: Color,
|
||||||
modifier: Modifier,
|
modifier: Modifier = Modifier,
|
||||||
barHeight: Dp = 3.5.dp,
|
barHeight: Dp = 3.5.dp,
|
||||||
scrubberColor: Color = color,
|
scrubberColor: Color = color,
|
||||||
scrubberRadius: Dp = 6.dp,
|
scrubberRadius: Dp = 6.dp,
|
||||||
@@ -47,9 +47,10 @@ fun SeekBar(
|
|||||||
}
|
}
|
||||||
.pointerInput(minimumValue, maximumValue) {
|
.pointerInput(minimumValue, maximumValue) {
|
||||||
if (maximumValue < minimumValue) return@pointerInput
|
if (maximumValue < minimumValue) return@pointerInput
|
||||||
|
|
||||||
detectTapGestures(
|
detectTapGestures(
|
||||||
onPress = { offset ->
|
onPress = { offset ->
|
||||||
onDragStart((offset.x / size.width * (maximumValue - minimumValue)).roundToLong())
|
onDragStart((offset.x / size.width * (maximumValue - minimumValue) + minimumValue).roundToLong())
|
||||||
},
|
},
|
||||||
onTap = {
|
onTap = {
|
||||||
onDragEnd()
|
onDragEnd()
|
||||||
@@ -63,7 +64,7 @@ fun SeekBar(
|
|||||||
val scrubberPosition = if (maximumValue < minimumValue) {
|
val scrubberPosition = if (maximumValue < minimumValue) {
|
||||||
0f
|
0f
|
||||||
} else {
|
} else {
|
||||||
(value.toFloat() + minimumValue) / (maximumValue - minimumValue) * size.width
|
(value.toFloat() - minimumValue) / (maximumValue - minimumValue) * size.width
|
||||||
}
|
}
|
||||||
|
|
||||||
drawCircle(
|
drawCircle(
|
||||||
@@ -84,7 +85,7 @@ fun SeekBar(
|
|||||||
Spacer(
|
Spacer(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.height(barHeight)
|
.height(barHeight)
|
||||||
.fillMaxWidth((value.toFloat() + minimumValue) / (maximumValue - minimumValue))
|
.fillMaxWidth((value.toFloat() - minimumValue) / (maximumValue - minimumValue))
|
||||||
.background(color = color, shape = shape)
|
.background(color = color, shape = shape)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user