From f191502a97865c8d8e4624e213c919a5ca4152b3 Mon Sep 17 00:00:00 2001 From: Dawn-used-yeet Date: Tue, 29 Oct 2024 13:04:34 +0530 Subject: [PATCH] fix: Swipy (#506) --- .../dantotsu/media/manga/mangareader/Swipy.kt | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/ani/dantotsu/media/manga/mangareader/Swipy.kt b/app/src/main/java/ani/dantotsu/media/manga/mangareader/Swipy.kt index bed646fc..07eb30e2 100644 --- a/app/src/main/java/ani/dantotsu/media/manga/mangareader/Swipy.kt +++ b/app/src/main/java/ani/dantotsu/media/manga/mangareader/Swipy.kt @@ -159,22 +159,20 @@ class Swipy @JvmOverloads constructor( } private fun handleDrag(pos: Float) { - val overscroll = (pos - initialMotion) * DRAG_RATE - if (overscroll > 0) { // Keep this check - parent.requestDisallowInterceptTouchEvent(true) - if (vertical) { - val totalDragDistance = Resources.getSystem().displayMetrics.heightPixels / dragDivider - if (verticalPos == VerticalPosition.Top) - topBeingSwiped.invoke(overscroll * 2 / totalDragDistance) - else - bottomBeingSwiped.invoke(overscroll * 2 / totalDragDistance) - } else { - val totalDragDistance = Resources.getSystem().displayMetrics.widthPixels / dragDivider - if (horizontalPos == HorizontalPosition.Left) - leftBeingSwiped.invoke(overscroll / totalDragDistance) - else - rightBeingSwiped.invoke(overscroll / totalDragDistance) - } + val overscroll = abs((pos - initialMotion) * DRAG_RATE) + parent.requestDisallowInterceptTouchEvent(true) + if (vertical) { + val totalDragDistance = Resources.getSystem().displayMetrics.heightPixels / dragDivider + if (verticalPos == VerticalPosition.Top) + topBeingSwiped.invoke(overscroll * 2 / totalDragDistance) + else + bottomBeingSwiped.invoke(overscroll * 2 / totalDragDistance) + } else { + val totalDragDistance = Resources.getSystem().displayMetrics.widthPixels / dragDivider + if (horizontalPos == HorizontalPosition.Left) + leftBeingSwiped.invoke(overscroll / totalDragDistance) + else + rightBeingSwiped.invoke(overscroll / totalDragDistance) } } @@ -183,7 +181,7 @@ class Swipy @JvmOverloads constructor( topBeingSwiped.invoke(0f) bottomBeingSwiped.invoke(0f) } else { - rightBeingSwiped.invoke( 0f) + rightBeingSwiped.invoke(0f) leftBeingSwiped.invoke(0f) } }