From e57a981406d744e825f093fa5a41c690df24a3aa Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 19 Feb 2020 15:18:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../page/delegate/SimulationPageDelegate.kt | 50 +++++++++++-------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt index 6e9050b07..a0702a6c9 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt @@ -138,27 +138,37 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi } override fun onScrollStart() { - val distanceX: Float - when (mDirection) { - Direction.NEXT -> distanceX = - if (isCancel) { - var dis = viewWidth - startX + touchX - if (dis > viewWidth) { - dis = viewWidth.toFloat() - } - viewWidth - dis - } else { - -(touchX + (viewWidth - startX)) - } - else -> distanceX = - if (isCancel) { - -(touchX - startX) - } else { - viewWidth - (touchX - startX) - } + var dx: Float + val dy: Float + // dx 水平方向滑动的距离,负值会使滚动向左滚动 + // dy 垂直方向滑动的距离,负值会使滚动向上滚动 + if (isCancel) { + dx = if (mCornerX > 0 && mDirection == Direction.NEXT) { + (viewWidth - touchX) + } else { + -touchX + } + if (mDirection != Direction.NEXT) { + dx = -(viewWidth + touchX) + } + dy = if (mCornerY > 0) { + (viewHeight - touchY) + } else { + -touchY // 防止mTouchY最终变为0 + } + } else { + dx = if (mCornerX > 0 && mDirection == Direction.NEXT) { + -(viewWidth + touchX) + } else { + (viewWidth - touchX + viewWidth) + } + dy = if (mCornerY > 0) { + (viewHeight - touchY) + } else { + (1 - touchY) // 防止mTouchY最终变为0 + } } - - startScroll(touchX.toInt(), 0, distanceX.toInt(), 0) + startScroll(touchX.toInt(), touchY.toInt(), dx.toInt(), dy.toInt()) } override fun onScrollStop() {