mirror of
https://github.com/bbara04/Purefin.git
synced 2026-03-31 17:10:08 +02:00
fix: use absolute seek position for gesture seeking to prevent snap-back
Capture the player position when the horizontal drag starts and compute an absolute seek target instead of using relative seekBy, which could drift or snap back due to playback advancing during the gesture.
This commit is contained in:
@@ -120,10 +120,10 @@ fun PlayerScreen(
|
|||||||
onHorizontalDragPreview = {
|
onHorizontalDragPreview = {
|
||||||
horizontalSeekFeedback = it
|
horizontalSeekFeedback = it
|
||||||
},
|
},
|
||||||
onHorizontalDrag = {
|
onHorizontalDragSeekTo = {
|
||||||
viewModel.seekBy(it)
|
viewModel.seekTo(it)
|
||||||
horizontalSeekFeedback = it
|
},
|
||||||
}
|
currentPositionProvider = { uiState.positionMs }
|
||||||
)
|
)
|
||||||
|
|
||||||
EmptyValueTimedVisibility(
|
EmptyValueTimedVisibility(
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ fun PlayerGesturesLayer(
|
|||||||
onVerticalDragLeft: (delta: Float) -> Unit,
|
onVerticalDragLeft: (delta: Float) -> Unit,
|
||||||
onVerticalDragRight: (delta: Float) -> Unit,
|
onVerticalDragRight: (delta: Float) -> Unit,
|
||||||
onHorizontalDragPreview: (deltaMs: Long?) -> Unit = {},
|
onHorizontalDragPreview: (deltaMs: Long?) -> Unit = {},
|
||||||
onHorizontalDrag: (deltaMs: Long) -> Unit,
|
onHorizontalDragSeekTo: (positionMs: Long) -> Unit,
|
||||||
|
currentPositionProvider: () -> Long,
|
||||||
) {
|
) {
|
||||||
val density = LocalDensity.current
|
val density = LocalDensity.current
|
||||||
val horizontalThresholdPx = with(density) { HorizontalSeekGestureHelper.START_THRESHOLD.toPx() }
|
val horizontalThresholdPx = with(density) { HorizontalSeekGestureHelper.START_THRESHOLD.toPx() }
|
||||||
@@ -67,6 +68,7 @@ fun PlayerGesturesLayer(
|
|||||||
var accumulatedHorizontalDrag = 0f
|
var accumulatedHorizontalDrag = 0f
|
||||||
var isHorizontalDragActive = false
|
var isHorizontalDragActive = false
|
||||||
var lastPreviewDelta: Long? = null
|
var lastPreviewDelta: Long? = null
|
||||||
|
var startPositionMs = 0L
|
||||||
|
|
||||||
drag(down.id) { change ->
|
drag(down.id) { change ->
|
||||||
val delta = change.positionChange()
|
val delta = change.positionChange()
|
||||||
@@ -86,6 +88,7 @@ fun PlayerGesturesLayer(
|
|||||||
accumulatedHorizontalDrag += delta.x
|
accumulatedHorizontalDrag += delta.x
|
||||||
if (!isHorizontalDragActive && abs(accumulatedHorizontalDrag) >= horizontalThresholdPx) {
|
if (!isHorizontalDragActive && abs(accumulatedHorizontalDrag) >= horizontalThresholdPx) {
|
||||||
isHorizontalDragActive = true
|
isHorizontalDragActive = true
|
||||||
|
startPositionMs = currentPositionProvider()
|
||||||
}
|
}
|
||||||
if (isHorizontalDragActive) {
|
if (isHorizontalDragActive) {
|
||||||
change.consume()
|
change.consume()
|
||||||
@@ -112,7 +115,8 @@ fun PlayerGesturesLayer(
|
|||||||
if (dragDirection == DragDirection.HORIZONTAL && isHorizontalDragActive) {
|
if (dragDirection == DragDirection.HORIZONTAL && isHorizontalDragActive) {
|
||||||
val deltaMs = HorizontalSeekGestureHelper.deltaMs(accumulatedHorizontalDrag)
|
val deltaMs = HorizontalSeekGestureHelper.deltaMs(accumulatedHorizontalDrag)
|
||||||
if (deltaMs != 0L) {
|
if (deltaMs != 0L) {
|
||||||
onHorizontalDrag(deltaMs)
|
val targetMs = (startPositionMs + deltaMs).coerceAtLeast(0L)
|
||||||
|
onHorizontalDragSeekTo(targetMs)
|
||||||
onHorizontalDragPreview(deltaMs)
|
onHorizontalDragPreview(deltaMs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user