From 4502b1b1b6de9250c769b23e2da37fa7f4ccac2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=AF=E6=AD=8C?= Date: Thu, 24 Jun 2021 18:47:03 +0800 Subject: [PATCH] fix viewpager's drag and scrolling --- README.md | 3 ++- src/gui/widget/view.cc | 2 +- src/gui/widget/viewpager.cc | 8 +++----- 3 files changed, 6 insertions(+), 7 deletions(-) mode change 100644 => 100755 README.md mode change 100644 => 100755 src/gui/widget/view.cc mode change 100644 => 100755 src/gui/widget/viewpager.cc diff --git a/README.md b/README.md old mode 100644 new mode 100755 index af083596..0eb9ac64 --- a/README.md +++ b/README.md @@ -3,12 +3,13 @@ # **Features:** * Multi Layer/Multi Window -* Intigated with 30+ UI Components and 15+ Drawables(compatibal with android) +* Integrated with 30+ UI Components and 15+ Drawables(compatibal with android) * Full compatible with Android * Smooth Scrolling * Scrolling with SpringBack Support # **Screen Shots** ![TextView](docs/images/screenshots/textviews.png) +![ViewPager](docs/videos/viewpager.gif) # **UI Components:** * View * TextView diff --git a/src/gui/widget/view.cc b/src/gui/widget/view.cc old mode 100644 new mode 100755 index 25cda8a6..7ccf8792 --- a/src/gui/widget/view.cc +++ b/src/gui/widget/view.cc @@ -2238,7 +2238,7 @@ void View::unscheduleDrawable(Drawable& who,Runnable what){ } void View::unscheduleDrawable(Drawable& who){ - LOGD(" %p ",&who); + LOGV(" %p ",&who); } ViewGroup*View::getParent()const{ diff --git a/src/gui/widget/viewpager.cc b/src/gui/widget/viewpager.cc old mode 100644 new mode 100755 index e490ab8f..165d8e96 --- a/src/gui/widget/viewpager.cc +++ b/src/gui/widget/viewpager.cc @@ -31,6 +31,7 @@ void ViewPager::initViewPager(){ mScroller = new Scroller(context, mInterpolator); mAdapter = nullptr; mObserver = nullptr; + mFakeDragging =false; ViewConfiguration configuration = ViewConfiguration::get(context); float density = 2.65f;//context.getResources().getDisplayMetrics().density; @@ -1482,7 +1483,7 @@ bool ViewPager::onInterceptTouchEvent(MotionEvent& ev){ float xDiff = std::abs(dx); float y = ev.getY(pointerIndex); float yDiff = std::abs(y - mInitialMotionY); - + if (dx != 0 && !isGutterDrag(mLastMotionX, dx) && canScroll(this, false, (int) dx, (int) x, (int) y)) { // Nested view has scrollable area under this point. Let it be handled there. @@ -1595,8 +1596,7 @@ bool ViewPager::onTouchEvent(MotionEvent& ev){ if (!mIsBeingDragged) { int pointerIndex = ev.findPointerIndex(mActivePointerId); if (pointerIndex == -1) { - // A child has consumed some touch events and put us into an inconsistent - // state. + // A child has consumed some touch events and put us into an inconsistent state. needsInvalidate = resetTouch(); break; } @@ -1605,8 +1605,6 @@ bool ViewPager::onTouchEvent(MotionEvent& ev){ float y = ev.getY(pointerIndex); float yDiff = std::abs(y - mLastMotionY); - LOGV("Moved xy to %f,%f xydiff=%f,%f",x,y,xDiff, yDiff); - if (xDiff > mTouchSlop && xDiff > yDiff) { LOGV("Starting drag!"); mIsBeingDragged = true;